YARP
Yet Another Robot Platform
Map2DServer.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 <sstream>
20 #include <limits>
21 #include "Map2DServer.h"
22 #include <yarp/dev/IMap2D.h>
23 #include <yarp/dev/INavigation2D.h>
24 #include <yarp/dev/GenericVocabs.h>
25 #include <yarp/math/Math.h>
26 #include <yarp/os/Log.h>
27 #include <yarp/os/LogComponent.h>
28 #include <yarp/os/LogStream.h>
29 #include <mutex>
30 #include <cstdlib>
31 #include <fstream>
32 #include <yarp/os/Publisher.h>
33 #include <yarp/os/Subscriber.h>
34 #include <yarp/os/Node.h>
36 #include <yarp/rosmsg/TickTime.h>
37 
38 using namespace yarp::sig;
39 using namespace yarp::dev;
40 using namespace yarp::dev::Nav2D;
41 using namespace yarp::os;
42 using namespace std;
43 
44 namespace {
45 YARP_LOG_COMPONENT(MAP2DSERVER, "yarp.device.map2DServer")
46 }
47 
53 {
54  m_enable_publish_ros_map = false;
55  m_enable_subscribe_ros_map = false;
56  m_rosNode = nullptr;
57 }
58 
59 Map2DServer::~Map2DServer() = default;
60 
61 void Map2DServer::parse_vocab_command(yarp::os::Bottle& in, yarp::os::Bottle& out)
62 {
63  int code = in.get(0).asVocab();
64 // bool ret = false;
65  if (code == VOCAB_IMAP)
66  {
67  int cmd = in.get(1).asVocab();
68  if (cmd == VOCAB_IMAP_SET_MAP)
69  {
70  MapGrid2D the_map;
71  Value& b = in.get(2);
72  if (Property::copyPortable(b, the_map))
73  {
74  string map_name = the_map.getMapName();
75  auto it = m_maps_storage.find(map_name);
76  if (it == m_maps_storage.end())
77  {
78  //add a new map
79  m_maps_storage[map_name] = the_map;
80  out.clear();
82  }
83  else
84  {
85  //the map already exists
86  m_maps_storage[map_name] = the_map;
87  out.clear();
89  }
90  }
91  else
92  {
93  out.clear();
95  yCError(MAP2DSERVER) << "Error in copyPortable";
96  }
97  }
98  else if (cmd == VOCAB_IMAP_GET_MAP)
99  {
100  string name = in.get(2).asString();
101  auto it = m_maps_storage.find(name);
102  if (it != m_maps_storage.end())
103  {
104  out.clear();
105  out.addVocab(VOCAB_IMAP_OK);
106  yarp::os::Bottle& mapbot = out.addList();
107  Property::copyPortable(it->second, mapbot);
108  }
109  else
110  {
111  out.clear();
113  yCError(MAP2DSERVER) << "Map" << name << "not found";
114  }
115  }
116  else if (cmd == VOCAB_IMAP_GET_NAMES)
117  {
118  out.clear();
119  out.addVocab(VOCAB_IMAP_OK);
120 
121  for (auto& it : m_maps_storage)
122  {
123  out.addString(it.first);
124  }
125  }
126  else if (cmd == VOCAB_IMAP_REMOVE)
127  {
128  string name = in.get(2).asString();
129  size_t rem = m_maps_storage.erase(name);
130  if (rem == 0)
131  {
132  yCError(MAP2DSERVER) << "Map not found";
133  out.clear();
135  }
136  else
137  {
138  out.clear();
139  out.addVocab(VOCAB_IMAP_OK);
140  }
141  }
142  else if (cmd == VOCAB_IMAP_CLEAR)
143  {
144  m_maps_storage.clear();
145  out.clear();
146  out.addVocab(VOCAB_IMAP_OK);
147  }
148  else if (cmd == VOCAB_IMAP_SAVE_COLLECTION)
149  {
150  string mapfile = in.get(2).asString();
151  if (saveMaps(mapfile))
152  {
153  out.clear();
154  out.addVocab(VOCAB_IMAP_OK);
155  }
156  else
157  {
158  yCError(MAP2DSERVER, "Unable to save collection");
159  out.clear();
161  }
162  }
163  else if (cmd == VOCAB_IMAP_LOAD_COLLECTION)
164  {
165  string mapfile = in.get(2).asString();
166  if (loadMaps(mapfile))
167  {
168  out.clear();
169  out.addVocab(VOCAB_IMAP_OK);
170  }
171  else
172  {
173  yCError(MAP2DSERVER, "Unable to load collection");
174  out.clear();
176  }
177  }
178  else
179  {
180  yCError(MAP2DSERVER, "Invalid vocab received in Map2DServer");
181  out.clear();
183  }
184  }
185  else if (code == VOCAB_INAVIGATION)
186  {
187  int cmd = in.get(1).asVocab();
188  if (cmd == VOCAB_NAV_GET_LIST_X && in.get(2).asVocab() == VOCAB_NAV_LOCATION)
189  {
190  std::string info;
191 
192  out.addVocab(VOCAB_OK);
193  Bottle& l = out.addList();
194 
195  std::map<std::string, Map2DLocation>::iterator it;
196  for (it = m_locations_storage.begin(); it != m_locations_storage.end(); ++it)
197  {
198  l.addString(it->first);
199  }
200  yCInfo(MAP2DSERVER) << "The following locations are currently stored in the server:" << l.toString();
201 // ret = true;
202  }
203  else if (cmd == VOCAB_NAV_GET_LIST_X && in.get(2).asVocab() == VOCAB_NAV_AREA)
204  {
205  std::string info;
206 
207  out.addVocab(VOCAB_OK);
208  Bottle& l = out.addList();
209 
210  std::map<std::string, Map2DArea>::iterator it;
211  for (it = m_areas_storage.begin(); it != m_areas_storage.end(); ++it)
212  {
213  l.addString(it->first);
214  }
215  yCInfo(MAP2DSERVER) << "The following areas are currently stored in the server:" << l.toString();
216 // ret = true;
217  }
218  else if (cmd == VOCAB_NAV_GET_LIST_X && in.get(2).asVocab() == VOCAB_NAV_PATH)
219  {
220  std::string info;
221 
222  out.addVocab(VOCAB_OK);
223  Bottle& l = out.addList();
224 
225  std::map<std::string, Map2DPath>::iterator it;
226  for (it = m_paths_storage.begin(); it != m_paths_storage.end(); ++it)
227  {
228  l.addString(it->first);
229  }
230  yCInfo(MAP2DSERVER) << "The following paths are currently stored in the server: " << l.toString();
231  // ret = true;
232  }
233  else if (cmd == VOCAB_NAV_CLEAR_X && in.get(2).asVocab() == VOCAB_NAV_LOCATION)
234  {
235  m_locations_storage.clear();
236  yCInfo(MAP2DSERVER) << "All locations deleted";
237  out.addVocab(VOCAB_OK);
238 // ret = true;
239  }
240  else if (cmd == VOCAB_NAV_CLEAR_X && in.get(2).asVocab() == VOCAB_NAV_AREA)
241  {
242  m_areas_storage.clear();
243  yCInfo(MAP2DSERVER) << "All areas deleted";
244  out.addVocab(VOCAB_OK);
245  // ret = true;
246  }
247  else if (cmd == VOCAB_NAV_CLEAR_X && in.get(2).asVocab() == VOCAB_NAV_PATH)
248  {
249  m_paths_storage.clear();
250  yCInfo(MAP2DSERVER) << "All paths deleted";
251  out.addVocab(VOCAB_OK);
252  // ret = true;
253  }
254  else if (cmd == VOCAB_NAV_DELETE_X && in.get(2).asVocab() == VOCAB_NAV_LOCATION)
255  {
256  std::string name = in.get(3).asString();
257 
258  std::map<std::string, Map2DLocation>::iterator it;
259  it = m_locations_storage.find(name);
260  if (it != m_locations_storage.end())
261  {
262  yCInfo(MAP2DSERVER) << "Deleted location" << name;
263  m_locations_storage.erase(it);
264  out.addVocab(VOCAB_OK);
265  }
266  else
267  {
268  yCError(MAP2DSERVER, "User requested an invalid location name");
269  out.addVocab(VOCAB_ERR);
270  }
271 
272 // ret = true;
273  }
274  else if (cmd == VOCAB_NAV_DELETE_X && in.get(2).asVocab() == VOCAB_NAV_PATH)
275  {
276  std::string name = in.get(3).asString();
277 
278  std::map<std::string, Map2DPath>::iterator it;
279  it = m_paths_storage.find(name);
280  if (it != m_paths_storage.end())
281  {
282  yCInfo(MAP2DSERVER) << "Deleted path" << name;
283  m_paths_storage.erase(it);
284  out.addVocab(VOCAB_OK);
285  }
286  else
287  {
288  yCError(MAP2DSERVER, "User requested an invalid location name");
289  out.addVocab(VOCAB_ERR);
290  }
291 
292  // ret = true;
293  }
294  else if (cmd == VOCAB_NAV_RENAME_X && in.get(2).asVocab() == VOCAB_NAV_LOCATION)
295  {
296  std::string orig_name = in.get(3).asString();
297  std::string new_name = in.get(4).asString();
298 
299  std::map<std::string, Map2DLocation>::iterator orig_it;
300  orig_it = m_locations_storage.find(orig_name);
301  std::map<std::string, Map2DLocation>::iterator new_it;
302  new_it = m_locations_storage.find(new_name);
303 
304  if (orig_it != m_locations_storage.end() &&
305  new_it == m_locations_storage.end())
306  {
307  yCInfo(MAP2DSERVER) << "Location:" << orig_name << "renamed to:" << new_name;
308  auto loc = orig_it->second;
309  m_locations_storage.erase(orig_it);
310  m_locations_storage.insert(std::pair<std::string, Map2DLocation>(new_name, loc));
311  out.addVocab(VOCAB_OK);
312  }
313  else
314  {
315  yCError(MAP2DSERVER, "User requested an invalid rename operation");
316  out.addVocab(VOCAB_ERR);
317  }
318  // ret = true;
319  }
320  else if (cmd == VOCAB_NAV_RENAME_X && in.get(2).asVocab() == VOCAB_NAV_AREA)
321  {
322  std::string orig_name = in.get(3).asString();
323  std::string new_name = in.get(4).asString();
324 
325  std::map<std::string, Map2DArea>::iterator orig_it;
326  orig_it = m_areas_storage.find(orig_name);
327  std::map<std::string, Map2DArea>::iterator new_it;
328  new_it = m_areas_storage.find(new_name);
329 
330  if (orig_it != m_areas_storage.end() &&
331  new_it == m_areas_storage.end())
332  {
333  yCInfo(MAP2DSERVER) << "Area:" << orig_name << "renamed to:" << new_name;
334  auto area = orig_it->second;
335  m_areas_storage.erase(orig_it);
336  m_areas_storage.insert(std::pair<std::string, Map2DArea>(new_name,area));
337  out.addVocab(VOCAB_OK);
338  }
339  else
340  {
341  yCError(MAP2DSERVER, "User requested an invalid rename operation");
342  out.addVocab(VOCAB_ERR);
343  }
344 // ret = true;
345  }
346  else if (cmd == VOCAB_NAV_RENAME_X && in.get(2).asVocab() == VOCAB_NAV_PATH)
347  {
348  std::string orig_name = in.get(3).asString();
349  std::string new_name = in.get(4).asString();
350 
351  std::map<std::string, Map2DPath>::iterator orig_it;
352  orig_it = m_paths_storage.find(orig_name);
353  std::map<std::string, Map2DPath>::iterator new_it;
354  new_it = m_paths_storage.find(new_name);
355 
356  if (orig_it != m_paths_storage.end() &&
357  new_it == m_paths_storage.end())
358  {
359  yCInfo(MAP2DSERVER) << "Path:" << orig_name << "renamed to:" << new_name;
360  auto area = orig_it->second;
361  m_paths_storage.erase(orig_it);
362  m_paths_storage.insert(std::pair<std::string, Map2DPath>(new_name, area));
363  out.addVocab(VOCAB_OK);
364  }
365  else
366  {
367  yCError(MAP2DSERVER, "User requested an invalid rename operation");
368  out.addVocab(VOCAB_ERR);
369  }
370  // ret = true;
371  }
372  else if (cmd == VOCAB_NAV_DELETE_X && in.get(2).asVocab() == VOCAB_NAV_AREA)
373  {
374  std::string name = in.get(3).asString();
375 
376  std::map<std::string, Map2DArea>::iterator it;
377  it = m_areas_storage.find(name);
378  if (it != m_areas_storage.end())
379  {
380  yCInfo(MAP2DSERVER) << "Deleted area" << name;
381  m_areas_storage.erase(it);
382  out.addVocab(VOCAB_OK);
383  }
384  else
385  {
386  yCError(MAP2DSERVER, "User requested an invalid area name");
387  out.addVocab(VOCAB_ERR);
388  }
389 
390  // ret = true;
391  }
392  else if (cmd == VOCAB_NAV_GET_X && in.get(2).asVocab() == VOCAB_NAV_LOCATION)
393  {
394  std::string name = in.get(3).asString();
395 
396  std::map<std::string, Map2DLocation>::iterator it;
397  it = m_locations_storage.find(name);
398  if (it != m_locations_storage.end())
399  {
400  out.addVocab(VOCAB_OK);
401  Map2DLocation loc = it->second;
402  yCInfo(MAP2DSERVER) << "Retrieved location" << name << "at" << loc.toString();
403  out.addString(loc.map_id);
404  out.addFloat64(loc.x);
405  out.addFloat64(loc.y);
406  out.addFloat64(loc.theta);
407  }
408  else
409  {
410  out.addVocab(VOCAB_ERR);
411  yCError(MAP2DSERVER, "User requested an invalid location name");
412  }
413  //ret = true;
414  }
415  else if (cmd == VOCAB_NAV_GET_X && in.get(2).asVocab() == VOCAB_NAV_AREA)
416  {
417  std::string area_name = in.get(3).asString();
418 
419  std::map<std::string, Map2DArea>::iterator it;
420  it = m_areas_storage.find(area_name);
421  if (it != m_areas_storage.end())
422  {
423  Map2DArea area = it->second;
424  yarp::os::Bottle areabot;
425  Map2DArea areatemp = area;
426  if (Property::copyPortable(areatemp, areabot) == false)
427  {
428  yCError(MAP2DSERVER) << "VOCAB_NAV_GET_X VOCAB_NAV_AREA failed copyPortable()";
429  out.addVocab(VOCAB_ERR);
430  }
431  else
432  {
433  yCInfo(MAP2DSERVER) << "Retrieved area" << area_name << "at" << area.toString();
434  out.addVocab(VOCAB_OK);
435 
436  yarp::os::Bottle& areabot = out.addList();
437  Property::copyPortable(areatemp, areabot);
438  }
439  }
440  else
441  {
442  out.addVocab(VOCAB_ERR);
443  yCError(MAP2DSERVER, "User requested an invalid area name");
444  }
445  //ret = true;
446  }
447  else if (cmd == VOCAB_NAV_GET_X && in.get(2).asVocab() == VOCAB_NAV_PATH)
448  {
449  std::string path_name = in.get(3).asString();
450 
451  std::map<std::string, Map2DPath>::iterator it;
452  it = m_paths_storage.find(path_name);
453  if (it != m_paths_storage.end())
454  {
455  Map2DPath path = it->second;
456  yarp::os::Bottle pathbot;
457  Map2DPath pathtemp = path;
458  if (Property::copyPortable(pathtemp, pathbot) == false)
459  {
460  yCError(MAP2DSERVER) << "VOCAB_NAV_GET_X VOCAB_NAV_PATH failed copyPortable()";
461  out.addVocab(VOCAB_ERR);
462  }
463  else
464  {
465  yCInfo(MAP2DSERVER) << "Retrieved path" << path_name << "at" << path.toString();
466  out.addVocab(VOCAB_OK);
467 
468  yarp::os::Bottle& pathbot = out.addList();
469  Property::copyPortable(pathtemp, pathbot);
470  }
471  }
472  else
473  {
474  out.addVocab(VOCAB_ERR);
475  yCError(MAP2DSERVER, "User requested an invalid path name");
476  }
477  //ret = true;
478  }
479  else if (cmd == VOCAB_NAV_STORE_X && in.get(2).asVocab() == VOCAB_NAV_LOCATION)
480  {
481  Map2DLocation location;
482  std::string name = in.get(3).asString();
483 
484  location.map_id = in.get(4).asString();
485  location.x = in.get(5).asFloat64();
486  location.y = in.get(6).asFloat64();
487  location.theta = in.get(7).asFloat64();
488 
489  m_locations_storage.insert(std::pair<std::string, Map2DLocation>(name, location));
490  yCInfo(MAP2DSERVER) << "Added location" << name << "at" << location.toString();
491  out.addVocab(VOCAB_OK);
492  //ret = true;
493  }
494  else if (cmd == VOCAB_NAV_STORE_X && in.get(2).asVocab() == VOCAB_NAV_AREA)
495  {
496  Map2DArea area;
497  std::string area_name = in.get(3).asString();
498 
499  Value& b = in.get(4);
500  if (Property::copyPortable(b, area))
501  {
502  m_areas_storage.insert(std::pair<std::string, Map2DArea>(area_name, area));
503  yCInfo(MAP2DSERVER) << "Added area" << area_name << "at" << area.toString();
504  out.addVocab(VOCAB_OK);
505  }
506  else
507  {
508  yCError(MAP2DSERVER) << "VOCAB_NAV_STORE_X VOCAB_NAV_AREA failed copyPortable()";
509  out.addVocab(VOCAB_ERR);
510  }
511  //ret = true;
512  }
513  else if (cmd == VOCAB_NAV_STORE_X && in.get(2).asVocab() == VOCAB_NAV_PATH)
514  {
515  Map2DPath path;
516  std::string path_name = in.get(3).asString();
517 
518  Value& b = in.get(4);
519  if (Property::copyPortable(b, path))
520  {
521  m_paths_storage.insert(std::pair<std::string, Map2DPath>(path_name, path));
522  yCInfo(MAP2DSERVER) << "Added path" << path_name << "at" << path.toString();
523  out.addVocab(VOCAB_OK);
524  }
525  else
526  {
527  yCError(MAP2DSERVER) << "VOCAB_NAV_STORE_X VOCAB_NAV_PATH failed copyPortable()";
528  out.addVocab(VOCAB_ERR);
529  }
530  //ret = true;
531  }
532  else
533  {
534  yCError(MAP2DSERVER) << "Invalid vocab received:" << in.toString();
535  out.clear();
536  out.addVocab(VOCAB_ERR);
537  }
538  }
539  else
540  {
541  yCError(MAP2DSERVER) << "Invalid vocab received:" << in.toString();
542  out.clear();
544  }
545 }
546 
547 void Map2DServer::parse_string_command(yarp::os::Bottle& in, yarp::os::Bottle& out)
548 {
549  if (in.get(0).asString() == "save_locations&areas" && in.get(1).isString())
550  {
551  if(save_locations_and_areas(in.get(1).asString()))
552  {
553  out.addString(in.get(1).asString() + " successfully saved");
554  }
555  else
556  {
557  out.addString("save_locations&areas failed");
558  }
559  }
560  else if (in.get(0).asString() == "load_locations&areas" && in.get(1).isString())
561  {
562  if(load_locations_and_areas(in.get(1).asString()))
563  {
564  out.addString(in.get(1).asString() + " successfully loaded");
565  }
566  else
567  {
568  out.addString("load_locations&areas failed");
569  }
570  }
571  else if(in.get(0).asString() == "list_locations")
572  {
573  std::map<std::string, Map2DLocation>::iterator it;
574  for (it = m_locations_storage.begin(); it != m_locations_storage.end(); ++it)
575  {
576  out.addString(it->first);
577  }
578  }
579  else if (in.get(0).asString() == "list_areas")
580  {
581  std::map<std::string, Map2DArea>::iterator it;
582  for (it = m_areas_storage.begin(); it != m_areas_storage.end(); ++it)
583  {
584  out.addString(it->first);
585  }
586  }
587  else if (in.get(0).asString() == "list_paths")
588  {
589  std::map<std::string, Map2DPath>::iterator it;
590  for (it = m_paths_storage.begin(); it != m_paths_storage.end(); ++it)
591  {
592  out.addString(it->first);
593  }
594  }
595  else if (in.get(0).asString() == "save_maps" && in.get(1).isString())
596  {
597  if(saveMaps(in.get(1).asString()))
598  {
599  out.addString(in.get(1).asString() + " successfully saved");
600  }
601  else
602  {
603  out.addString("save_maps failed");
604  }
605  }
606  else if (in.get(0).asString() == "load_maps" && in.get(1).isString())
607  {
608  if(loadMaps(in.get(1).asString()))
609  {
610  out.addString(in.get(1).asString() + " successfully loaded");
611  }
612  else
613  {
614  out.addString("load_maps failed");
615  }
616  }
617  else if (in.get(0).asString() == "save_map" && in.get(1).isString() && in.get(2).isString())
618  {
619  std::string map_name = in.get(1).asString();
620  std::string map_file = in.get(2).asString() + ".map";
621  auto p = m_maps_storage.find(map_name);
622  if (p == m_maps_storage.end())
623  {
624  out.addString("save_map failed: map " + map_name + " not found");
625  }
626  else
627  {
628  bool b = p->second.saveToFile(map_file);
629  if (b)
630  {
631  out.addString(map_file + " successfully saved");
632  }
633  else
634  {
635  out.addString("save_map failed: unable to save " + map_name + " to "+ map_file);
636  }
637  }
638  }
639  else if (in.get(0).asString() == "load_map" && in.get(1).isString())
640  {
641  MapGrid2D map;
642  bool r = map.loadFromFile(in.get(1).asString());
643  if(r)
644  {
645  string map_name= map.getMapName();
646  auto p = m_maps_storage.find(map_name);
647  if (p == m_maps_storage.end())
648  {
649  m_maps_storage[map_name] = map;
650  out.addString(in.get(1).asString() + " successfully loaded.");
651  }
652  else
653  {
654  out.addString(in.get(1).asString() + " already exists, skipping.");
655  }
656  }
657  else
658  {
659  out.addString("load_map failed. Unable to load " + in.get(1).asString());
660  }
661  }
662  else if(in.get(0).asString() == "list_maps")
663  {
664  std::map<std::string, MapGrid2D>::iterator it;
665  for (it = m_maps_storage.begin(); it != m_maps_storage.end(); ++it)
666  {
667  out.addString(it->first);
668  }
669  }
670  else if(in.get(0).asString() == "clear_all_locations")
671  {
672  m_locations_storage.clear();
673  out.addString("all locations cleared");
674  }
675  else if (in.get(0).asString() == "clear_all_areas")
676  {
677  m_areas_storage.clear();
678  out.addString("all areas cleared");
679  }
680  else if (in.get(0).asString() == "clear_all_paths")
681  {
682  m_paths_storage.clear();
683  out.addString("all paths cleared");
684  }
685  else if(in.get(0).asString() == "clear_all_maps")
686  {
687  m_maps_storage.clear();
688  out.addString("all maps cleared");
689  }
690  else if(in.get(0).asString() == "help")
691  {
692  out.addVocab(Vocab::encode("many"));
693  out.addString("'save_locations&areas <full path filename>' to save locations and areas on a file");
694  out.addString("'load_locations&areas <full path filename>' to load locations and areas from a file");
695  out.addString("'list_locations' to view a list of all stored locations");
696  out.addString("'list_areas' to view a list of all stored areas");
697  out.addString("'list_paths' to view a list of all stored paths");
698  out.addString("'clear_all_locations' to clear all stored locations");
699  out.addString("'clear_all_areas' to clear all stored areas");
700  out.addString("'clear_all_paths' to clear all stored paths");
701  out.addString("'save_maps <full path>' to save a map collection to a folder");
702  out.addString("'load_maps <full path>' to load a map collection from a folder");
703  out.addString("'save_map <map_name> <full path>' to save a single map");
704  out.addString("'load_map <full path>' to load a single map");
705  out.addString("'list_maps' to view a list of all stored maps");
706  out.addString("'clear_all_maps' to clear all stored maps");
707  }
708  else
709  {
710  out.addString("request not understood, call 'help' to see a list of available commands");
711  }
712 
713  //updateVizMarkers();
714 }
715 
716 bool Map2DServer::read(yarp::os::ConnectionReader& connection)
717 {
718  std::lock_guard<std::mutex> lock(m_mutex);
719  yarp::os::Bottle in;
720  yarp::os::Bottle out;
721  bool ok = in.read(connection);
722  if (!ok) return false;
723 
724  //parse string command
725  if(in.get(0).isString())
726  {
727  parse_string_command(in, out);
728  }
729  // parse vocab command
730  else if(in.get(0).isVocab())
731  {
732  parse_vocab_command(in, out);
733  }
734 
735  yarp::os::ConnectionWriter *returnToSender = connection.getWriter();
736  if (returnToSender != nullptr)
737  {
738  out.write(*returnToSender);
739  }
740  else
741  {
742  yCError(MAP2DSERVER) << "Invalid return to sender";
743  }
744  return true;
745 }
746 
747 bool Map2DServer::saveMaps(std::string mapsfile)
748 {
749  if (m_maps_storage.size() == 0)
750  {
751  yCError(MAP2DSERVER) << "Map storage is empty";
752  return false;
753  }
754  std::ofstream file;
755  file.open(mapsfile.c_str());
756  if (!file.is_open())
757  {
758  yCError(MAP2DSERVER) << "Sorry unable to open" << mapsfile;
759  return false;
760  }
761  bool ret = true;
762  for (auto& it : m_maps_storage)
763  {
764  string map_filename = it.first + ".map";
765  file << "mapfile: ";
766  file << map_filename;
767  file << endl;
768  ret &= it.second.saveToFile(map_filename);
769  }
770  file.close();
771  return ret;
772 }
773 
774 bool Map2DServer::loadMaps(std::string mapsfile)
775 {
776  bool ret = true;
777  std::ifstream file;
778  file.open(mapsfile.c_str());
779  if (!file.is_open())
780  {
781  yCError(MAP2DSERVER) << "loadMaps() Unable to open:" << mapsfile;
782  return false;
783  }
784  while (!file.eof())
785  {
786  string dummy;
787  string buffer;
788  std::getline(file, buffer);
789  std::istringstream iss(buffer);
790  iss >> dummy;
791  if (dummy == "") break;
792  if (dummy == "mapfile:")
793  {
794  string mapfilename;
795  iss >> mapfilename;
796  string option;
797  iss >> option;
798  string mapfilenameWithPath = m_rf_mapCollection.findFile(mapfilename);
799  MapGrid2D map;
800  bool r = map.loadFromFile(mapfilenameWithPath);
801  if (r)
802  {
803  string map_name= map.getMapName();
804  auto p = m_maps_storage.find(map_name);
805  if (p == m_maps_storage.end())
806  {
807  if (option == "crop")
808  map.crop(-1,-1,-1,-1);
809  m_maps_storage[map_name] = map;
810  }
811  else
812  {
813  yCError(MAP2DSERVER) << "A map with the same name '" << map_name << "'was found, skipping...";
814  ret = false;
815  }
816  }
817  else
818  {
819  yCError(MAP2DSERVER) << "Problems opening map file" << mapfilenameWithPath;
820  ret = false;
821  }
822  }
823  else
824  {
825  yCError(MAP2DSERVER) << "Invalid syntax, missing mapfile tag";
826  ret = false;
827  }
828  }
829  file.close();
830  return ret;
831 }
832 
834 {
835  Property params;
836  params.fromString(config.toString());
837 
838  string collection_file_name="maps_collection.ini";
839  string locations_file_name="locations.ini";
840  if (config.check("mapCollectionFile"))
841  {
842  collection_file_name= config.find("mapCollectionFile").asString();
843  }
844 
845  if (config.check("mapCollectionContext"))
846  {
847  string collection_context_name= config.find("mapCollectionContext").asString();
848  m_rf_mapCollection.setDefaultContext(collection_context_name.c_str());
849  string collection_file_with_path = m_rf_mapCollection.findFile(collection_file_name);
850  string locations_file_with_path = m_rf_mapCollection.findFile(locations_file_name);
851 
852  if (collection_file_with_path=="")
853  {
854  yCInfo(MAP2DSERVER) << "No locations loaded";
855  }
856  else
857  {
858  bool ret = load_locations_and_areas(locations_file_with_path);
859  if (ret) { yCInfo(MAP2DSERVER) << "Location file" << locations_file_with_path << "successfully loaded."; }
860  else { yCError(MAP2DSERVER) << "Problems opening file" << locations_file_with_path; }
861  }
862 
863  if (collection_file_with_path=="")
864  {
865  yCError(MAP2DSERVER) << "Unable to find file" << collection_file_name << "within the specified context:" << collection_context_name;
866  return false;
867  }
868  if (loadMaps(collection_file_with_path))
869  {
870  yCInfo(MAP2DSERVER) << "Map collection file:" << collection_file_with_path << "successfully loaded.";
871  if (m_maps_storage.size() > 0)
872  {
873  yCInfo(MAP2DSERVER) << "Available maps are:";
874  for (auto& it : m_maps_storage)
875  {
876  yCInfo(MAP2DSERVER) << it.first;
877  }
878  }
879  else
880  {
881  yCInfo(MAP2DSERVER) << "No maps available";
882  }
883  if (m_locations_storage.size() > 0)
884  {
885  yCInfo(MAP2DSERVER) << "Available Locations are:";
886  for (auto& it : m_locations_storage)
887  {
888  yCInfo(MAP2DSERVER) << it.first;
889  }
890  }
891  else
892  {
893  yCInfo(MAP2DSERVER) << "No locations available";
894  }
895 
896  if (m_areas_storage.size() > 0)
897  {
898  yCInfo(MAP2DSERVER) << "Available areas are:";
899  for (auto& it : m_areas_storage)
900  {
901  yCInfo(MAP2DSERVER) << it.first;
902  }
903  }
904  else
905  {
906  yCInfo(MAP2DSERVER) << "No areas available";
907  }
908  }
909  else
910  {
911  yCError(MAP2DSERVER) << "Unable to load map collection file:" << collection_file_with_path;
912  return false;
913  }
914  }
915 
916  if (!config.check("name"))
917  {
918  m_rpcPortName = "/mapServer/rpc";
919  }
920  else
921  {
922  m_rpcPortName = config.find("name").asString();
923  }
924 
925  //open rpc port
926  if (!m_rpcPort.open(m_rpcPortName))
927  {
928  yCError(MAP2DSERVER, "Failed to open port %s", m_rpcPortName.c_str());
929  return false;
930  }
931  m_rpcPort.setReader(*this);
932 
933  //ROS configuration
934  if (config.check("ROS"))
935  {
936  yCInfo(MAP2DSERVER, "Configuring ROS params");
937  Bottle ROS_config = config.findGroup("ROS");
938  if (ROS_config.check("enable_ros_publisher") == false)
939  {
940  yCError(MAP2DSERVER) << "Missing 'enable_ros_publisher' in ROS group";
941  return false;
942  }
943  if (ROS_config.find("enable_ros_publisher").asInt32() == 1 || ROS_config.find("enable_ros_publisher").asString() == "true")
944  {
945  m_enable_publish_ros_map = true;
946  yCInfo(MAP2DSERVER) << "Enabled ROS publisher";
947  }
948  if (ROS_config.check("enable_ros_subscriber") == false)
949  {
950  yCError(MAP2DSERVER) << "Missing 'enable_ros_subscriber' in ROS group";
951  return false;
952  }
953  if (ROS_config.find("enable_ros_subscriber").asInt32() == 1 || ROS_config.find("enable_ros_subscriber").asString() == "true")
954  {
955  m_enable_subscribe_ros_map = true;
956  yCInfo(MAP2DSERVER) << "Enabled ROS subscriber";
957  }
958 
959  if (m_enable_subscribe_ros_map || m_enable_publish_ros_map)
960  {
961  if (m_rosNode == nullptr)
962  {
963  m_rosNode = new yarp::os::Node(ROSNODENAME);
964  }
965  if (m_enable_publish_ros_map && !m_rosPublisherPort_map.topic(ROSTOPICNAME_MAP))
966  {
967  yCError(MAP2DSERVER) << "Unable to publish to" << ROSTOPICNAME_MAP << "topic, check your YARP-ROS network configuration";
968  return false;
969  }
970  if (m_enable_publish_ros_map && !m_rosPublisherPort_metamap.topic(ROSTOPICNAME_MAPMETADATA))
971  {
972  yCError(MAP2DSERVER) << "Unable to publish to " << ROSTOPICNAME_MAPMETADATA << " topic, check your YARP-ROS network configuration";
973  return false;
974  }
975 
976  if (m_enable_subscribe_ros_map && !m_rosSubscriberPort_map.topic(ROSTOPICNAME_MAP))
977  {
978  yCError(MAP2DSERVER) << "Unable to subscribe to " << ROSTOPICNAME_MAP << " topic, check your YARP-ROS network configuration";
979  return false;
980  }
981  if (m_enable_subscribe_ros_map && !m_rosSubscriberPort_metamap.topic(ROSTOPICNAME_MAPMETADATA))
982  {
983  yCError(MAP2DSERVER) << "Unable to subscribe to " << ROSTOPICNAME_MAPMETADATA << " topic, check your YARP-ROS network configuration";
984  return false;
985  }
986  m_rosSubscriberPort_map.setStrict();
987  m_rosSubscriberPort_metamap.setStrict();
988 
989  }
990  // m_rosPublisherPort_markers.topic("/locationServerMarkers");
991  }
992  else
993  {
994  //no ROS options
995  }
996  //yarp::os::Time::delay(5);
997  yarp::rosmsg::nav_msgs::OccupancyGrid* map_ros = nullptr;
998  yarp::rosmsg::nav_msgs::MapMetaData* metamap_ros = nullptr;
999 
1000  map_ros = m_rosSubscriberPort_map.read(true);
1001  metamap_ros = m_rosSubscriberPort_metamap.read(true);
1002  if (map_ros!=nullptr && metamap_ros!=nullptr)
1003  {
1004  yCInfo(MAP2DSERVER) << "Received map for ROS";
1005  string map_name = "ros_map";
1006  MapGrid2D map;
1007  map.setSize_in_cells(map_ros->info.width,map_ros->info.height);
1008  map.setResolution( map_ros->info.resolution);
1009  map.setMapName(map_name);
1011  map_ros->info.origin.orientation.y,
1012  map_ros->info.origin.orientation.z,
1013  map_ros->info.origin.orientation.w);
1016  double orig_angle = vec[2];
1017  map.setOrigin(map_ros->info.origin.position.x,map_ros->info.origin.position.y,orig_angle);
1018  for (size_t y=0; y< map_ros->info.height; y++)
1019  for (size_t x=0; x< map_ros->info.width; x++)
1020  {
1021  XYCell cell(x,map_ros->info.height-1-y);
1022  double occ = map_ros->data[x+y*map_ros->info.width];
1023  map.setOccupancyData(cell,occ);
1024 
1025  if (occ >= 0 && occ <= 70) map.setMapFlag(cell, MapGrid2D::MAP_CELL_FREE);
1026  else if (occ >= 71 && occ <= 100) map.setMapFlag(cell, MapGrid2D::MAP_CELL_WALL);
1027  else map.setMapFlag(cell, MapGrid2D::MAP_CELL_UNKNOWN);
1028  }
1029  auto p = m_maps_storage.find(map_name);
1030  if (p == m_maps_storage.end())
1031  {
1032  yCInfo(MAP2DSERVER) << "Added map "<< map_name <<" to mapServer";
1033  m_maps_storage[map_name] = map;
1034  }
1035  }
1036  return true;
1037 }
1038 
1040 {
1041  yCTrace(MAP2DSERVER, "Close");
1042  if (m_enable_publish_ros_map)
1043  {
1044  m_rosPublisherPort_map.interrupt();
1045  m_rosPublisherPort_metamap.interrupt();
1046  m_rosPublisherPort_map.close();
1047  m_rosPublisherPort_metamap.close();
1048  }
1049  if (m_enable_subscribe_ros_map)
1050  {
1051  m_rosSubscriberPort_map.interrupt();
1052  m_rosSubscriberPort_metamap.interrupt();
1053  m_rosSubscriberPort_map.close();
1054  m_rosSubscriberPort_metamap.close();
1055  }
1056  return true;
1057 }
1058 
1059 bool Map2DServer::priv_load_locations_and_areas_v1(std::ifstream& file)
1060 {
1061  std::string buffer;
1062  std::getline(file, buffer);
1063  if (buffer != "Locations:")
1064  {
1065  yCError(MAP2DSERVER) << "Unable to parse Locations section!";
1066  return false;
1067  }
1068 
1069  while (1)
1070  {
1071  std::getline(file, buffer);
1072  if (buffer == "Areas:") break;
1073  if (file.eof())
1074  {
1075  yCError(MAP2DSERVER) << "Unexpected End Of File";
1076  return false;
1077  }
1078  Bottle b;
1079  b.fromString(buffer);
1080  size_t bot_size = b.size();
1081  if (bot_size != 5)
1082  {
1083  yCError(MAP2DSERVER) << "Unable to parse contents of Areas section!";
1084  return false;
1085  }
1086  Map2DLocation location;
1087  std::string name = b.get(0).asString();
1088  location.map_id = b.get(1).asString();
1089  location.x = b.get(2).asFloat64();
1090  location.y = b.get(3).asFloat64();
1091  location.theta = b.get(4).asFloat64();
1092  m_locations_storage[name] = location;
1093  }
1094 
1095  if (buffer != "Areas:")
1096  {
1097  yCError(MAP2DSERVER) << "Unable to parse Areas section!";
1098  return false;
1099  }
1100 
1101  while (1)
1102  {
1103  Map2DArea area;
1104  std::getline(file, buffer);
1105  if (file.eof()) break;
1106 
1107  Bottle b;
1108  b.fromString(buffer);
1109  size_t bot_size = b.size();
1110  std::string name = b.get(0).asString();
1111  area.map_id = b.get(1).asString();
1112  size_t area_size = b.get(2).asInt32();
1113  if (area_size <= 0 || bot_size != area_size * 2 + 3)
1114  {
1115  yCError(MAP2DSERVER) << "Unable to parse contents of Areas section!";
1116  return false;
1117  }
1118  for (size_t ai = 3; ai < bot_size; ai += 2)
1119  {
1120  double xpos = b.get(ai).asFloat64();
1121  double ypos = b.get(ai + 1).asFloat64();
1122  area.points.push_back(yarp::math::Vec2D<double>(xpos, ypos));
1123  }
1124  m_areas_storage[name] = area;
1125  }
1126  return true;
1127 }
1128 
1129 bool Map2DServer::priv_load_locations_and_areas_v2(std::ifstream& file)
1130 {
1131  std::string buffer;
1132  std::getline(file, buffer);
1133  if (buffer != "Locations:")
1134  {
1135  yCError(MAP2DSERVER) << "Unable to parse Locations section!";
1136  return false;
1137  }
1138 
1139  while (1)
1140  {
1141  std::getline(file, buffer);
1142  if (buffer == "Areas:") break;
1143  if (file.eof())
1144  {
1145  yCError(MAP2DSERVER) << "Unexpected End Of File";
1146  return false;
1147  }
1148  Bottle b;
1149  b.fromString(buffer);
1150  size_t bot_size = b.size();
1151  if (bot_size != 5)
1152  {
1153  yCError(MAP2DSERVER) << "Unable to parse contents of Areas section!";
1154  return false;
1155  }
1156  Map2DLocation location;
1157  std::string name = b.get(0).asString();
1158  location.map_id = b.get(1).asString();
1159  location.x = b.get(2).asFloat64();
1160  location.y = b.get(3).asFloat64();
1161  location.theta = b.get(4).asFloat64();
1162  m_locations_storage[name] = location;
1163  }
1164 
1165  if (buffer != "Areas:")
1166  {
1167  yCError(MAP2DSERVER) << "Unable to parse Areas section!";
1168  return false;
1169  }
1170 
1171  while (1)
1172  {
1173  Map2DArea area;
1174  std::getline(file, buffer);
1175  if (file.eof()) break;
1176 
1177  Bottle b;
1178  b.fromString(buffer);
1179  size_t bot_size = b.size();
1180  std::string name = b.get(0).asString();
1181  area.map_id = b.get(1).asString();
1182  size_t area_size = b.get(2).asInt32();
1183  if (area_size <= 0 || bot_size != area_size * 2 + 3)
1184  {
1185  yCError(MAP2DSERVER) << "Unable to parse contents of Areas section!";
1186  return false;
1187  }
1188  for (size_t ai = 3; ai < bot_size; ai += 2)
1189  {
1190  double xpos = b.get(ai).asFloat64();
1191  double ypos = b.get(ai + 1).asFloat64();
1192  area.points.push_back(yarp::math::Vec2D<double>(xpos, ypos));
1193  }
1194  m_areas_storage[name] = area;
1195  }
1196  return true;
1197 }
1198 
1199 bool Map2DServer::load_locations_and_areas(std::string locations_file)
1200 {
1201  std::ifstream file;
1202  file.open (locations_file.c_str());
1203 
1204  if(!file.is_open())
1205  {
1206  yCError(MAP2DSERVER) << "Unable to open" << locations_file << "locations file.";
1207  return false;
1208  }
1209 
1210  std::string buffer;
1211 
1212  std::getline(file, buffer);
1213  if (buffer != "Version:")
1214  {
1215  yCError(MAP2DSERVER) << "Unable to parse Version section!";
1216  file.close();
1217  return false;
1218  }
1219  std::getline(file, buffer);
1220  int version = atoi(buffer.c_str());
1221 
1222  if (version == 1)
1223  {
1224  if (!priv_load_locations_and_areas_v1(file))
1225  {
1226  yCError(MAP2DSERVER) << "Call to load_locations_and_areas_v1 failed";
1227  file.close();
1228  return false;
1229  }
1230  }
1231  else if (version == 2)
1232  {
1233  if (!priv_load_locations_and_areas_v2(file))
1234  {
1235  yCError(MAP2DSERVER) << "Call to load_locations_and_areas_v2 failed";
1236  file.close();
1237  return false;
1238  }
1239  }
1240  else
1241  {
1242  yCError(MAP2DSERVER) << "Only versions 1,2 supported!";
1243  file.close();
1244  return false;
1245  }
1246 
1247  //on success
1248  file.close();
1249  yCDebug(MAP2DSERVER) << "Locations file" << locations_file << "loaded, " << m_locations_storage.size() << "locations and "<< m_areas_storage.size() << " areas available";
1250  return true;
1251 }
1252 
1253 bool Map2DServer::save_locations_and_areas(std::string locations_file)
1254 {
1255  std::ofstream file;
1256  file.open (locations_file.c_str());
1257 
1258  if(!file.is_open())
1259  {
1260  yCError(MAP2DSERVER) << "Unable to open" << locations_file << "locations file.";
1261  return false;
1262  }
1263 
1264  std::string s;
1265  Map2DLocation loc;
1266  Map2DArea area;
1267  s = " ";
1268 
1269  file << "Version: \n";
1270  file << "2\n";
1271 
1272  {
1273  file << "Locations: \n";
1274  std::map<std::string, Map2DLocation>::iterator it;
1275  for (it = m_locations_storage.begin(); it != m_locations_storage.end(); ++it)
1276  {
1277  loc = it->second;
1278  file << it->first << s << loc.map_id << s << loc.x << s << loc.y << s << loc.theta << "\n";
1279  }
1280  }
1281 
1282  {
1283  file << "Areas: \n";
1284  std::map<std::string, Map2DArea>::iterator it2;
1285  for (it2 = m_areas_storage.begin(); it2 != m_areas_storage.end(); ++it2)
1286  {
1287  area = it2->second;
1288  file << it2->first << s << area.map_id << s << area.points.size() << s;
1289  for (size_t i = 0; i < area.points.size(); i++)
1290  {
1291  file << area.points[i].x << s;
1292  file << area.points[i].y << s;
1293  }
1294  file << "\n";
1295  }
1296  }
1297 
1298  {
1299  file << "Paths: \n";
1300  std::map<std::string, Map2DPath>::iterator it3;
1301  for (it3 = m_paths_storage.begin(); it3 != m_paths_storage.end(); ++it3)
1302  {
1303  file << it3->first; // the name of the path
1304  for (size_t i=0; i<it3->second.size(); i++)
1305  {
1306  loc = it3->second[i];
1307  file << "( " <<loc.map_id << s << loc.x << s << loc.y << s << loc.theta << ") ";
1308  }
1309  file << "\n";
1310  }
1311  }
1312 
1313  file.close();
1314  yCDebug(MAP2DSERVER) << "Locations file" << locations_file << "saved.";
1315  return true;
1316 }
1317 
1318 bool Map2DServer::updateVizMarkers()
1319 {
1320  yarp::rosmsg::TickDuration dur; dur.sec = 0xFFFFFFFF;
1321  double yarpTimeStamp = yarp::os::Time::now();
1322  uint64_t time;
1323  uint64_t nsec_part;
1324  uint64_t sec_part;
1326  time = (uint64_t)(yarpTimeStamp * 1000000000UL);
1327  nsec_part = (time % 1000000000UL);
1328  sec_part = (time / 1000000000UL);
1329  if (sec_part > std::numeric_limits<unsigned int>::max())
1330  {
1331  yCWarning(MAP2DSERVER) << "Timestamp exceeded the 64 bit representation, resetting it to 0";
1332  sec_part = 0;
1333  }
1334 
1337  yarp::sig::Vector rpy(3);
1339 
1340  yarp::rosmsg::visualization_msgs::MarkerArray& markers = m_rosPublisherPort_markers.prepare();
1341  markers.markers.clear();
1342 
1343  std::map<std::string, Map2DLocation>::iterator it;
1344  int count = 1;
1345  for (it = m_locations_storage.begin(); it != m_locations_storage.end(); ++it, ++count)
1346  {
1347  rpy[0] = 0; //x
1348  rpy[1] = 0; //y
1349  rpy[2] = it->second.theta / 180 * 3.14159265359; //z
1351  q.fromRotationMatrix(m);
1352 
1353  marker.header.frame_id = "map";
1354  tt.sec = (yarp::os::NetUint32) sec_part;;
1355  tt.nsec = (yarp::os::NetUint32) nsec_part;;
1356  marker.header.stamp = tt;
1357  marker.ns = "my_namespace";
1358  marker.id = count;
1361  marker.pose.position.x = it->second.x;
1362  marker.pose.position.y = it->second.y;
1363  marker.pose.position.z = 0;
1364  marker.pose.orientation.x = q.x();
1365  marker.pose.orientation.y = q.y();
1366  marker.pose.orientation.z = q.z();
1367  marker.pose.orientation.w = q.w();
1368  marker.scale.x = 1;
1369  marker.scale.y = 0.1;
1370  marker.scale.z = 0.1;
1371  marker.color.a = 1.0;
1372  marker.color.r = 0.0;
1373  marker.color.g = 1.0;
1374  marker.color.b = 0.0;
1375  marker.lifetime = dur;
1376  marker.text = it->first;
1377  markers.markers.push_back(marker);
1378  }
1379 
1380  m_rosPublisherPort_markers.write();
1381  return true;
1382 }
LogStream.h
INavigation2D.h
yarp::rosmsg::geometry_msgs::Quaternion::y
yarp::conf::float64_t y
Definition: Quaternion.h:38
yarp::rosmsg::geometry_msgs::Vector3::z
yarp::conf::float64_t z
Definition: Vector3.h:42
yarp::rosmsg::visualization_msgs::MarkerArray::markers
std::vector< yarp::rosmsg::visualization_msgs::Marker > markers
Definition: MarkerArray.h:33
yarp::rosmsg::nav_msgs::MapMetaData::height
std::uint32_t height
Definition: MapMetaData.h:48
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
VOCAB_IMAP_SET_MAP
constexpr yarp::conf::vocab32_t VOCAB_IMAP_SET_MAP
Definition: IMap2D.h:210
yarp::rosmsg::TickDuration::sec
std::uint32_t sec
Definition: TickDuration.h:32
VOCAB_IMAP_REMOVE
constexpr yarp::conf::vocab32_t VOCAB_IMAP_REMOVE
Definition: IMap2D.h:214
yarp::os::Value::asVocab
virtual std::int32_t asVocab() const
Get vocabulary identifier as an integer.
Definition: Value.cpp:231
TickTime.h
Map2DServer::saveMaps
bool saveMaps(std::string filename)
Definition: Map2DServer.cpp:747
yarp::os::Bottle::toString
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:214
Map2DServer::close
bool close() override
Close the DeviceDriver.
Definition: Map2DServer.cpp:1039
yarp::rosmsg::std_msgs::ColorRGBA::a
yarp::conf::float32_t a
Definition: ColorRGBA.h:38
yarp::os::Bottle::clear
void clear()
Empties the bottle of any objects it contains.
Definition: Bottle.cpp:124
yarp::rosmsg::geometry_msgs::Point::z
yarp::conf::float64_t z
Definition: Point.h:37
yarp::dev::Nav2D::Map2DArea::map_id
std::string map_id
Definition: Map2DArea.h:113
yarp::rosmsg::visualization_msgs::Marker
Definition: Marker.h:79
Map2DServer::save_locations_and_areas
bool save_locations_and_areas(std::string locations_file)
Definition: Map2DServer.cpp:1253
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
yarp::rosmsg::visualization_msgs::Marker::color
yarp::rosmsg::std_msgs::ColorRGBA color
Definition: Marker.h:104
yarp::math::Quaternion::fromRotationMatrix
void fromRotationMatrix(const yarp::sig::Matrix &R)
Converts a rotation matrix to a quaternion.
Definition: Quaternion.cpp:154
yarp::rosmsg::visualization_msgs::Marker::scale
yarp::rosmsg::geometry_msgs::Vector3 scale
Definition: Marker.h:103
yarp::rosmsg::std_msgs::ColorRGBA::g
yarp::conf::float32_t g
Definition: ColorRGBA.h:36
yarp::os::Bottle::size
size_type size() const
Gets the number of elements in the bottle.
Definition: Bottle.cpp:254
yarp::dev::Map2DLocationData::y
double y
Definition: Map2DLocationData.h:32
yarp::sig
Signal processing.
Definition: Image.h:25
ROSTOPICNAME_MAP
#define ROSTOPICNAME_MAP
Definition: Map2DServer.h:109
TickDuration.h
Subscriber.h
yarp::math::Quaternion::y
double y() const
Definition: Quaternion.cpp:80
yarp::rosmsg::visualization_msgs::Marker::type
std::int32_t type
Definition: Marker.h:100
yarp::dev::Nav2D::MapGrid2D::setMapName
bool setMapName(std::string map_name)
Sets the map name.
Definition: MapGrid2D.cpp:900
yarp::os::Searchable::findGroup
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
yarp::rosmsg::geometry_msgs::Pose::position
yarp::rosmsg::geometry_msgs::Point position
Definition: Pose.h:36
VOCAB_NAV_LOCATION
constexpr yarp::conf::vocab32_t VOCAB_NAV_LOCATION
Definition: ILocalization2D.h:136
yCWarning
#define yCWarning(component,...)
Definition: LogComponent.h:146
VOCAB_IMAP_GET_MAP
constexpr yarp::conf::vocab32_t VOCAB_IMAP_GET_MAP
Definition: IMap2D.h:211
yarp::math::dcm2rpy
yarp::sig::Vector dcm2rpy(const yarp::sig::Matrix &R)
Converts a dcm (direction cosine matrix) rotation matrix to roll-pitch-yaw angles (defined in Math....
Definition: math.cpp:780
yarp::rosmsg::visualization_msgs::Marker::pose
yarp::rosmsg::geometry_msgs::Pose pose
Definition: Marker.h:102
yarp::os::Searchable::toString
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
yarp::dev::Nav2D::MapGrid2D::setOccupancyData
bool setOccupancyData(XYCell cell, double occupancy)
Set the occupancy data of a specific cell of the map.
Definition: MapGrid2D.cpp:984
yarp::dev::Nav2D::Map2DLocation::toString
std::string toString() const
Returns text representation of the location.
Definition: Map2DLocation.h:77
yarp::os::Property::fromString
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
Definition: Property.cpp:1046
yarp::math::Quaternion::z
double z() const
Definition: Quaternion.cpp:85
YARP_LOG_COMPONENT
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:80
yarp::rosmsg::geometry_msgs::Vector3::y
yarp::conf::float64_t y
Definition: Vector3.h:41
yarp::rosmsg::std_msgs::Header::frame_id
std::string frame_id
Definition: Header.h:49
VOCAB_NAV_DELETE_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_DELETE_X
Definition: ILocalization2D.h:132
yarp::math::Quaternion::toRotationMatrix4x4
yarp::sig::Matrix toRotationMatrix4x4() const
Converts a quaternion to a rotation matrix.
Definition: Quaternion.cpp:211
yarp::os::Bottle::fromString
void fromString(const std::string &text)
Initializes bottle from a string.
Definition: Bottle.cpp:207
yarp::rosmsg::geometry_msgs::Vector3::x
yarp::conf::float64_t x
Definition: Vector3.h:40
yarp::rosmsg::nav_msgs::MapMetaData::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: MapMetaData.h:133
yarp::rosmsg::geometry_msgs::Quaternion::x
yarp::conf::float64_t x
Definition: Quaternion.h:37
yarp::dev::Nav2D::Map2DArea::toString
std::string toString() const
Returns text representation of the area.
Definition: Map2DArea.cpp:137
yarp::dev::Nav2D::MapGrid2D::crop
bool crop(int left, int top, int right, int bottom)
Modifies the map, cropping pixels at the boundaries.
Definition: MapGrid2D.cpp:614
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
yarp::rosmsg::geometry_msgs::Pose::orientation
yarp::rosmsg::geometry_msgs::Quaternion orientation
Definition: Pose.h:37
yarp::rosmsg::visualization_msgs::Marker::lifetime
yarp::rosmsg::TickDuration lifetime
Definition: Marker.h:105
VOCAB_NAV_CLEAR_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_CLEAR_X
Definition: ILocalization2D.h:131
VOCAB_NAV_RENAME_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_RENAME_X
Definition: ILocalization2D.h:133
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_IMAP_GET_NAMES
constexpr yarp::conf::vocab32_t VOCAB_IMAP_GET_NAMES
Definition: IMap2D.h:212
yarp::os::Bottle::find
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition: Bottle.cpp:290
yarp::math::Vec2D
Definition: Vec2D.h:26
yarp::os::Time::now
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition: Time.cpp:124
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::math::rpy2dcm
yarp::sig::Matrix rpy2dcm(const yarp::sig::Vector &rpy)
Converts roll-pitch-yaw angles in the corresponding dcm (direction cosine matrix) rotation matrix (de...
Definition: math.cpp:818
yarp::dev::Nav2D::MapGrid2D::getMapName
std::string getMapName() const
Retrieves the map name.
Definition: MapGrid2D.cpp:911
VOCAB_NAV_GET_LIST_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_LIST_X
Definition: ILocalization2D.h:118
yarp::math::Quaternion::x
double x() const
Definition: Quaternion.cpp:75
yarp::sig::VectorOf< double >
yarp::os::Bottle::check
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition: Bottle.cpp:280
yarp::rosmsg::TickDuration
Definition: TickDuration.h:30
Log.h
yarp::rosmsg::TickTime
Definition: TickTime.h:30
yarp::os::Value::isString
virtual bool isString() const
Checks if value is a string.
Definition: Value.cpp:159
yarp::dev::Nav2D::MapGrid2D::setOrigin
bool setOrigin(double x, double y, double theta)
Sets the origin of the map reference frame (according to ROS convention)
Definition: MapGrid2D.cpp:850
Map2DServer.h
yarp::rosmsg::nav_msgs::MapMetaData
Definition: MapMetaData.h:43
Map2DServer::Map2DServer
Map2DServer()
Map2DServer.
Definition: Map2DServer.cpp:52
ROSNODENAME
#define ROSNODENAME
Definition: Map2DServer.h:108
VOCAB_IMAP_LOAD_COLLECTION
constexpr yarp::conf::vocab32_t VOCAB_IMAP_LOAD_COLLECTION
Definition: IMap2D.h:215
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
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::dev::Nav2D::MapGrid2D::setSize_in_cells
bool setSize_in_cells(size_t x, size_t y)
Sets the size of the map in cells.
Definition: MapGrid2D.cpp:934
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
Math.h
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::os::NetUint32
std::uint32_t NetUint32
Definition of the NetUint32 type.
Definition: NetUint32.h:33
IMap2D.h
yarp::rosmsg::TickTime::sec
std::uint32_t sec
Definition: TickTime.h:32
yarp::dev::Nav2D::Map2DArea::points
std::vector< yarp::math::Vec2D< double > > points
Definition: Map2DArea.h:114
yarp::os::Value::asString
virtual std::string asString() const
Get string value.
Definition: Value.cpp:237
yarp::rosmsg::visualization_msgs::Marker::action
std::int32_t action
Definition: Marker.h:101
VOCAB_NAV_AREA
constexpr yarp::conf::vocab32_t VOCAB_NAV_AREA
Definition: ILocalization2D.h:135
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.
Node.h
Map2DServer::open
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
Definition: Map2DServer.cpp:833
buffer
Definition: V4L_camera.h:75
yarp::rosmsg::nav_msgs::MapMetaData::origin
yarp::rosmsg::geometry_msgs::Pose origin
Definition: MapMetaData.h:49
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::os::Node
The Node class.
Definition: Node.h:27
yarp::math::Quaternion
Definition: Quaternion.h:27
yarp::rosmsg::std_msgs::ColorRGBA::b
yarp::conf::float32_t b
Definition: ColorRGBA.h:37
yarp::os::ConnectionReader::getWriter
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
yarp::rosmsg::visualization_msgs::Marker::ADD
static const std::uint8_t ADD
Definition: Marker.h:93
yarp::rosmsg::geometry_msgs::Quaternion::w
yarp::conf::float64_t w
Definition: Quaternion.h:40
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
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
yarp::dev::Nav2D::MapGrid2D::setResolution
bool setResolution(double resolution)
Sets the resolution of the map, i.e.
Definition: MapGrid2D.cpp:884
LogComponent.h
VOCAB_IMAP_CLEAR
constexpr yarp::conf::vocab32_t VOCAB_IMAP_CLEAR
Definition: IMap2D.h:213
yarp::rosmsg::visualization_msgs::Marker::ns
std::string ns
Definition: Marker.h:98
yarp::dev::Nav2D::MapGrid2D::loadFromFile
bool loadFromFile(std::string map_filename)
Loads a yarp map file from disk.
Definition: MapGrid2D.cpp:512
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
VOCAB_IMAP_OK
constexpr yarp::conf::vocab32_t VOCAB_IMAP_OK
Definition: IMap2D.h:217
Map2DServer::~Map2DServer
~Map2DServer()
VOCAB_IMAP_SAVE_COLLECTION
constexpr yarp::conf::vocab32_t VOCAB_IMAP_SAVE_COLLECTION
Definition: IMap2D.h:216
yCError
#define yCError(component,...)
Definition: LogComponent.h:157
yarp::rosmsg::geometry_msgs::Quaternion::z
yarp::conf::float64_t z
Definition: Quaternion.h:39
yarp::math::Quaternion::w
double w() const
Definition: Quaternion.cpp:70
yarp::os::Value::asInt32
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition: Value.cpp:207
VOCAB_IMAP_ERROR
constexpr yarp::conf::vocab32_t VOCAB_IMAP_ERROR
Definition: IMap2D.h:218
yCInfo
#define yCInfo(component,...)
Definition: LogComponent.h:135
yarp::rosmsg::geometry_msgs::Point::y
yarp::conf::float64_t y
Definition: Point.h:36
yarp::rosmsg::nav_msgs::OccupancyGrid
Definition: OccupancyGrid.h:42
yarp::rosmsg::visualization_msgs::MarkerArray
Definition: MarkerArray.h:31
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
yCDebug
#define yCDebug(component,...)
Definition: LogComponent.h:112
Publisher.h
yarp::rosmsg::nav_msgs::OccupancyGrid::data
std::vector< std::int8_t > data
Definition: OccupancyGrid.h:46
VOCAB_NAV_PATH
constexpr yarp::conf::vocab32_t VOCAB_NAV_PATH
Definition: ILocalization2D.h:137
VOCAB_NAV_STORE_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_STORE_X
Definition: ILocalization2D.h:134
Map2DServer::load_locations_and_areas
bool load_locations_and_areas(std::string locations_file)
Definition: Map2DServer.cpp:1199
yarp::dev::Nav2D::Map2DPath::toString
std::string toString() const
Returns text representation of the path.
Definition: Map2DPath.cpp:46
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::dev::Nav2D::Map2DArea
Definition: Map2DArea.h:30
yarp::rosmsg::TickTime::nsec
std::uint32_t nsec
Definition: TickTime.h:33
yarp::rosmsg::nav_msgs::OccupancyGrid::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: OccupancyGrid.h:121
yarp::dev::Map2DLocationData::x
double x
Definition: Map2DLocationData.h:31
yCTrace
#define yCTrace(component,...)
Definition: LogComponent.h:88
yarp::dev::Nav2D::MapGrid2D::setMapFlag
bool setMapFlag(XYCell cell, map_flags flag)
Set the flag of a specific cell of the map.
Definition: MapGrid2D.cpp:962
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:47
yarp::rosmsg::visualization_msgs::Marker::id
std::int32_t id
Definition: Marker.h:99
yarp::rosmsg::nav_msgs::OccupancyGrid::info
yarp::rosmsg::nav_msgs::MapMetaData info
Definition: OccupancyGrid.h:45
yarp::rosmsg::nav_msgs::MapMetaData::width
std::uint32_t width
Definition: MapMetaData.h:47
GenericVocabs.h
yarp::dev::Map2DLocationData::map_id
std::string map_id
Definition: Map2DLocationData.h:30
yarp::os::Value::asFloat64
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition: Value.cpp:225
yarp::rosmsg::std_msgs::ColorRGBA::r
yarp::conf::float32_t r
Definition: ColorRGBA.h:35
yarp::rosmsg::std_msgs::Header::stamp
yarp::rosmsg::TickTime stamp
Definition: Header.h:48
yarp::rosmsg::visualization_msgs::Marker::header
yarp::rosmsg::std_msgs::Header header
Definition: Marker.h:97
VOCAB_OK
constexpr yarp::conf::vocab32_t VOCAB_OK
Definition: GenericVocabs.h:18
Map2DServer::loadMaps
bool loadMaps(std::string filename)
Definition: Map2DServer.cpp:774
VOCAB_IMAP
constexpr yarp::conf::vocab32_t VOCAB_IMAP
Definition: IMap2D.h:209
VOCAB_INAVIGATION
constexpr yarp::conf::vocab32_t VOCAB_INAVIGATION
Definition: ILocalization2D.h:110
yarp::os::Value::isVocab
virtual bool isVocab() const
Checks if value is a vocabulary identifier.
Definition: Value.cpp:177
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37
ROSTOPICNAME_MAPMETADATA
#define ROSTOPICNAME_MAPMETADATA
Definition: Map2DServer.h:110
yarp::rosmsg::visualization_msgs::Marker::ARROW
static const std::uint8_t ARROW
Definition: Marker.h:81
yarp::rosmsg::geometry_msgs::Point::x
yarp::conf::float64_t x
Definition: Point.h:35
yarp::sig::Matrix
A class for a Matrix.
Definition: Matrix.h:46
yarp::rosmsg::nav_msgs::MapMetaData::resolution
yarp::conf::float32_t resolution
Definition: MapMetaData.h:46
yarp::rosmsg::visualization_msgs::Marker::text
std::string text
Definition: Marker.h:109