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
36 auto ret = m_iNav_ctrl->stopNavigation();
37 if (!ret)
38 {
39 yCError(NAVIGATION2DSERVER, "Unable to stopNavigation");
40 }
41 m_current_goal_name.clear();
42 return ret;
43}
44
46{
47 std::lock_guard <std::mutex> lg(m_mutex);
48
49 auto ret = m_iNav_ctrl->resumeNavigation();
50 if (!ret)
51 {
52 yCError(NAVIGATION2DSERVER, "Unable to resumeNavigation");
53 }
54 return ret;
55}
56
58{
59 std::lock_guard <std::mutex> lg(m_mutex);
60
61 auto ret = m_iNav_ctrl->suspendNavigation(time_s);
62 if (!ret)
63 {
64 yCError(NAVIGATION2DSERVER, "Unable to suspendNavigation");
65 return ret;
66 }
67 return ret;
68}
69
71{
72 std::lock_guard <std::mutex> lg(m_mutex);
73
74 auto ret = m_iNav_ctrl->recomputeCurrentNavigationPath();
75 if (!ret)
76 {
77 yCError(NAVIGATION2DSERVER, "Unable to recomputeCurrentNavigationPath");
78 return ret;
79 }
80 return ret;
81}
82
84{
85 std::lock_guard <std::mutex> lg(m_mutex);
86
88
90 ret.ret = m_iNav_ctrl->getNavigationStatus(status);
91 if (!ret.ret)
92 {
93 yCError(NAVIGATION2DSERVER, "Unable to getNavigationStatus");
94 return ret;
95 }
96 else
97 {
98 ret.status = status;
99 }
100 return ret;
101}
102
104{
105 std::lock_guard <std::mutex> lg(m_mutex);
106
108
109 Map2DLocation loc;
110 ret.ret = m_iNav_ctrl->getCurrentNavigationWaypoint(loc);
111 if (!ret.ret)
112 {
113 yCError(NAVIGATION2DSERVER, "Unable to getCurrentNavigationWaypoint");
114 return ret;
115 }
116 else
117 {
118 ret.waypoint = loc;
119 }
120 return ret;
121}
122
124{
125 std::lock_guard <std::mutex> lg(m_mutex);
126
128
129 Map2DPath path;
130 ret.ret = m_iNav_ctrl->getAllNavigationWaypoints(trajectory_type, path);
131 if (!ret.ret)
132 {
133 yCError(NAVIGATION2DSERVER, "Unable to getAllNavigationWaypoints");
134 return ret;
135 }
136 else
137 {
138 ret.waypoints = path;
139 }
140 return ret;
141}
142
144{
145 std::lock_guard <std::mutex> lg(m_mutex);
146
148
149 MapGrid2D themap;
150 ret.ret = m_iNav_ctrl->getCurrentNavigationMap(map_type,themap);
151 if (!ret.ret)
152 {
153 yCError(NAVIGATION2DSERVER, "Unable to getRelativeLocationOfCurrentTarget");
154 return ret;
155 }
156 else
157 {
158 ret.mapgrid = themap;
159 }
160 return ret;
161}
162
163
164
165// ------------ INavigation2DTargetActions
167{
168 std::lock_guard <std::mutex> lg(m_mutex);
169
170 auto ret = m_iNav_target->gotoTargetByAbsoluteLocation(loc);
171 if (!ret)
172 {
173 yCError(NAVIGATION2DSERVER, "Unable to gotoTargetByAbsoluteLocation");
174 }
175 m_current_goal_name.clear();
176 return ret;
177}
178
180{
181 std::lock_guard <std::mutex> lg(m_mutex);
182
183 auto ret = m_iNav_target->gotoTargetByRelativeLocation(x, y);
184 if (!ret)
185 {
186 yCError(NAVIGATION2DSERVER, "Unable to gotoTargetByRelativeLocation");
187 }
188 m_current_goal_name.clear();
189 return ret;
190}
191
193{
194 std::lock_guard <std::mutex> lg(m_mutex);
195
196 auto ret = m_iNav_target->gotoTargetByRelativeLocation(x, y, theta);
197 if (!ret)
198 {
199 yCError(NAVIGATION2DSERVER, "Unable to gotoTargetByRelativeLocation");
200 }
201 m_current_goal_name.clear();
202 return ret;
203}
204
206{
207 std::lock_guard <std::mutex> lg(m_mutex);
208
209 auto ret = m_iNav_target->gotoTargetByAbsoluteLocation(loc);
210 if (!ret)
211 {
212 yCError(NAVIGATION2DSERVER, "Unable to gotoTargetByAbsoluteLocation");
213 }
214
215 m_current_goal_name.set_current_goal_name(name);
216 return ret;
217}
218
220{
221 std::lock_guard <std::mutex> lg(m_mutex);
222
223 auto ret = m_iNav_target->followPath(path);
224 if (!ret)
225 {
226 yCError(NAVIGATION2DSERVER, "Unable to follow path");
227 }
228 m_current_goal_name.clear();
229 return ret;
230}
231
233{
234 std::lock_guard <std::mutex> lg(m_mutex);
235
237
239 ret.ret = m_iNav_target->getAbsoluteLocationOfCurrentTarget(loc);
240 if (!ret.ret)
241 {
242 yCError(NAVIGATION2DSERVER, "Unable to getAbsoluteLocationOfCurrentTarget");
243 return ret;
244 }
245 else
246 {
247 ret.loc = loc;
248 }
249 return ret;
250}
251
253{
254 std::lock_guard <std::mutex> lg(m_mutex);
255
257
258 double x,y,t;
259 ret.ret = m_iNav_target->getRelativeLocationOfCurrentTarget(x, y, t);
260 if (!ret.ret)
261 {
262 yCError(NAVIGATION2DSERVER, "Unable to getRelativeLocationOfCurrentTarget");
263 return ret;
264 }
265 else
266 {
267 ret.x = x;
268 ret.y = y;
269 ret.theta = t;
270 }
271 return ret;
272}
273
274// ------------ INavigation2DVelocityActions
275ReturnValue INavigation2DRPCd::apply_velocity_command_RPC(double x_vel, double y_vel, double theta_vel, double timeout)
276{
277 std::lock_guard <std::mutex> lg(m_mutex);
278
279 auto ret = m_iNav_vel->applyVelocityCommand(x_vel, y_vel, theta_vel);
280 if (!ret)
281 {
282 yCError(NAVIGATION2DSERVER, "Unable to applyVelocityCommand");
283 return ret;
284 }
285 return ret;
286}
287
289{
290 std::lock_guard <std::mutex> lg(m_mutex);
291
293
294 double x, y, t;
295 ret.ret = m_iNav_vel->getLastVelocityCommand(x, y, t);
296 if (!ret.ret)
297 {
298 yCError(NAVIGATION2DSERVER, "Unable to getLastVelocityCommand");
299 return ret;
300 }
301 else
302 {
303 ret.x_vel = x;
304 ret.y_vel = y;
305 ret.theta_vel = t;
306 }
307 return ret;
308}
309
310// ------------ extra
312{
313 std::lock_guard <std::mutex> lg(m_mutex);
314
316
317 bool b = m_current_goal_name.get_current_goal_name(ret.name);
318 if (!b)
319 {
320 yCError(NAVIGATION2DSERVER, "Unable to getNameOfCurrentTarget");
321 ret.ret = ReturnValue::return_code::return_value_error_method_failed;
322 return ret;
323 }
324
325 ret.ret = ReturnValue::return_code::return_value_ok;
326 return ret;
327}
328
329// ------------ internal stuff
330bool LastGoalStorage::set_current_goal_name(const std::string& name)
331{
332 m_current_goal_name = name;
333 return true;
334}
335
337{
338 if (m_current_goal_name == "")
339 {
340 return true;
341 }
342 name = m_current_goal_name;
343 return true;
344}
345
347{
348 m_current_goal_name = "";
349 return true;
350}
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
yarp::dev::ReturnValue suspend_navigation_RPC(double time_s) override
return_get_abs_loc_of_curr_target get_absolute_location_of_current_target_RPC() override
return_get_name_of_current_target get_name_of_current_target_RPC() override
yarp::dev::ReturnValue stop_navigation_RPC() override
return_get_current_nav_map get_current_navigation_map_RPC(yarp::dev::Nav2D::NavigationMapTypeEnum map_type) override
yarp::dev::ReturnValue goto_target_by_relative_location2_RPC(double x, double y, double theta) override
yarp::dev::ReturnValue resume_navigation_RPC() override
INavigation2DRPCd(yarp::dev::Nav2D::INavigation2DTargetActions *iNav_target, yarp::dev::Nav2D::INavigation2DControlActions *iNav_ctrl, yarp::dev::Nav2D::INavigation2DVelocityActions *iNav_vel)
yarp::dev::ReturnValue recompute_current_navigation_path_RPC() override
yarp::dev::ReturnValue goto_target_by_absolute_location_and_set_name_RPC(const yarp::dev::Nav2D::Map2DLocation &loc, const std::string &name) override
yarp::dev::ReturnValue goto_target_by_absolute_location_RPC(const yarp::dev::Nav2D::Map2DLocation &loc) override
return_get_rel_loc_of_curr_target get_relative_location_of_current_target_RPC() override
return_get_last_velocity_command get_last_velocity_command_RPC() override
yarp::dev::ReturnValue follow_path_RPC(const yarp::dev::Nav2D::Map2DPath &path) override
return_get_navigation_status get_navigation_status_RPC() override
yarp::dev::ReturnValue apply_velocity_command_RPC(double x_vel, double y_vel, double theta_vel, double timeout) override
yarp::dev::ReturnValue goto_target_by_relative_location1_RPC(double x, double y) override
bool set_current_goal_name(const std::string &name)
bool get_current_goal_name(std::string &name)
virtual yarp::dev::ReturnValue 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 yarp::dev::ReturnValue getCurrentNavigationWaypoint(yarp::dev::Nav2D::Map2DLocation &curr_waypoint)=0
Returns the current waypoint pursued by the navigation algorithm.
virtual yarp::dev::ReturnValue getAllNavigationWaypoints(yarp::dev::Nav2D::TrajectoryTypeEnum trajectory_type, yarp::dev::Nav2D::Map2DPath &waypoints)=0
Returns the list of waypoints generated by the navigation algorithm.
virtual yarp::dev::ReturnValue resumeNavigation()=0
Resume a previously suspended navigation task.
virtual yarp::dev::ReturnValue recomputeCurrentNavigationPath()=0
Forces the navigation system to recompute the path from the current robot position to the current goa...
virtual yarp::dev::ReturnValue getNavigationStatus(NavigationStatusEnum &status)=0
Gets the current status of the navigation task.
virtual yarp::dev::ReturnValue stopNavigation()=0
Terminates the current navigation task.
virtual yarp::dev::ReturnValue getCurrentNavigationMap(yarp::dev::Nav2D::NavigationMapTypeEnum map_type, yarp::dev::Nav2D::MapGrid2D &map)=0
Returns the current navigation map processed by the navigation algorithm.
virtual yarp::dev::ReturnValue getAbsoluteLocationOfCurrentTarget(yarp::dev::Nav2D::Map2DLocation &loc)=0
Gets the last navigation target in the world reference frame.
virtual yarp::dev::ReturnValue getRelativeLocationOfCurrentTarget(double &x, double &y, double &theta)=0
Gets the last navigation target in the robot reference frame.
virtual yarp::dev::ReturnValue gotoTargetByRelativeLocation(double x, double y)=0
Ask the robot to reach a position defined in the robot reference frame.
virtual yarp::dev::ReturnValue 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 yarp::dev::ReturnValue gotoTargetByAbsoluteLocation(yarp::dev::Nav2D::Map2DLocation loc)=0
Ask the robot to reach a position defined in the world reference frame.
virtual yarp::dev::ReturnValue getLastVelocityCommand(double &x_vel, double &y_vel, double &theta_vel)=0
Returns the last applied velocity command.
virtual yarp::dev::ReturnValue applyVelocityCommand(double x_vel, double y_vel, double theta_vel, double timeout=0.1)=0
Apply a 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.
An interface to the operating system, including Port based communication.