Biorbd Release_1.13.0
Loading...
Searching...
No Matches
HillThelenType.cpp
1#define BIORBD_API_EXPORTS
2#include "InternalForces/Muscles/HillThelenType.h"
3
4#include <math.h>
5
6#include "InternalForces/Muscles/Characteristics.h"
7#include "InternalForces/Muscles/MuscleGeometry.h"
8#include "Utils/String.h"
9
10#ifdef USE_SMOOTH_IF_ELSE
11#include "Utils/CasadiExpand.h"
12#endif
13
14using namespace BIORBD_NAMESPACE;
15
17 : internal_forces::muscles::HillType() {
18 setType();
19}
27
36
38 const utils::String &name,
41 const internal_forces::PathModifiers &pathModifiers)
42 : internal_forces::muscles::HillType(
43 name,
44 geometry,
46 pathModifiers) {
47 setType();
48}
49
51 const utils::String &name,
54 const internal_forces::PathModifiers &pathModifiers,
56 : internal_forces::muscles::HillType(
57 name,
58 geometry,
60 pathModifiers,
61 emg) {
62 setType();
63}
64
68
70 const std::shared_ptr<Muscle> other)
71 : internal_forces::muscles::HillType(other) {}
72
79
84
86 utils::Scalar normLength =
87 position().length() / characteristics().optimalLength();
88 utils::Scalar kpe = 5.0;
89 utils::Scalar e0 = 0.6;
90 utils::Scalar t5 = exp(kpe * (normLength - 1) / e0);
91 utils::Scalar t7 = exp(kpe);
92
93#ifdef BIORBD_USE_CASADI_MATH
94 *m_FlPE = IF_ELSE_NAMESPACE::if_else_zero(
95 IF_ELSE_NAMESPACE::gt(normLength, 1), ((t5 - 1) / (t7 - 1)));
96#else
97 *m_FlPE = normLength > 1 ? (t5 - 1) / (t7 - 1) : 0;
98#endif
99}
100
103 utils::Scalar normLength =
104 position().length() / characteristics().optimalLength();
105 *m_FlCE = exp(-((normLength - 1) * (normLength - 1)) / 0.45);
106}
107
109 utils::Scalar v = m_position->velocity();
110 utils::Scalar norm_v = v / (characteristics().optimalLength() *
111 this->characteristics().maxShorteningSpeed());
112 utils::Scalar kvce = 0.06;
113 utils::Scalar flen = 1.6;
114
115 // WARNING CONCENTRIC IS NOT FROM THELEN (see header file for precisions)
116 utils::Scalar a = 3.0 / 11.0;
117 utils::Scalar b = 3.0 / 11.0;
118
119#ifdef BIORBD_USE_CASADI_MATH
120 *m_FvCE = IF_ELSE_NAMESPACE::if_else(
121 IF_ELSE_NAMESPACE::ge(norm_v, 0),
122 ((1 + norm_v * flen / kvce) / (1 + norm_v / kvce)), // If norm_v >= 0
123 IF_ELSE_NAMESPACE::if_else(
124 IF_ELSE_NAMESPACE::ge(norm_v, -1),
125 (1 + a) * b / (-norm_v + b) - a, // if norm_v >= -1
126 0 // if norm_v < -1
127 ));
128#else
129
130 if (norm_v >= 0) {
131 *m_FvCE = (1 + norm_v * flen / kvce) / (1 + norm_v / kvce);
132 } else if (norm_v >= -1) {
133 *m_FvCE = (1 + a) * b / (-norm_v + b) - a;
134 } else {
135 *m_FvCE = 0;
136 }
137#endif
138}
140 *m_type = internal_forces::muscles::MUSCLE_TYPE::HILL_THELEN;
141}
const utils::String & name() const
Return the name of the muscle.
Definition Compound.cpp:48
Holder of all the path modifiers of a muscle.
Muscle of Hill type augmented by Thelen https://simtk-confluence.stanford.edu/display/OpenSim/Thelen+...
HillThelenType DeepCopy() const
Deep copy of a Hill-Thelen-type muscle.
virtual void computeFlCE(const State &emg)
Compute the Force-Length of the passive element.
virtual void computeFlPE()
Compute the Force-Length of the passive element.
virtual void computeFvCE()
Compute the Force-Velocity of the passive element.
HillType DeepCopy() const
Deep copy of a Hill-type muscle.
Definition HillType.cpp:177
std::shared_ptr< utils::Scalar > m_FlCE
Force-Length of the contractile element.
Definition HillType.h:216
std::shared_ptr< utils::Scalar > m_FvCE
Force-Velocity of the contractile element.
Definition HillType.h:220
std::shared_ptr< utils::Scalar > m_FlPE
Force-Length of the passive element.
Definition HillType.h:218
Characteristics & characteristics() const
Return the muscle characteristics.
Definition Muscle.cpp:254
std::shared_ptr< internal_forces::muscles::MuscleGeometry > m_position
The geometry (position of the nodes) of the muscle.
Definition Muscle.h:345
std::shared_ptr< MUSCLE_TYPE > m_type
The type of the muscle.
Definition Muscle.h:343
const internal_forces::muscles::MuscleGeometry & position() const
Return the position of all the points attached to the muscle (0 being the origin).
Definition Muscle.cpp:174
EMG holder to interact with the muscle.
Definition State.h:17
Wrapper around the std::string class with augmented functionality.
Definition String.h:18