YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Map2D_nwc_yarp.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
8#include "Map2D_nwc_yarp.h"
9#include <yarp/os/Log.h>
11#include <yarp/os/LogStream.h>
12#include <mutex>
15
16using namespace yarp::dev;
17using namespace yarp::dev::Nav2D;
18using namespace yarp::os;
19using namespace yarp::sig;
20
21namespace {
22YARP_LOG_COMPONENT(MAP2D_NWC_YARP, "yarp.device.map2D_nwc_yarp")
23}
24
25//------------------------------------------------------------------------------------------------------------------------------
26
28{
29 if (!parseParams(config)) { return false; }
30
31 std::string local_rpc1 = m_local;
32 local_rpc1 += "/mapClient_rpc";
33
34 std::string remote_rpc1 = m_remote;
35 remote_rpc1 += "/rpc";
36
38 {
39 yCError(MAP2D_NWC_YARP, "open() error could not open rpc port %s, check network", local_rpc1.c_str());
40 return false;
41 }
42
43 bool ok=false;
44 ok=Network::connect(local_rpc1, remote_rpc1, m_carrier);
45 if (!ok)
46 {
47 yCError(MAP2D_NWC_YARP, "open() error could not connect to %s", remote_rpc1.c_str());
48 return false;
49 }
50
52 {
53 yCError(MAP2D_NWC_YARP, "Error! Cannot attach the port as a client");
54 return false;
55 }
56
57 return true;
58}
59
61{
62 std::lock_guard <std::mutex> lg(m_mutex);
63 return m_map_RPC.store_map_RPC(map);
64}
65
66bool Map2D_nwc_yarp::get_map(std::string map_name, MapGrid2D& map)
67{
68 std::lock_guard <std::mutex> lg(m_mutex);
69 auto ret = m_map_RPC.get_map_RPC(map_name);
70 if (!ret.retval)
71 {
72 yCError(MAP2D_NWC_YARP, "Unable to get_map");
73 return false;
74 }
75 map = ret.themap;
76 return true;
77}
78
80{
81 std::lock_guard <std::mutex> lg(m_mutex);
83}
84
85bool Map2D_nwc_yarp::get_map_names(std::vector<std::string>& map_names)
86{
87 std::lock_guard <std::mutex> lg(m_mutex);
89 if (!ret.retval)
90 {
91 yCError(MAP2D_NWC_YARP, "Unable to get_map_names");
92 return false;
93 }
94 map_names = ret.map_names;
95 return true;
96}
97
98bool Map2D_nwc_yarp::remove_map(std::string map_name)
99{
100 std::lock_guard <std::mutex> lg(m_mutex);
101 return m_map_RPC.remove_map_RPC(map_name);
102}
103
104bool Map2D_nwc_yarp::storeLocation(std::string location_name, Map2DLocation loc)
105{
106 std::lock_guard <std::mutex> lg(m_mutex);
107 return m_map_RPC.store_location_RPC(location_name,loc);
108}
109
110bool Map2D_nwc_yarp::storeArea(std::string area_name, Map2DArea area)
111{
112 std::lock_guard <std::mutex> lg(m_mutex);
113 return m_map_RPC.store_area_RPC(area_name, area);
114}
115
116bool Map2D_nwc_yarp::storePath(std::string path_name, Map2DPath path)
117{
118 std::lock_guard <std::mutex> lg(m_mutex);
119 return m_map_RPC.store_path_RPC(path_name, path);
120}
121
122bool Map2D_nwc_yarp::getLocationsList(std::vector<std::string>& locations)
123{
124 std::lock_guard <std::mutex> lg(m_mutex);
126 if (!ret.retval)
127 {
128 yCError(MAP2D_NWC_YARP, "Unable to getLocationsList");
129 return false;
130 }
131 locations = ret.locations;
132 return true;
133}
134
135bool Map2D_nwc_yarp::getAreasList(std::vector<std::string>& areas)
136{
137 std::lock_guard <std::mutex> lg(m_mutex);
139 if (!ret.retval)
140 {
141 yCError(MAP2D_NWC_YARP, "Unable to getAreasList");
142 return false;
143 }
144 areas = ret.areas;
145 return true;
146}
147
148bool Map2D_nwc_yarp::getPathsList(std::vector<std::string>& paths)
149{
150 std::lock_guard <std::mutex> lg(m_mutex);
152 if (!ret.retval)
153 {
154 yCError(MAP2D_NWC_YARP, "Unable to getPathsList");
155 return false;
156 }
157 paths = ret.paths;
158 return true;
159}
160
161bool Map2D_nwc_yarp::getAllLocations(std::vector<yarp::dev::Nav2D::Map2DLocation>& locations)
162{
163 std::lock_guard <std::mutex> lg(m_mutex);
165 if (!ret.retval)
166 {
167 yCError(MAP2D_NWC_YARP, "Unable to getAllLocations");
168 return false;
169 }
170 locations = ret.locations;
171 return true;
172}
173
174bool Map2D_nwc_yarp::getAllAreas(std::vector<yarp::dev::Nav2D::Map2DArea>& areas)
175{
176 std::lock_guard <std::mutex> lg(m_mutex);
178 if (!ret.retval)
179 {
180 yCError(MAP2D_NWC_YARP, "Unable to getAllAreas");
181 return false;
182 }
183 areas = ret.areas;
184 return true;
185}
186
187bool Map2D_nwc_yarp::getAllPaths(std::vector<yarp::dev::Nav2D::Map2DPath>& paths)
188{
189 std::lock_guard <std::mutex> lg(m_mutex);
191 if (!ret.retval)
192 {
193 yCError(MAP2D_NWC_YARP, "Unable to getAllPaths");
194 return false;
195 }
196 paths = ret.paths;
197 return true;
198}
199
200bool Map2D_nwc_yarp::getLocation(std::string location_name, Map2DLocation& loc)
201{
202 std::lock_guard <std::mutex> lg(m_mutex);
203 auto ret = m_map_RPC.get_location_RPC(location_name);
204 if (!ret.retval)
205 {
206 yCError(MAP2D_NWC_YARP, "Unable to getLocation");
207 return false;
208 }
209 loc = ret.loc;
210 return true;
211}
212
213bool Map2D_nwc_yarp::getArea(std::string area_name, Map2DArea& area)
214{
215 std::lock_guard <std::mutex> lg(m_mutex);
216 auto ret = m_map_RPC.get_area_RPC(area_name);
217 if (!ret.retval)
218 {
219 yCError(MAP2D_NWC_YARP, "Unable to getArea");
220 return false;
221 }
222 area = ret.area;
223 return true;
224}
225
226bool Map2D_nwc_yarp::getPath(std::string path_name, Map2DPath& path)
227{
228 std::lock_guard <std::mutex> lg(m_mutex);
229 auto ret = m_map_RPC.get_path_RPC(path_name);
230 if (!ret.retval)
231 {
232 yCError(MAP2D_NWC_YARP, "Unable to getPath");
233 return false;
234 }
235 path = ret.path;
236 return true;
237}
238
239bool Map2D_nwc_yarp::deleteLocation(std::string location_name)
240{
241 std::lock_guard <std::mutex> lg(m_mutex);
242 return m_map_RPC.delete_location_RPC(location_name);
243}
244
245bool Map2D_nwc_yarp::renameLocation(std::string original_name, std::string new_name)
246{
247 std::lock_guard <std::mutex> lg(m_mutex);
248 return m_map_RPC.rename_location_RPC(original_name,new_name);
249}
250
251bool Map2D_nwc_yarp::deleteArea(std::string location_name)
252{
253 std::lock_guard <std::mutex> lg(m_mutex);
254 return m_map_RPC.delete_area_RPC(location_name);
255}
256
257bool Map2D_nwc_yarp::deletePath(std::string path_name)
258{
259 std::lock_guard <std::mutex> lg(m_mutex);
260 return m_map_RPC.delete_path_RPC(path_name);
261}
262
263bool Map2D_nwc_yarp::renameArea(std::string original_name, std::string new_name)
264{
265 std::lock_guard <std::mutex> lg(m_mutex);
266 return m_map_RPC.rename_area_RPC(original_name, new_name);
267}
268
269bool Map2D_nwc_yarp::renamePath(std::string original_name, std::string new_name)
270{
271 std::lock_guard <std::mutex> lg(m_mutex);
272 return m_map_RPC.rename_path_RPC(original_name, new_name);
273}
274
276{
277 std::lock_guard <std::mutex> lg(m_mutex);
279}
280
282{
283 std::lock_guard <std::mutex> lg(m_mutex);
285}
286
288{
289 std::lock_guard <std::mutex> lg(m_mutex);
291}
292
294{
295 std::lock_guard <std::mutex> lg(m_mutex);
297}
298
300{
301 std::lock_guard <std::mutex> lg(m_mutex);
303}
304
306{
307 return true;
308}
309
311{
312 std::lock_guard <std::mutex> lg(m_mutex);
314}
315
317{
318 std::lock_guard <std::mutex> lg(m_mutex);
320}
321
327
333
334bool Map2D_nwc_yarp::saveMapToDisk(std::string map_name, std::string file_name)
335{
336 std::lock_guard <std::mutex> lg(m_mutex);
337 return m_map_RPC.save_map_to_disk_RPC(map_name,file_name);
338}
339
340bool Map2D_nwc_yarp::loadMapFromDisk(std::string file_name)
341{
342 std::lock_guard <std::mutex> lg(m_mutex);
343 return m_map_RPC.load_map_from_disk_RPC(file_name);
344}
345
347{
348 std::lock_guard <std::mutex> lg(m_mutex);
350}
bool ret
virtual return_get_map_names get_map_names_RPC()
virtual bool rename_path_RPC(const std::string &original_name, const std::string &new_name)
virtual bool store_path_RPC(const std::string &path_name, const yarp::dev::Nav2D::Map2DPath &path)
virtual bool clear_all_areas_RPC()
virtual bool clear_all_paths_RPC()
virtual bool save_map_to_disk_RPC(const std::string &map_name, const std::string &file_name)
virtual bool store_map_RPC(const yarp::dev::Nav2D::MapGrid2D &themap)
virtual bool load_map_from_disk_RPC(const std::string &file_name)
virtual bool delete_location_RPC(const std::string &location_name)
virtual bool clear_all_maps_temporary_flags_RPC()
virtual return_get_all_areas get_all_areas_RPC()
virtual bool load_locations_and_extras_RPC(const std::string &locations_collection_file)
virtual bool clear_map_temporary_flags_RPC(const std::string &map_name)
virtual return_get_location get_location_RPC(const std::string &location_name)
virtual bool load_maps_collection_RPC(const std::string &maps_collection_file)
virtual bool delete_path_RPC(const std::string &path_name)
virtual return_get_areas_list get_areas_list_RPC()
virtual return_get_path get_path_RPC(const std::string &path_name)
virtual bool store_location_RPC(const std::string &location_name, const yarp::dev::Nav2D::Map2DLocation &loc)
virtual bool clear_all_maps_RPC()
virtual return_get_area get_area_RPC(const std::string &area_name)
virtual return_get_all_paths get_all_paths_RPC()
virtual return_get_map get_map_RPC(const std::string &map_name)
virtual return_get_paths_list get_paths_list_RPC()
virtual bool remove_map_RPC(const std::string &map_name)
virtual return_get_locations_list get_locations_list_RPC()
virtual bool rename_location_RPC(const std::string &original_name, const std::string &new_name)
virtual bool save_locations_and_extras_RPC(const std::string &locations_collection_file)
virtual return_get_all_locations get_all_locations_RPC()
virtual bool save_maps_collection_RPC(const std::string &maps_collection_file)
virtual bool rename_area_RPC(const std::string &original_name, const std::string &new_name)
virtual bool store_area_RPC(const std::string &area_name, const yarp::dev::Nav2D::Map2DArea &area)
virtual bool clear_all_locations_RPC()
virtual bool enable_maps_compression_RPC(const bool enable_compression)
virtual bool delete_area_RPC(const std::string &area_name)
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
bool getAllLocations(std::vector< yarp::dev::Nav2D::Map2DLocation > &locations) override
Get a list of all stored locations.
bool clearAllLocations() override
Delete all stored locations.
bool saveMapToDisk(std::string map_name, std::string file_name) override
Save a map to disk.
bool get_map(std::string map_name, yarp::dev::Nav2D::MapGrid2D &map) override
Gets a map from the map server.
bool renameArea(std::string original_name, std::string new_name) override
Searches for an area and renames it.
bool store_map(const yarp::dev::Nav2D::MapGrid2D &map) override
Stores a map into the map server.
bool getArea(std::string location_name, yarp::dev::Nav2D::Map2DArea &area) override
Retrieves an area.
bool storePath(std::string path_name, yarp::dev::Nav2D::Map2DPath path) override
Store a path.
bool loadMapFromDisk(std::string file_name) override
Load a map from disk.
bool getLocationsList(std::vector< std::string > &locations) override
Get a list of the names of all stored locations.
bool saveMapsCollection(std::string maps_collection_file) override
Save a collection of maps to disk.
bool renameLocation(std::string original_name, std::string new_name) override
Searches for a location and renames it.
bool getAllPaths(std::vector< yarp::dev::Nav2D::Map2DPath > &paths) override
Get a list of all stored paths.
bool getAllAreas(std::vector< yarp::dev::Nav2D::Map2DArea > &areas) override
Get a list of all stored areas.
bool remove_map(std::string map_name) override
Removes a map from the map server.
bool getLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation &loc) override
Retrieves a location specified by the user in the world reference frame.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::os::Port m_rpcPort_to_Map2D_nws
bool saveLocationsAndExtras(std::string locations_collection_file) override
Save a collection of locations/area/paths etc to disk.
bool clearAllPaths() override
Delete all stored paths.
bool deleteArea(std::string location_name) override
Delete an area.
bool loadLocationsAndExtras(std::string locations_collection_file) override
Load a collection of locations/areas/paths etc from disk.
bool storeArea(std::string area_name, yarp::dev::Nav2D::Map2DArea area) override
Store an area.
bool clearAllMapsTemporaryFlags() override
Clear all temporary flags from all stored maps.
bool clearAllAreas() override
Delete all stored areas.
IMap2DMsgs m_map_RPC
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 clearAllMaps() override
Removes all the registered maps from the server.
bool getPathsList(std::vector< std::string > &paths) override
Get a list of the names of all stored paths.
bool deletePath(std::string path_name) override
Delete a path.
bool clearMapTemporaryFlags(std::string map_name) override
Clear all temporary flags from a specific map.
bool loadMapsCollection(std::string maps_collection_file) override
Load a collection of maps from disk.
bool deleteLocation(std::string location_name) override
Delete a location.
std::mutex m_mutex
bool renamePath(std::string original_name, std::string new_name) override
Searches for a path and renames it.
bool getPath(std::string path_name, yarp::dev::Nav2D::Map2DPath &path) override
Retrieves a path.
bool close() override
Close the DeviceDriver.
bool get_map_names(std::vector< std::string > &map_names) override
Gets a list containing the names of all registered maps.
bool getAreasList(std::vector< std::string > &locations) override
Get a list of the names of all stored areas.
bool enableMapsCompression(bool enable) override
99999999999
A mini-server for performing network communication in the background.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
A base class for nested structures that can be searched.
Definition Searchable.h:31
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition Wire.h:28
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.