Biorbd Release_1.13.0
Loading...
Searching...
No Matches
Ligament.cpp
1#define BIORBD_API_EXPORTS
2
3#include "InternalForces/Ligaments/Ligament.h"
4
5#include "InternalForces/Compound.h"
6#include "InternalForces/Geometry.h"
7#include "InternalForces/Ligaments/LigamentCharacteristics.h"
8#include "InternalForces/Ligaments/LigamentsEnums.h"
9#include "InternalForces/PathModifiers.h"
10#include "RigidBody/GeneralizedCoordinates.h"
11#include "RigidBody/GeneralizedVelocity.h"
12#include "RigidBody/Joints.h"
13#include "Utils/Error.h"
14
15#ifdef USE_SMOOTH_IF_ELSE
16#include "Utils/CasadiExpand.h"
17#endif
18
19using namespace BIORBD_NAMESPACE;
21 : internal_forces::Compound(),
22 m_position(std::make_shared<internal_forces::Geometry>()),
23 m_type(
24 std::make_shared<internal_forces::ligaments::LIGAMENT_TYPE>(
25 internal_forces::ligaments::LIGAMENT_TYPE::NO_LIGAMENT_TYPE)),
27 std::make_shared<
28 internal_forces::ligaments::LigamentCharacteristics>()),
29 m_Fl(std::make_shared<utils::Scalar>()),
30 m_damping(std::make_shared<utils::Scalar>())
31
32{
33 setType();
34}
35
37 const utils::String &name,
40 : internal_forces::Compound(name),
41 m_position(std::make_shared<internal_forces::Geometry>(position)),
42 m_type(
43 std::make_shared<internal_forces::ligaments::LIGAMENT_TYPE>(
44 internal_forces::ligaments::LIGAMENT_TYPE::NO_LIGAMENT_TYPE)),
46 std::make_shared<internal_forces::ligaments::LigamentCharacteristics>(
48 m_Fl(std::make_shared<utils::Scalar>()),
49 m_damping(std::make_shared<utils::Scalar>()) {
50 setType();
51}
52
54 const utils::String &name,
57 const internal_forces::PathModifiers &pathModifiers)
58 : internal_forces::Compound(name, pathModifiers),
59 m_position(std::make_shared<internal_forces::Geometry>(position)),
60 m_type(
61 std::make_shared<internal_forces::ligaments::LIGAMENT_TYPE>(
62 internal_forces::ligaments::LIGAMENT_TYPE::NO_LIGAMENT_TYPE)),
64 std::make_shared<internal_forces::ligaments::LigamentCharacteristics>(
66 m_Fl(std::make_shared<utils::Scalar>()),
67 m_damping(std::make_shared<utils::Scalar>()) {
68 setType();
69}
70
79
81 const std::shared_ptr<Ligament> other)
82 : internal_forces::Compound(other),
83 m_position(other->m_position),
84 m_type(other->m_type),
86 m_Fl(other->m_Fl),
87 m_damping(other->m_damping) {}
88
92
96 *m_position = other.m_position->DeepCopy();
97 *m_type = *other.m_type;
98 *m_characteristics = other.m_characteristics->DeepCopy();
99 *m_Fl = *other.m_Fl;
100 *m_damping = *other.m_damping;
101}
102
103internal_forces::ligaments::LIGAMENT_TYPE
107
109 *m_type = internal_forces::ligaments::LIGAMENT_TYPE::NO_LIGAMENT_TYPE;
110}
111
113 rigidbody::Joints &updatedModel,
115 // Update de la position des insertions et origines
116 m_position->updateKinematics(updatedModel, *m_pathChanger, &Q, nullptr);
117}
119 rigidbody::Joints &updatedModel,
122
123{
124 // Update de la position des insertions et origines
125 m_position->updateKinematics(updatedModel, *m_pathChanger, &Q, &Qdot);
126}
128 std::vector<utils::Vector3d> &ligamentPointsInGlobal,
129 utils::Matrix &jacoPointsInGlobal) {
130 // Update de la position des insertions et origines
131 m_position->updateKinematics(
132 ligamentPointsInGlobal, jacoPointsInGlobal, nullptr);
133}
135 std::vector<utils::Vector3d> &ligamentPointsInGlobal,
136 utils::Matrix &jacoPointsInGlobal,
137 const rigidbody::GeneralizedVelocity &Qdot) {
138 // Update de la position des insertions et origines
139 m_position->updateKinematics(
140 ligamentPointsInGlobal, jacoPointsInGlobal, &Qdot);
141}
142
151
153 rigidbody::Joints &updatedModel,
155 bool updateLigamentKinematics) {
156 if (updateLigamentKinematics)
157 m_position->updateKinematics(updatedModel, *m_pathChanger, &Q, nullptr);
158 return position().length();
159}
160
162 rigidbody::Joints &updatedModel,
165 bool updateLigamentKinematics) {
166 if (updateLigamentKinematics) {
167 m_position->updateKinematics(updatedModel, *m_pathChanger, &Q, &Qdot);
168 }
169
170 return m_position->velocity();
171}
172
174 rigidbody::Joints &updatedModel,
177 bool updateLigamentKinematics) {
178 // Update the ligament configuration if necessary
179 if (updateLigamentKinematics) updateOrientations(updatedModel, Q, Qdot);
180
181 // Computation
182 computeFl();
183 computeForce();
184 return *m_force;
185}
186
188 rigidbody::Joints &updatedModel,
190 bool updateLigamentKinematics) {
191 // Update the ligament configuration if necessary
192 if (updateLigamentKinematics) updateOrientations(updatedModel, Q);
193
194 // Computation
195 computeFl();
196 computeForce();
197 return *m_force;
198}
199
201 // Computation
202 computeFl();
203 computeForce();
204 return *m_force;
205}
206
210
212 return *m_Fl + damping();
213}
214
215const std::vector<utils::Vector3d> &
217 rigidbody::Joints &updatedModel,
219 bool updateLigamentKinematics) {
220 if (updateLigamentKinematics)
221 m_position->updateKinematics(updatedModel, *m_pathChanger, &Q);
223}
224
225const std::vector<utils::Vector3d> &
229
235
240
242 computeFl();
243 return *m_Fl;
244}
245
248 return *m_damping;
249}
250
252#ifdef BIORBD_USE_CASADI_MATH
253 *m_damping = IF_ELSE_NAMESPACE::if_else_zero(
254 IF_ELSE_NAMESPACE::gt(position().velocity(), 0),
255 ((position().velocity() / characteristics().maxShorteningSpeed()) *
256 characteristics().dampingParam()));
257
258#else
259 if (position().velocity() > 0) {
260 *m_damping =
261 (position().velocity() / characteristics().maxShorteningSpeed()) *
262 characteristics().dampingParam();
263 } else {
264 *m_damping = 0;
265 }
266#endif
267}
const utils::String & name() const
Return the name of the muscle.
Definition Compound.cpp:48
void DeepCopy(const Compound &other)
Deep copy of a compound.
Definition Compound.cpp:41
std::shared_ptr< utils::Scalar > m_force
The last computed force.
Definition Compound.h:108
Compound()
Construct muscle compound.
Definition Compound.cpp:11
std::shared_ptr< internal_forces::PathModifiers > m_pathChanger
The set of path modifiers.
Definition Compound.h:107
Class Geometry of the muscle.
Definition Geometry.h:31
void updateKinematics(rigidbody::Joints &updatedModel, const rigidbody::GeneralizedCoordinates *Q=nullptr, const rigidbody::GeneralizedVelocity *Qdot=nullptr)
Updates the position and dynamic elements of the muscles.
Definition Geometry.cpp:88
Holder of all the path modifiers of a muscle.
void setCharacteristics(const LigamentCharacteristics &characteristics)
Set the ligament characteristics.
Definition Ligament.cpp:230
const utils::Scalar & velocity(rigidbody::Joints &updatedModel, const rigidbody::GeneralizedCoordinates &Q, const rigidbody::GeneralizedVelocity &Qdot, bool updateLigamentKinematics=true)
Return the velocity of the ligament.
Definition Ligament.cpp:161
const std::vector< utils::Vector3d > & ligamentsPointsInGlobal(rigidbody::Joints &updatedModel, const rigidbody::GeneralizedCoordinates &Q, bool updateLigamentKinematics=true)
Return the ligament points in global reference frame.
Definition Ligament.cpp:216
std::shared_ptr< internal_forces::Geometry > m_position
Definition Ligament.h:272
const internal_forces::Geometry & position() const
Return the position of all the points attached to the ligament (0 being the origin).
Definition Ligament.cpp:148
virtual void computeFl()=0
Compute the Force-length.
std::shared_ptr< utils::Scalar > m_damping
The ligament damping term.
Definition Ligament.h:277
const utils::Scalar & length(rigidbody::Joints &updatedModel, const rigidbody::GeneralizedCoordinates &Q, bool updateLigamentKinematics=true)
Get the length of the ligament.
Definition Ligament.cpp:152
const std::vector< utils::Vector3d > & ligamentsPointsInGlobal() const
Return the previously computed ligament points in global reference frame.
Definition Ligament.cpp:226
void computeDamping()
Compute the ligament damping.
Definition Ligament.cpp:251
const utils::Scalar & Fl()
Return the Force-Length of the passive element.
Definition Ligament.cpp:241
void DeepCopy(const Ligament &other)
Deep copy of a ligament in new ligament.
Definition Ligament.cpp:93
virtual utils::Scalar getForce()
Function allowing modification of the way the force is computed in computeForce().
Definition Ligament.cpp:211
const LigamentCharacteristics & characteristics() const
Return the ligament characteristics.
Definition Ligament.cpp:237
std::shared_ptr< utils::Scalar > m_Fl
Force-Length.
Definition Ligament.h:292
void updateOrientations(rigidbody::Joints &updatedModel, const rigidbody::GeneralizedCoordinates &Q)
Update the position of the origin and insertion positions of the ligament.
Definition Ligament.cpp:112
LIGAMENT_TYPE type() const
Return the type of the ligament.
Definition Ligament.cpp:104
virtual void computeForce()
Compute the force of the ligament.
Definition Ligament.cpp:207
void setPosition(const internal_forces::Geometry &positions)
Set the position of all the points attached to the ligament (0 being the origin).
Definition Ligament.cpp:143
const utils::Scalar & damping()
Return the ligament damping (spring force).
Definition Ligament.cpp:246
std::shared_ptr< LigamentCharacteristics > m_characteristics
The ligament characteristics.
Definition Ligament.h:276
virtual const utils::Scalar & force()
Return the computed force norm. The ligament orientation had to be computed before calling this funct...
Definition Ligament.cpp:200
std::shared_ptr< LIGAMENT_TYPE > m_type
The type of the ligament.
Definition Ligament.h:274
virtual void setType()
Set the type of ligament.
Definition Ligament.cpp:108
This is the core of the musculoskeletal model in biorbd.
Definition Joints.h:48
A wrapper for the Eigen::MatrixXd.
Definition Matrix.h:18
Wrapper around the std::string class with augmented functionality.
Definition String.h:18