YARP
Yet Another Robot Platform
Map2DServer.h
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 #ifndef YARP_DEV_MAP2DSERVER_H
20 #define YARP_DEV_MAP2DSERVER_H
21 
22 #include <vector>
23 #include <iostream>
24 #include <string>
25 #include <sstream>
26 #include <mutex>
27 
28 #include <yarp/os/Network.h>
29 #include <yarp/os/Port.h>
30 #include <yarp/os/Bottle.h>
31 #include <yarp/os/Time.h>
32 #include <yarp/os/Property.h>
33 
34 #include <yarp/os/PeriodicThread.h>
35 #include <yarp/os/BufferedPort.h>
36 #include <yarp/os/RpcServer.h>
37 #include <yarp/sig/Vector.h>
38 #include <yarp/dev/MapGrid2D.h>
39 #include <yarp/dev/Map2DLocation.h>
40 #include <yarp/dev/Map2DArea.h>
41 #include <yarp/dev/Map2DPath.h>
42 #include <yarp/os/ResourceFinder.h>
43 
44 #include <yarp/dev/PolyDriver.h>
45 #include <yarp/dev/DeviceDriver.h>
46 #include <yarp/dev/api.h>
47 #include <yarp/os/Publisher.h>
48 #include <yarp/os/Subscriber.h>
49 #include <yarp/os/Node.h>
53 
54 
55 #define DEFAULT_THREAD_PERIOD 20 //ms
56 
73 class Map2DServer :
76 {
77 private:
78  std::map<std::string, yarp::dev::Nav2D::MapGrid2D> m_maps_storage;
79  std::map<std::string, yarp::dev::Nav2D::Map2DLocation> m_locations_storage;
80  std::map<std::string, yarp::dev::Nav2D::Map2DPath> m_paths_storage;
81  std::map<std::string, yarp::dev::Nav2D::Map2DArea> m_areas_storage;
82 
83 public:
84  Map2DServer();
86 
87  bool saveMaps(std::string filename);
88  bool loadMaps(std::string filename);
89  bool load_locations_and_areas(std::string locations_file);
90  bool save_locations_and_areas(std::string locations_file);
91  bool open(yarp::os::Searchable &params) override;
92  bool close() override;
94 
95 private:
96  bool priv_load_locations_and_areas_v1(std::ifstream& file);
97  bool priv_load_locations_and_areas_v2(std::ifstream& file);
98 
99 private:
100  yarp::os::ResourceFinder m_rf_mapCollection;
101  std::mutex m_mutex;
102  std::string m_rpcPortName;
103  yarp::os::Node* m_rosNode;
104  bool m_enable_publish_ros_map;
105  bool m_enable_subscribe_ros_map;
106 
107  #define ROSNODENAME "/map2DServerNode"
108  #define ROSTOPICNAME_MAP "/map"
109  #define ROSTOPICNAME_MAPMETADATA "/map_metadata"
110 
111  yarp::os::RpcServer m_rpcPort;
117 
118  bool read(yarp::os::ConnectionReader& connection) override;
119  inline void list_response(yarp::os::Bottle& out);
120 
121  void parse_string_command(yarp::os::Bottle& in, yarp::os::Bottle& out);
122  void parse_vocab_command(yarp::os::Bottle& in, yarp::os::Bottle& out);
123  bool updateVizMarkers();
124 };
125 
126 #endif // YARP_DEV_MAP2DSERVER_H
contains the definition of a Map2DArea type
contains the definition of a Map2DLocation type
contains the definition of a Map2DPath type
contains the definition of a map type
contains the definition of a Vector type
yarp::os::Bottle getOptions()
bool close() override
Close the DeviceDriver.
Map2DServer()
Map2DServer.
Definition: Map2DServer.cpp:52
bool loadMaps(std::string filename)
bool saveMaps(std::string filename)
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
bool load_locations_and_areas(std::string locations_file)
bool save_locations_and_areas(std::string locations_file)
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
An interface for reading from a network connection.
The Node class.
Definition: Node.h:27
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
Helper class for finding config files and other external resources.
A port that is specialized as an RPC server.
Definition: RpcServer.h:27
A base class for nested structures that can be searched.
Definition: Searchable.h:69