Control Libraries 7.4.0
Loading...
Searching...
No Matches
Dissipative.hpp
1#pragma once
2
3#include "controllers/impedance/Impedance.hpp"
4#include "state_representation/parameters/Parameter.hpp"
5#include "state_representation/space/cartesian/CartesianState.hpp"
6#include <eigen3/Eigen/Core>
7#include <eigen3/Eigen/Dense>
8
9namespace controllers::impedance {
10
19enum class ComputationalSpaceType {
20 LINEAR, ANGULAR, DECOUPLED_TWIST, FULL
21};
22
27template<class S>
28class Dissipative : public Impedance<S> {
29
30public:
31
37 explicit Dissipative(const ComputationalSpaceType& computational_space, unsigned int dimensions = 6);
38
45 explicit Dissipative(
46 const std::list<std::shared_ptr<state_representation::ParameterInterface>>& parameters,
47 const ComputationalSpaceType& computational_space, unsigned int dimensions = 6
48 );
49
57 S compute_command(const S& command_state, const S& feedback_state) override;
58
59protected:
60
65 void validate_and_set_parameter(const std::shared_ptr<state_representation::ParameterInterface>& parameter) override;
66
74 static Eigen::MatrixXd orthonormalize_basis(const Eigen::MatrixXd& basis, const Eigen::VectorXd& main_eigenvector);
75
82 Eigen::MatrixXd compute_orthonormal_basis(const S& desired_velocity);
83
90 void compute_damping(const S& desired_velocity);
91
92 std::shared_ptr<state_representation::Parameter<Eigen::VectorXd>>
94
95 const ComputationalSpaceType computational_space_;
96
97 Eigen::MatrixXd basis_;
98
99};
100
101template<class S>
102Dissipative<S>::Dissipative(const ComputationalSpaceType& computational_space, unsigned int dimensions) :
103 Impedance<S>(dimensions),
104 damping_eigenvalues_(
105 state_representation::make_shared_parameter<Eigen::VectorXd>(
106 "damping_eigenvalues", Eigen::ArrayXd::Ones(dimensions))),
107 computational_space_(computational_space),
108 basis_(Eigen::MatrixXd::Random(dimensions, dimensions)) {
109 this->parameters_.erase("stiffness");
110 this->stiffness_->set_value(Eigen::MatrixXd::Zero(dimensions, dimensions));
111 this->parameters_.erase("inertia");
112 this->inertia_->set_value(Eigen::MatrixXd::Zero(dimensions, dimensions));
113
114 this->damping_->set_value(Eigen::MatrixXd::Identity(dimensions, dimensions));
115 this->parameters_.insert(std::make_pair("damping_eigenvalues", damping_eigenvalues_));
116}
117
118template<class S>
120 const std::list<std::shared_ptr<state_representation::ParameterInterface>>& parameters,
121 const ComputationalSpaceType& computational_space, unsigned int dimensions
122) :
123 Dissipative<S>(computational_space, dimensions) {
124 this->set_parameters(parameters);
125}
126
127template<class S>
129 const std::shared_ptr<state_representation::ParameterInterface>& parameter
130) {
131 if (parameter->get_name() == "damping_eigenvalues") {
132 this->damping_eigenvalues_->set_value(this->gain_matrix_from_parameter(parameter).diagonal());
133 }
134}
135
136template<class S>
138 const Eigen::MatrixXd& basis, const Eigen::VectorXd& main_eigenvector
139) {
140 Eigen::MatrixXd orthonormal_basis = basis;
141 uint dim = basis.rows();
142 orthonormal_basis.col(0) = main_eigenvector.normalized();
143 for (uint i = 1; i < dim; i++) {
144 for (uint j = 0; j < i; j++) {
145 orthonormal_basis.col(i) -= orthonormal_basis.col(j).dot(orthonormal_basis.col(i)) * orthonormal_basis.col(j);
146 }
147 orthonormal_basis.col(i).normalize();
148 }
149 return orthonormal_basis;
150}
151
152template<class S>
154 const S& command_state, const S& feedback_state
155) {
156 // compute the damping matrix out of the command_state twist
157 this->compute_damping(command_state);
158 // apply the impedance control law
159 return this->Impedance<S>::compute_command(command_state, feedback_state);
160}
161
162template<class S>
163void Dissipative<S>::compute_damping(const S& desired_velocity) {
164 this->basis_ = this->compute_orthonormal_basis(desired_velocity);
165 auto diagonal_eigenvalues = this->damping_eigenvalues_->get_value().asDiagonal();
166 this->damping_->set_value(this->basis_ * diagonal_eigenvalues * this->basis_.transpose());
167}
168
169}// namespace controllers
Definition of a dissipative impedance controller (PassiveDS) in task space.
const ComputationalSpaceType computational_space_
the space in which to compute the command vector
Dissipative(const ComputationalSpaceType &computational_space, unsigned int dimensions=6)
Base constructor.
static Eigen::MatrixXd orthonormalize_basis(const Eigen::MatrixXd &basis, const Eigen::VectorXd &main_eigenvector)
Orthornormalize the basis matrix given in input wrt the main engenvector.
void validate_and_set_parameter(const std::shared_ptr< state_representation::ParameterInterface > &parameter) override
Validate and set parameter for damping eigenvalues.
Eigen::MatrixXd basis_
basis matrix used to compute the damping matrix
std::shared_ptr< state_representation::Parameter< Eigen::VectorXd > > damping_eigenvalues_
coefficient of eigenvalues used in the damping matrix computation
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...
Dissipative(const std::list< std::shared_ptr< state_representation::ParameterInterface > > &parameters, const ComputationalSpaceType &computational_space, unsigned int dimensions=6)
Constructor from an initial parameter list.
void compute_damping(const S &desired_velocity)
Compute the damping matrix as the orthonormal basis to the direction of the desired velocity.
Eigen::MatrixXd compute_orthonormal_basis(const S &desired_velocity)
Compute the orthonormal basis based on the desired velocity input.
Definition of an impedance controller in either joint or task space.
Definition Impedance.hpp:18
std::shared_ptr< state_representation::Parameter< Eigen::MatrixXd > > stiffness_
stiffness matrix of the controller associated to position
Definition Impedance.hpp:62
std::shared_ptr< state_representation::Parameter< Eigen::MatrixXd > > inertia_
inertia matrix of the controller associated to acceleration
Definition Impedance.hpp:66
S compute_command(const S &command_state, const S &feedback_state) override
Compute the command output based on the commanded state and a feedback state To be redefined based on...
Definition Impedance.cpp:12
std::shared_ptr< state_representation::Parameter< Eigen::MatrixXd > > damping_
damping matrix of the controller associated to velocity
Definition Impedance.hpp:64
void set_parameters(const ParameterInterfaceList &parameters)
Set parameters from a list of parameters.
ParameterInterfaceMap parameters_
map of parameters by name
Core state variables and objects.