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 
74 class Map2DServer :
77 {
78 private:
79  std::map<std::string, yarp::dev::Nav2D::MapGrid2D> m_maps_storage;
80  std::map<std::string, yarp::dev::Nav2D::Map2DLocation> m_locations_storage;
81  std::map<std::string, yarp::dev::Nav2D::Map2DPath> m_paths_storage;
82  std::map<std::string, yarp::dev::Nav2D::Map2DArea> m_areas_storage;
83 
84 public:
85  Map2DServer();
87 
88  bool saveMaps(std::string filename);
89  bool loadMaps(std::string filename);
90  bool load_locations_and_areas(std::string locations_file);
91  bool save_locations_and_areas(std::string locations_file);
92  bool open(yarp::os::Searchable &params) override;
93  bool close() override;
95 
96 private:
97  bool priv_load_locations_and_areas_v1(std::ifstream& file);
98  bool priv_load_locations_and_areas_v2(std::ifstream& file);
99 
100 private:
101  yarp::os::ResourceFinder m_rf_mapCollection;
102  std::mutex m_mutex;
103  std::string m_rpcPortName;
104  yarp::os::Node* m_rosNode;
105  bool m_enable_publish_ros_map;
106  bool m_enable_subscribe_ros_map;
107 
108  #define ROSNODENAME "/map2DServerNode"
109  #define ROSTOPICNAME_MAP "/map"
110  #define ROSTOPICNAME_MAPMETADATA "/map_metadata"
111 
112  yarp::os::RpcServer m_rpcPort;
118 
119  bool read(yarp::os::ConnectionReader& connection) override;
120  inline void list_response(yarp::os::Bottle& out);
121 
122  void parse_string_command(yarp::os::Bottle& in, yarp::os::Bottle& out);
123  void parse_vocab_command(yarp::os::Bottle& in, yarp::os::Bottle& out);
124  bool updateVizMarkers();
125 };
126 
127 #endif // YARP_DEV_MAP2DSERVER_H
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
MapGrid2D.h
contains the definition of a map type
Map2DServer::saveMaps
bool saveMaps(std::string filename)
Definition: Map2DServer.cpp:747
Map2DServer::close
bool close() override
Close the DeviceDriver.
Definition: Map2DServer.cpp:1039
Network.h
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
Map2DArea.h
contains the definition of a Map2DArea type
Vector.h
contains the definition of a Vector type
Subscriber.h
Port.h
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
MapMetaData.h
yarp::os::Publisher< yarp::rosmsg::nav_msgs::OccupancyGrid >
Map2DServer::Map2DServer
Map2DServer()
Map2DServer.
Definition: Map2DServer.cpp:52
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
Property.h
RpcServer.h
OccupancyGrid.h
PolyDriver.h
Map2DServer::getOptions
yarp::os::Bottle getOptions()
yarp::os::RpcServer
A port that is specialized as an RPC server.
Definition: RpcServer.h:27
Node.h
Map2DServer::open
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
Definition: Map2DServer.cpp:833
Map2DLocation.h
contains the definition of a Map2DLocation type
yarp::os::Node
The Node class.
Definition: Node.h:27
BufferedPort.h
Map2DServer
map2DServer: A device capable of read/save collections of maps from disk, and make them accessible to...
Definition: Map2DServer.h:77
PeriodicThread.h
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
Map2DPath.h
contains the definition of a Map2DPath type
Map2DServer::~Map2DServer
~Map2DServer()
MarkerArray.h
Publisher.h
Map2DServer::load_locations_and_areas
bool load_locations_and_areas(std::string locations_file)
Definition: Map2DServer.cpp:1199
yarp::os::Subscriber< yarp::rosmsg::nav_msgs::OccupancyGrid >
Time.h
api.h
Bottle.h
Map2DServer::loadMaps
bool loadMaps(std::string filename)
Definition: Map2DServer.cpp:774
ResourceFinder.h
DeviceDriver.h
yarp::os::ResourceFinder
Helper class for finding config files and other external resources.
Definition: ResourceFinder.h:33