YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
INavigation2DServerImpl.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
7#include <yarp/os/LogStream.h>
10
13using namespace yarp::os;
14using namespace yarp::dev;
15using namespace yarp::dev::Nav2D;
16using namespace std;
17
18namespace {
19YARP_LOG_COMPONENT(NAVIGATION2DSERVER, "yarp.device.navigation2DServer")
20}
21
22#define CHECK_POINTER(xxx) {if (xxx==nullptr) {yCError(NAVIGATION2DSERVER, "Invalid interface"); return false;}}
23
25{
26 m_iNav_target = iNav_target;
27 m_iNav_ctrl = iNav_ctrl;
28 m_iNav_vel = iNav_vel;
29}
30
31// ------------ INavigation2DControlActions
33{
34 std::lock_guard <std::mutex> lg(m_mutex);
35 {if (m_iNav_ctrl == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return false; }}
36
37 if (!m_iNav_ctrl->stopNavigation())
38 {
39 yCError(NAVIGATION2DSERVER, "Unable to stopNavigation");
40 return false;
41 }
42 m_current_goal_name.clear();
43 return true;
44}
45
47{
48 std::lock_guard <std::mutex> lg(m_mutex);
49 {if (m_iNav_ctrl == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return false; }}
50
51 if (!m_iNav_ctrl->resumeNavigation())
52 {
53 yCError(NAVIGATION2DSERVER, "Unable to resumeNavigation");
54 return false;
55 }
56 return true;
57}
58
60{
61 std::lock_guard <std::mutex> lg(m_mutex);
62 {if (m_iNav_ctrl == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return false; }}
63
64 if (!m_iNav_ctrl->suspendNavigation(time_s))
65 {
66 yCError(NAVIGATION2DSERVER, "Unable to suspendNavigation");
67 return false;
68 }
69 return true;
70}
71
73{
74 std::lock_guard <std::mutex> lg(m_mutex);
75 {if (m_iNav_ctrl == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return false; }}
76
77 if (!m_iNav_ctrl->recomputeCurrentNavigationPath())
78 {
79 yCError(NAVIGATION2DSERVER, "Unable to recomputeCurrentNavigationPath");
80 return false;
81 }
82 return true;
83}
84
86{
87 std::lock_guard <std::mutex> lg(m_mutex);
88
90
91 {if (m_iNav_ctrl == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return ret; }}
92
94 if (!m_iNav_ctrl->getNavigationStatus(status))
95 {
96 yCError(NAVIGATION2DSERVER, "Unable to getNavigationStatus");
97 ret.ret = false;
98 }
99 else
100 {
101 ret.ret = true;
102 ret.status = status;
103 }
104 return ret;
105}
106
108{
109 std::lock_guard <std::mutex> lg(m_mutex);
110
112
113 {if (m_iNav_ctrl == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return ret; }}
114
115 Map2DLocation loc;
116 if (!m_iNav_ctrl->getCurrentNavigationWaypoint(loc))
117 {
118 yCError(NAVIGATION2DSERVER, "Unable to getCurrentNavigationWaypoint");
119 ret.ret = false;
120 }
121 else
122 {
123 ret.ret = true;
124 ret.waypoint = loc;
125 }
126 return ret;
127}
128
130{
131 std::lock_guard <std::mutex> lg(m_mutex);
132
134
135 {if (m_iNav_ctrl == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return ret; }}
136
137 Map2DPath path;
138 if (!m_iNav_ctrl->getAllNavigationWaypoints(trajectory_type, path))
139 {
140 yCError(NAVIGATION2DSERVER, "Unable to getAllNavigationWaypoints");
141 ret.ret = false;
142 }
143 else
144 {
145 ret.ret = true;
146 ret.waypoints = path;
147 }
148 return ret;
149}
150
152{
153 std::lock_guard <std::mutex> lg(m_mutex);
154
156
157 {if (m_iNav_ctrl == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return ret; }}
158
159 MapGrid2D themap;
160 if (!m_iNav_ctrl->getCurrentNavigationMap(map_type,themap))
161 {
162 yCError(NAVIGATION2DSERVER, "Unable to getRelativeLocationOfCurrentTarget");
163 ret.ret = false;
164 }
165 else
166 {
167 ret.ret = true;
168 ret.mapgrid = themap;
169 }
170 return ret;
171}
172
173
174
175// ------------ INavigation2DTargetActions
177{
178 std::lock_guard <std::mutex> lg(m_mutex);
179 {if (m_iNav_target == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return false; }}
180
181 if (!m_iNav_target->gotoTargetByAbsoluteLocation(loc))
182 {
183 yCError(NAVIGATION2DSERVER, "Unable to gotoTargetByAbsoluteLocation");
184 return false;
185 }
186 m_current_goal_name.clear();
187 return true;
188}
189
191{
192 std::lock_guard <std::mutex> lg(m_mutex);
193 {if (m_iNav_target == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return false; }}
194
195 if (!m_iNav_target->gotoTargetByRelativeLocation(x,y))
196 {
197 yCError(NAVIGATION2DSERVER, "Unable to gotoTargetByRelativeLocation");
198 return false;
199 }
200 m_current_goal_name.clear();
201 return true;
202}
203
205{
206 std::lock_guard <std::mutex> lg(m_mutex);
207 {if (m_iNav_target == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return false; }}
208
209 if (!m_iNav_target->gotoTargetByRelativeLocation(x,y,theta))
210 {
211 yCError(NAVIGATION2DSERVER, "Unable to gotoTargetByRelativeLocation");
212 return false;
213 }
214 m_current_goal_name.clear();
215 return true;
216}
217
219{
220 std::lock_guard <std::mutex> lg(m_mutex);
221 {if (m_iNav_target == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return false; }}
222
223 if (!m_iNav_target->gotoTargetByAbsoluteLocation(loc))
224 {
225 yCError(NAVIGATION2DSERVER, "Unable to gotoTargetByAbsoluteLocation");
226 return false;
227 }
228
229 m_current_goal_name.set_current_goal_name(name);
230 return true;
231}
232
234{
235 std::lock_guard <std::mutex> lg(m_mutex);
236 {if (m_iNav_target == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return false; }}
237
238 if (!m_iNav_target->followPath(path))
239 {
240 yCError(NAVIGATION2DSERVER, "Unable to follow path");
241 return false;
242 }
243 m_current_goal_name.clear();
244 return true;
245}
246
248{
249 std::lock_guard <std::mutex> lg(m_mutex);
250
252
253 {if (m_iNav_target == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return ret; }}
254
256 if (!m_iNav_target->getAbsoluteLocationOfCurrentTarget(loc))
257 {
258 yCError(NAVIGATION2DSERVER, "Unable to getAbsoluteLocationOfCurrentTarget");
259 ret.ret = false;
260 }
261 else
262 {
263 ret.ret = true;
264 ret.loc = loc;
265 }
266 return ret;
267}
268
270{
271 std::lock_guard <std::mutex> lg(m_mutex);
272
274
275 {if (m_iNav_target == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return ret; }}
276
277 double x,y,t;
278 if (!m_iNav_target->getRelativeLocationOfCurrentTarget(x,y,t))
279 {
280 yCError(NAVIGATION2DSERVER, "Unable to getRelativeLocationOfCurrentTarget");
281 ret.ret = false;
282 }
283 else
284 {
285 ret.ret = true;
286 ret.x = x;
287 ret.y = y;
288 ret.theta = t;
289 }
290 return ret;
291}
292
293// ------------ INavigation2DVelocityActions
294bool INavigation2DRPCd::apply_velocity_command_RPC(double x_vel, double y_vel, double theta_vel, double timeout)
295{
296 std::lock_guard <std::mutex> lg(m_mutex);
297 {if (m_iNav_vel == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return false; }}
298
299 if (!m_iNav_vel->applyVelocityCommand(x_vel, y_vel, theta_vel))
300 {
301 yCError(NAVIGATION2DSERVER, "Unable to applyVelocityCommand");
302 return false;
303 }
304 return true;
305}
306
308{
309 std::lock_guard <std::mutex> lg(m_mutex);
310
312
313 {if (m_iNav_vel == nullptr) { yCError(NAVIGATION2DSERVER, "Invalid interface"); return ret; }}
314
315 double x, y, t;
316 if (!m_iNav_vel->getLastVelocityCommand(x, y, t))
317 {
318 yCError(NAVIGATION2DSERVER, "Unable to getLastVelocityCommand");
319 ret.ret = false;
320 }
321 else
322 {
323 ret.ret = true;
324 ret.x_vel = x;
325 ret.y_vel = y;
326 ret.theta_vel = t;
327 }
328 return ret;
329}
330
331// ------------ extra
333{
334 std::lock_guard <std::mutex> lg(m_mutex);
335
337
338 if (m_current_goal_name.get_current_goal_name(ret.name))
339 {
340 ret.ret = true;
341 }
342 else
343 {
344 yCError(NAVIGATION2DSERVER, "Unable to getNameOfCurrentTarget");
345 ret.ret = false;
346 }
347
348 std::string name;
349 return ret;
350}
351
352// ------------ internal stuff
353bool LastGoalStorage::set_current_goal_name(const std::string& name)
354{
355 m_current_goal_name = name;
356 return true;
357}
358
360{
361 if (m_current_goal_name == "")
362 {
363 return true;
364 }
365 name = m_current_goal_name;
366 return true;
367}
368
370{
371 m_current_goal_name = "";
372 return true;
373}
float t
bool ret
contains the definition of a Map2DPath type
return_get_current_nav_waypoint get_current_nav_waypoint_RPC() override
return_get_all_nav_waypoints get_all_navigation_waypoints_RPC(yarp::dev::Nav2D::TrajectoryTypeEnum trajectory_type) override
bool goto_target_by_relative_location2_RPC(double x, double y, double theta) override
return_get_abs_loc_of_curr_target get_absolute_location_of_current_target_RPC() override
bool suspend_navigation_RPC(double time_s) override
return_get_name_of_current_target get_name_of_current_target_RPC() override
void setInterfaces(yarp::dev::Nav2D::INavigation2DTargetActions *iNav_target, yarp::dev::Nav2D::INavigation2DControlActions *iNav_ctrl, yarp::dev::Nav2D::INavigation2DVelocityActions *iNav_vel)
return_get_current_nav_map get_current_navigation_map_RPC(yarp::dev::Nav2D::NavigationMapTypeEnum map_type) override
bool follow_path_RPC(const yarp::dev::Nav2D::Map2DPath &path) override
return_get_rel_loc_of_curr_target get_relative_location_of_current_target_RPC() override
bool apply_velocity_command_RPC(double x_vel, double y_vel, double theta_vel, double timeout) override
return_get_last_velocity_command get_last_velocity_command_RPC() override
bool goto_target_by_absolute_location_RPC(const yarp::dev::Nav2D::Map2DLocation &loc) override
bool goto_target_by_absolute_location_and_set_name_RPC(const yarp::dev::Nav2D::Map2DLocation &loc, const std::string &name) override
return_get_navigation_status get_navigation_status_RPC() override
bool recompute_current_navigation_path_RPC() override
bool resume_navigation_RPC() override
bool goto_target_by_relative_location1_RPC(double x, double y) override
bool stop_navigation_RPC() override
bool set_current_goal_name(const std::string &name)
bool get_current_goal_name(std::string &name)
virtual bool recomputeCurrentNavigationPath()=0
Forces the navigation system to recompute the path from the current robot position to the current goa...
virtual bool getAllNavigationWaypoints(yarp::dev::Nav2D::TrajectoryTypeEnum trajectory_type, yarp::dev::Nav2D::Map2DPath &waypoints)=0
Returns the list of waypoints generated by the navigation algorithm.
virtual bool getCurrentNavigationWaypoint(yarp::dev::Nav2D::Map2DLocation &curr_waypoint)=0
Returns the current waypoint pursued by the navigation algorithm.
virtual bool resumeNavigation()=0
Resume a previously suspended navigation task.
virtual bool getNavigationStatus(NavigationStatusEnum &status)=0
Gets the current status of the navigation task.
virtual bool stopNavigation()=0
Terminates the current navigation task.
virtual bool suspendNavigation(const double time_s=std::numeric_limits< double >::infinity())=0
Ask to the robot to suspend the current navigation task for a defined amount of time.
virtual bool getCurrentNavigationMap(yarp::dev::Nav2D::NavigationMapTypeEnum map_type, yarp::dev::Nav2D::MapGrid2D &map)=0
Returns the current navigation map processed by the navigation algorithm.
virtual bool gotoTargetByRelativeLocation(double x, double y)=0
Ask the robot to reach a position defined in the robot reference frame.
virtual bool gotoTargetByAbsoluteLocation(yarp::dev::Nav2D::Map2DLocation loc)=0
Ask the robot to reach a position defined in the world reference frame.
virtual bool getAbsoluteLocationOfCurrentTarget(yarp::dev::Nav2D::Map2DLocation &loc)=0
Gets the last navigation target in the world reference frame.
virtual bool followPath(const yarp::dev::Nav2D::Map2DPath &path)=0
Ask the robot to navigate through a set of locations defined in the world reference frame.
virtual bool getRelativeLocationOfCurrentTarget(double &x, double &y, double &theta)=0
Gets the last navigation target in the robot reference frame.
virtual bool applyVelocityCommand(double x_vel, double y_vel, double theta_vel, double timeout=0.1)=0
Apply a velocity command.
virtual bool getLastVelocityCommand(double &x_vel, double &y_vel, double &theta_vel)=0
Returns the last applied velocity command.
A mini-server for performing network communication in the background.
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
STL namespace.
For streams capable of holding different kinds of content, check what they actually have.
Definition jointData.cpp:13
An interface to the operating system, including Port based communication.