orwell 0.0.0
JointImpedanceController.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 <orwell/torque/JointImpedanceController.hpp>
23
24namespace orwell
25{
26
27 template <int dof>
28 JointImpedanceController<dof>::JointImpedanceController(const sackmesser::Interface::Ptr &interface, const std::string &name)
29 : TorqueReferenceController<dof, Eigen::Vector<double, dof>>(interface, name)
30 {
31 config_ = interface->getConfigurations()->load<Configuration>(name);
32 }
33
34 template <int dof>
35 bool JointImpedanceController<dof>::Configuration::load(const std::string &ns, const std::shared_ptr<sackmesser::Configurations> &server)
36 {
37 std::array<double, dof> stiffness, damping, position_difference_limit;
38
39 if (!(server->loadParameter<dof>(ns + "/stiffness", &stiffness) //
40 && server->loadParameter<dof>(ns + "/damping", &damping) //
41 && server->loadParameter<dof>(ns + "/position_difference_limit", &position_difference_limit)))
42 {
43 return false;
44 }
45
46 stiffness_ = Eigen::DiagonalMatrix<double, dof, dof>(Eigen::Vector<double, dof>(stiffness.data()));
47 damping_ = Eigen::DiagonalMatrix<double, dof, dof>(Eigen::Vector<double, dof>(damping.data()));
48 position_difference_limit_ = Eigen::Vector<double, dof>(position_difference_limit.data());
49
50 return true;
51 }
52
53 template <int dof>
54 JointImpedanceController<dof>::~JointImpedanceController() = default;
55
56 template <int dof>
58 {
59 Eigen::Vector<double, dof> torque = Eigen::Vector<double, dof>::Zero();
60
61 Eigen::Vector<double, dof> position_error = limit(this->getReference() - this->getRobotState().getPosition());
62
63 torque = config_.stiffness_ * position_error + config_.damping_ * (-this->getRobotState().getVelocity());
64
65 return torque;
66 }
67
68 template <int dof>
69 Eigen::Vector<double, dof> JointImpedanceController<dof>::limit(const Eigen::Vector<double, dof> &position_difference)
70 {
71 return position_difference.array().min(config_.position_difference_limit_.array()).max(-config_.position_difference_limit_.array());
72 }
73
74} // namespace orwell
defines an impedance control law in joint space
Eigen::Vector< double, dof > computeCommand()
computes the control command for the impedance control law in joint space
JointImpedanceController(const sackmesser::Interface::Ptr &interface, const std::string &name)
loads configuration parameters
base implementation of a Controller tracking a given Reference
const Reference & getReference() const
provide access to the Reference to derived classes