YARP
Yet Another Robot Platform
Navigation2DClient.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "Navigation2DClient.h"
20 #include <yarp/dev/INavigation2D.h>
21 #include <yarp/os/Log.h>
22 #include <yarp/os/LogComponent.h>
23 #include <yarp/os/LogStream.h>
24 #include <mutex>
25 #include <cmath>
26 
29 using namespace yarp::dev;
30 using namespace yarp::dev::Nav2D;
31 using namespace yarp::os;
32 using namespace yarp::sig;
33 
34 namespace {
35 YARP_LOG_COMPONENT(NAVIGATION2DCLIENT, "yarp.device.navigation2DClient")
36 }
37 
38 bool Navigation2DClient::set_current_goal_name(const std::string& name)
39 {
40  m_current_goal_name = name;
41  return true;
42 }
43 
44 bool Navigation2DClient::get_current_goal_name(std::string& name)
45 {
46  if (m_current_goal_name == "")
47  {
48  return false;
49  }
50  name = m_current_goal_name;
51  return true;
52 }
53 
54 bool Navigation2DClient::reset_current_goal_name()
55 {
56  m_current_goal_name = "";
57  return true;
58 }
59 
60 //------------------------------------------------------------------------------------------------------------------------------
61 
63 {
64  m_local_name.clear();
65  m_navigation_server_name.clear();
66  m_map_locations_server_name.clear();
67  m_localization_server_name.clear();
68 
69  m_local_name = config.find("local").asString();
70  m_navigation_server_name = config.find("navigation_server").asString();
71  m_map_locations_server_name = config.find("map_locations_server").asString();
72  m_localization_server_name = config.find("localization_server").asString();
73 
74  if (m_local_name == "")
75  {
76  yCError(NAVIGATION2DCLIENT, "open() error you have to provide a valid 'local' param");
77  return false;
78  }
79 
80  if (m_navigation_server_name == "")
81  {
82  yCError(NAVIGATION2DCLIENT, "open() error you have to provide a valid 'navigation_server' param");
83  return false;
84  }
85 
86  if (m_map_locations_server_name == "")
87  {
88  yCError(NAVIGATION2DCLIENT, "open() error you have to provide valid 'map_locations_server' param");
89  return false;
90  }
91 
92  if (m_localization_server_name == "")
93  {
94  yCError(NAVIGATION2DCLIENT, "open() error you have to provide valid 'localization_server' param");
95  return false;
96  }
97 
98  if (config.check("period"))
99  {
100  m_period = config.find("period").asInt32();
101  }
102  else
103  {
104  m_period = 10;
105  yCWarning(NAVIGATION2DCLIENT, "Using default period of %d ms" , m_period);
106  }
107 
108  std::string
109  local_rpc_1,
110  local_rpc_2,
111  local_rpc_3,
112  local_rpc_4,
113  remote_rpc_1,
114  remote_rpc_2,
115  remote_rpc_3,
116  remote_streaming_name,
117  local_streaming_name;
118 
119  local_rpc_1 = m_local_name + "/navigation/rpc";
120  local_rpc_2 = m_local_name + "/locations/rpc";
121  local_rpc_3 = m_local_name + "/localization/rpc";
122  local_rpc_4 = m_local_name + "/user_commands/rpc";
123  remote_rpc_1 = m_navigation_server_name + "/rpc";
124  remote_rpc_2 = m_map_locations_server_name + "/rpc";
125  remote_rpc_3 = m_localization_server_name + "/rpc";
126  remote_streaming_name = m_localization_server_name + "/stream:o";
127  local_streaming_name = m_local_name + "/stream:i";
128 
129  if (!m_rpc_port_navigation_server.open(local_rpc_1))
130  {
131  yCError(NAVIGATION2DCLIENT, "open() error could not open rpc port %s, check network", local_rpc_1.c_str());
132  return false;
133  }
134 
135  if (!m_rpc_port_map_locations_server.open(local_rpc_2))
136  {
137  yCError(NAVIGATION2DCLIENT, "open() error could not open rpc port %s, check network", local_rpc_2.c_str());
138  return false;
139  }
140 
141  if (!m_rpc_port_localization_server.open(local_rpc_3))
142  {
143  yCError(NAVIGATION2DCLIENT, "open() error could not open rpc port %s, check network", local_rpc_3.c_str());
144  return false;
145  }
146 
147  bool ok = true;
148 
149  ok = Network::connect(local_rpc_1, remote_rpc_1);
150  if (!ok)
151  {
152  yCError(NAVIGATION2DCLIENT, "open() error could not connect to %s", remote_rpc_1.c_str());
153  return false;
154  }
155 
156  ok = Network::connect(local_rpc_2, remote_rpc_2);
157  if (!ok)
158  {
159  yCError(NAVIGATION2DCLIENT, "open() error could not connect to %s", remote_rpc_2.c_str());
160  return false;
161  }
162 
163  ok = Network::connect(local_rpc_3, remote_rpc_3);
164  if (!ok)
165  {
166  yCError(NAVIGATION2DCLIENT, "open() error could not connect to %s", remote_rpc_3.c_str());
167  return false;
168  }
169 
170  if (!m_rpc_port_user_commands.open(local_rpc_4.c_str()))
171  {
172  yCError(NAVIGATION2DCLIENT, "Failed to open port %s", local_rpc_4.c_str());
173  return false;
174  }
175  m_rpc_port_user_commands.setReader(*this);
176 
177  return true;
178 }
179 
181 {
182  m_rpc_port_navigation_server.close();
183  m_rpc_port_map_locations_server.close();
184  m_rpc_port_localization_server.close();
185  m_rpc_port_user_commands.close();
186  return true;
187 }
188 
190 {
191  if (command.get(0).isString() == false)
192  {
193  yCError(NAVIGATION2DCLIENT) << "General error in parse_respond_string";
194  return false;
195  }
196 
197  if (command.get(0).asString() == "help")
198  {
199  reply.addVocab(Vocab::encode("many"));
200  reply.addString("Available commands are:");
201  reply.addString("goto <locationName>");
202  //reply.addString("gotoAbs <x> <y> <angle in degrees>");
203  //reply.addString("gotoRel <x> <y> <angle in degrees>");
204  reply.addString("store_location <location_name> <map_id> <x> <y> <y>");
205  reply.addString("store_current_location <location_name>");
206  reply.addString("delete_location <location_name>");
207  reply.addString("clear_all_locations");
208  reply.addString("get_last_target");
209  reply.addString("get_location_list");
210  reply.addString("get_navigation_status");
211  reply.addString("stop_loc");
212  reply.addString("start_loc");
213  reply.addString("stop_nav");
214  reply.addString("pause_nav");
215  reply.addString("resume_nav");
216  reply.addString("get_current_loc");
217  reply.addString("initLoc <map_name> <x> <y> <angle in degrees>");
218  }
219  else if (command.get(0).asString() == "store_current_location")
220  {
221  bool ret = this->storeCurrentPosition(command.get(1).asString());
222  if (ret)
223  {
224  reply.addString("store_current_location done");
225  }
226  else
227  {
228  reply.addString("store_current_location failed");
229  }
230  }
231  else if (command.get(0).asString() == "gotoAbs")
232  {
233  Map2DLocation loc;
234  loc.map_id = command.get(1).asString();
235  loc.x = command.get(2).asFloat64();
236  loc.y = command.get(3).asFloat64();
237  if (command.size() == 5)
238  {
239  loc.theta = command.get(4).asFloat64();
240  }
241  else
242  {
243  loc.theta = nan("");
244  }
245 
246  bool ret = this->gotoTargetByAbsoluteLocation(loc);
247  if (ret)
248  {
249  reply.addString("gotoTargetByAbsoluteLocation() executed successfully");
250  }
251  else
252  {
253  reply.addString("gotoTargetByAbsoluteLocation() returned an error");
254  }
255  }
256 
257  else if (command.get(0).asString() == "gotoRel")
258  {
260  double x = command.get(1).asFloat64();
261  double y = command.get(2).asFloat64();
262  bool ret;
263  if (command.size() == 4)
264  {
265  double t = command.get(3).asFloat64();
266  ret = this->gotoTargetByRelativeLocation(x, y, t);
267  }
268  else
269  {
270  ret = this->gotoTargetByRelativeLocation(x, y);
271  }
272 
273  if (ret)
274  {
275  reply.addString("gotoTargetByRelativeLocation() executed successfully");
276  }
277  else
278  {
279  reply.addString("gotoTargetByRelativeLocation() returned an error");
280  }
281  }
282  else if (command.get(0).asString() == "get_location_list")
283  {
284  std::vector<std::string> locations;
285  bool ret = getLocationsList(locations);
286  if (ret)
287  {
288  for (size_t i=0; i < locations.size(); i++)
289  {
290  reply.addString(locations[i]);
291  }
292  }
293  else
294  {
295  reply.addString("get_location_list failed");
296  }
297  }
298  else if (command.get(0).asString() == "get_navigation_status")
299  {
301  bool ret = this->getNavigationStatus(ss);
302  if (ret)
303  {
305  reply.addString(s.c_str());
306  }
307  else
308  {
309  reply.addString("getNavigationStatus() failed");
310  }
311  }
312  else if (command.get(0).isString() && command.get(0).asString() == "get_current_loc")
313  {
314  {
315  Map2DLocation curr_loc;
316  bool ret1 = this->getCurrentPosition(curr_loc);
317  if (ret1)
318  {
319  std::string s = std::string("Current Location is: ") + curr_loc.toString();
320  reply.addString(s);
321  }
322  else
323  {
324  reply.addString("getCurrentPosition(curr_loc) failed");
325  }
326  }
327  {
328  Map2DLocation curr_loc;
329  Matrix cov;
330  bool ret2 = this->getCurrentPosition(curr_loc, cov);
331  if (ret2)
332  {
333  std::string s = std::string("Current Location with covariance is: ") + curr_loc.toString() + "\n" + cov.toString();
334  reply.addString(s);
335  }
336  else
337  {
338  reply.addString("getCurrentPosition(curr_loc, covariance) failed");
339  }
340  }
341  }
342  else if (command.get(0).isString() && command.get(0).asString() == "initLoc")
343  {
344  Map2DLocation init_loc;
345  bool ret = false;
346  if (command.size() == 5)
347  {
348  init_loc.map_id = command.get(1).asString();
349  init_loc.x = command.get(2).asFloat64();
350  init_loc.y = command.get(3).asFloat64();
351  init_loc.theta = command.get(4).asFloat64();
352  ret = this->setInitialPose(init_loc);
353  }
354  else if (command.size() == 6)
355  {
356  init_loc.map_id = command.get(1).asString();
357  init_loc.x = command.get(2).asFloat64();
358  init_loc.y = command.get(3).asFloat64();
359  init_loc.theta = command.get(4).asFloat64();
360  Bottle* b= command.get(5).asList();
361  if (b && b->size()==9)
362  {
363  yarp::sig::Matrix cov(3,3);
364  for (size_t i = 0; i < 3; i++) { for (size_t j = 0; j < 3; j++) { cov[i][j] = b->get(i * 3 + j).asFloat64(); } }
365  ret = this->setInitialPose(init_loc, cov);
366  }
367  else ret = false;
368  }
369 
370  if (ret)
371  {
372  std::string s = std::string("Localization initialized to: ") + init_loc.toString();
373  reply.addString(s);
374  }
375  else
376  {
377  reply.addString("setInitialPose() failed");
378  }
379  }
380  else if (command.get(0).asString() == "store_location")
381  {
382  if (command.size() != 6)
383  {
384  reply.addString("store_location failed (invalid params)");
385  }
386  else
387  {
388  Map2DLocation loc;
389  loc.map_id = command.get(2).asString();
390  loc.x = command.get(3).asFloat64();
391  loc.y = command.get(4).asFloat64();
392  loc.theta = command.get(5).asFloat64();
393  bool ret = this->storeLocation(command.get(1).asString(), loc);
394  if (ret)
395  {
396  reply.addString("store_location done");
397  }
398  else
399  {
400  reply.addString("store_location failed");
401  }
402  }
403  }
404  else if (command.get(0).asString() == "delete_location")
405  {
406  bool ret = this->deleteLocation(command.get(1).asString());
407  if (ret)
408  {
409  reply.addString("delete_location done");
410  }
411  else
412  {
413  reply.addString("delete_location failed");
414  }
415  }
416  else if (command.get(0).asString() == "clear_all_locations")
417  {
418  std::vector<std::string> locations;
419  bool ret = getLocationsList(locations);
420  if (ret)
421  {
422  for (size_t i = 0; i < locations.size(); i++)
423  {
424  bool ret = this->deleteLocation(locations[i]);
425  if (ret == false)
426  {
427  reply.addString("clear_all_locations failed");
428  }
429  }
430  reply.addString("clear_all_locations done");
431  }
432  else
433  {
434  reply.addString("clear_all_locations failed");
435  }
436  }
437  else if (command.get(0).asString() == "goto")
438  {
439  bool ret = this->gotoTargetByLocationName(command.get(1).asString());
440  if (ret)
441  {
442  reply.addString("goto done");
443  }
444  else
445  {
446  reply.addString("goto failed");
447  }
448 
449  }
450  else if (command.get(0).asString() == "get_last_target")
451  {
452  std::string last_target;
453  bool b = this->getNameOfCurrentTarget(last_target);
454  if (b)
455  {
456  reply.addString(last_target);
457  }
458  else
459  {
460  yCError(NAVIGATION2DCLIENT) << "get_last_target failed: goto <location_name> target not found.";
461  reply.addString("not found");
462  }
463  }
464  else if (command.get(0).asString() == "stop_nav")
465  {
466  this->stopNavigation();
467  reply.addString("Stopping movement.");
468  }
469  else if (command.get(0).asString() == "stop_loc")
470  {
471  this->stopLocalizationService();
472  reply.addString("Stopping localization service.");
473  }
474  else if (command.get(0).asString() == "pause_nav")
475  {
476  double time = -1;
477  if (command.size() > 1)
478  time = command.get(1).asFloat64();
479  this->suspendNavigation(time);
480  reply.addString("Pausing.");
481  }
482  else if (command.get(0).asString() == "resume_nav")
483  {
484  this->resumeNavigation();
485  reply.addString("Resuming.");
486  }
487  else if (command.get(0).asString() == "start_loc")
488  {
489  this->startLocalizationService();
490  reply.addString("Starting localization service.");
491  }
492  else
493  {
494  yCError(NAVIGATION2DCLIENT) << "Unknown command";
495  reply.addVocab(VOCAB_ERR);
496  }
497  return true;
498 }
499 
501 {
502  yarp::os::Bottle command;
503  yarp::os::Bottle reply;
504  bool ok = command.read(connection);
505  if (!ok) return false;
506  reply.clear();
507 
508  if (command.get(0).isString())
509  {
510  parse_respond_string(command, reply);
511  }
512  else
513  {
514  yCError(NAVIGATION2DCLIENT) << "Invalid command type";
515  reply.addVocab(VOCAB_ERR);
516  }
517 
518  yarp::os::ConnectionWriter *returnToSender = connection.getWriter();
519  if (returnToSender != nullptr)
520  {
521  reply.write(*returnToSender);
522  }
523  return true;
524 }
525 
527 {
529  yarp::os::Bottle resp;
530 
533  bool ret = m_rpc_port_navigation_server.write(b, resp);
534  if (ret)
535  {
536  if (resp.get(0).asVocab() != VOCAB_OK)
537  {
538  yCError(NAVIGATION2DCLIENT) << "getNavigationStatus() received error from navigation server";
539  return false;
540  }
541  else
542  {
543  status = (NavigationStatusEnum) resp.get(1).asInt32();
544  return true;
545  }
546  }
547  else
548  {
549  yCError(NAVIGATION2DCLIENT) << "getNavigationStatus() error on writing on rpc port";
550  return false;
551  }
552  return true;
553 }
554 
555 
557 {
559  yarp::os::Bottle resp;
560 
563  b.addString(loc.map_id);
564  b.addFloat64(loc.x);
565  b.addFloat64(loc.y);
566  b.addFloat64(loc.theta);
567  bool ret = m_rpc_port_navigation_server.write(b, resp);
568  if (ret)
569  {
570  if (resp.get(0).asVocab() != VOCAB_OK)
571  {
572  yCError(NAVIGATION2DCLIENT) << "gotoTargetByAbsoluteLocation() received error from navigation server";
573  return false;
574  }
575  }
576  else
577  {
578  yCError(NAVIGATION2DCLIENT) << "gotoTargetByAbsoluteLocation() error on writing on rpc port";
579  return false;
580  }
581 
582  reset_current_goal_name();
583  return true;
584 }
585 
586 bool Navigation2DClient::checkNearToLocation(Map2DLocation loc, double linear_tolerance, double angular_tolerance)
587 {
588  Map2DLocation curr_loc;
589  if (getCurrentPosition(curr_loc) == false)
590  {
591  yCError(NAVIGATION2DCLIENT) << "checkInsideArea() unable to get robot position";
592  return false;
593  }
594 
595  return curr_loc.is_near_to(loc, linear_tolerance, angular_tolerance);
596 }
597 
598 bool Navigation2DClient::checkNearToLocation(std::string location_name, double linear_tolerance, double angular_tolerance)
599 {
600  Map2DLocation loc;
601  Map2DLocation curr_loc;
602  if (this->getLocation(location_name, loc) == false)
603  {
604  yCError(NAVIGATION2DCLIENT) << "Location" << location_name << "not found";
605  return false;
606  }
607 
608  if (getCurrentPosition(curr_loc) == false)
609  {
610  yCError(NAVIGATION2DCLIENT) << "checkInsideArea() unable to get robot position";
611  return false;
612  }
613 
614  return curr_loc.is_near_to(loc, linear_tolerance, angular_tolerance);
615 }
616 
618 {
619  Map2DLocation curr_loc;
620  if (getCurrentPosition(curr_loc) == false)
621  {
622  yCError(NAVIGATION2DCLIENT) << "checkInsideArea() unable to get robot position";
623  return false;
624  }
625 
626  if (area.checkLocationInsideArea(curr_loc) == false)
627  {
628  //yCDebug(NAVIGATION2DCLIENT) << "Not inside Area";
629  return false;
630  }
631 
632  return true;
633 }
634 
635 bool Navigation2DClient::checkInsideArea(std::string area_name)
636 {
637  Map2DLocation curr_loc;
638  Map2DArea area;
639  if (this->getArea(area_name, area) == false)
640  {
641  yCError(NAVIGATION2DCLIENT) << "Area" << area_name << "not found";
642  return false;
643  }
644 
645  if (getCurrentPosition(curr_loc) == false)
646  {
647  yCError(NAVIGATION2DCLIENT) << "checkInsideArea() unable to get robot position";
648  return false;
649  }
650 
651  if (area.checkLocationInsideArea(curr_loc) == false)
652  {
653  //yCDebug(NAVIGATION2DCLIENT) << "Not inside Area";
654  return false;
655  }
656 
657  return true;
658 }
659 
660 bool Navigation2DClient::gotoTargetByLocationName(std::string location_name)
661 {
662  Map2DLocation loc;
663  Map2DArea area;
664 
665  //first of all, ask to the location server if location_name exists as a location_name...
666  bool found = this->getLocation(location_name, loc);
667 
668  //...if found, ok...otherwise check if location_name is an area name instead...
669  if (found == false)
670  {
671  found = this->getArea(location_name, area);
672  if (found)
673  {
674  area.getRandomLocation(loc);
675  }
676  }
677 
678  //...if it is neither a location, nor an area then quit...
679  if (found == false)
680  {
681  yCError(NAVIGATION2DCLIENT) << "Location not found";
682  return false;
683  }
684 
685  //...otherwise we can go to the found/computed location!
686  this->gotoTargetByAbsoluteLocation(loc);
687  set_current_goal_name(location_name);
688 
689  return true;
690 }
691 
693 {
695  yarp::os::Bottle resp;
696 
699  b.addFloat64(x);
700  b.addFloat64(y);
701 
702  bool ret = m_rpc_port_navigation_server.write(b, resp);
703  if (ret)
704  {
705  if (resp.get(0).asVocab() != VOCAB_OK)
706  {
707  yCError(NAVIGATION2DCLIENT) << "gotoTargetByRelativeLocation() received error from navigation server";
708  return false;
709  }
710  }
711  else
712  {
713  yCError(NAVIGATION2DCLIENT) << "gotoTargetByRelativeLocation() error on writing on rpc port";
714  return false;
715  }
716 
717  reset_current_goal_name();
718  return true;
719 }
720 
721 bool Navigation2DClient::gotoTargetByRelativeLocation(double x, double y, double theta)
722 {
724  yarp::os::Bottle resp;
725 
728  b.addFloat64(x);
729  b.addFloat64(y);
730  b.addFloat64(theta);
731 
732  bool ret = m_rpc_port_navigation_server.write(b, resp);
733  if (ret)
734  {
735  if (resp.get(0).asVocab() != VOCAB_OK)
736  {
737  yCError(NAVIGATION2DCLIENT) << "gotoTargetByRelativeLocation() received error from navigation server";
738  return false;
739  }
740  }
741  else
742  {
743  yCError(NAVIGATION2DCLIENT) << "gotoTargetByRelativeLocation() error on writing on rpc port";
744  return false;
745  }
746 
747  reset_current_goal_name();
748  return true;
749 }
750 
752 {
754  yarp::os::Bottle resp;
755 
758 
759  bool ret = m_rpc_port_navigation_server.write(b, resp);
760  if (ret)
761  {
762  if (resp.get(0).asVocab() != VOCAB_OK)
763  {
764  yCError(NAVIGATION2DCLIENT) << "recomputeCurrentNavigationPath() received error from navigation server";
765  return false;
766  }
767  }
768  else
769  {
770  yCError(NAVIGATION2DCLIENT) << "recomputeCurrentNavigationPath() error on writing on rpc port";
771  return false;
772  }
773  return true;
774 }
775 
777 {
779  yarp::os::Bottle resp;
780 
783  b.addString(loc.map_id);
784  b.addFloat64(loc.x);
785  b.addFloat64(loc.y);
786  b.addFloat64(loc.theta);
787 
788  bool ret = m_rpc_port_localization_server.write(b, resp);
789  if (ret)
790  {
791  if (resp.get(0).asVocab() != VOCAB_OK)
792  {
793  yCError(NAVIGATION2DCLIENT) << "setInitialPose() received error from localization server";
794  return false;
795  }
796  }
797  else
798  {
799  yCError(NAVIGATION2DCLIENT) << "setInitialPose() error on writing on rpc port";
800  return false;
801  }
802  return true;
803 }
804 
806 {
807  if (cov.rows() != 3 || cov.cols() != 3)
808  {
809  yCError(NAVIGATION2DCLIENT) << "Covariance matrix is expected to have size (3,3)";
810  return false;
811  }
813  yarp::os::Bottle resp;
814 
817  b.addString(loc.map_id);
818  b.addFloat64(loc.x);
819  b.addFloat64(loc.y);
820  b.addFloat64(loc.theta);
821  yarp::os::Bottle& mc = b.addList();
822  for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { mc.addFloat64(cov[i][j]); } }
823 
824  bool ret = m_rpc_port_localization_server.write(b, resp);
825  if (ret)
826  {
827  if (resp.get(0).asVocab() != VOCAB_OK)
828  {
829  yCError(NAVIGATION2DCLIENT) << "setInitialPose() received error from localization server";
830  return false;
831  }
832  }
833  else
834  {
835  yCError(NAVIGATION2DCLIENT) << "setInitialPose() error on writing on rpc port";
836  return false;
837  }
838  return true;
839 }
840 
842 {
844  yarp::os::Bottle resp;
845 
848 
849  bool ret = m_rpc_port_localization_server.write(b, resp);
850  if (ret)
851  {
852  if (resp.get(0).asVocab() != VOCAB_OK || resp.size() != 6)
853  {
854  yCError(NAVIGATION2DCLIENT) << "getCurrentPosition() received error from localization server";
855  return false;
856  }
857  else
858  {
859  if (cov.rows() != 3 || cov.cols() != 3)
860  {
861  yCDebug(NAVIGATION2DCLIENT) << "Performance warning: covariance matrix is not (3,3), resizing...";
862  cov.resize(3, 3);
863  }
864  loc.map_id = resp.get(1).asString();
865  loc.x = resp.get(2).asFloat64();
866  loc.y = resp.get(3).asFloat64();
867  loc.theta = resp.get(4).asFloat64();
868  Bottle* mc = resp.get(5).asList();
869  if (mc == nullptr) return false;
870  for (size_t i = 0; i < 3; i++) { for (size_t j = 0; j < 3; j++) { cov[i][j] = mc->get(i * 3 + j).asFloat64(); } }
871  return true;
872  }
873  }
874  else
875  {
876  yCError(NAVIGATION2DCLIENT) << "getCurrentPosition() error on writing on rpc port";
877  return false;
878  }
879  return true;
880 }
881 
883 {
884  yCError(NAVIGATION2DCLIENT) << " getEstimatedOdometry is not yet implemented";
885  return false;
886 }
887 
889 {
891  yarp::os::Bottle resp;
892 
895 
896  bool ret = m_rpc_port_localization_server.write(b, resp);
897  if (ret)
898  {
899  if (resp.get(0).asVocab() != VOCAB_OK || resp.size() != 5)
900  {
901  yCError(NAVIGATION2DCLIENT) << "getCurrentPosition() received error from localization server";
902  return false;
903  }
904  else
905  {
906  loc.map_id = resp.get(1).asString();
907  loc.x = resp.get(2).asFloat64();
908  loc.y = resp.get(3).asFloat64();
909  loc.theta = resp.get(4).asFloat64();
910  return true;
911  }
912  }
913  else
914  {
915  yCError(NAVIGATION2DCLIENT) << "getCurrentPosition() error on writing on rpc port";
916  return false;
917  }
918  return true;
919 }
920 
921 bool Navigation2DClient::suspendNavigation(const double time_s)
922 {
924  yarp::os::Bottle resp;
925 
928  b.addFloat64(time_s);
929 
930  bool ret = m_rpc_port_navigation_server.write(b, resp);
931  if (ret)
932  {
933  if (resp.get(0).asVocab() != VOCAB_OK)
934  {
935  yCError(NAVIGATION2DCLIENT) << "suspendNavigation() received error from navigation server";
936  return false;
937  }
938  }
939  else
940  {
941  yCError(NAVIGATION2DCLIENT) << "suspendNavigation() error on writing on rpc port";
942  return false;
943  }
944  return true;
945 }
946 
948 {
950  yarp::os::Bottle resp;
951 
954 
955  bool ret = m_rpc_port_navigation_server.write(b, resp);
956  if (ret)
957  {
958  if (resp.get(0).asVocab() != VOCAB_OK || resp.size() != 5)
959  {
960  yCError(NAVIGATION2DCLIENT) << "getAbsoluteLocationOfCurrentTarget() received error from navigation server";
961  return false;
962  }
963  else
964  {
965  loc.map_id = resp.get(1).asString();
966  loc.x = resp.get(2).asFloat64();
967  loc.y = resp.get(3).asFloat64();
968  loc.theta = resp.get(4).asFloat64();
969  return true;
970  }
971  }
972  else
973  {
974  yCError(NAVIGATION2DCLIENT) << "getAbsoluteLocationOfCurrentTarget() error on writing on rpc port";
975  return false;
976  }
977  return true;
978 }
979 
980 bool Navigation2DClient::getNameOfCurrentTarget(std::string& location_name)
981 {
982  std::string s;
983  if (get_current_goal_name(s))
984  {
985  location_name = s;
986  return true;
987  }
988 
989  location_name = "";
990  yCError(NAVIGATION2DCLIENT) << "No name for the current target, or no target set";
991  return true;
992 }
993 
994 bool Navigation2DClient::getRelativeLocationOfCurrentTarget(double& x, double& y, double& theta)
995 {
997  yarp::os::Bottle resp;
998 
1001 
1002  bool ret = m_rpc_port_navigation_server.write(b, resp);
1003  if (ret)
1004  {
1005  if (resp.get(0).asVocab() != VOCAB_OK || resp.size()!=4)
1006  {
1007  yCError(NAVIGATION2DCLIENT) << "getRelativeLocationOfCurrentTarget() received error from navigation server";
1008  return false;
1009  }
1010  else
1011  {
1012  x = resp.get(1).asFloat64();
1013  y = resp.get(2).asFloat64();
1014  theta = resp.get(3).asFloat64();
1015  return true;
1016  }
1017  }
1018  else
1019  {
1020  yCError(NAVIGATION2DCLIENT) << "getRelativeLocationOfCurrentTarget() error on writing on rpc port";
1021  return false;
1022  }
1023  return true;
1024 }
1025 
1026 bool Navigation2DClient::storeCurrentPosition(std::string location_name)
1027 {
1028  yarp::os::Bottle b_nav;
1029  yarp::os::Bottle resp_nav;
1030  yarp::os::Bottle b_loc;
1031  yarp::os::Bottle resp_loc;
1032  Map2DLocation loc;
1033 
1034  b_nav.addVocab(VOCAB_INAVIGATION);
1036  bool ret_nav = m_rpc_port_localization_server.write(b_nav, resp_nav);
1037  if (ret_nav)
1038  {
1039  if (resp_nav.get(0).asVocab() != VOCAB_OK || resp_nav.size()!=5)
1040  {
1041  yCError(NAVIGATION2DCLIENT) << "storeCurrentPosition() received error from localization server";
1042  return false;
1043  }
1044  else
1045  {
1046  loc.map_id = resp_nav.get(1).asString();
1047  loc.x = resp_nav.get(2).asFloat64();
1048  loc.y = resp_nav.get(3).asFloat64();
1049  loc.theta = resp_nav.get(4).asFloat64();
1050  }
1051  }
1052  else
1053  {
1054  yCError(NAVIGATION2DCLIENT) << "storeCurrentPosition() error on writing on rpc port";
1055  return false;
1056  }
1057 
1058  b_loc.addVocab(VOCAB_INAVIGATION);
1059  b_loc.addVocab(VOCAB_NAV_STORE_X);
1061  b_loc.addString(location_name);
1062  b_loc.addString(loc.map_id);
1063  b_loc.addFloat64(loc.x);
1064  b_loc.addFloat64(loc.y);
1065  b_loc.addFloat64(loc.theta);
1066 
1067  bool ret_loc = m_rpc_port_map_locations_server.write(b_loc, resp_loc);
1068  if (ret_loc)
1069  {
1070  if (resp_loc.get(0).asVocab() != VOCAB_OK)
1071  {
1072  yCError(NAVIGATION2DCLIENT) << "storeCurrentPosition() received error from locations server";
1073  return false;
1074  }
1075  }
1076  else
1077  {
1078  yCError(NAVIGATION2DCLIENT) << "storeCurrentPosition() error on writing on rpc port";
1079  return false;
1080  }
1081  return true;
1082 }
1083 
1084 bool Navigation2DClient::storeLocation(std::string location_name, Map2DLocation loc)
1085 {
1086  yarp::os::Bottle b;
1087  yarp::os::Bottle resp;
1088 
1092  b.addString(location_name);
1093  b.addString(loc.map_id);
1094  b.addFloat64(loc.x);
1095  b.addFloat64(loc.y);
1096  b.addFloat64(loc.theta);
1097 
1098  bool ret = m_rpc_port_map_locations_server.write(b, resp);
1099  if (ret)
1100  {
1101  if (resp.get(0).asVocab() != VOCAB_OK)
1102  {
1103  yCError(NAVIGATION2DCLIENT) << "storeLocation() received error from locations server";
1104  return false;
1105  }
1106  }
1107  else
1108  {
1109  yCError(NAVIGATION2DCLIENT) << "storeLocation() error on writing on rpc port";
1110  return false;
1111  }
1112  return true;
1113 }
1114 
1115 bool Navigation2DClient::getLocationsList(std::vector<std::string>& locations)
1116 {
1117  yarp::os::Bottle b;
1118  yarp::os::Bottle resp;
1119 
1123 
1124  bool ret = m_rpc_port_map_locations_server.write(b, resp);
1125  if (ret)
1126  {
1127  if (resp.get(0).asVocab() != VOCAB_OK)
1128  {
1129  yCError(NAVIGATION2DCLIENT) << "getLocationsList() received error from locations server";
1130  return false;
1131  }
1132  else
1133  {
1134  Bottle* list = resp.get(1).asList();
1135  if (list)
1136  {
1137  locations.clear();
1138  for (size_t i = 0; i < list->size(); i++)
1139  {
1140  locations.push_back(list->get(i).asString());
1141  }
1142  return true;
1143  }
1144  else
1145  {
1146  yCError(NAVIGATION2DCLIENT) << "getLocationsList() error while reading from locations server";
1147  return false;
1148  }
1149  }
1150  }
1151  else
1152  {
1153  yCError(NAVIGATION2DCLIENT) << "getLocationsList() error on writing on rpc port";
1154  return false;
1155  }
1156  return true;
1157 }
1158 
1159 bool Navigation2DClient::getLocation(std::string location_name, Map2DLocation& loc)
1160 {
1161  yarp::os::Bottle b;
1162  yarp::os::Bottle resp;
1163 
1167  b.addString(location_name);
1168 
1169  bool ret = m_rpc_port_map_locations_server.write(b, resp);
1170  if (ret)
1171  {
1172  if (resp.get(0).asVocab() != VOCAB_OK)
1173  {
1174  yCError(NAVIGATION2DCLIENT) << "getLocation() received error from locations server";
1175  return false;
1176  }
1177  else
1178  {
1179  loc.map_id = resp.get(1).asString();
1180  loc.x = resp.get(2).asFloat64();
1181  loc.y = resp.get(3).asFloat64();
1182  loc.theta = resp.get(4).asFloat64();
1183  }
1184  }
1185  else
1186  {
1187  yCError(NAVIGATION2DCLIENT) << "getLocation() error on writing on rpc port";
1188  return false;
1189  }
1190  return true;
1191 }
1192 
1193 bool Navigation2DClient::getArea(std::string area_name, Map2DArea& area)
1194 {
1195  yarp::os::Bottle b_loc;
1196  yarp::os::Bottle resp_loc;
1197 
1198  {
1199  b_loc.clear();
1200  b_loc.addVocab(VOCAB_INAVIGATION);
1201  b_loc.addVocab(VOCAB_NAV_GET_X);
1202  b_loc.addVocab(VOCAB_NAV_AREA);
1203  b_loc.addString(area_name);
1204 
1205  bool ret = m_rpc_port_map_locations_server.write(b_loc, resp_loc);
1206  if (ret)
1207  {
1208  if (resp_loc.get(0).asVocab() != VOCAB_OK)
1209  {
1210  yCError(NAVIGATION2DCLIENT) << "getArea() received error from locations server";
1211  return false;
1212  }
1213  else
1214  {
1215  Value& b = resp_loc.get(1);
1216  if (Property::copyPortable(b, area) == false)
1217  {
1218  yCError(NAVIGATION2DCLIENT) << "getArea() received error from locations server";
1219  return false;
1220  }
1221  }
1222  }
1223  else
1224  {
1225  yCError(NAVIGATION2DCLIENT) << "getArea() error on writing on rpc port";
1226  return false;
1227  }
1228  }
1229  return true;
1230 }
1231 
1232 bool Navigation2DClient::deleteLocation(std::string location_name)
1233 {
1234  yarp::os::Bottle b;
1235  yarp::os::Bottle resp;
1236 
1240  b.addString(location_name);
1241 
1242  bool ret = m_rpc_port_map_locations_server.write(b, resp);
1243  if (ret)
1244  {
1245  if (resp.get(0).asVocab() != VOCAB_OK)
1246  {
1247  yCError(NAVIGATION2DCLIENT) << "deleteLocation() received error from locations server";
1248  return false;
1249  }
1250  }
1251  else
1252  {
1253  yCError(NAVIGATION2DCLIENT) << "deleteLocation() error on writing on rpc port";
1254  return false;
1255  }
1256  return true;
1257 }
1258 
1260 {
1261  yarp::os::Bottle b;
1262  yarp::os::Bottle resp;
1263 
1267 
1268  bool ret = m_rpc_port_map_locations_server.write(b, resp);
1269  if (ret)
1270  {
1271  if (resp.get(0).asVocab() != VOCAB_OK)
1272  {
1273  yCError(NAVIGATION2DCLIENT) << "clearAllLocations() received error from locations server";
1274  return false;
1275  }
1276  }
1277  else
1278  {
1279  yCError(NAVIGATION2DCLIENT) << "clearAllLocations() error on writing on rpc port";
1280  return false;
1281  }
1282  return true;
1283 }
1284 
1286 {
1287  yarp::os::Bottle b;
1288  yarp::os::Bottle resp;
1289 
1292 
1293  bool ret = m_rpc_port_navigation_server.write(b, resp);
1294  if (ret)
1295  {
1296  if (resp.get(0).asVocab() != VOCAB_OK)
1297  {
1298  yCError(NAVIGATION2DCLIENT) << "stopNavigation() received error from navigation server";
1299  return false;
1300  }
1301  }
1302  else
1303  {
1304  yCError(NAVIGATION2DCLIENT) << "stopNavigation() error on writing on rpc port";
1305  return false;
1306  }
1307  return true;
1308 }
1309 
1311 {
1312  yarp::os::Bottle b;
1313  yarp::os::Bottle resp;
1314 
1317 
1318  bool ret = m_rpc_port_navigation_server.write(b, resp);
1319  if (ret)
1320  {
1321  if (resp.get(0).asVocab() != VOCAB_OK)
1322  {
1323  yCError(NAVIGATION2DCLIENT) << "resumeNavigation() received error from navigation server";
1324  return false;
1325  }
1326  }
1327  else
1328  {
1329  yCError(NAVIGATION2DCLIENT) << "resumeNavigation() error on writing on rpc port";
1330  return false;
1331  }
1332  return true;
1333 }
1334 
1336 {
1337  yarp::os::Bottle b;
1338  yarp::os::Bottle resp;
1339 
1342  b.addVocab(trajectory_type);
1343 
1344  bool ret = m_rpc_port_navigation_server.write(b, resp);
1345  if (ret)
1346  {
1347  if (resp.get(0).asVocab() != VOCAB_OK)
1348  {
1349  yCError(NAVIGATION2DCLIENT) << "getNavigationWaypoints() received error from navigation server";
1350  return false;
1351  }
1352  else if (resp.get(1).isList() && resp.get(1).asList()->size()>0)
1353  {
1354  waypoints.clear();
1355  Bottle* waypoints_bottle = resp.get(1).asList();
1356  if (waypoints_bottle == 0) { yCError(NAVIGATION2DCLIENT) << "getNavigationWaypoints parsing error"; return false; }
1357  for (size_t i = 0; i < waypoints_bottle->size(); i++)
1358  {
1359  Bottle* the_waypoint = waypoints_bottle->get(i).asList();
1360  if (the_waypoint == 0) { yCError(NAVIGATION2DCLIENT) << "getNavigationWaypoints parsing error"; return false; }
1361  Map2DLocation loc;
1362  loc.map_id = the_waypoint->get(0).asString();
1363  loc.x = the_waypoint->get(1).asFloat64();
1364  loc.y = the_waypoint->get(2).asFloat64();
1365  loc.theta = the_waypoint->get(3).asFloat64();
1366  waypoints.push_back(loc);
1367  }
1368  return true;
1369  }
1370  else
1371  {
1372  //not available
1373  waypoints.clear();
1374  return false;
1375  }
1376  }
1377  else
1378  {
1379  yCError(NAVIGATION2DCLIENT) << "getCurrentPosition() error on writing on rpc port";
1380  return false;
1381  }
1382  return true;
1383 }
1384 
1386 {
1387  yarp::os::Bottle b;
1388  yarp::os::Bottle resp;
1389 
1392 
1393  bool ret = m_rpc_port_navigation_server.write(b, resp);
1394  if (ret)
1395  {
1396  if (resp.get(0).asVocab() != VOCAB_OK)
1397  {
1398  yCError(NAVIGATION2DCLIENT) << "getCurrentNavigationWaypoint() received error from navigation server";
1399  return false;
1400  }
1401  else if (resp.size() == 5)
1402  {
1403  curr_waypoint.map_id = resp.get(1).asString();
1404  curr_waypoint.x = resp.get(2).asFloat64();
1405  curr_waypoint.y = resp.get(3).asFloat64();
1406  curr_waypoint.theta = resp.get(4).asFloat64();
1407  return true;
1408  }
1409  else
1410  {
1411  //not available
1412  curr_waypoint.map_id = "invalid";
1413  curr_waypoint.x = std::nan("");
1414  curr_waypoint.y = std::nan("");
1415  curr_waypoint.theta = std::nan("");
1416  return false;
1417  }
1418  }
1419  else
1420  {
1421  yCError(NAVIGATION2DCLIENT) << "getCurrentPosition() error on writing on rpc port";
1422  return false;
1423  }
1424  return true;
1425 }
1426 
1428 {
1429  yarp::os::Bottle b;
1430  yarp::os::Bottle resp;
1431 
1434  b.addVocab(map_type);
1435 
1436  bool ret = m_rpc_port_navigation_server.write(b, resp);
1437  if (ret)
1438  {
1439  if (resp.get(0).asVocab() != VOCAB_OK)
1440  {
1441  yCError(NAVIGATION2DCLIENT) << "getCurrentNavigationMap() received error from server";
1442  return false;
1443  }
1444  else
1445  {
1446  Value& b = resp.get(1);
1447  if (Property::copyPortable(b, map))
1448  {
1449  return true;
1450  }
1451  else
1452  {
1453  yCError(NAVIGATION2DCLIENT) << "getCurrentNavigationMap() failed copyPortable()";
1454  return false;
1455  }
1456  }
1457  }
1458  else
1459  {
1460  yCError(NAVIGATION2DCLIENT) << "getCurrentNavigationMap() error on writing on rpc port";
1461  return false;
1462  }
1463  return true;
1464 }
1465 
1467 {
1468  yarp::os::Bottle b;
1469  yarp::os::Bottle resp;
1470 
1473 
1474  bool ret = m_rpc_port_localization_server.write(b, resp);
1475  if (ret)
1476  {
1477  if (resp.get(0).asVocab() != VOCAB_OK || resp.size() != 2)
1478  {
1479  yCError(NAVIGATION2DCLIENT) << "getLocalizationStatus() received error from localization server";
1480  return false;
1481  }
1482  else
1483  {
1485  return true;
1486  }
1487  }
1488  else
1489  {
1490  yCError(NAVIGATION2DCLIENT) << "getLocalizationStatus() error on writing on rpc port";
1491  return false;
1492  }
1493  return true;
1494 }
1495 
1496 bool Navigation2DClient::applyVelocityCommand(double x_vel, double y_vel, double theta_vel, double timeout)
1497 {
1498  yarp::os::Bottle b;
1499  yarp::os::Bottle resp;
1500 
1503  b.addFloat64(x_vel);
1504  b.addFloat64(y_vel);
1505  b.addFloat64(theta_vel);
1506  b.addFloat64(timeout);
1507 
1508  bool ret = m_rpc_port_navigation_server.write(b, resp);
1509  if (ret)
1510  {
1511  if (resp.get(0).asVocab() != VOCAB_OK)
1512  {
1513  yCError(NAVIGATION2DCLIENT) << "applyVelocityCommand() received error from navigation server";
1514  return false;
1515  }
1516  }
1517  else
1518  {
1519  yCError(NAVIGATION2DCLIENT) << "applyVelocityCommand() error on writing on rpc port";
1520  return false;
1521  }
1522 
1523  reset_current_goal_name();
1524  return true;
1525 }
1526 
1527 bool Navigation2DClient::getEstimatedPoses(std::vector<Map2DLocation>& poses)
1528 {
1529  yarp::os::Bottle b;
1530  yarp::os::Bottle resp;
1531 
1534 
1535  bool ret = m_rpc_port_localization_server.write(b, resp);
1536  if (ret)
1537  {
1538  if (resp.get(0).asVocab() != VOCAB_OK)
1539  {
1540  yCError(NAVIGATION2DCLIENT) << "getEstimatedPoses() received error from localization server";
1541  return false;
1542  }
1543  else
1544  {
1545  int nposes = resp.get(1).asInt32();
1546  poses.clear();
1547  for (int i = 0; i < nposes; i++)
1548  {
1549  Map2DLocation loc;
1550  Bottle* b = resp.get(2 + i).asList();
1551  if (b)
1552  {
1553  loc.map_id = b->get(0).asString();
1554  loc.x = b->get(1).asFloat64();
1555  loc.y = b->get(2).asFloat64();
1556  loc.theta = b->get(3).asFloat64();
1557  }
1558  else
1559  {
1560  poses.clear();
1561  yCError(NAVIGATION2DCLIENT) << "getEstimatedPoses() parsing error";
1562  return false;
1563  }
1564  poses.push_back(loc);
1565  }
1566  return true;
1567  }
1568  }
1569  else
1570  {
1571  yCError(NAVIGATION2DCLIENT) << "getEstimatedPoses() error on writing on rpc port";
1572  return false;
1573  }
1574  return true;
1575 }
1576 
1577 //this function receives an angle from (-inf,+inf) and returns an angle in (0,180) or (-180,0)
1578 double Navigation2DClient::normalize_angle(double angle)
1579 {
1580  angle = std::remainder(angle, 360);
1581 
1582  if (angle > 180 && angle < 360)
1583  {
1584  angle = angle - 360;
1585  }
1586 
1587  if (angle<-180 && angle>-360)
1588  {
1589  angle = angle + 360;
1590  }
1591  return angle;
1592 }
1593 
1595 {
1596  yarp::os::Bottle b;
1597  yarp::os::Bottle resp;
1598 
1601 
1602  bool ret = m_rpc_port_localization_server.write(b, resp);
1603  if (ret)
1604  {
1605  if (resp.get(0).asVocab() != VOCAB_OK)
1606  {
1607  yCError(NAVIGATION2DCLIENT) << "startLocalizationService() received error from navigation server";
1608  return false;
1609  }
1610  }
1611  else
1612  {
1613  yCError(NAVIGATION2DCLIENT) << "startLocalizationService() error on writing on rpc port";
1614  return false;
1615  }
1616  return true;
1617 }
1618 
1620 {
1621  yarp::os::Bottle b;
1622  yarp::os::Bottle resp;
1623 
1626 
1627  bool ret = m_rpc_port_localization_server.write(b, resp);
1628  if (ret)
1629  {
1630  if (resp.get(0).asVocab() != VOCAB_OK)
1631  {
1632  yCError(NAVIGATION2DCLIENT) << "stopLocalizationService() received error from navigation server";
1633  return false;
1634  }
1635  }
1636  else
1637  {
1638  yCError(NAVIGATION2DCLIENT) << "stopLocalizationService() error on writing on rpc port";
1639  return false;
1640  }
1641  return true;
1642 }
LogStream.h
INavigation2D.h
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
Navigation2DClient::gotoTargetByAbsoluteLocation
bool gotoTargetByAbsoluteLocation(yarp::dev::Nav2D::Map2DLocation loc) override
Ask the robot to reach a position defined in the world reference frame.
Definition: Navigation2DClient.cpp:556
yarp::os::Value::asVocab
virtual std::int32_t asVocab() const
Get vocabulary identifier as an integer.
Definition: Value.cpp:231
Navigation2DClient::getNavigationStatus
bool getNavigationStatus(yarp::dev::Nav2D::NavigationStatusEnum &status) override
Gets the current status of the navigation task.
Definition: Navigation2DClient.cpp:526
Navigation2DClient::getAbsoluteLocationOfCurrentTarget
bool getAbsoluteLocationOfCurrentTarget(yarp::dev::Nav2D::Map2DLocation &loc) override
Gets the last navigation target in the world reference frame.
Definition: Navigation2DClient.cpp:947
yarp::sig::Matrix::toString
std::string toString(int precision=-1, int width=-1, const char *endRowStr="\n") const
Print matrix to a string.
Definition: Matrix.cpp:167
yarp::os::Bottle::clear
void clear()
Empties the bottle of any objects it contains.
Definition: Bottle.cpp:124
VOCAB_NAV_GET_CURRENT_POS
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_CURRENT_POS
Definition: ILocalization2D.h:122
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
VOCAB_NAV_GET_LOCALIZER_POSES
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_LOCALIZER_POSES
Definition: ILocalization2D.h:130
yarp::os::Bottle::size
size_type size() const
Gets the number of elements in the bottle.
Definition: Bottle.cpp:254
VOCAB_NAV_GET_ABS_TARGET
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_ABS_TARGET
Definition: ILocalization2D.h:119
yarp::dev::Map2DLocationData::y
double y
Definition: Map2DLocationData.h:32
Navigation2DClient::getRelativeLocationOfCurrentTarget
bool getRelativeLocationOfCurrentTarget(double &x, double &y, double &theta) override
Gets the last navigation target in the robot reference frame.
Definition: Navigation2DClient.cpp:994
yarp::sig
Signal processing.
Definition: Image.h:25
t
float t
Definition: FfmpegWriter.cpp:74
Navigation2DClient::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: Navigation2DClient.cpp:62
Navigation2DClient::storeLocation
bool storeLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation loc) override
Store a location specified by the user in the world reference frame.
Definition: Navigation2DClient.cpp:1084
Navigation2DClient::suspendNavigation
bool suspendNavigation(const double time_s) override
Ask to the robot to suspend the current navigation task for a defined amount of time.
Definition: Navigation2DClient.cpp:921
VOCAB_NAV_LOCATION
constexpr yarp::conf::vocab32_t VOCAB_NAV_LOCATION
Definition: ILocalization2D.h:136
yCWarning
#define yCWarning(component,...)
Definition: LogComponent.h:146
VOCAB_NAV_SUSPEND
constexpr yarp::conf::vocab32_t VOCAB_NAV_SUSPEND
Definition: INavigation2D.h:308
Navigation2DClient::stopLocalizationService
bool stopLocalizationService() override
Stops the localization service.
Definition: Navigation2DClient.cpp:1619
yarp::dev::Nav2D::Map2DLocation::toString
std::string toString() const
Returns text representation of the location.
Definition: Map2DLocation.h:77
Navigation2DClient::recomputeCurrentNavigationPath
bool recomputeCurrentNavigationPath() override
Forces the navigation system to recompute the path from the current robot position to the current goa...
Definition: Navigation2DClient.cpp:751
Navigation2DClient::getAllNavigationWaypoints
bool getAllNavigationWaypoints(yarp::dev::Nav2D::TrajectoryTypeEnum trajectory_type, yarp::dev::Nav2D::Map2DPath &waypoints) override
Returns the list of waypoints generated by the navigation algorithm.
Definition: Navigation2DClient.cpp:1335
YARP_LOG_COMPONENT
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:80
yarp::dev::Nav2D::TrajectoryTypeEnum
TrajectoryTypeEnum
Definition: INavigation2D.h:52
VOCAB_NAV_DELETE_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_DELETE_X
Definition: ILocalization2D.h:132
yarp::sig::Matrix::rows
size_t rows() const
Return number of rows.
Definition: Matrix.h:95
Navigation2DClient::checkInsideArea
virtual bool checkInsideArea(yarp::dev::Nav2D::Map2DArea area) override
Check if the robot is currently inside the specified area.
Definition: Navigation2DClient.cpp:617
Navigation2DClient::getEstimatedPoses
bool getEstimatedPoses(std::vector< yarp::dev::Nav2D::Map2DLocation > &poses) override
Gets a set of pose estimates computed by the localization algorithm.
Definition: Navigation2DClient.cpp:1527
yarp::dev::Nav2D::Map2DArea::getRandomLocation
bool getRandomLocation(yarp::dev::Nav2D::Map2DLocation &loc)
get a random Map2DLocation inside the Map2DArea @loc the computed Map2DLocation
Definition: Map2DArea.cpp:205
VOCAB_NAV_GET_CURRENT_WAYPOINT
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_CURRENT_WAYPOINT
Definition: INavigation2D.h:311
Navigation2DClient::parse_respond_string
bool parse_respond_string(const yarp::os::Bottle &command, yarp::os::Bottle &reply)
Definition: Navigation2DClient.cpp:189
Navigation2DClient::gotoTargetByLocationName
bool gotoTargetByLocationName(std::string location_name) override
Ask the robot to reach a previously stored location/area.
Definition: Navigation2DClient.cpp:660
yarp::dev::Nav2D::LocalizationStatusEnum
LocalizationStatusEnum
Definition: ILocalization2D.h:25
yarp::dev::Nav2D::NavigationStatusEnum
NavigationStatusEnum
Definition: INavigation2D.h:32
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
Navigation2DClient::getLocation
bool getLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation &loc) override
Retrieves a location previously stored by the user.
Definition: Navigation2DClient.cpp:1159
VOCAB_NAV_CLEAR_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_CLEAR_X
Definition: ILocalization2D.h:131
yarp::os::Bottle::addFloat64
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
Definition: Bottle.cpp:161
yarp::dev::Map2DLocationData::theta
double theta
Definition: Map2DLocationData.h:33
VOCAB_NAV_VELOCITY_CMD
constexpr yarp::conf::vocab32_t VOCAB_NAV_VELOCITY_CMD
Definition: ILocalization2D.h:114
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::dev::OdometryData
Definition: OdometryData.h:27
Navigation2DClient::applyVelocityCommand
bool applyVelocityCommand(double x_vel, double y_vel, double theta_vel, double timeout=0.1) override
Apply a velocity command.
Definition: Navigation2DClient.cpp:1496
Navigation2DClient::getCurrentNavigationMap
bool getCurrentNavigationMap(yarp::dev::Nav2D::NavigationMapTypeEnum map_type, yarp::dev::Nav2D::MapGrid2D &map) override
Returns the current navigation map processed by the navigation algorithm.
Definition: Navigation2DClient.cpp:1427
Navigation2DClient::getLocationsList
bool getLocationsList(std::vector< std::string > &locations) override
Get a list of all stored locations.
Definition: Navigation2DClient.cpp:1115
Navigation2DClient::stopNavigation
bool stopNavigation() override
Terminates the current navigation task.
Definition: Navigation2DClient.cpp:1285
Navigation2DClient::setInitialPose
bool setInitialPose(const yarp::dev::Nav2D::Map2DLocation &loc) override
Sets the initial pose for the localization algorithm which estimates the current position of the robo...
Definition: Navigation2DClient.cpp:776
VOCAB_NAV_GET_LIST_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_LIST_X
Definition: ILocalization2D.h:118
yarp::sig::VectorOf< double >
Navigation2DClient::getLocalizationStatus
bool getLocalizationStatus(yarp::dev::Nav2D::LocalizationStatusEnum &status) override
Gets the current status of the localization task.
Definition: Navigation2DClient.cpp:1466
VOCAB_NAV_GOTOABS
constexpr yarp::conf::vocab32_t VOCAB_NAV_GOTOABS
Definition: ILocalization2D.h:112
Log.h
yarp::os::Value::isString
virtual bool isString() const
Checks if value is a string.
Definition: Value.cpp:159
VOCAB_NAV_GET_NAVIGATION_WAYPOINTS
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_NAVIGATION_WAYPOINTS
Definition: INavigation2D.h:310
VOCAB_NAV_GET_NAV_MAP
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_NAV_MAP
Definition: INavigation2D.h:312
yarp::os::Bottle::get
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition: Bottle.cpp:249
VOCAB_NAV_GET_NAVIGATION_STATUS
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_NAVIGATION_STATUS
Definition: ILocalization2D.h:128
yarp::os::Bottle::addList
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
Definition: Bottle.cpp:185
yarp::os::Bottle::write
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
Definition: Bottle.cpp:233
yarp::dev::Nav2D::MapGrid2D
Definition: MapGrid2D.h:32
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
Navigation2DClient::gotoTargetByRelativeLocation
bool gotoTargetByRelativeLocation(double x, double y, double theta) override
Ask the robot to reach a position defined in the robot reference frame.
Definition: Navigation2DClient.cpp:721
yarp::dev::Nav2D::Map2DPath::push_back
void push_back(yarp::dev::Nav2D::Map2DLocation loc)
Inserts a new location into the path @loc the location to be inserted.
Definition: Map2DPath.cpp:127
yarp::os::Value::asString
virtual std::string asString() const
Get string value.
Definition: Value.cpp:237
VOCAB_NAV_GET_REL_TARGET
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_REL_TARGET
Definition: ILocalization2D.h:120
VOCAB_NAV_AREA
constexpr yarp::conf::vocab32_t VOCAB_NAV_AREA
Definition: ILocalization2D.h:135
Navigation2DClient::getEstimatedOdometry
bool getEstimatedOdometry(yarp::dev::OdometryData &odom) override
Gets the estimated odometry the robot, including its velocity expressed in the world and in the local...
Definition: Navigation2DClient.cpp:882
VOCAB_NAV_GET_LOCALIZER_STATUS
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_LOCALIZER_STATUS
Definition: ILocalization2D.h:129
VOCAB_NAV_GET_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_X
Definition: ILocalization2D.h:117
yarp::os::Searchable::check
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
VOCAB_NAV_LOCALIZATION_START
constexpr yarp::conf::vocab32_t VOCAB_NAV_LOCALIZATION_START
Definition: ILocalization2D.h:126
yarp::os::Searchable::find
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
yarp::os::Vocab::encode
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
Definition: Vocab.cpp:14
yarp::dev::Nav2D::Map2DPath::clear
void clear()
Remove all elements from the path.
Definition: Map2DPath.cpp:58
yarp::os::ConnectionReader::getWriter
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
Navigation2DClient::read
virtual bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Navigation2DClient.cpp:500
yarp::dev::Nav2D::Map2DPath
Definition: Map2DPath.h:27
yarp::dev::Nav2D
Definition: ILocalization2D.h:21
yarp::os::Bottle::addString
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition: Bottle.cpp:173
VOCAB_NAV_SET_INITIAL_POSCOV
constexpr yarp::conf::vocab32_t VOCAB_NAV_SET_INITIAL_POSCOV
Definition: ILocalization2D.h:125
yarp::sig::Matrix::cols
size_t cols() const
Return number of columns.
Definition: Matrix.h:101
Navigation2DClient.h
yarp::os::Bottle::addVocab
void addVocab(int x)
Places a vocabulary item in the bottle, at the end of the list.
Definition: Bottle.cpp:167
VOCAB_NAV_GET_CURRENT_POSCOV
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_CURRENT_POSCOV
Definition: ILocalization2D.h:124
LogComponent.h
yarp::sig::Matrix::resize
void resize(size_t r, size_t c)
Resize the matrix, if matrix is not empty preserve old content.
Definition: Matrix.cpp:251
yarp::os::Value::isList
virtual bool isList() const
Checks if value is a list.
Definition: Value.cpp:165
Navigation2DClient::close
bool close() override
Close the DeviceDriver.
Definition: Navigation2DClient.cpp:180
Navigation2DClient::deleteLocation
bool deleteLocation(std::string location_name) override
Delete a location.
Definition: Navigation2DClient.cpp:1232
VOCAB_ERR
constexpr yarp::conf::vocab32_t VOCAB_ERR
Definition: GenericVocabs.h:20
yarp::dev::Nav2D::Map2DLocation
Definition: Map2DLocation.h:30
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yCError
#define yCError(component,...)
Definition: LogComponent.h:157
Navigation2DClient::storeCurrentPosition
bool storeCurrentPosition(std::string location_name) override
Store the current location of the robot.
Definition: Navigation2DClient.cpp:1026
VOCAB_NAV_RESUME
constexpr yarp::conf::vocab32_t VOCAB_NAV_RESUME
Definition: INavigation2D.h:309
yarp::os::Value::asInt32
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition: Value.cpp:207
yarp::dev::Nav2D::NavigationMapTypeEnum
NavigationMapTypeEnum
Definition: INavigation2D.h:46
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
yCDebug
#define yCDebug(component,...)
Definition: LogComponent.h:112
yarp::dev::Nav2D::INavigation2DHelpers::statusToString
std::string statusToString(NavigationStatusEnum status)
Definition: INavigation2D.cpp:11
Navigation2DClient::startLocalizationService
bool startLocalizationService() override
Starts the localization service.
Definition: Navigation2DClient.cpp:1594
VOCAB_NAV_STOP
constexpr yarp::conf::vocab32_t VOCAB_NAV_STOP
Definition: INavigation2D.h:307
VOCAB_NAV_STORE_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_STORE_X
Definition: ILocalization2D.h:134
Navigation2DClient::checkNearToLocation
virtual bool checkNearToLocation(yarp::dev::Nav2D::Map2DLocation loc, double linear_tolerance, double angular_tolerance=std::numeric_limits< double >::infinity()) override
Check if the robot is currently near to the specified area.
Definition: Navigation2DClient.cpp:586
VOCAB_NAV_RECOMPUTE_PATH
constexpr yarp::conf::vocab32_t VOCAB_NAV_RECOMPUTE_PATH
Definition: ILocalization2D.h:115
yarp::os::Bottle::read
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Definition: Bottle.cpp:243
yarp::os::Value::asList
virtual Bottle * asList() const
Get list value.
Definition: Value.cpp:243
yarp::dev::Nav2D::Map2DArea
Definition: Map2DArea.h:30
yarp::dev::Map2DLocationData::x
double x
Definition: Map2DLocationData.h:31
Navigation2DClient::getArea
bool getArea(std::string area_name, yarp::dev::Nav2D::Map2DArea &area) override
Retrieves an area previously stored by the user.
Definition: Navigation2DClient.cpp:1193
VOCAB_NAV_GOTOREL
constexpr yarp::conf::vocab32_t VOCAB_NAV_GOTOREL
Definition: ILocalization2D.h:113
Navigation2DClient::getCurrentPosition
bool getCurrentPosition(yarp::dev::Nav2D::Map2DLocation &loc) override
Gets the current position of the robot w.r.t world reference frame.
Definition: Navigation2DClient.cpp:888
Navigation2DClient::getNameOfCurrentTarget
bool getNameOfCurrentTarget(std::string &location_name) override
Gets the name of the current target, if available (set by gotoTargetByLocationName)
Definition: Navigation2DClient.cpp:980
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:47
VOCAB_NAV_LOCALIZATION_STOP
constexpr yarp::conf::vocab32_t VOCAB_NAV_LOCALIZATION_STOP
Definition: ILocalization2D.h:127
yarp::dev::Map2DLocationData::map_id
std::string map_id
Definition: Map2DLocationData.h:30
Navigation2DClient::clearAllLocations
bool clearAllLocations() override
Delete all stored locations.
Definition: Navigation2DClient.cpp:1259
yarp::os::Value::asFloat64
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition: Value.cpp:225
VOCAB_OK
constexpr yarp::conf::vocab32_t VOCAB_OK
Definition: GenericVocabs.h:18
VOCAB_INAVIGATION
constexpr yarp::conf::vocab32_t VOCAB_INAVIGATION
Definition: ILocalization2D.h:110
yarp::dev::Nav2D::Map2DArea::checkLocationInsideArea
bool checkLocationInsideArea(yarp::dev::Nav2D::Map2DLocation loc)
Check if a Map2DLocation is inside a Map2DArea.
Definition: Map2DArea.cpp:150
Navigation2DClient::resumeNavigation
bool resumeNavigation() override
Resume a previously suspended navigation task.
Definition: Navigation2DClient.cpp:1310
VOCAB_NAV_SET_INITIAL_POS
constexpr yarp::conf::vocab32_t VOCAB_NAV_SET_INITIAL_POS
Definition: ILocalization2D.h:123
yarp::sig::Matrix
A class for a Matrix.
Definition: Matrix.h:46
yarp::dev::Nav2D::Map2DLocation::is_near_to
bool is_near_to(const Map2DLocation &other_loc, double linear_tolerance, double angular_tolerance) const
Compares two Map2DLocations.
Definition: Map2DLocation.cpp:19
Navigation2DClient::getCurrentNavigationWaypoint
bool getCurrentNavigationWaypoint(yarp::dev::Nav2D::Map2DLocation &curr_waypoint) override
Returns the current waypoint pursued by the navigation algorithm.
Definition: Navigation2DClient.cpp:1385