Control Libraries 7.4.0
Loading...
Searching...
No Matches
CompliantTwist.cpp
1#include "controllers/impedance/CompliantTwist.hpp"
2
3#include "state_representation/exceptions/InvalidParameterException.hpp"
4
5namespace controllers::impedance {
6
7using namespace state_representation;
8
10 double linear_principle_damping, double linear_orthogonal_damping, double angular_stiffness, double angular_damping
11) : linear_principle_damping_(
12 std::make_shared<Parameter<double>>("linear_principle_damping", linear_principle_damping)),
13 linear_orthogonal_damping_(
14 std::make_shared<Parameter<double>>("linear_orthogonal_damping", linear_orthogonal_damping)),
15 angular_stiffness_(std::make_shared<Parameter<double>>("angular_stiffness", angular_stiffness)),
16 angular_damping_(std::make_shared<Parameter<double>>("angular_damping", angular_damping)),
17 dissipative_ctrl_(ComputationalSpaceType::LINEAR),
18 velocity_impedance_ctrl_(6) {
19 this->parameters_.insert(std::make_pair("linear_principle_damping", linear_principle_damping_));
20 this->parameters_.insert(std::make_pair("linear_orthogonal_damping", linear_orthogonal_damping_));
21 this->parameters_.insert(std::make_pair("angular_stiffness", angular_stiffness_));
22 this->parameters_.insert(std::make_pair("angular_damping", angular_damping_));
23
24 set_linear_gains(linear_principle_damping, linear_orthogonal_damping);
25 set_angular_gains(angular_stiffness, angular_damping);
26}
27
29 const std::list<std::shared_ptr<state_representation::ParameterInterface>>& parameters
30) : CompliantTwist(1, 1, 1, 1) {
31 this->set_parameters(parameters);
32}
33
34void CompliantTwist::set_linear_principle_damping(double linear_principle_damping) {
35 set_linear_gains(linear_principle_damping, linear_orthogonal_damping_->get_value());
36}
37
38void CompliantTwist::set_linear_orthogonal_damping(double linear_orthogonal_damping) {
39 set_linear_gains(linear_principle_damping_->get_value(), linear_orthogonal_damping);
40}
41
42void CompliantTwist::set_linear_gains(double linear_principle_damping, double linear_orthogonal_damping) {
43 linear_principle_damping_->set_value(linear_principle_damping);
44 linear_orthogonal_damping_->set_value(linear_orthogonal_damping);
45
46 Eigen::VectorXd damping(6);
47 damping << linear_principle_damping, linear_orthogonal_damping, linear_orthogonal_damping, 0, 0, 0;
48 dissipative_ctrl_.set_parameter_value("damping_eigenvalues", damping);
49}
50
51void CompliantTwist::set_angular_stiffness(double angular_stiffness) {
52 set_angular_gains(angular_stiffness, angular_damping_->get_value());
53}
54
55void CompliantTwist::set_angular_damping(double angular_damping) {
56 set_angular_gains(angular_stiffness_->get_value(), angular_damping);
57}
58
59void CompliantTwist::set_angular_gains(double angular_stiffness, double angular_damping) {
60 angular_stiffness_->set_value(angular_stiffness);
61 angular_damping_->set_value(angular_damping);
62
63 Eigen::MatrixXd k = Eigen::MatrixXd::Zero(6, 6);
64 Eigen::MatrixXd d = Eigen::MatrixXd::Zero(6, 6);
65 k.diagonal() << 0, 0, 0, angular_stiffness, angular_stiffness, angular_stiffness;
66 d.diagonal() << 0, 0, 0, angular_damping, angular_damping, angular_damping;
69}
70
72 const CartesianState& desired_state, const CartesianState& feedback_state
73) {
74 CartesianState command = dissipative_ctrl_.compute_command(desired_state, feedback_state);
75 command += velocity_impedance_ctrl_.compute_command(desired_state, feedback_state);
76 return command;
77}
78
80 const std::shared_ptr<state_representation::ParameterInterface>& parameter
81) {
82 if (parameter->get_parameter_type() != ParameterType::DOUBLE) {
84 "Parameter " + parameter->get_name() + " must be a double");
85 }
86 double value = std::static_pointer_cast<Parameter<double>>(parameter)->get_value();
87 if (parameter->get_name() == "linear_principle_damping") {
89 } else if (parameter->get_name() == "linear_orthogonal_damping") {
91 } else if (parameter->get_name() == "angular_stiffness") {
92 this->set_angular_stiffness(value);
93 } else if (parameter->get_name() == "angular_damping") {
94 this->set_angular_damping(value);
95 } else {
97 "No parameter with name '" + parameter->get_name() + "' found"
98 );
99 }
100}
101
102}
A concrete controller class specifically for controlling 6 degree of freedom Cartesian twist with a c...
std::shared_ptr< state_representation::Parameter< double > > angular_stiffness_
stiffness of angular displacement
void set_linear_orthogonal_damping(double linear_orthogonal_damping)
Setter of the linear orthogonal damping.
void set_linear_principle_damping(double linear_principle_damping)
Setter of the linear principle damping.
Dissipative< state_representation::CartesianState > dissipative_ctrl_
controller for linear space
std::shared_ptr< state_representation::Parameter< double > > angular_damping_
damping of angular velocity error
void set_angular_stiffness(double angular_stiffness)
Setter of the angular stiffness.
std::shared_ptr< state_representation::Parameter< double > > linear_principle_damping_
damping along principle eigenvector of linear velocity error
VelocityImpedance< state_representation::CartesianState > velocity_impedance_ctrl_
controller for angular space
void set_linear_gains(double linear_principle_damping, double linear_orthogonal_damping)
Setter of the linear damping values.
CompliantTwist(const std::list< std::shared_ptr< state_representation::ParameterInterface > > &parameters)
Constructor from an initial parameter list.
void set_angular_gains(double angular_stiffness, double angular_damping)
Setter of the angular damping.
state_representation::CartesianState compute_command(const state_representation::CartesianState &desired_state, const state_representation::CartesianState &feedback_state) override
Compute the force (task space) or torque (joint space) command based on the input state of the system...
std::shared_ptr< state_representation::Parameter< double > > linear_orthogonal_damping_
damping along secondary eigenvectors of linear velocity error
void set_angular_damping(double angular_damping)
Setter of the angular damping.
void validate_and_set_parameter(const std::shared_ptr< state_representation::ParameterInterface > &parameter) override
Validate and set parameters for controller gains.
S compute_command(const S &command_state, const S &feedback_state) override
Compute the force (task space) or torque (joint space) command based on the input state of the system...
S compute_command(const S &desired_state, const S &feedback_state) override
Compute the force (task space) or torque (joint space) command based on the input state of the system...
Class to represent a state in Cartesian space.
Class to represent name-value pairs of different types.
Definition Parameter.hpp:18
void set_parameters(const ParameterInterfaceList &parameters)
Set parameters from a list of parameters.
ParameterInterfaceMap parameters_
map of parameters by name
void set_parameter_value(const std::string &name, const T &value)
Set a parameter value by its name.
Core state variables and objects.