moveit2
The MoveIt Motion Planning Framework for ROS 2.
srdf_publisher_node.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2024, PickNik Robotics Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of PickNik Robotics Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 // SrdfPublisher Node
36 // Author: Tyler Weaver
37 //
38 // Node with a single parameter and single publisher using transient local QoS.
39 // Publishes string set on parameter `robot_description_semantic` to topic
40 // `/robot_description_semantic`.
41 //
42 // This is similar to what [robot_state_publisher](https://github.com/ros/robot_state_publisher)
43 // does for the URDF using parameter `robot_description` and topic `/robot_description`.
44 //
45 // As MoveIt subscribes to the topic `/robot_description_semantic` for the srdf
46 // this node can be used when you want to set the SRDF parameter on only one node
47 // and have the rest of your system use a subscriber to that topic to get the
48 // SRDF.
49 
50 #include <rclcpp/rclcpp.hpp>
51 #include <std_msgs/msg/string.hpp>
52 
53 #include <string>
54 
56 {
57 
58 class SrdfPublisher : public rclcpp::Node
59 {
60  rclcpp::Publisher<std_msgs::msg::String>::SharedPtr srdf_publisher_;
61  rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr on_set_parameters_handle_;
62 
63 public:
64  SrdfPublisher(const rclcpp::NodeOptions& options) : rclcpp::Node("srdf_publisher", options)
65  {
66  srdf_publisher_ = this->create_publisher<std_msgs::msg::String>("robot_description_semantic",
67  rclcpp::QoS(1).transient_local().reliable());
68 
69  // TODO: Update the callback used here once Humble is EOL
70  // Using add_on_set_parameters_callback as it is the only parameter callback available in Humble.
71  // This is also why we have to return an always success validation.
72  // Once Humble is EOL use add_post_set_parameters_callback.
73  on_set_parameters_handle_ =
74  this->add_on_set_parameters_callback([this](const std::vector<rclcpp::Parameter>& parameters) {
75  for (auto const& parameter : parameters)
76  {
77  if (parameter.get_name() == "robot_description_semantic")
78  {
79  std_msgs::msg::String msg;
80  msg.data = parameter.get_value<std::string>();
81  srdf_publisher_->publish(msg);
82  break;
83  }
84  }
85 
86  rcl_interfaces::msg::SetParametersResult result;
87  result.successful = true;
88  return result;
89  });
90 
91  rcl_interfaces::msg::ParameterDescriptor descriptor;
92  descriptor.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING;
93  descriptor.description = "Semantic Robot Description Format";
94  this->declare_parameter("robot_description_semantic", rclcpp::ParameterType::PARAMETER_STRING, descriptor);
95  }
96 };
97 
98 } // namespace moveit_ros_planning
99 
100 #include "rclcpp_components/register_node_macro.hpp"
101 RCLCPP_COMPONENTS_REGISTER_NODE(moveit_ros_planning::SrdfPublisher)
SrdfPublisher(const rclcpp::NodeOptions &options)