orwell 0.0.0
CartesianImpedanceController.hxx
1/*
2 Copyright (c) Tobias Löw
3 Written by Tobias Löw <https://tobiloew.ch>
4
5 This file is part of orwell.
6
7 gafro is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 3 as
9 published by the Free Software Foundation.
10
11 gafro is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with gafro. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <sackmesser/Configurations.hpp>
23//
24#include <orwell/torque/CartesianImpedanceController.hpp>
25
26namespace orwell
27{
28
29 template <int dof, class Reference>
30 CartesianImpedanceController<dof, Reference>::CartesianImpedanceController(const sackmesser::Interface::Ptr &interface, const std::string &name)
31 : TorqueReferenceController<dof, Reference>(interface, name)
32 {
33 config_ = interface->getConfigurations()->load<Configuration>(name);
34
35 position_error_ = Eigen::Vector<double, 6>::Zero();
36 velocity_error_ = Eigen::Vector<double, 6>::Zero();
37 acceleration_error_ = Eigen::Vector<double, 6>::Zero();
38 }
39
40 template <int dof, class Reference>
42 const std::shared_ptr<sackmesser::Configurations> &server)
43 {
44 std::array<double, 6> stiffness, damping, inertia, wrench_limits;
45
46 if (!(server->loadParameter<6>(ns + "/stiffness", &stiffness) //
47 && server->loadParameter<6>(ns + "/damping", &damping) //
48 && server->loadParameter<6>(ns + "/inertia", &inertia) //
49 && server->loadParameter<6>(ns + "/wrench_limits", &wrench_limits)))
50 {
51 return false;
52 }
53
54 stiffness_ = Eigen::DiagonalMatrix<double, 6, 6>(Eigen::Vector<double, 6>(stiffness.data()));
55 damping_ = Eigen::DiagonalMatrix<double, 6, 6>(Eigen::Vector<double, 6>(damping.data()));
56 inertia_ = Eigen::DiagonalMatrix<double, 6, 6>(Eigen::Vector<double, 6>(inertia.data()));
57 wrench_limits_ = Eigen::Vector<double, 6>(wrench_limits.data());
58
59 return true;
60 }
61
62 template <int dof, class Reference>
63 CartesianImpedanceController<dof, Reference>::~CartesianImpedanceController() = default;
64
65 template <int dof, class Reference>
67 {
69
70 return this->getRobotModel()->getJacobian().transpose() * limitWrench(this->getDesiredWrench());
71 }
72
73 template <int dof, class Reference>
75 {
76 return config_.stiffness_ * position_error_ + //
77 config_.damping_ * velocity_error_ + //
78 config_.inertia_ * acceleration_error_;
79 }
80
81 template <int dof, class Reference>
82 void CartesianImpedanceController<dof, Reference>::setPositionError(const Eigen::Vector<double, 6> &position_error)
83 {
84 position_error_ = position_error;
85 }
86
87 template <int dof, class Reference>
88 void CartesianImpedanceController<dof, Reference>::setVelocityError(const Eigen::Vector<double, 6> &velocity_error)
89 {
90 velocity_error_ = velocity_error;
91 }
92
93 template <int dof, class Reference>
94 void CartesianImpedanceController<dof, Reference>::setAccelerationError(const Eigen::Vector<double, 6> &acceleration_error)
95 {
96 acceleration_error_ = acceleration_error;
97 }
98
99 template <int dof, class Reference>
100 Eigen::Vector<double, 6> CartesianImpedanceController<dof, Reference>::limitWrench(const Eigen::Vector<double, 6> &wrench)
101 {
102 return wrench.array().min(config_.wrench_limits_.array()).max(-config_.wrench_limits_.array());
103 }
104
105} // namespace orwell
base class for an impedance controller derived from TorqueController
void setVelocityError(const Eigen::Vector< double, 6 > &velocity_error)
set the value of velocity_error_
void setAccelerationError(const Eigen::Vector< double, 6 > &acceleration_error)
set the value of acceleration_error_
void setPositionError(const Eigen::Vector< double, 6 > &position_error)
set the value of position_error_
CartesianImpedanceController(const sackmesser::Interface::Ptr &interface, const std::string &name)
loads configuration parameters
Eigen::Vector< double, 6 > limitWrench(const Eigen::Vector< double, 6 > &wrench)
limit the end-effector wrench to the given wrench_limit_
virtual void computeStateError()=0
computes the state error for the impedance control law
RobotState< dof >::Vector computeCommand()
implements the impedance control law
base implementation of a Controller tracking a given Reference
Eigen::Vector< double, dof > Vector
typedef