Biorbd
ActuatorGauss6p.cpp
1 #define BIORBD_API_EXPORTS
2 #include "Actuators/ActuatorGauss6p.h"
3 
4 #include "Utils/Error.h"
5 #include "RigidBody/GeneralizedCoordinates.h"
6 #include "RigidBody/GeneralizedVelocity.h"
7 
9  biorbd::actuator::Actuator(),
10  m_k(std::make_shared<biorbd::utils::Scalar>(4.3)),
11  m_Tmax(std::make_shared<biorbd::utils::Scalar>(0)),
12  m_T0(std::make_shared<biorbd::utils::Scalar>(0)),
13  m_wmax(std::make_shared<biorbd::utils::Scalar>(0)),
14  m_wc(std::make_shared<biorbd::utils::Scalar>(0)),
15  m_amax(std::make_shared<biorbd::utils::Scalar>(1.0)),
16  m_amin(std::make_shared<biorbd::utils::Scalar>(0)),
17  m_wr(std::make_shared<biorbd::utils::Scalar>(0)),
18  m_w1(std::make_shared<biorbd::utils::Scalar>(0)),
19  m_r(std::make_shared<biorbd::utils::Scalar>(0)),
20  m_qopt(std::make_shared<biorbd::utils::Scalar>(0)),
21  m_facteur(std::make_shared<biorbd::utils::Scalar>(0)),
22  m_r2(std::make_shared<biorbd::utils::Scalar>(0)),
23  m_qopt2(std::make_shared<biorbd::utils::Scalar>(0))
24 {
25  setType();
26 }
27 
29  const biorbd::actuator::ActuatorGauss6p &other) :
30  biorbd::actuator::Actuator(other),
31  m_k(other.m_k),
32  m_Tmax(other.m_Tmax),
33  m_T0(other.m_T0),
34  m_wmax(other.m_wmax),
35  m_wc(other.m_wc),
36  m_amax(other.m_amax),
37  m_amin(other.m_amin),
38  m_wr(other.m_wr),
39  m_w1(other.m_w1),
40  m_r(other.m_r),
41  m_qopt(other.m_qopt),
42  m_facteur(other.m_facteur),
43  m_r2(other.m_r2),
44  m_qopt2(other.m_qopt2)
45 {
46 
47 }
49  int direction,
50  const biorbd::utils::Scalar& Tmax,
51  const biorbd::utils::Scalar& T0,
52  const biorbd::utils::Scalar& wmax,
53  const biorbd::utils::Scalar& wc,
54  const biorbd::utils::Scalar& amin,
55  const biorbd::utils::Scalar& wr,
56  const biorbd::utils::Scalar& w1,
57  const biorbd::utils::Scalar& r,
58  const biorbd::utils::Scalar& qopt,
59  const biorbd::utils::Scalar& facteur,
60  const biorbd::utils::Scalar& r2,
61  const biorbd::utils::Scalar& qopt2,
62  unsigned int dofIdx) :
63  Actuator(direction, dofIdx),
64  m_k(std::make_shared<biorbd::utils::Scalar>(4.3)),
65  m_Tmax(std::make_shared<biorbd::utils::Scalar>(Tmax)),
66  m_T0(std::make_shared<biorbd::utils::Scalar>(T0)),
67  m_wmax(std::make_shared<biorbd::utils::Scalar>(wmax)),
68  m_wc(std::make_shared<biorbd::utils::Scalar>(wc)),
69  m_amax(std::make_shared<biorbd::utils::Scalar>(1.0)),
70  m_amin(std::make_shared<biorbd::utils::Scalar>(amin)),
71  m_wr(std::make_shared<biorbd::utils::Scalar>(wr)),
72  m_w1(std::make_shared<biorbd::utils::Scalar>(w1)),
73  m_r(std::make_shared<biorbd::utils::Scalar>(r)),
74  m_qopt(std::make_shared<biorbd::utils::Scalar>(qopt)),
75  m_facteur(std::make_shared<biorbd::utils::Scalar>(facteur)),
76  m_r2(std::make_shared<biorbd::utils::Scalar>(r2)),
77  m_qopt2(std::make_shared<biorbd::utils::Scalar>(qopt2))
78 {
79  setType();
80 }
81 
83  int direction,
84  const biorbd::utils::Scalar& Tmax,
85  const biorbd::utils::Scalar& T0,
86  const biorbd::utils::Scalar& wmax,
87  const biorbd::utils::Scalar& wc,
88  const biorbd::utils::Scalar& amin,
89  const biorbd::utils::Scalar& wr,
90  const biorbd::utils::Scalar& w1,
91  const biorbd::utils::Scalar& r,
92  const biorbd::utils::Scalar& qopt,
93  const biorbd::utils::Scalar& facteur,
94  const biorbd::utils::Scalar& r2,
95  const biorbd::utils::Scalar& qopt2,
96  unsigned int dofIdx,
97  const biorbd::utils::String &jointName) :
98  Actuator(direction, dofIdx, jointName),
99  m_k(std::make_shared<biorbd::utils::Scalar>(4.3)),
100  m_Tmax(std::make_shared<biorbd::utils::Scalar>(Tmax)),
101  m_T0(std::make_shared<biorbd::utils::Scalar>(T0)),
102  m_wmax(std::make_shared<biorbd::utils::Scalar>(wmax)),
103  m_wc(std::make_shared<biorbd::utils::Scalar>(wc)),
104  m_amax(std::make_shared<biorbd::utils::Scalar>(1.0)),
105  m_amin(std::make_shared<biorbd::utils::Scalar>(amin)),
106  m_wr(std::make_shared<biorbd::utils::Scalar>(wr)),
107  m_w1(std::make_shared<biorbd::utils::Scalar>(w1)),
108  m_r(std::make_shared<biorbd::utils::Scalar>(r)),
109  m_qopt(std::make_shared<biorbd::utils::Scalar>(qopt)),
110  m_facteur(std::make_shared<biorbd::utils::Scalar>(facteur)),
111  m_r2(std::make_shared<biorbd::utils::Scalar>(r2)),
112  m_qopt2(std::make_shared<biorbd::utils::Scalar>(qopt2))
113 {
114  setType();
115 }
116 
118 {
119 
120 }
121 
123 {
125  copy.DeepCopy(*this);
126  return copy;
127 }
128 
131 {
133  *m_k = *other.m_k;
134  *m_Tmax = *other.m_Tmax;
135  *m_T0 = *other.m_T0;
136  *m_wmax = *other.m_wmax;
137  *m_wc = *other.m_wc;
138  *m_amax = *other.m_amax;
139  *m_amin = *other.m_amin;
140  *m_wr = *other.m_wr;
141  *m_w1 = *other.m_w1;
142  *m_r = *other.m_r;
143  *m_qopt = *other.m_qopt;
144  *m_facteur = *other.m_facteur;
145  *m_r2 = *other.m_r2;
146  *m_qopt2 = *other.m_qopt2;
147 }
148 
150 {
151  biorbd::utils::Error::raise("torqueMax for ActuatorGauss6p must be called with Q and Qdot");
152 }
153 
157  biorbd::utils::Scalar pos(Q[*m_dofIdx] * 180/M_PI);
158  biorbd::utils::Scalar speed(Qdot[*m_dofIdx] * 180/M_PI);
159 
160  // Tetanic torque max
161  biorbd::utils::Scalar Tc = *m_T0 * *m_wc / *m_wmax;
162  biorbd::utils::Scalar C = Tc*(*m_wmax + *m_wc); // concentric
163  biorbd::utils::Scalar we = ( (*m_Tmax - *m_T0) * *m_wmax * *m_wc ) / ( *m_k * *m_T0 * (*m_wmax + *m_wc) );
164  biorbd::utils::Scalar E = -( *m_Tmax - *m_T0 ) * we; // eccentric
165 
166  biorbd::utils::Scalar Tw;
167 #ifdef BIORBD_USE_CASADI_MATH
168  Tw = casadi::MX::if_else(casadi::MX::ge(speed, 0),
169  C / ( *m_wc + speed ) - Tc,
170  E / ( we - speed ) + *m_Tmax);
171 #else
172  if (speed >= 0)
173  Tw = C / ( *m_wc + speed ) - Tc; // For the concentric
174  else
175  Tw = E / ( we - speed ) + *m_Tmax; // For the eccentric
176 #endif
177 
178  // Differential activation
179  biorbd::utils::Scalar A =
180  *m_amin + ( *m_amax - *m_amin )
181  / ( 1 + biorbd::utils::Scalar(exp( -(speed - *m_w1) / *m_wr )) );
182 
183  // Torque angle
184  biorbd::utils::Scalar Ta = biorbd::utils::Scalar(exp( -(*m_qopt - pos) * (*m_qopt - pos) / (2* *m_r * *m_r ) ))
185  + *m_facteur * biorbd::utils::Scalar(exp( -(*m_qopt2 - pos) * (*m_qopt2 - pos) / (2 * *m_r2 * *m_r2) ));
186 
187  // Calculation of the max torque
188  return Tw * A * Ta;
189 }
190 
192 {
193  *m_type = biorbd::actuator::TYPE::GAUSS6P;
194 }
biorbd::actuator::ActuatorGauss6p::m_qopt
std::shared_ptr< biorbd::utils::Scalar > m_qopt
1st Optimal position
Definition: ActuatorGauss6p.h:158
biorbd::actuator::ActuatorGauss6p::torqueMax
virtual biorbd::utils::Scalar torqueMax()
Return the maximal torque (invalid)
Definition: ActuatorGauss6p.cpp:149
biorbd::actuator::ActuatorGauss6p::m_wr
std::shared_ptr< biorbd::utils::Scalar > m_wr
1/10 of the distance amax/amin
Definition: ActuatorGauss6p.h:153
biorbd::actuator::ActuatorGauss6p::m_k
std::shared_ptr< biorbd::utils::Scalar > m_k
Ratio of slope of the eccentric and concentric phases.
Definition: ActuatorGauss6p.h:144
biorbd::actuator::ActuatorGauss6p::m_w1
std::shared_ptr< biorbd::utils::Scalar > m_w1
Mid point plateau.
Definition: ActuatorGauss6p.h:154
biorbd::actuator::Actuator
Class Actuator.
Definition: Actuator.h:20
biorbd::actuator::ActuatorGauss6p::m_wc
std::shared_ptr< biorbd::utils::Scalar > m_wc
Angular velocity of the vertical asymptote of the concentric hyperbola.
Definition: ActuatorGauss6p.h:148
biorbd::actuator::ActuatorGauss6p::m_amax
std::shared_ptr< biorbd::utils::Scalar > m_amax
Maximum activation level (set to 1)
Definition: ActuatorGauss6p.h:151
biorbd::actuator::ActuatorGauss6p::~ActuatorGauss6p
virtual ~ActuatorGauss6p()
Destroy the class properly.
Definition: ActuatorGauss6p.cpp:117
biorbd::rigidbody::GeneralizedCoordinates
Class GeneralizedCoordinates.
Definition: GeneralizedCoordinates.h:15
biorbd::actuator::ActuatorGauss6p::m_Tmax
std::shared_ptr< biorbd::utils::Scalar > m_Tmax
Maximum torque in the eccentric phase.
Definition: ActuatorGauss6p.h:145
biorbd::actuator::ActuatorGauss6p::ActuatorGauss6p
ActuatorGauss6p()
Construct Gauss6p actuator.
Definition: ActuatorGauss6p.cpp:8
biorbd::utils::Error::raise
static void raise(const biorbd::utils::String &message)
Throw an error message.
Definition: Error.cpp:4
biorbd::actuator::ActuatorGauss6p::m_facteur
std::shared_ptr< biorbd::utils::Scalar > m_facteur
Factor of the 6p.
Definition: ActuatorGauss6p.h:159
biorbd::actuator::ActuatorGauss6p::setType
virtual void setType()
Set the type of actuator.
Definition: ActuatorGauss6p.cpp:191
biorbd::actuator::ActuatorGauss6p::m_r
std::shared_ptr< biorbd::utils::Scalar > m_r
width of the 1st gaussian curve
Definition: ActuatorGauss6p.h:157
biorbd::actuator::ActuatorGauss6p::m_amin
std::shared_ptr< biorbd::utils::Scalar > m_amin
Low plateau level.
Definition: ActuatorGauss6p.h:152
biorbd::actuator::ActuatorGauss6p::m_r2
std::shared_ptr< biorbd::utils::Scalar > m_r2
width of the 2nd gaussian curve
Definition: ActuatorGauss6p.h:160
biorbd::actuator::Actuator::DeepCopy
void DeepCopy(const biorbd::actuator::Actuator &other)
Deep copy of actuator.
Definition: Actuator.cpp:55
biorbd::actuator::ActuatorGauss6p
Class ActuatorGauss6p is a joint actuator type which maximum is bimodal 6 parameter gaussian (Gauss6p...
Definition: ActuatorGauss6p.h:18
biorbd::utils::String
Wrapper around the std::string class with augmented functionality.
Definition: String.h:17
biorbd::actuator::ActuatorGauss6p::m_qopt2
std::shared_ptr< biorbd::utils::Scalar > m_qopt2
2nd Optimal position
Definition: ActuatorGauss6p.h:161
biorbd::actuator::ActuatorGauss6p::DeepCopy
biorbd::actuator::ActuatorGauss6p DeepCopy() const
Deep copy of the Gauss6p actuator.
Definition: ActuatorGauss6p.cpp:122
biorbd::actuator::ActuatorGauss6p::m_T0
std::shared_ptr< biorbd::utils::Scalar > m_T0
Maximum torque isometric.
Definition: ActuatorGauss6p.h:146
biorbd::actuator::ActuatorGauss6p::m_wmax
std::shared_ptr< biorbd::utils::Scalar > m_wmax
Maximum angular velocity above which torque cannot be produced.
Definition: ActuatorGauss6p.h:147
biorbd::rigidbody::GeneralizedVelocity
Class GeneralizedVelocity.
Definition: GeneralizedVelocity.h:15