6#ifndef _USE_MATH_DEFINES
7#define _USE_MATH_DEFINES
26#include <rclcpp/qos.hpp>
33using namespace std::placeholders;
47 driver->
view(m_iMap2D);
50 m_currentMapName =
maps[0];
53 if (
nullptr == m_iMap2D)
77 m_rpcPortName =
"/"+
m_name+
"/rpc";
80 if (!m_rpcPort.
open(m_rpcPortName))
101 qos.liveliness_lease_duration=time;
105 qos.avoid_ros_namespace_conventions =
true;
106 m_ros2Service_getMap = m_node->create_service<nav_msgs::srv::GetMap>(
m_getmap,
108 m_ros2Service_getMapByName = m_node->create_service<map2d_nws_ros2_msgs::srv::GetMapByName>(
m_getmapbyname,
110 m_ros2Service_rosCmdParser = m_node->create_service<test_msgs::srv::BasicTypes>(
m_roscmdparser,
142 std::lock_guard<std::mutex> lock(m_mutex);
146 if (!ok)
return false;
173 if (!m_ros2Publisher_markers)
175 m_ros2Publisher_markers = m_node->create_publisher<visualization_msgs::msg::MarkerArray>(
m_markers_pub, 10);
177 builtin_interfaces::msg::Duration
dur;
178 dur.sec = 0xFFFFFFFF;
185 if (
sec_part > std::numeric_limits<unsigned int>::max())
190 visualization_msgs::msg::Marker
marker;
191 builtin_interfaces::msg::Time
tt;
194 visualization_msgs::msg::MarkerArray
markers;
196 std::vector<std::string> locations;
199 for (
auto it : locations)
204 if(loc.
map_id != m_currentMapName && m_currentMapName !=
"none")
213 q.fromRotationMatrix(
m);
215 marker.header.frame_id =
"map";
220 marker.type = visualization_msgs::msg::Marker::ARROW;
221 marker.action = visualization_msgs::msg::Marker::ADD;
222 marker.pose.position.x = loc.
x;
223 marker.pose.position.y = loc.
y;
224 marker.pose.position.z = 0;
225 marker.pose.orientation.x =
q.x();
226 marker.pose.orientation.y =
q.y();
227 marker.pose.orientation.z =
q.z();
228 marker.pose.orientation.w =
q.w();
242 m_ros2Publisher_markers->publish(
markers);
248 const std::shared_ptr<nav_msgs::srv::GetMap::Request> request,
249 std::shared_ptr<nav_msgs::srv::GetMap::Response> response)
252 nav_msgs::msg::OccupancyGrid
mapToGo;
253 mapToGo.header.frame_id =
"map";
259 const std::shared_ptr<test_msgs::srv::BasicTypes::Request> request,
260 std::shared_ptr<test_msgs::srv::BasicTypes::Response> response)
262 if(request->string_value ==
"updatemarkerviz")
265 else response->set__string_value(
"error");
269 response->set__string_value(
"unknown_command");
275 const std::shared_ptr<map2d_nws_ros2_msgs::srv::GetMapByName::Request> request,
276 std::shared_ptr<map2d_nws_ros2_msgs::srv::GetMapByName::Response> response)
278 if (!m_ros2Publisher_map)
280 m_ros2Publisher_map = m_node->create_publisher<nav_msgs::msg::OccupancyGrid>(
m_getmapbyname+
"/pub", 10);
282 nav_msgs::msg::OccupancyGrid
mapToGo;
283 nav_msgs::msg::MapMetaData
metaToGo;
284 mapToGo.header.frame_id =
"map";
288 mapToGo.header.frame_id =
"invalid_frame";
292 mapToGo.info.map_load_time = m_node->get_clock()->now();
293 mapToGo.header.stamp = m_node->get_clock()->now();
303 mapToGo.info.origin.position.x=x;
304 mapToGo.info.origin.position.y=y;
307 v[0]=0; v[1]=0; v[2]=1; v[3]=t*
DEG2RAD;
309 mapToGo.info.origin.orientation.x =
q.x();
310 mapToGo.info.origin.orientation.y =
q.y();
311 mapToGo.info.origin.orientation.z =
q.z();
312 mapToGo.info.origin.orientation.w =
q.w();
326 m_currentMapName = request->name;
334 if (m_ros2Publisher_map)
336 m_ros2Publisher_map->publish(
mapToGo);
std::string m_roscmdparser
std::string m_markers_pub
std::string m_getmapbyname
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
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).
static rclcpp::Node::SharedPtr createNode(std::string name)
bool view(T *&x)
Get an interface to the device driver.
std::string map_id
name of the map
double theta
orientation [deg] in the map reference frame
double y
y position of the location [m], expressed in the map reference frame
double x
x position of the location [m], expressed in the map reference frame
virtual yarp::dev::ReturnValue get_map_names(std::vector< std::string > &map_names)=0
Gets a list containing the names of all registered maps.
virtual yarp::dev::ReturnValue getLocationsList(std::vector< std::string > &locations)=0
Get a list of the names of all stored locations.
virtual yarp::dev::ReturnValue get_map(std::string map_name, yarp::dev::Nav2D::MapGrid2D &map)=0
Gets a map from the map server.
virtual yarp::dev::ReturnValue getLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation &loc)=0
Retrieves a location specified by the user in the world reference frame.
A container for a device driver.
bool isValid() const
Check if device is valid.
A simple collection of objects that can be described and transmitted in a portable way.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
An interface for writing to a network connection.
A base class for nested structures that can be searched.
bool start()
Start the new thread running.
virtual bool isString() const
Checks if value is a string.
virtual bool isVocab32() const
Checks if value is a vocabulary identifier.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
yarp::sig::Matrix rpy2dcm(const yarp::sig::Vector &rpy)
Converts roll-pitch-yaw angles in the corresponding dcm (direction cosine matrix) rotation matrix (de...
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.
std::uint32_t NetUint32
Definition of the NetUint32 type.