66 #ifndef __SICK_ROS_WRAPPER_H_INCLUDED
67 #define __SICK_ROS_WRAPPER_H_INCLUDED
69 #define _USE_MATH_DEFINES
81 #if !defined __ROS_VERSION
82 #define __ROS_VERSION 0 // default: native Linux or Windows
86 #define SICK_LITTLE_ENDIAN 1 // LITTLE_ENDIAN and BIG_ENDIAN might already be defined differently on a system or in a 3rd party headerfile,
87 #define SICK_BIG_ENDIAN 2 // SICK_TARGET_ENDIANESS, SICK_LITTLE_ENDIAN and SICK_BIG_ENDIAN are used to avoid conflicts
88 #ifndef SICK_TARGET_ENDIANESS
89 #define SICK_TARGET_ENDIANESS SICK_LITTLE_ENDIAN
91 #if SICK_TARGET_ENDIANESS==SICK_LITTLE_ENDIAN
92 #define TARGET_IS_LITTLE_ENDIAN 1
94 #define TARGET_IS_LITTLE_ENDIAN 0
97 #if defined _MSC_VER && defined min
100 #if defined _MSC_VER && defined max
104 template <
typename T> std::string
paramToString(
const std::vector<T>& param_value)
107 s << param_value.size();
120 #if __ROS_VERSION <= 1 // ROS-SIMU (native Linux or Windows) or ROS-1 (Linux only)
122 #if __ROS_VERSION == 0 // native Linux or Windows uses ros simu
124 #define diagnostic_msgs_DiagnosticStatus_OK (SICK_DIAGNOSTIC_STATUS::OK)
125 #define diagnostic_msgs_DiagnosticStatus_WARN (SICK_DIAGNOSTIC_STATUS::WARN)
126 #define diagnostic_msgs_DiagnosticStatus_ERROR (SICK_DIAGNOSTIC_STATUS::SICK_DIAG_ERROR)
142 #include <tf2/LinearMath/Quaternion.h>
143 #include <tf2_ros/transform_broadcaster.h>
147 #define ros_nav_msgs nav_msgs
148 #define ros_sensor_msgs sensor_msgs
149 #define ros_std_msgs std_msgs
150 #define ros_geometry_msgs geometry_msgs
151 #define ros_visualization_msgs visualization_msgs
153 #ifndef diagnostic_msgs_DiagnosticStatus_OK
154 #define diagnostic_msgs_DiagnosticStatus_OK diagnostic_msgs::DiagnosticStatus::OK
156 #ifndef diagnostic_msgs_DiagnosticStatus_WARN
157 #define diagnostic_msgs_DiagnosticStatus_WARN diagnostic_msgs::DiagnosticStatus::WARN
159 #ifndef diagnostic_msgs_DiagnosticStatus_ERROR
160 #define diagnostic_msgs_DiagnosticStatus_ERROR diagnostic_msgs::DiagnosticStatus::ERROR
162 #define ROS_HEADER_SEQ(msgheader,value) msgheader.seq=value
195 if(topic.empty() || topic[0] !=
'/')
196 topic2 = std::string(
"/") + topic;
199 ROS_INFO_STREAM(
"Publishing on topic \"" << topic2 <<
"\", qos=" << qos);
221 #define sick_scan_msg sick_scan_xd
231 #define sick_scan_srv sick_scan_xd
232 #if __ROS_VERSION == 1
233 #include "sick_scan_xd/FieldSetReadSrv.h"
234 #include "sick_scan_xd/FieldSetWriteSrv.h"
249 #define ROS_CREATE_SRV_CLIENT(nh,srv,name) nh->serviceClient<srv>(name)
250 #define ROS_CREATE_SRV_SERVER(nh,srv,name,cbfunction,cbobject) nh->advertiseService(name,cbfunction,cbobject)
252 #elif __ROS_VERSION == 2 // ROS-2 (Linux or Windows)
254 #include <rclcpp/clock.hpp>
255 #include <rclcpp/rclcpp.hpp>
256 #include <rclcpp/time_source.hpp>
257 #include <geometry_msgs/msg/point.hpp>
258 #include <geometry_msgs/msg/transform_stamped.hpp>
259 #include <nav_msgs/msg/odometry.hpp>
260 #include <sensor_msgs/msg/laser_scan.hpp>
261 #include <sensor_msgs/msg/point_cloud.hpp>
262 #include <sensor_msgs/msg/point_cloud2.hpp>
263 #include <sensor_msgs/msg/imu.hpp>
264 #include <std_msgs/msg/string.hpp>
265 #include <std_msgs/msg/color_rgba.hpp>
266 #include <visualization_msgs/msg/marker.hpp>
267 #include <visualization_msgs/msg/marker_array.hpp>
268 #include <tf2/LinearMath/Quaternion.h>
269 #include <tf2_ros/transform_broadcaster.h>
273 #define ros_nav_msgs nav_msgs::msg
274 #define ros_sensor_msgs sensor_msgs::msg
275 #define ros_std_msgs std_msgs::msg
276 #define ros_geometry_msgs geometry_msgs::msg
277 #define ros_visualization_msgs visualization_msgs::msg
279 #ifndef diagnostic_msgs_DiagnosticStatus_OK
280 #define diagnostic_msgs_DiagnosticStatus_OK 0 //diagnostic_msgs::msg::DiagnosticStatus::OK
282 #ifndef diagnostic_msgs_DiagnosticStatus_WARN
283 #define diagnostic_msgs_DiagnosticStatus_WARN 1 // diagnostic_msgs::msg::DiagnosticStatus::WARN
285 #ifndef diagnostic_msgs_DiagnosticStatus_ERROR
286 #define diagnostic_msgs_DiagnosticStatus_ERROR 2 // diagnostic_msgs::msg::DiagnosticStatus::ERROR
288 #define ROS_HEADER_SEQ(msgheader,seq)
292 inline void rosConvParam(
const std::string& str_value, std::string& val){ val = str_value; }
293 inline void rosConvParam(
const std::string& str_value,
bool& val){ val = std::stoi(str_value) > 0; }
294 inline void rosConvParam(
const std::string& str_value,
int& val){ val = std::stoi(str_value); }
295 inline void rosConvParam(
const std::string& str_value,
float& val){ val = std::stof(str_value); }
296 inline void rosConvParam(
const std::string& str_value,
double& val){ val = std::stod(str_value); }
298 template <
typename T>
void rosDeclareParam(
rosNodePtr nh,
const std::string& param_name,
const T& param_value) {
if(!nh->has_parameter(param_name)) nh->declare_parameter<T>(param_name, param_value); }
303 bool bRet = nh->get_parameter(param_name, param_value);
307 catch(
const std::exception& exc)
309 ROS_WARN_STREAM(
"## WARNING rosGetParam(" << param_name <<
", " <<
paramToString(param_value) <<
", " <<
typeid(param_value).
name() <<
") failed, " <<
typeid(exc).
name() <<
", exception " << exc.what());
313 std::string str_value;
314 bool bRet = nh->get_parameter(param_name, str_value);
315 if (std::is_arithmetic<T>::value)
317 rosConvParam(str_value, param_value);
318 ROS_INFO_STREAM(
"rosGetParam(" << param_name <<
"): converted to " << param_value);
326 catch(
const std::exception& exc)
328 ROS_WARN_STREAM(
"## WARNING rosGetParam(" << param_name <<
", " <<
paramToString(param_value) <<
", " <<
typeid(param_value).
name() <<
") failed, " <<
typeid(exc).
name() <<
", exception " << exc.what());
332 template <
typename T>
void rosSetParam(
rosNodePtr nh,
const std::string& param_name,
const T& param_value)
337 nh->set_parameter(rclcpp::Parameter(param_name, param_value));
339 catch(
const std::exception& exc)
341 ROS_WARN_STREAM(
"## WARNING rosSetParam(" << param_name <<
", " <<
paramToString(param_value) <<
", " <<
typeid(param_value).
name() <<
") failed, exception " << exc.what());
345 typedef rclcpp::QoS
rosQoS;
349 inline uint32_t
sec(
const rosTime& time) {
return (uint32_t)(time.nanoseconds() / 1000000000); }
350 inline uint32_t
nsec(
const rosTime& time) {
return (uint32_t)(time.nanoseconds() - 1000000000 *
sec(time)); }
351 inline uint32_t
sec(
const rosDuration& time) {
return (uint32_t)(time.nanoseconds() / 1000000000); }
352 inline uint32_t
nsec(
const rosDuration& time) {
return (uint32_t)(time.nanoseconds() - 1000000000 *
sec(time)); }
361 for (std::map<int,rosQoS>::const_iterator qos_iter = m_qos_map.cbegin(); qos_iter != m_qos_map.cend(); qos_iter++)
362 if (qos_iter->second == qos)
363 return qos_iter->first;
368 for (std::map<int,rosQoS>::const_iterator qos_iter = m_qos_map.cbegin(); qos_iter != m_qos_map.cend(); qos_iter++)
369 if (qos_iter->first == qos)
370 return qos_iter->second;
371 return rclcpp::SystemDefaultsQoS();
374 std::map<int,rosQoS> m_qos_map = { {0, rclcpp::SystemDefaultsQoS()}, {1, rclcpp::ParameterEventsQoS()}, {2, rclcpp::ServicesQoS()}, {3, rclcpp::ParametersQoS()}, {4, rclcpp::SensorDataQoS()} };
377 template <
class T>
class rosPublisher :
public rclcpp::Publisher<T>::SharedPtr
385 QoSConverter qos_converter;
390 qos = qos_converter.convert(qos_val);
394 overwriteByOptionalQOSconfig(nh, qos);
395 QoSConverter qos_converter;
396 ROS_INFO_STREAM(
"Publishing on topic \"" << topic <<
"\", qos=" << qos_converter.convert(qos));
397 auto publisher = nh->create_publisher<T>(topic, qos);
407 inline void rosSleep(
double seconds) { rclcpp::sleep_for(std::chrono::nanoseconds((int64_t)(
seconds * 1.0e9))); }
410 #include <sick_scan_xd/msg/radar_scan.hpp>
411 #include <sick_scan_xd/msg/encoder.hpp>
412 #include <sick_scan_xd/msg/li_dinputstate_msg.hpp>
413 #include <sick_scan_xd/msg/li_doutputstate_msg.hpp>
414 #include <sick_scan_xd/msg/lf_erec_msg.hpp>
415 #include <sick_scan_xd/msg/nav_pose_data.hpp>
416 #include <sick_scan_xd/msg/nav_landmark_data.hpp>
417 #include <sick_scan_xd/msg/nav_odom_velocity.hpp>
418 #define sick_scan_msg sick_scan_xd::msg
420 #include "sick_scan_xd/srv/cola_msg_srv.hpp"
421 #include "sick_scan_xd/srv/ecr_change_arr_srv.hpp"
422 #include "sick_scan_xd/srv/li_doutputstate_srv.hpp"
423 #include "sick_scan_xd/srv/s_cdevicestate_srv.hpp"
424 #include "sick_scan_xd/srv/s_creboot_srv.hpp"
425 #include "sick_scan_xd/srv/s_csoftreset_srv.hpp"
426 #include "sick_scan_xd/srv/sick_scan_exit_srv.hpp"
427 #include "sick_scan_xd/srv/get_contamination_result_srv.hpp"
428 #define sick_scan_srv sick_scan_xd::srv
429 #include "sick_scan_xd/srv/field_set_read_srv.hpp"
430 #include "sick_scan_xd/srv/field_set_write_srv.hpp"
432 template <
class T>
class rosServiceClient :
public rclcpp::Client<T>::SharedPtr
438 template <
class T>
class rosServiceServer :
public rclcpp::Service<T>::SharedPtr
442 template <
class U>
rosServiceServer(U& _server) : rclcpp::Service<T>::SharedPtr(_server) {}
444 #define ROS_CREATE_SRV_CLIENT(nh,srv,name) nh->create_client<srv>(name)
445 #define ROS_CREATE_SRV_SERVER(nh,srv,name,cbfunction,cbobject) nh->create_service<srv>(name,std::bind(cbfunction,cbobject,std::placeholders::_1,std::placeholders::_2))
449 #error __ROS_VERSION undefined or unsupported, build with __ROS_VERSION 0, 1 or 2
451 #endif //__ROS_VERSION
456 #if __ROS_VERSION == 2 // ROS 2
457 #ifdef ROS_DIAGNOSTICS_UPDATER_AVAILABLE
458 #include <diagnostic_updater/diagnostic_updater.hpp>
459 #include <diagnostic_updater/publisher.hpp>
460 #include <rcl_interfaces/msg/set_parameters_result.hpp>
461 #define USE_DYNAMIC_RECONFIGURE
462 #define USE_DIAGNOSTIC_UPDATER
476 virtual ~DiagnosedPublishAdapter()
479 template <
typename MessageType>
void publish(
const std::shared_ptr<MessageType> & message)
484 template <
typename MessageType>
void publish(
const MessageType & message)
490 DiagnosedPublisherT publisher_;
493 #endif // ROS_DIAGNOSTICS_UPDATER_AVAILABLE
494 #elif __ROS_VERSION == 1 // ROS 1
497 #include <diagnostic_updater/diagnostic_updater.h>
498 #include <diagnostic_updater/publisher.h>
500 #include <sick_scan_xd/SickLDMRSDriverConfig.h>
501 #define USE_DYNAMIC_RECONFIGURE
502 #define USE_DIAGNOSTIC_UPDATER
504 #include <sick_scan_xd/SickScanConfig.h>
506 #include <diagnostic_updater/diagnostic_updater.h>
507 #include <diagnostic_updater/publisher.h>
509 #if __ROS_VERSION != 1
530 #endif // __SICK_ROS_WRAPPER_H_INCLUDED