6#ifndef _USE_MATH_DEFINES
7#define _USE_MATH_DEFINES
26#include <rclcpp/qos.hpp>
27#include <rclcpp/version.h>
34using namespace std::placeholders;
48 driver->
view(m_iMap2D);
51 m_currentMapName =
maps[0];
54 if (
nullptr == m_iMap2D)
78 m_rpcPortName =
"/"+
m_name+
"/rpc";
81 if (!m_rpcPort.
open(m_rpcPortName))
102 qos_rmw.liveliness_lease_duration=time;
106 qos_rmw.avoid_ros_namespace_conventions =
true;
107 m_ros2Service_getMap = m_node->create_service<nav_msgs::srv::GetMap>(
m_getmap,
109#if RCLCPP_VERSION_GTE(17,0,0)
110 rclcpp::QoS(rclcpp::QoSInitialization::from_rmw(
qos_rmw))
115 m_ros2Service_getMapByName = m_node->create_service<map2d_nws_ros2_msgs::srv::GetMapByName>(
m_getmapbyname,
117 m_ros2Service_rosCmdParser = m_node->create_service<test_msgs::srv::BasicTypes>(
m_roscmdparser,
149 std::lock_guard<std::mutex> lock(m_mutex);
152 bool ok = in.
read(connection);
153 if (!ok)
return false;
180 if (!m_ros2Publisher_markers)
182 m_ros2Publisher_markers = m_node->create_publisher<visualization_msgs::msg::MarkerArray>(
m_markers_pub, 10);
184 builtin_interfaces::msg::Duration
dur;
185 dur.sec = 0xFFFFFFFF;
192 if (
sec_part > std::numeric_limits<unsigned int>::max())
197 visualization_msgs::msg::Marker
marker;
198 builtin_interfaces::msg::Time
tt;
201 visualization_msgs::msg::MarkerArray
markers;
203 std::vector<std::string> locations;
206 for (
auto it : locations)
211 if(loc.
map_id != m_currentMapName && m_currentMapName !=
"none")
222 marker.header.frame_id =
"map";
227 marker.type = visualization_msgs::msg::Marker::ARROW;
228 marker.action = visualization_msgs::msg::Marker::ADD;
229 marker.pose.position.x = loc.
x;
230 marker.pose.position.y = loc.
y;
231 marker.pose.position.z = 0;
232 marker.pose.orientation.x = q.
x();
233 marker.pose.orientation.y = q.
y();
234 marker.pose.orientation.z = q.
z();
235 marker.pose.orientation.w = q.
w();
249 m_ros2Publisher_markers->publish(
markers);
255 const std::shared_ptr<nav_msgs::srv::GetMap::Request>
request,
256 std::shared_ptr<nav_msgs::srv::GetMap::Response> response)
259 nav_msgs::msg::OccupancyGrid
mapToGo;
260 mapToGo.header.frame_id =
"map";
266 const std::shared_ptr<test_msgs::srv::BasicTypes::Request>
request,
267 std::shared_ptr<test_msgs::srv::BasicTypes::Response> response)
269 if(
request->string_value ==
"updatemarkerviz")
272 else response->set__string_value(
"error");
276 response->set__string_value(
"unknown_command");
282 const std::shared_ptr<map2d_nws_ros2_msgs::srv::GetMapByName::Request>
request,
283 std::shared_ptr<map2d_nws_ros2_msgs::srv::GetMapByName::Response> response)
285 if (!m_ros2Publisher_map)
287 m_ros2Publisher_map = m_node->create_publisher<nav_msgs::msg::OccupancyGrid>(
m_getmapbyname+
"/pub", 10);
289 nav_msgs::msg::OccupancyGrid
mapToGo;
290 nav_msgs::msg::MapMetaData
metaToGo;
291 mapToGo.header.frame_id =
"map";
295 mapToGo.header.frame_id =
"invalid_frame";
299 mapToGo.info.map_load_time = m_node->get_clock()->now();
300 mapToGo.header.stamp = m_node->get_clock()->now();
310 mapToGo.info.origin.position.x=x;
311 mapToGo.info.origin.position.y=y;
314 v[0]=0; v[1]=0; v[2]=1; v[3]=t*
DEG2RAD;
316 mapToGo.info.origin.orientation.x = q.
x();
317 mapToGo.info.origin.orientation.y = q.
y();
318 mapToGo.info.origin.orientation.z = q.
z();
319 mapToGo.info.origin.orientation.w = q.
w();
333 m_currentMapName =
request->name;
341 if (m_ros2Publisher_map)
343 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.
void fromRotationMatrix(const yarp::sig::Matrix &R)
Converts a rotation matrix to a quaternion.
void fromAxisAngle(const yarp::sig::Vector &v)
Computes the quaternion from an axis-angle representation.
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.
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
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 32bit 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.