| Line |
Branch |
Exec |
Source |
| 1 |
|
|
// |
| 2 |
|
|
// Copyright (c) 2017-2020 CNRS, Inria |
| 3 |
|
|
// |
| 4 |
|
|
// This file is part of tsid |
| 5 |
|
|
// tsid is free software: you can redistribute it |
| 6 |
|
|
// and/or modify it under the terms of the GNU Lesser General Public |
| 7 |
|
|
// License as published by the Free Software Foundation, either version |
| 8 |
|
|
// 3 of the License, or (at your option) any later version. |
| 9 |
|
|
// tsid is distributed in the hope that it will be |
| 10 |
|
|
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
| 11 |
|
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
|
|
// General Lesser Public License for more details. You should have |
| 13 |
|
|
// received a copy of the GNU Lesser General Public License along with |
| 14 |
|
|
// tsid If not, see |
| 15 |
|
|
// <http://www.gnu.org/licenses/>. |
| 16 |
|
|
// |
| 17 |
|
|
|
| 18 |
|
|
#include "tsid/tasks/task-com-equality.hpp" |
| 19 |
|
|
#include "tsid/robots/robot-wrapper.hpp" |
| 20 |
|
|
|
| 21 |
|
|
namespace tsid { |
| 22 |
|
|
namespace tasks { |
| 23 |
|
|
using namespace math; |
| 24 |
|
|
using namespace trajectories; |
| 25 |
|
|
using namespace pinocchio; |
| 26 |
|
|
|
| 27 |
|
✗ |
TaskComEquality::TaskComEquality(const std::string& name, RobotWrapper& robot) |
| 28 |
|
✗ |
: TaskMotion(name, robot), m_constraint(name, 3, robot.nv()) { |
| 29 |
|
✗ |
m_Kp.setZero(3); |
| 30 |
|
✗ |
m_Kd.setZero(3); |
| 31 |
|
✗ |
m_p_error_vec.setZero(3); |
| 32 |
|
✗ |
m_v_error_vec.setZero(3); |
| 33 |
|
✗ |
m_p_com.setZero(3); |
| 34 |
|
✗ |
m_v_com.setZero(3); |
| 35 |
|
✗ |
m_a_des_vec.setZero(3); |
| 36 |
|
✗ |
m_ref.resize(3); |
| 37 |
|
✗ |
m_mask.resize(3); |
| 38 |
|
✗ |
m_mask.fill(1.); |
| 39 |
|
✗ |
setMask(m_mask); |
| 40 |
|
|
} |
| 41 |
|
|
|
| 42 |
|
✗ |
void TaskComEquality::setMask(math::ConstRefVector mask) { |
| 43 |
|
✗ |
PINOCCHIO_CHECK_INPUT_ARGUMENT( |
| 44 |
|
|
mask.size() == 3, "The size of the mask vector needs to equal 3"); |
| 45 |
|
✗ |
TaskMotion::setMask(mask); |
| 46 |
|
✗ |
int n = dim(); |
| 47 |
|
✗ |
m_constraint.resize(n, m_robot.nv()); |
| 48 |
|
✗ |
m_p_error_masked_vec.resize(n); |
| 49 |
|
✗ |
m_v_error_masked_vec.resize(n); |
| 50 |
|
✗ |
m_drift_masked.resize(n); |
| 51 |
|
✗ |
m_a_des_masked.resize(n); |
| 52 |
|
|
} |
| 53 |
|
|
|
| 54 |
|
✗ |
int TaskComEquality::dim() const { return int(m_mask.sum()); } |
| 55 |
|
|
|
| 56 |
|
✗ |
const Vector3& TaskComEquality::Kp() { return m_Kp; } |
| 57 |
|
|
|
| 58 |
|
✗ |
const Vector3& TaskComEquality::Kd() { return m_Kd; } |
| 59 |
|
|
|
| 60 |
|
✗ |
void TaskComEquality::Kp(ConstRefVector Kp) { |
| 61 |
|
✗ |
PINOCCHIO_CHECK_INPUT_ARGUMENT(Kp.size() == 3, |
| 62 |
|
|
"The size of the Kp vector needs to equal 3"); |
| 63 |
|
✗ |
m_Kp = Kp; |
| 64 |
|
|
} |
| 65 |
|
|
|
| 66 |
|
✗ |
void TaskComEquality::Kd(ConstRefVector Kd) { |
| 67 |
|
✗ |
PINOCCHIO_CHECK_INPUT_ARGUMENT(Kd.size() == 3, |
| 68 |
|
|
"The size of the Kd vector needs to equal 3"); |
| 69 |
|
✗ |
m_Kd = Kd; |
| 70 |
|
|
} |
| 71 |
|
|
|
| 72 |
|
✗ |
void TaskComEquality::setReference(const TrajectorySample& ref) { m_ref = ref; } |
| 73 |
|
|
|
| 74 |
|
✗ |
const TrajectorySample& TaskComEquality::getReference() const { return m_ref; } |
| 75 |
|
|
|
| 76 |
|
✗ |
const Vector& TaskComEquality::getDesiredAcceleration() const { |
| 77 |
|
✗ |
return m_a_des_masked; |
| 78 |
|
|
} |
| 79 |
|
|
|
| 80 |
|
✗ |
Vector TaskComEquality::getAcceleration(ConstRefVector dv) const { |
| 81 |
|
✗ |
return m_constraint.matrix() * dv - m_drift_masked; |
| 82 |
|
|
} |
| 83 |
|
|
|
| 84 |
|
✗ |
const Vector& TaskComEquality::position_error() const { |
| 85 |
|
✗ |
return m_p_error_masked_vec; |
| 86 |
|
|
} |
| 87 |
|
|
|
| 88 |
|
✗ |
const Vector& TaskComEquality::velocity_error() const { |
| 89 |
|
✗ |
return m_v_error_masked_vec; |
| 90 |
|
|
} |
| 91 |
|
|
|
| 92 |
|
✗ |
const Vector& TaskComEquality::position() const { return m_p_com; } |
| 93 |
|
|
|
| 94 |
|
✗ |
const Vector& TaskComEquality::velocity() const { return m_v_com; } |
| 95 |
|
|
|
| 96 |
|
✗ |
const Vector& TaskComEquality::position_ref() const { return m_ref.getValue(); } |
| 97 |
|
|
|
| 98 |
|
✗ |
const Vector& TaskComEquality::velocity_ref() const { |
| 99 |
|
✗ |
return m_ref.getDerivative(); |
| 100 |
|
|
} |
| 101 |
|
|
|
| 102 |
|
✗ |
const ConstraintBase& TaskComEquality::getConstraint() const { |
| 103 |
|
✗ |
return m_constraint; |
| 104 |
|
|
} |
| 105 |
|
|
|
| 106 |
|
✗ |
const ConstraintBase& TaskComEquality::compute(const double, ConstRefVector, |
| 107 |
|
|
ConstRefVector, Data& data) { |
| 108 |
|
✗ |
m_robot.com(data, m_p_com, m_v_com, m_drift); |
| 109 |
|
|
|
| 110 |
|
|
// Compute errors |
| 111 |
|
✗ |
m_p_error = m_p_com - m_ref.getValue(); |
| 112 |
|
✗ |
m_v_error = m_v_com - m_ref.getDerivative(); |
| 113 |
|
✗ |
m_a_des = -m_Kp.cwiseProduct(m_p_error) - m_Kd.cwiseProduct(m_v_error) + |
| 114 |
|
✗ |
m_ref.getSecondDerivative(); |
| 115 |
|
|
|
| 116 |
|
✗ |
m_p_error_vec = m_p_error; |
| 117 |
|
✗ |
m_v_error_vec = m_v_error; |
| 118 |
|
✗ |
m_a_des_vec = m_a_des; |
| 119 |
|
|
#ifndef NDEBUG |
| 120 |
|
|
// std::cout<<m_name<<" errors: "<<m_p_error.norm()<<" " |
| 121 |
|
|
// <<m_v_error.norm()<<std::endl; |
| 122 |
|
|
#endif |
| 123 |
|
|
|
| 124 |
|
|
// Get CoM jacobian |
| 125 |
|
✗ |
const Matrix3x& Jcom = m_robot.Jcom(data); |
| 126 |
|
|
|
| 127 |
|
✗ |
int idx = 0; |
| 128 |
|
✗ |
for (int i = 0; i < 3; i++) { |
| 129 |
|
✗ |
if (m_mask(i) != 1.) continue; |
| 130 |
|
|
|
| 131 |
|
✗ |
m_constraint.matrix().row(idx) = Jcom.row(i); |
| 132 |
|
✗ |
m_constraint.vector().row(idx) = (m_a_des - m_drift).row(i); |
| 133 |
|
|
|
| 134 |
|
✗ |
m_a_des_masked(idx) = m_a_des(i); |
| 135 |
|
✗ |
m_drift_masked(idx) = m_drift(i); |
| 136 |
|
✗ |
m_p_error_masked_vec(idx) = m_p_error_vec(i); |
| 137 |
|
✗ |
m_v_error_masked_vec(idx) = m_v_error_vec(i); |
| 138 |
|
|
|
| 139 |
|
✗ |
idx += 1; |
| 140 |
|
|
} |
| 141 |
|
|
|
| 142 |
|
✗ |
return m_constraint; |
| 143 |
|
|
} |
| 144 |
|
|
|
| 145 |
|
|
} // namespace tasks |
| 146 |
|
|
} // namespace tsid |
| 147 |
|
|
|