-
Notifications
You must be signed in to change notification settings - Fork 580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
srdf publisher node #2682
srdf publisher node #2682
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
add_library(srdf_publisher_node SHARED src/srdf_publisher_node.cpp) | ||
ament_target_dependencies(srdf_publisher_node PUBLIC std_msgs rclcpp | ||
rclcpp_components) | ||
|
||
if(BUILD_TESTING) | ||
find_package(launch_testing_ament_cmake REQUIRED) | ||
|
||
add_launch_test(test/srdf_publisher_test.py TARGET test-srdf_publisher) | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/********************************************************************* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Copyright (c) 2024, PickNik Robotics Inc. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of PickNik Robotics Inc. nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*********************************************************************/ | ||
|
||
// SrdfPublisher Node | ||
// Author: Tyler Weaver | ||
// | ||
// Node with a single parameter and single publisher using transient local QoS. | ||
// Publishes string set on parameter `robot_description_semantic` to topic | ||
// `/robot_description_semantic`. | ||
// | ||
// This is similar to what [robot_state_publisher](https://github.com/ros/robot_state_publisher) | ||
// does for the URDF using parameter `robot_description` and topic `/robot_description`. | ||
// | ||
// As MoveIt subscribes to the topic `/robot_description_semantic` for the srdf | ||
// this node can be used when you want to set the SRDF parameter on only one node | ||
// and have the rest of your system use a subscriber to that topic to get the | ||
// SRDF. | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
#include <std_msgs/msg/string.hpp> | ||
|
||
#include <string> | ||
|
||
namespace moveit_ros_planning | ||
{ | ||
|
||
class SrdfPublisher : public rclcpp::Node | ||
{ | ||
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr srdf_publisher_; | ||
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr on_set_parameters_handle_; | ||
|
||
public: | ||
SrdfPublisher(const rclcpp::NodeOptions& options) : rclcpp::Node("srdf_publisher", options) | ||
{ | ||
srdf_publisher_ = this->create_publisher<std_msgs::msg::String>("robot_description_semantic", | ||
rclcpp::QoS(1).transient_local().reliable()); | ||
|
||
// TODO: Update the callback used here once Humble is EOL | ||
// Using add_on_set_parameters_callback as it is the only parameter callback available in Humble. | ||
// This is also why we have to return an always success validation. | ||
// Once Humble is EOL use add_post_set_parameters_callback. | ||
on_set_parameters_handle_ = | ||
this->add_on_set_parameters_callback([this](const std::vector<rclcpp::Parameter>& parameters) { | ||
for (auto const& parameter : parameters) | ||
{ | ||
if (parameter.get_name() == "robot_description_semantic") | ||
{ | ||
std_msgs::msg::String msg; | ||
msg.data = parameter.get_value<std::string>(); | ||
srdf_publisher_->publish(msg); | ||
break; | ||
} | ||
} | ||
|
||
rcl_interfaces::msg::SetParametersResult result; | ||
result.successful = true; | ||
return result; | ||
Comment on lines
+86
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this callback always suppose to return success or should it return success in the if, and false otherwise? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm adding a comment about this. In humble the only callback we have for parameters is the validation one. You may ask, why don't I validate this is a valid srdf? I considered that until I realized the srdf parser requires a urdf as a parameter which I don't want to make this node get the urdf just to validate the srdf. This node is just a relay anyway and if you use it to set an invalid srdf the nodes that depend on it will blow up. After humble is eol we can use add_post_set_parameters_callback which is only in rolling now. I'm adding a comment explaining this. |
||
}); | ||
|
||
rcl_interfaces::msg::ParameterDescriptor descriptor; | ||
descriptor.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING; | ||
descriptor.description = "Semantic Robot Description Format"; | ||
this->declare_parameter("robot_description_semantic", rclcpp::ParameterType::PARAMETER_STRING, descriptor); | ||
} | ||
}; | ||
|
||
} // namespace moveit_ros_planning | ||
|
||
#include "rclcpp_components/register_node_macro.hpp" | ||
RCLCPP_COMPONENTS_REGISTER_NODE(moveit_ros_planning::SrdfPublisher) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can there be multiple
robot_description_semantic
parameter? or should if the get_name( ) == then should this function return?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a break here instead of a return because we need to return success through the result for now.