-
Notifications
You must be signed in to change notification settings - Fork 391
Add filtering capability to ft_broadcaster #1814
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
Open
OscarMrZ
wants to merge
37
commits into
ros-controls:master
Choose a base branch
from
pal-robotics-forks:ft_broadcaster/add-filtering-capability
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
fe36000
Add support for publishing additional topics to the FTS Broadcaster
destogl ef7ad6a
Added filtering capabilities
guihomework a47926a
Added more tests with filters
guihomework a413217
Removed helper that only shows declared params
guihomework 3652ab1
Fixed filter handling and unitialized frame_id
guihomework 8163413
Added test for additional_frames_to_publish
guihomework a58bd31
Merge branch 'master' into add-filtering-capability-to-fts-broadcaste…
christophfroehlich 31e79e2
Fix test parameters
christophfroehlich 41853ab
Merge remote-tracking branch 'origin/master' into add-filtering-capab…
christophfroehlich c9b52f1
compile filters from source on humble
christophfroehlich 206da96
Merge branch 'master' into add-filtering-capability-to-fts-broadcaste…
bmagyar 0759030
Use filters from binary
christophfroehlich aa12321
Update ros2_controllers-not-released.humble.repos
christophfroehlich 3d15fa5
Fix pre-commit
christophfroehlich b431110
Merge remote-tracking branch 'origin/master' into add-filtering-capab…
christophfroehlich a78dab0
Fix the tests
christophfroehlich 714400d
Merge branch 'master' into add-filtering-capability-to-fts-broadcaste…
christophfroehlich 834e1ad
Apply suggestions from code review
christophfroehlich 98fac42
Apply suggestions from code review
christophfroehlich 3a6978c
Use correct hpp file
christophfroehlich 204e5d3
Merge branch 'master' into add-filtering-capability-to-fts-broadcaste…
christophfroehlich 63dcce2
Fix format
christophfroehlich cad2b29
Update description of limit() function in speed_limiter (#1793)
Amronos c6b8ca7
Improve paths filtering of docs CI job (#1796)
christophfroehlich da21fd4
fix rqt_joint_trajectory_controller for robots with namespace (#1792)
oscar-lima 8c1fa73
Mecanum Drive: Populate the pose covariance matrix (#1772)
hilary-luo 284c4a1
Explicit cast `rcutils_duration_value_t` (#1808)
christophfroehlich 9619195
Applying review suggestions
OscarMrZ b1de60b
Simplified testing
OscarMrZ 4062e15
Improving logic to check if there's a filter chain
OscarMrZ ad4dcfa
Fixing with pre-commit
OscarMrZ 59eb2ea
Merge branch 'ros-controls:master' into ft_broadcaster/add-filtering-…
OscarMrZ 45647df
Merge branch 'ros-controls:master' into ft_broadcaster/add-filtering-…
OscarMrZ 61e9b55
Removing unnecesarily added deps
OscarMrZ 3afca35
Improving tests with dummy filter
OscarMrZ 7306d25
Removing unnecessary temporary objects created while calling emplace_…
OscarMrZ 94106c2
Merge branch 'master' into ft_broadcaster/add-filtering-capability
christophfroehlich 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
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 |
---|---|---|
|
@@ -18,9 +18,12 @@ | |
|
||
#include "force_torque_sensor_broadcaster/force_torque_sensor_broadcaster.hpp" | ||
|
||
#include <limits> | ||
#include <memory> | ||
#include <string> | ||
|
||
#include "rclcpp/logging.hpp" | ||
|
||
namespace force_torque_sensor_broadcaster | ||
{ | ||
ForceTorqueSensorBroadcaster::ForceTorqueSensorBroadcaster() | ||
|
@@ -87,12 +90,39 @@ controller_interface::CallbackReturn ForceTorqueSensorBroadcaster::on_configure( | |
torque_names.z)); | ||
} | ||
|
||
try | ||
{ | ||
filter_chain_ = | ||
std::make_unique<filters::FilterChain<WrenchMsgType>>("geometry_msgs::msg::WrenchStamped"); | ||
} | ||
catch (const std::exception & e) | ||
{ | ||
fprintf(stderr, "Exception thrown during filter chain creation with message : %s \n", e.what()); | ||
return CallbackReturn::ERROR; | ||
} | ||
|
||
// As the sensor_filter_chain parameter is of type 'none', we cannot directly check if it is | ||
// present. Even if the sensor_filter_chain parameter is not specified, the filter chain will be | ||
// correctly configured with an empty list of filters (https://github.com/ros/filters/issues/89). | ||
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. how to proceed here? |
||
has_filter_chain_ = filter_chain_->configure( | ||
"sensor_filter_chain", get_node()->get_node_logging_interface(), | ||
get_node()->get_node_parameters_interface()); | ||
|
||
RCLCPP_INFO_EXPRESSION( | ||
get_node()->get_logger(), has_filter_chain_, "Filter chain is successfully configured!"); | ||
|
||
try | ||
{ | ||
// register ft sensor data publisher | ||
sensor_state_publisher_ = get_node()->create_publisher<geometry_msgs::msg::WrenchStamped>( | ||
sensor_raw_state_publisher_ = get_node()->create_publisher<geometry_msgs::msg::WrenchStamped>( | ||
"~/wrench", rclcpp::SystemDefaultsQoS()); | ||
realtime_publisher_ = std::make_unique<StatePublisher>(sensor_state_publisher_); | ||
realtime_raw_publisher_ = std::make_unique<StateRTPublisher>(sensor_raw_state_publisher_); | ||
|
||
sensor_filtered_state_publisher_ = | ||
get_node()->create_publisher<geometry_msgs::msg::WrenchStamped>( | ||
"~/wrench_filtered", rclcpp::SystemDefaultsQoS()); | ||
realtime_filtered_publisher_ = | ||
std::make_unique<StateRTPublisher>(sensor_filtered_state_publisher_); | ||
} | ||
catch (const std::exception & e) | ||
{ | ||
|
@@ -102,9 +132,19 @@ controller_interface::CallbackReturn ForceTorqueSensorBroadcaster::on_configure( | |
return controller_interface::CallbackReturn::ERROR; | ||
} | ||
|
||
realtime_publisher_->lock(); | ||
realtime_publisher_->msg_.header.frame_id = params_.frame_id; | ||
realtime_publisher_->unlock(); | ||
wrench_raw_.header.frame_id = params_.frame_id; | ||
wrench_filtered_.header.frame_id = params_.frame_id; | ||
|
||
realtime_raw_publisher_->lock(); | ||
realtime_raw_publisher_->msg_.header.frame_id = params_.frame_id; | ||
realtime_raw_publisher_->unlock(); | ||
|
||
if (has_filter_chain_) | ||
{ | ||
realtime_filtered_publisher_->lock(); | ||
realtime_filtered_publisher_->msg_.header.frame_id = params_.frame_id; | ||
realtime_filtered_publisher_->unlock(); | ||
} | ||
|
||
RCLCPP_INFO(get_node()->get_logger(), "configure successful"); | ||
return controller_interface::CallbackReturn::SUCCESS; | ||
|
@@ -146,13 +186,28 @@ controller_interface::return_type ForceTorqueSensorBroadcaster::update_and_write | |
{ | ||
param_listener_->try_get_params(params_); | ||
|
||
if (realtime_publisher_ && realtime_publisher_->trylock()) | ||
wrench_raw_.header.stamp = time; | ||
force_torque_sensor_->get_values_as_message(wrench_raw_.wrench); | ||
this->apply_sensor_offset(params_, wrench_raw_); | ||
this->apply_sensor_multiplier(params_, wrench_raw_); | ||
|
||
if (realtime_raw_publisher_ && realtime_raw_publisher_->trylock()) | ||
{ | ||
realtime_raw_publisher_->msg_.header.stamp = time; | ||
realtime_raw_publisher_->msg_.wrench = wrench_raw_.wrench; | ||
realtime_raw_publisher_->unlockAndPublish(); | ||
} | ||
|
||
if (has_filter_chain_) | ||
{ | ||
realtime_publisher_->msg_.header.stamp = time; | ||
force_torque_sensor_->get_values_as_message(realtime_publisher_->msg_.wrench); | ||
this->apply_sensor_offset(params_, realtime_publisher_->msg_); | ||
this->apply_sensor_multiplier(params_, realtime_publisher_->msg_); | ||
realtime_publisher_->unlockAndPublish(); | ||
// Filter sensor data, if no filter chain config was specified, wrench_filtered_ = wrench_raw_ | ||
auto filtered = filter_chain_->update(wrench_raw_, wrench_filtered_); | ||
if (filtered && realtime_filtered_publisher_ && realtime_filtered_publisher_->trylock()) | ||
{ | ||
realtime_filtered_publisher_->msg_.header.stamp = time; | ||
realtime_filtered_publisher_->msg_.wrench = wrench_filtered_.wrench; | ||
realtime_filtered_publisher_->unlockAndPublish(); | ||
} | ||
} | ||
|
||
return controller_interface::return_type::OK; | ||
|
@@ -198,38 +253,32 @@ ForceTorqueSensorBroadcaster::on_export_state_interfaces() | |
if (!force_names[0].empty()) | ||
{ | ||
exported_state_interfaces.emplace_back( | ||
hardware_interface::StateInterface( | ||
export_prefix, force_names[0], &realtime_publisher_->msg_.wrench.force.x)); | ||
export_prefix, force_names[0], &realtime_raw_publisher_->msg_.wrench.force.x); | ||
} | ||
if (!force_names[1].empty()) | ||
{ | ||
exported_state_interfaces.emplace_back( | ||
hardware_interface::StateInterface( | ||
export_prefix, force_names[1], &realtime_publisher_->msg_.wrench.force.y)); | ||
export_prefix, force_names[1], &realtime_raw_publisher_->msg_.wrench.force.y); | ||
} | ||
if (!force_names[2].empty()) | ||
{ | ||
exported_state_interfaces.emplace_back( | ||
hardware_interface::StateInterface( | ||
export_prefix, force_names[2], &realtime_publisher_->msg_.wrench.force.z)); | ||
export_prefix, force_names[2], &realtime_raw_publisher_->msg_.wrench.force.z); | ||
} | ||
if (!torque_names[0].empty()) | ||
{ | ||
exported_state_interfaces.emplace_back( | ||
hardware_interface::StateInterface( | ||
export_prefix, torque_names[0], &realtime_publisher_->msg_.wrench.torque.x)); | ||
export_prefix, torque_names[0], &realtime_raw_publisher_->msg_.wrench.torque.x); | ||
} | ||
if (!torque_names[1].empty()) | ||
{ | ||
exported_state_interfaces.emplace_back( | ||
hardware_interface::StateInterface( | ||
export_prefix, torque_names[1], &realtime_publisher_->msg_.wrench.torque.y)); | ||
export_prefix, torque_names[1], &realtime_raw_publisher_->msg_.wrench.torque.y); | ||
} | ||
if (!torque_names[2].empty()) | ||
{ | ||
exported_state_interfaces.emplace_back( | ||
hardware_interface::StateInterface( | ||
export_prefix, torque_names[2], &realtime_publisher_->msg_.wrench.torque.z)); | ||
export_prefix, torque_names[2], &realtime_raw_publisher_->msg_.wrench.torque.z); | ||
} | ||
return exported_state_interfaces; | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
// Copyright (c) 2025, PAL Robotics | ||
// | ||
// 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: Oscar Martinez | ||
*/ | ||
|
||
#include <rclcpp/logger.hpp> | ||
#include <rclcpp/logging.hpp> | ||
|
||
#include "geometry_msgs/msg/wrench_stamped.hpp" | ||
|
||
#include "filters/increment.hpp" | ||
|
||
namespace filters | ||
{ | ||
|
||
template <> | ||
bool IncrementFilter<geometry_msgs::msg::WrenchStamped>::update( | ||
const geometry_msgs::msg::WrenchStamped & data_in, geometry_msgs::msg::WrenchStamped & data_out) | ||
{ | ||
if (!this->configured_) | ||
{ | ||
throw std::runtime_error("Filter is not configured"); | ||
} | ||
|
||
// Just increment every value | ||
data_out.wrench.force.x = data_in.wrench.force.x + 1; | ||
data_out.wrench.force.y = data_in.wrench.force.y + 1; | ||
data_out.wrench.force.z = data_in.wrench.force.z + 1; | ||
data_out.wrench.torque.x = data_in.wrench.torque.x + 1; | ||
data_out.wrench.torque.y = data_in.wrench.torque.y + 1; | ||
data_out.wrench.torque.z = data_in.wrench.torque.z + 1; | ||
|
||
return true; | ||
} | ||
|
||
} // namespace filters | ||
|
||
#include "pluginlib/class_list_macros.hpp" | ||
|
||
PLUGINLIB_EXPORT_CLASS( | ||
filters::IncrementFilter<geometry_msgs::msg::WrenchStamped>, | ||
filters::FilterBase<geometry_msgs::msg::WrenchStamped>) |
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,9 @@ | ||
<class_libraries> | ||
<library path="dummy_filter"> | ||
<class name="filters/IncrementFilterWrench" type="filters::IncrementFilter<geometry_msgs::msg::WrenchStamped>" base_class_type="filters::FilterBase<geometry_msgs::msg::WrenchStamped>"> | ||
<description> | ||
This is a increment filter which works on a wrench message. | ||
</description> | ||
</class> | ||
</library> | ||
</class_libraries> |
9 changes: 8 additions & 1 deletion
9
force_torque_sensor_broadcaster/test/force_torque_sensor_broadcaster_params.yaml
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 |
---|---|---|
@@ -1,4 +1,11 @@ | ||
test_force_torque_sensor_broadcaster: | ||
ros__parameters: | ||
|
||
frame_id: "fts_sensor_frame" | ||
test_force_torque_sensor_broadcaster_with_chain: | ||
ros__parameters: | ||
frame_id: "fts_sensor_frame" | ||
sensor_name: "fts_sensor" | ||
sensor_filter_chain: | ||
filter1: | ||
name: dummy | ||
type: filters/IncrementFilterWrench |
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.
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.
do we have to link against the parameters here?