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