YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Map2D_nws_ros2.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_DEV_MAP2D_NWS_ROS2_H
7#define YARP_DEV_MAP2D_NWS_ROS2_H
8
9#include <vector>
10#include <iostream>
11#include <string>
12#include <sstream>
13#include <mutex>
14
15#include <yarp/os/Network.h>
16#include <yarp/os/Port.h>
17#include <yarp/os/Bottle.h>
18#include <yarp/os/Time.h>
19#include <yarp/os/Property.h>
20
22#include <yarp/os/Thread.h>
24#include <yarp/os/RpcServer.h>
25#include <yarp/sig/Vector.h>
26#include <yarp/dev/IMap2D.h>
27#include <yarp/dev/MapGrid2D.h>
29#include <yarp/dev/Map2DArea.h>
30#include <yarp/dev/Map2DPath.h>
33
34#include <yarp/dev/PolyDriver.h>
36#include <yarp/dev/api.h>
38
39#include <rclcpp/rclcpp.hpp>
40
41#include <nav_msgs/msg/occupancy_grid.hpp>
42#include <nav_msgs/srv/get_map.hpp>
43#include <test_msgs/srv/basic_types.hpp>
44#include <visualization_msgs/msg/marker_array.hpp>
45#include <visualization_msgs/msg/marker.hpp>
46
47//Custom ros2 interfaces
48#include <map2d_nws_ros2_msgs/srv/get_map_by_name.hpp>
49
50
65 public yarp::os::Thread,
70{
71public:
73 ~Map2D_nws_ros2() override = default;
74
75
76 //IMultipleWrapper
77 bool attach(yarp::dev::PolyDriver* driver) override;
78 bool detach() override;
79
80 // DeviceDriver
81 bool open(yarp::os::Searchable &config) override;
82 bool close() override;
83 bool read(yarp::os::ConnectionReader& connection) override;
84
85 //Other stuff
86 void getMapCallback(const std::shared_ptr<rmw_request_id_t> request_header,
87 const std::shared_ptr<nav_msgs::srv::GetMap::Request> request,
88 std::shared_ptr<nav_msgs::srv::GetMap::Response> response);
89 void getMapByNameCallback(const std::shared_ptr<rmw_request_id_t> request_header,
90 const std::shared_ptr<map2d_nws_ros2_msgs::srv::GetMapByName::Request> request,
91 std::shared_ptr<map2d_nws_ros2_msgs::srv::GetMapByName::Response> response);
92 void rosCmdParserCallback(const std::shared_ptr<rmw_request_id_t> request_header,
93 const std::shared_ptr<test_msgs::srv::BasicTypes::Request> request,
94 std::shared_ptr<test_msgs::srv::BasicTypes::Response> response);
95 bool updateVizMarkers();
96
97 void run() override;
98
99private:
100 //drivers and interfaces
101 yarp::dev::Nav2D::IMap2D* m_iMap2D = nullptr;
103
104 std::mutex m_mutex;
105 std::string m_rpcPortName;
106 std::string m_currentMapName{"none"};
107 bool m_spinned{false};
108
109 yarp::os::RpcServer m_rpcPort;
110 rclcpp::Node::SharedPtr m_node;
111 rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr m_ros2Publisher_markers{nullptr};
112 rclcpp::Publisher<nav_msgs::msg::OccupancyGrid>::SharedPtr m_ros2Publisher_map{nullptr};
113 rclcpp::Service<nav_msgs::srv::GetMap>::SharedPtr m_ros2Service_getMap{nullptr};
114 rclcpp::Service<map2d_nws_ros2_msgs::srv::GetMapByName>::SharedPtr m_ros2Service_getMapByName{nullptr};
115 rclcpp::Service<test_msgs::srv::BasicTypes>::SharedPtr m_ros2Service_rosCmdParser{nullptr};
116};
117
118
119#endif //YARP_DEV_MAP2D_NWS_ROS2_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
This class is the parameters parser for class Map2D_nws_ros2.
Map2D_nws_ros2: A device capable of read/save collections of maps from disk, and make them accessible...
~Map2D_nws_ros2() override=default
void getMapCallback(const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< nav_msgs::srv::GetMap::Request > request, std::shared_ptr< nav_msgs::srv::GetMap::Response > response)
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
void getMapByNameCallback(const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< map2d_nws_ros2_msgs::srv::GetMapByName::Request > request, std::shared_ptr< map2d_nws_ros2_msgs::srv::GetMapByName::Response > response)
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool close() override
Close the DeviceDriver.
bool attach(yarp::dev::PolyDriver *driver) override
Attach to another object.
void rosCmdParserCallback(const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< test_msgs::srv::BasicTypes::Request > request, std::shared_ptr< test_msgs::srv::BasicTypes::Response > response)
void run() override
Main body of the new thread.
bool detach() override
Detach the object (you must have first called attach).
Interface implemented by all device drivers.
IMap2D Interface.
Definition IMap2D.h:30
A container for a device driver.
Definition PolyDriver.h:23
Helper interface for an object that can wrap/or "attach" to a single other device.
An interface for reading from a network connection.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
A port that is specialized as an RPC server.
Definition RpcServer.h:23
A base class for nested structures that can be searched.
Definition Searchable.h:31
An abstraction for a thread of execution.
Definition Thread.h:21