-
Notifications
You must be signed in to change notification settings - Fork 456
Add utility node for transform wrench messages for a list of frames #2021
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
Merged
saikishor
merged 14 commits into
ros-controls:master
from
Juliaj:fts_broadercaster_utility_node_1842_2
Nov 28, 2025
Merged
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a56457c
Create a utility node that transforms input Wrench for a given list o…
Juliaj ab7b06a
Make linter happy
Juliaj 9ba1144
Remove the test to load yaml file
Juliaj f16a304
Fix the doc building error and add more tests
Juliaj 94d63f7
Update per review feedback
Juliaj 9b52cef
Merge branch 'master' into fts_broadercaster_utility_node_1842_2
Juliaj 7647163
Fix the tf2 header files
Juliaj 45ef512
Apply suggestions from code review
Juliaj 973e235
Add a non-identity transform test
Juliaj 6925dc8
Merge branch 'fts_broadercaster_utility_node_1842_2' of github.com:ju…
Juliaj 4324325
Increasing the tolerance from 1e-5 to 1e-4 for NonIdentityTransform test
Juliaj 6364400
Remove NE validation check from non-identity tranform test.
Juliaj ba5c0f6
Update per review feedback to simplify param handling
Juliaj 97a9495
Add the change to release_notes
Juliaj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
..._torque_sensor_broadcaster/include/force_torque_sensor_broadcaster/wrench_transformer.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Copyright (c) 2025, ros2_control development team | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| /* | ||
| * Authors: Julia Jia | ||
| */ | ||
|
|
||
| #ifndef FORCE_TORQUE_SENSOR_BROADCASTER__WRENCH_TRANSFORMER_HPP_ | ||
| #define FORCE_TORQUE_SENSOR_BROADCASTER__WRENCH_TRANSFORMER_HPP_ | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
|
|
||
| #include "geometry_msgs/msg/wrench_stamped.hpp" | ||
| #include "rclcpp/rclcpp.hpp" | ||
| #include "tf2_geometry_msgs/tf2_geometry_msgs.hpp" | ||
| #include "tf2_ros/buffer.h" | ||
| #include "tf2_ros/transform_listener.h" | ||
christophfroehlich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // auto-generated by generate_parameter_library | ||
| #include "force_torque_sensor_broadcaster/wrench_transformer_parameters.hpp" | ||
|
|
||
| namespace force_torque_sensor_broadcaster | ||
| { | ||
|
|
||
| class WrenchTransformer : public rclcpp::Node | ||
| { | ||
| public: | ||
| explicit WrenchTransformer(const rclcpp::NodeOptions & options = rclcpp::NodeOptions()); | ||
|
|
||
| void init(); | ||
|
|
||
| ~WrenchTransformer() = default; | ||
|
|
||
| private: | ||
| void wrench_callback(const geometry_msgs::msg::WrenchStamped::SharedPtr msg); | ||
| bool transform_wrench( | ||
| const geometry_msgs::msg::WrenchStamped & input_wrench, const std::string & target_frame, | ||
| geometry_msgs::msg::WrenchStamped & output_wrench); | ||
|
|
||
| void setup_subscriber(); | ||
| void setup_publishers(); | ||
|
|
||
| std::shared_ptr<force_torque_wrench_transformer::ParamListener> param_listener_; | ||
| force_torque_wrench_transformer::Params params_; | ||
|
|
||
| rclcpp::Subscription<geometry_msgs::msg::WrenchStamped>::SharedPtr wrench_subscriber_; | ||
| std::unordered_map<std::string, rclcpp::Publisher<geometry_msgs::msg::WrenchStamped>::SharedPtr> | ||
| transformed_wrench_publishers_; | ||
|
|
||
| std::shared_ptr<tf2_ros::Buffer> tf_buffer_; | ||
| std::shared_ptr<tf2_ros::TransformListener> tf_listener_; | ||
|
|
||
| std::string input_topic_; | ||
| std::vector<std::string> target_frames_; | ||
| }; | ||
|
|
||
| } // namespace force_torque_sensor_broadcaster | ||
|
|
||
| #endif // FORCE_TORQUE_SENSOR_BROADCASTER__WRENCH_TRANSFORMER_HPP_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
force_torque_sensor_broadcaster/src/wrench_transformer.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| // Copyright (c) 2025, ros2_control development team | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| /* | ||
| * Authors: Julia Jia | ||
| */ | ||
|
|
||
| #include "force_torque_sensor_broadcaster/wrench_transformer.hpp" | ||
|
|
||
| #include <limits> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "tf2/utils.hpp" | ||
|
|
||
| namespace force_torque_sensor_broadcaster | ||
| { | ||
|
|
||
| WrenchTransformer::WrenchTransformer(const rclcpp::NodeOptions & options) | ||
| : rclcpp::Node("fts_wrench_transformer", options) | ||
| { | ||
| // Initialize TF2 | ||
| tf_buffer_ = std::make_shared<tf2_ros::Buffer>(this->get_clock()); | ||
| tf_listener_ = std::make_shared<tf2_ros::TransformListener>(*tf_buffer_); | ||
| } | ||
|
|
||
| void WrenchTransformer::init() | ||
| { | ||
| try | ||
| { | ||
| param_listener_ = | ||
| std::make_shared<force_torque_wrench_transformer::ParamListener>(shared_from_this()); | ||
| params_ = param_listener_->get_params(); | ||
| } | ||
| catch (const std::exception & e) | ||
| { | ||
| RCLCPP_ERROR(this->get_logger(), "Exception thrown during initialization: %s", e.what()); | ||
| return; | ||
| } | ||
|
|
||
| // Setup subscriber and publishers | ||
| setup_subscriber(); | ||
| setup_publishers(); | ||
| } | ||
|
|
||
| void WrenchTransformer::wrench_callback(const geometry_msgs::msg::WrenchStamped::SharedPtr msg) | ||
| { | ||
| if (!msg || msg->header.frame_id.empty()) | ||
| { | ||
| RCLCPP_ERROR_THROTTLE( | ||
| this->get_logger(), *this->get_clock(), 5000, "Invalid wrench message or frame_id is empty"); | ||
| return; | ||
| } | ||
|
|
||
| for (const auto & target_frame : params_.target_frames) | ||
| { | ||
| geometry_msgs::msg::WrenchStamped output_wrench; | ||
| // preserve timestamp | ||
| output_wrench.header.stamp = msg->header.stamp; | ||
| output_wrench.header.frame_id = target_frame; | ||
| if (transform_wrench(*msg, target_frame, output_wrench)) | ||
| { | ||
| auto publisher = transformed_wrench_publishers_[target_frame]; | ||
| if (publisher) | ||
| { | ||
| publisher->publish(output_wrench); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| RCLCPP_WARN_THROTTLE( | ||
| this->get_logger(), *this->get_clock(), 5000, | ||
| "Failed to transform wrench for frame %s, skipping publication", target_frame.c_str()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| bool WrenchTransformer::transform_wrench( | ||
| const geometry_msgs::msg::WrenchStamped & input_wrench, const std::string & target_frame, | ||
| geometry_msgs::msg::WrenchStamped & output_wrench) | ||
| { | ||
| try | ||
| { | ||
| auto transform = tf_buffer_->lookupTransform( | ||
| target_frame, input_wrench.header.frame_id, rclcpp::Time(0), | ||
| rclcpp::Duration::from_seconds(params_.tf_timeout)); | ||
| output_wrench.header.frame_id = target_frame; | ||
| tf2::doTransform(input_wrench, output_wrench, transform); | ||
| // Preserve original timestamp after transform (doTransform may modify it) | ||
| output_wrench.header.stamp = input_wrench.header.stamp; | ||
| return true; | ||
| } | ||
| catch (const tf2::TransformException & e) | ||
| { | ||
| RCLCPP_ERROR_THROTTLE( | ||
| this->get_logger(), *this->get_clock(), 5000, "Transform exception: %s", e.what()); | ||
| return false; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| void WrenchTransformer::setup_subscriber() | ||
| { | ||
| input_topic_ = | ||
| params_.broadcaster_namespace.empty() ? "~/wrench" : params_.broadcaster_namespace + "/wrench"; | ||
| if (params_.use_filtered_input) | ||
| { | ||
| input_topic_ += "_filtered"; | ||
| } | ||
| wrench_subscriber_ = this->create_subscription<geometry_msgs::msg::WrenchStamped>( | ||
| input_topic_, rclcpp::SystemDefaultsQoS(), | ||
| std::bind(&WrenchTransformer::wrench_callback, this, std::placeholders::_1)); | ||
| if (wrench_subscriber_ == nullptr) | ||
| { | ||
| RCLCPP_ERROR_THROTTLE( | ||
| this->get_logger(), *this->get_clock(), 5000, "Failed to create wrench subscriber"); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| void WrenchTransformer::setup_publishers() | ||
| { | ||
| for (const auto & target_frame : params_.target_frames) | ||
| { | ||
| std::string topic_name = params_.output_topic_prefix + "_" + target_frame; | ||
| transformed_wrench_publishers_[target_frame] = | ||
| this->create_publisher<geometry_msgs::msg::WrenchStamped>( | ||
| topic_name, rclcpp::SystemDefaultsQoS()); | ||
| if (transformed_wrench_publishers_[target_frame] == nullptr) | ||
| { | ||
| RCLCPP_ERROR_THROTTLE( | ||
| this->get_logger(), *this->get_clock(), 5000, | ||
| "Failed to create publisher for target frame %s", target_frame.c_str()); | ||
| return; | ||
| } | ||
| RCLCPP_INFO(this->get_logger(), "Created publisher for target frame %s", target_frame.c_str()); | ||
| } | ||
| } | ||
|
|
||
| } // namespace force_torque_sensor_broadcaster |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.