-
Notifications
You must be signed in to change notification settings - Fork 99
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
Add gravity compensation filter #153
Open
guihomework
wants to merge
29
commits into
ros-controls:ros2-master
Choose a base branch
from
guihomework:add-gravity-compensation-filter-rolling
base: ros2-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
29 commits
Select commit
Hold shift + click to select a range
5471301
Added initial files of control filters
destogl 7532c93
Apply suggestions from code review
dzumkeller d61437a
Added initial files of control filters
destogl e63a7a1
Update version of gravity compensation to use parameter_handler and o…
destogl d5a55a7
Apply formatting to filters.
destogl 3817947
Update filters to use full impl of parameter hanlder.
destogl c046598
Fixed PR115 especially for humble
guihomework e6d3e27
Switched to generate_parameter_library
guihomework 9cee59e
Reworked and activated control filter loading test
guihomework 5715e8f
Improved parameter_handler usage when re-configure
guihomework fcb9cca
Applied code-review suggestions and fixed includes
guihomework b18ffbd
Fixed missing namespace forwarding
guihomework ebd7481
Switched to wrench transforms
guihomework b7ffc66
Fail update at failed lookupTransform
guihomework 94ed150
Allow data_out frame of reference selection
guihomework fc47ee0
Renaming test nodes for consistency
guihomework c910033
Made computation clearer & for generic const force
guihomework 8fec166
Clarified error msg of GravityCompensation update
guihomework 73072fb
Fixed, simplified & clarified Gravity computations
guihomework fdf43db
Cleaned-up
guihomework b74a1ee
Improved understandability of the filter
guihomework 88d6b8a
Switched to yaml-based param in filter test
guihomework b22a754
Applied suggested formatting and typo fixes
guihomework f181fe7
Merge branch 'ros2-master' into add-gravity-compensation-filter-rolling
christophfroehlich 819941c
Cleaned up TODO
guihomework 1c960dd
Fixed build fail in symlink mode
guihomework 7b59f3c
Merge remote-tracking branch 'upstream/ros2-master' into add-gravity-…
guihomework 5915fe1
Merge branch 'ros2-master' into add-gravity-compensation-filter-rolling
destogl 1e7d9dc
Merge branch 'ros2-master' into add-gravity-compensation-filter-rolling
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 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 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 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,18 +1,29 @@ | ||
<class_libraries> | ||
<library path="low_pass_filter"> | ||
<class name="control_filters/LowPassFilterDouble" | ||
type="control_filters::LowPassFilter<double>" | ||
base_class_type="filters::FilterBase<double>"> | ||
<description> | ||
This is a low pass filter working with a double value. | ||
</description> | ||
</class> | ||
<class name="control_filters/LowPassFilterWrench" | ||
type="control_filters::LowPassFilter<geometry_msgs::msg::WrenchStamped>" | ||
base_class_type="filters::FilterBase<geometry_msgs::msg::WrenchStamped>"> | ||
<description> | ||
This is a low pass filter working with geometry_msgs::WrenchStamped. | ||
</description> | ||
</class> | ||
</library> | ||
<library path="gravity_compensation"> | ||
<class name="control_filters/GravityCompensationWrench" | ||
type="control_filters::GravityCompensation<geometry_msgs::msg::WrenchStamped>" | ||
base_class_type="filters::FilterBase<geometry_msgs::msg::WrenchStamped>"> | ||
<description> | ||
This is a gravity compensation filter working with geometry_msgs::WrenchStamped. | ||
It subtracts the influence of a force caused by the gravitational force from force | ||
measurements. | ||
</description> | ||
</class> | ||
</library> | ||
<library path="low_pass_filter"> | ||
<class name="control_filters/LowPassFilterDouble" | ||
type="control_filters::LowPassFilter<double>" | ||
base_class_type="filters::FilterBase<double>"> | ||
<description> | ||
This is a low pass filter working with a double value. | ||
</description> | ||
</class> | ||
<class name="control_filters/LowPassFilterWrench" | ||
type="control_filters::LowPassFilter<geometry_msgs::msg::WrenchStamped>" | ||
base_class_type="filters::FilterBase<geometry_msgs::msg::WrenchStamped>"> | ||
<description> | ||
This is a low pass filter working with geometry_msgs::WrenchStamped. | ||
</description> | ||
</class> | ||
</library> | ||
</class_libraries> |
This file contains 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,130 @@ | ||
// Copyright (c) 2023, Stogl Robotics Consulting UG (haftungsbeschränkt) | ||
// | ||
// 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. | ||
|
||
#ifndef CONTROL_FILTERS__GRAVITY_COMPENSATION_HPP_ | ||
#define CONTROL_FILTERS__GRAVITY_COMPENSATION_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "gravity_compensation_filter_parameters.hpp" | ||
#include "filters/filter_base.hpp" | ||
#include "geometry_msgs/msg/vector3_stamped.hpp" | ||
#include "tf2_ros/buffer.h" | ||
#include "tf2_ros/transform_listener.h" | ||
|
||
namespace control_filters | ||
{ | ||
|
||
|
||
template <typename T> | ||
class GravityCompensation : public filters::FilterBase<T> | ||
{ | ||
public: | ||
/** \brief Constructor */ | ||
GravityCompensation(); | ||
|
||
/** \brief Destructor */ | ||
~GravityCompensation(); | ||
|
||
/** @brief Configure filter parameters */ | ||
bool configure() override; | ||
|
||
/** \brief Update the filter and return the data separately | ||
* \param data_in T array with length width | ||
* \param data_out T array with length width | ||
*/ | ||
bool update(const T & data_in, T & data_out) override; | ||
|
||
protected: | ||
void compute_internal_params() | ||
{ | ||
cog_.vector.x = parameters_.CoG.pos[0]; | ||
cog_.vector.y = parameters_.CoG.pos[1]; | ||
cog_.vector.z = parameters_.CoG.pos[2]; | ||
cst_ext_force_.vector.x = parameters_.CoG.force[0]; | ||
cst_ext_force_.vector.y = parameters_.CoG.force[1]; | ||
cst_ext_force_.vector.z = parameters_.CoG.force[2]; | ||
}; | ||
|
||
private: | ||
rclcpp::Clock::SharedPtr clock_; | ||
std::shared_ptr<rclcpp::Logger> logger_; | ||
std::shared_ptr<gravity_compensation_filter::ParamListener> parameter_handler_; | ||
gravity_compensation_filter::Params parameters_; | ||
|
||
// Frames for Transformation of Gravity / CoG Vector | ||
std::string world_frame_; // frame in which gravity is given | ||
std::string sensor_frame_; // frame in which Cog is given and compution occur | ||
// Storage for Calibration Values | ||
geometry_msgs::msg::Vector3Stamped cog_; // Center of Gravity Vector (wrt sensor frame) | ||
geometry_msgs::msg::Vector3Stamped cst_ext_force_; // Gravity Force Vector (wrt world frame) | ||
|
||
// Filter objects | ||
std::unique_ptr<tf2_ros::Buffer> p_tf_Buffer_; | ||
std::unique_ptr<tf2_ros::TransformListener> p_tf_Listener_; | ||
geometry_msgs::msg::TransformStamped transform_sensor_datain_, transform_world_dataout_, | ||
transform_data_out_sensor_, transform_sensor_world_; | ||
}; | ||
|
||
template <typename T> | ||
GravityCompensation<T>::GravityCompensation() | ||
{ | ||
} | ||
|
||
template <typename T> | ||
GravityCompensation<T>::~GravityCompensation() | ||
{ | ||
} | ||
|
||
template <typename T> | ||
bool GravityCompensation<T>::configure() | ||
{ | ||
clock_ = std::make_shared<rclcpp::Clock>(RCL_SYSTEM_TIME); | ||
p_tf_Buffer_.reset(new tf2_ros::Buffer(clock_)); | ||
p_tf_Listener_.reset(new tf2_ros::TransformListener(*p_tf_Buffer_.get(), true)); | ||
|
||
logger_.reset( | ||
new rclcpp::Logger(this->logging_interface_->get_logger().get_child(this->filter_name_))); | ||
|
||
// Initialize the parameter_listener once | ||
if (!parameter_handler_) | ||
{ | ||
try | ||
{ | ||
parameter_handler_ = | ||
std::make_shared<gravity_compensation_filter::ParamListener>(this->params_interface_, | ||
this->param_prefix_); | ||
} | ||
catch (rclcpp::exceptions::ParameterUninitializedException & ex) { | ||
RCLCPP_ERROR((*logger_), "GravityCompensation filter cannot be configured: %s", ex.what()); | ||
parameter_handler_.reset(); | ||
return false; | ||
} | ||
catch (rclcpp::exceptions::InvalidParameterValueException & ex) { | ||
RCLCPP_ERROR((*logger_), "GravityCompensation filter cannot be configured: %s", ex.what()); | ||
parameter_handler_.reset(); | ||
return false; | ||
} | ||
} | ||
parameters_ = parameter_handler_->get_params(); | ||
compute_internal_params(); | ||
|
||
return true; | ||
} | ||
|
||
} // namespace control_filters | ||
|
||
#endif // CONTROL_FILTERS__GRAVITY_COMPENSATION_HPP_ |
This file contains 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 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
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.
would it be possible to get somehow clock from the node? This could lead to wrong definition of clocks and thus not getting correct transformations.
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.
Unless the filter_base is changed, I don't think the filter has any access to the node (only its logger and parameter interfaces). Maybe the filter should get a time and dt passed when updated (as controllers do)
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.
maybe for a follow-up PR, you could augment the filterbase to also store a clock interface