-
Notifications
You must be signed in to change notification settings - Fork 98
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
Ported LowPass and GravityCompensation filters iirob_filters repository #115
Closed
destogl
wants to merge
15
commits into
ros-controls:ros2-master
from
StoglRobotics-forks:add-control-filters-gravity-compensation
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e8794ee
Added initial files of control filters
destogl c41eb9a
Ported low_pass_filter from iirob_filters:
dzumkeller ee8a6ff
Update low_pass_filter.hpp
dzumkeller f0ec3be
Apply suggestions from code review
dzumkeller ff01bf1
added new testcase after review
dzumkeller 2cecfd6
Merge branch 'add-control-filters-gravity-compensation' of https://gi…
dzumkeller 79aeeb2
Added initial files of control filters
destogl 1ea8b37
Ported low_pass_filter from iirob_filters:
dzumkeller 06391d8
added new testcase after review
dzumkeller 1cebf05
Update low_pass_filter.hpp
dzumkeller c0f365a
Apply suggestions from code review
dzumkeller 8b391c6
Update version of gravity compensation to use parameter_handler and o…
destogl 9457c9f
Apply formatting to filters.
destogl f2d02af
Update filters to use full impl of parameter hanlder.
destogl 978e590
Merge branch 'add-control-filters-gravity-compensation' of https://gi…
dzumkeller 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<class_libraries> | ||
<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/LowPassFilter" | ||
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,171 @@ | ||||||
// Copyright (c) 2021, 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 "control_toolbox/parameter_handler.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 | ||||||
{ | ||||||
class GravityCompensationParameters : public control_toolbox::ParameterHandler | ||||||
{ | ||||||
public: | ||||||
explicit GravityCompensationParameters(const std::string & params_prefix) | ||||||
: control_toolbox::ParameterHandler(params_prefix, 0, 0, 4, 3) | ||||||
{ | ||||||
add_string_parameter("world_frame", false); | ||||||
add_string_parameter("sensor_frame", false); | ||||||
add_string_parameter("force_frame", false); | ||||||
|
||||||
add_double_parameter("CoG.x", true); | ||||||
add_double_parameter("CoG.y", true); | ||||||
add_double_parameter("CoG.z", true); | ||||||
add_double_parameter("force", true); | ||||||
} | ||||||
|
||||||
bool check_if_parameters_are_valid() override | ||||||
{ | ||||||
bool ret = true; | ||||||
|
||||||
// Check if any string parameter is empty | ||||||
ret = !empty_parameter_in_list(string_parameters_); | ||||||
|
||||||
for (size_t i = 0; i < 4; ++i) | ||||||
{ | ||||||
if (std::isnan(double_parameters_[i].second)) | ||||||
{ | ||||||
RCUTILS_LOG_ERROR_NAMED( | ||||||
logger_name_.c_str(), "Parameter '%s' has to be set", | ||||||
double_parameters_[i].first.name.c_str()); | ||||||
ret = false; | ||||||
} | ||||||
} | ||||||
|
||||||
return ret; | ||||||
} | ||||||
|
||||||
void update_storage() override | ||||||
{ | ||||||
world_frame_ = string_parameters_[0].second; | ||||||
RCUTILS_LOG_INFO_NAMED(logger_name_.c_str(), "World frame: %s", world_frame_.c_str()); | ||||||
sensor_frame_ = string_parameters_[0].second; | ||||||
RCUTILS_LOG_INFO_NAMED(logger_name_.c_str(), "Sensor frame: %s", sensor_frame_.c_str()); | ||||||
force_frame_ = string_parameters_[0].second; | ||||||
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.
Suggested change
|
||||||
RCUTILS_LOG_INFO_NAMED(logger_name_.c_str(), "Force frame: %s", force_frame_.c_str()); | ||||||
|
||||||
cog_.vector.x = double_parameters_[0].second; | ||||||
RCUTILS_LOG_INFO_NAMED(logger_name_.c_str(), "CoG X is %e", cog_.vector.x); | ||||||
cog_.vector.y = double_parameters_[1].second; | ||||||
RCUTILS_LOG_INFO_NAMED(logger_name_.c_str(), "CoG Y is %e", cog_.vector.y); | ||||||
cog_.vector.z = double_parameters_[2].second; | ||||||
RCUTILS_LOG_INFO_NAMED(logger_name_.c_str(), "CoG Z is %e", cog_.vector.z); | ||||||
|
||||||
force_z_ = double_parameters_[3].second; | ||||||
RCUTILS_LOG_INFO_NAMED(logger_name_.c_str(), "Force is %e", force_z_); | ||||||
} | ||||||
|
||||||
// Frames for Transformation of Gravity / CoG Vector | ||||||
std::string world_frame_; | ||||||
std::string sensor_frame_; | ||||||
std::string force_frame_; | ||||||
|
||||||
// Storage for Calibration Values | ||||||
geometry_msgs::msg::Vector3Stamped cog_; // Center of Gravity Vector (wrt Sensor Frame) | ||||||
double force_z_; // Gravitational Force | ||||||
}; | ||||||
|
||||||
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; | ||||||
|
||||||
private: | ||||||
rclcpp::Clock::SharedPtr clock_; | ||||||
std::shared_ptr<rclcpp::Logger> logger_; | ||||||
std::unique_ptr<GravityCompensationParameters> parameters_; | ||||||
|
||||||
// Callback for updating dynamic parameters | ||||||
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr on_set_callback_handle_; | ||||||
|
||||||
// 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_, transform_back_, transform_cog_; | ||||||
}; | ||||||
|
||||||
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_))); | ||||||
parameters_.reset(new GravityCompensationParameters(this->param_prefix_)); | ||||||
|
||||||
parameters_->initialize(this->params_interface_, logger_->get_name()); | ||||||
|
||||||
parameters_->declare_parameters(); | ||||||
|
||||||
if (!parameters_->get_parameters()) | ||||||
{ | ||||||
return false; | ||||||
} | ||||||
|
||||||
// Add callback to dynamically update parameters | ||||||
on_set_callback_handle_ = this->params_interface_->add_on_set_parameters_callback( | ||||||
[this](const std::vector<rclcpp::Parameter> & parameters) { | ||||||
return parameters_->set_parameter_callback(parameters); | ||||||
}); | ||||||
|
||||||
return true; | ||||||
} | ||||||
|
||||||
} // namespace control_filters | ||||||
|
||||||
#endif // CONTROL_FILTERS__GRAVITY_COMPENSATION_HPP_ |
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.