ros2_control - humble
Loading...
Searching...
No Matches
admittance_rule.hpp
1// Copyright (c) 2021, PickNik, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
16
17#ifndef ADMITTANCE_CONTROLLER__ADMITTANCE_RULE_HPP_
18#define ADMITTANCE_CONTROLLER__ADMITTANCE_RULE_HPP_
19
20#include <Eigen/Core>
21#include <Eigen/Geometry>
22#include <map>
23#include <memory>
24#include <string>
25#include <vector>
26
27#include "control_msgs/msg/admittance_controller_state.hpp"
28#include "control_toolbox/filters.hpp"
29#include "controller_interface/controller_interface.hpp"
30#include "geometry_msgs/msg/wrench_stamped.hpp"
31#include "kinematics_interface/kinematics_interface.hpp"
32#include "pluginlib/class_loader.hpp"
33#include "tf2_eigen/tf2_eigen.hpp"
34#include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
35#include "tf2_kdl/tf2_kdl.hpp"
36#include "tf2_ros/buffer.h"
37#include "tf2_ros/transform_listener.h"
38#include "trajectory_msgs/msg/joint_trajectory_point.hpp"
39
41{
43{
44 // transformation from force torque sensor frame to base link frame at reference joint angles
45 Eigen::Isometry3d ref_base_ft_;
46 // transformation from force torque sensor frame to base link frame at reference + admittance
47 // offset joint angles
48 Eigen::Isometry3d base_ft_;
49 // transformation from control frame to base link frame at reference + admittance offset joint
50 // angles
51 Eigen::Isometry3d base_control_;
52 // transformation from end effector frame to base link frame at reference + admittance offset
53 // joint angles
54 Eigen::Isometry3d base_tip_;
55 // transformation from center of gravity frame to base link frame at reference + admittance offset
56 // joint angles
57 Eigen::Isometry3d base_cog_;
58 // transformation from world frame to base link frame
59 Eigen::Isometry3d world_base_;
60};
61
63{
64 explicit AdmittanceState(size_t num_joints)
65 {
66 admittance_velocity.setZero();
67 admittance_acceleration.setZero();
68 damping.setZero();
69 mass.setOnes();
70 mass_inv.setZero();
71 stiffness.setZero();
72 selected_axes.setZero();
73 auto idx = static_cast<Eigen::Index>(num_joints);
74 current_joint_pos = Eigen::VectorXd::Zero(idx);
75 joint_pos = Eigen::VectorXd::Zero(idx);
76 joint_vel = Eigen::VectorXd::Zero(idx);
77 joint_acc = Eigen::VectorXd::Zero(idx);
78 }
79
80 Eigen::VectorXd current_joint_pos;
81 Eigen::VectorXd joint_pos;
82 Eigen::VectorXd joint_vel;
83 Eigen::VectorXd joint_acc;
84 Eigen::Matrix<double, 6, 1> damping;
85 Eigen::Matrix<double, 6, 1> mass;
86 Eigen::Matrix<double, 6, 1> mass_inv;
87 Eigen::Matrix<double, 6, 1> selected_axes;
88 Eigen::Matrix<double, 6, 1> stiffness;
89 Eigen::Matrix<double, 6, 1> wrench_base;
90 Eigen::Matrix<double, 6, 1> admittance_acceleration;
91 Eigen::Matrix<double, 6, 1> admittance_velocity;
92 Eigen::Isometry3d admittance_position;
93 Eigen::Matrix<double, 3, 3> rot_base_control;
94 Eigen::Isometry3d ref_trans_base_ft;
95 std::string ft_sensor_frame;
96};
97
99{
100public:
101 explicit AdmittanceRule(
102 const std::shared_ptr<admittance_controller::ParamListener> & parameter_handler)
103 {
104 parameter_handler_ = parameter_handler;
105 parameters_ = parameter_handler_->get_params();
106 num_joints_ = parameters_.joints.size();
107 admittance_state_ = AdmittanceState(num_joints_);
108 reset(num_joints_);
109 }
110
112 controller_interface::return_type configure(
113 const std::shared_ptr<rclcpp_lifecycle::LifecycleNode> & node, const size_t num_joint);
114
116 controller_interface::return_type reset(const size_t num_joints);
117
126 const trajectory_msgs::msg::JointTrajectoryPoint & current_joint_state,
127 const trajectory_msgs::msg::JointTrajectoryPoint & reference_joint_state);
128
135
147 controller_interface::return_type update(
148 const trajectory_msgs::msg::JointTrajectoryPoint & current_joint_state,
149 const geometry_msgs::msg::Wrench & measured_wrench,
150 const trajectory_msgs::msg::JointTrajectoryPoint & reference_joint_state,
151 const rclcpp::Duration & period,
152 trajectory_msgs::msg::JointTrajectoryPoint & desired_joint_states);
153
160 const control_msgs::msg::AdmittanceControllerState & get_controller_state();
161
162public:
163 // admittance config parameters
164 std::shared_ptr<admittance_controller::ParamListener> parameter_handler_;
165 admittance_controller::Params parameters_;
166
167protected:
175 bool calculate_admittance_rule(AdmittanceState & admittance_state, double dt);
176
186 const geometry_msgs::msg::Wrench & measured_wrench,
187 const Eigen::Matrix<double, 3, 3> & sensor_world_rot,
188 const Eigen::Matrix<double, 3, 3> & cog_world_rot);
189
190 template <typename T1, typename T2>
191 void vec_to_eigen(const std::vector<T1> & data, T2 & matrix);
192
193 // number of robot joint
194 size_t num_joints_;
195
196 // Kinematics interface plugin loader
197 std::shared_ptr<pluginlib::ClassLoader<kinematics_interface::KinematicsInterface>>
198 kinematics_loader_;
199 std::unique_ptr<kinematics_interface::KinematicsInterface> kinematics_;
200
201 // filtered wrench in world frame
202 Eigen::Matrix<double, 6, 1> wrench_world_;
203
204 // admittance controllers internal state
205 AdmittanceState admittance_state_{0};
206
207 // transforms needed for admittance update
208 AdmittanceTransforms admittance_transforms_;
209
210 // position of center of gravity in cog_frame
211 Eigen::Vector3d cog_pos_;
212
213 // force applied to sensor due to weight of end effector
214 Eigen::Vector3d end_effector_weight_;
215
216 // ROS
217 control_msgs::msg::AdmittanceControllerState state_message_;
218};
219
220} // namespace admittance_controller
221
222#endif // ADMITTANCE_CONTROLLER__ADMITTANCE_RULE_HPP_
Definition admittance_rule.hpp:99
bool calculate_admittance_rule(AdmittanceState &admittance_state, double dt)
Definition admittance_rule_impl.hpp:230
bool get_all_transforms(const trajectory_msgs::msg::JointTrajectoryPoint &current_joint_state, const trajectory_msgs::msg::JointTrajectoryPoint &reference_joint_state)
Definition admittance_rule_impl.hpp:144
controller_interface::return_type reset(const size_t num_joints)
Reset all values back to default.
Definition admittance_rule_impl.hpp:84
void apply_parameters_update()
Definition admittance_rule_impl.hpp:121
const control_msgs::msg::AdmittanceControllerState & get_controller_state()
Definition admittance_rule_impl.hpp:344
controller_interface::return_type configure(const std::shared_ptr< rclcpp_lifecycle::LifecycleNode > &node, const size_t num_joint)
Configure admittance rule memory using number of joints.
Definition admittance_rule_impl.hpp:35
controller_interface::return_type update(const trajectory_msgs::msg::JointTrajectoryPoint &current_joint_state, const geometry_msgs::msg::Wrench &measured_wrench, const trajectory_msgs::msg::JointTrajectoryPoint &reference_joint_state, const rclcpp::Duration &period, trajectory_msgs::msg::JointTrajectoryPoint &desired_joint_states)
Definition admittance_rule_impl.hpp:172
void process_wrench_measurements(const geometry_msgs::msg::Wrench &measured_wrench, const Eigen::Matrix< double, 3, 3 > &sensor_world_rot, const Eigen::Matrix< double, 3, 3 > &cog_world_rot)
Definition admittance_rule_impl.hpp:316
Definition admittance_controller.hpp:48
Definition admittance_rule.hpp:63
Definition admittance_rule.hpp:43