Biorbd Release_1.13.0
Loading...
Searching...
No Matches
LigamentSpringLinear.cpp
1#define BIORBD_API_EXPORTS
2
3#include "InternalForces/Ligaments/LigamentSpringLinear.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::ligaments::Ligament(),
22 m_stiffness(std::make_shared<utils::Scalar>()) {
23 setType();
24}
25
35
37 const utils::Scalar &stiffness,
38 const utils::String &name,
41 const internal_forces::PathModifiers &pathModifiers)
42 : internal_forces::ligaments::Ligament(
43 name,
46 pathModifiers),
47 m_stiffness(std::make_shared<utils::Scalar>(stiffness)) {
48 setType();
49}
50
52 const std::shared_ptr<Ligament> other)
53 : internal_forces::ligaments::Ligament(other) {
54 const std::shared_ptr<internal_forces::ligaments::LigamentSpringLinear>
55 ligament_tp(
56 std::dynamic_pointer_cast<
59 ligament_tp != nullptr, "ligament must be of a spring linear Type");
60 m_stiffness = ligament_tp->m_stiffness;
61}
62
69
75
76const utils::Scalar &
80
82 const utils::Scalar &val) {
83 *m_stiffness = val;
84}
85
94
96
98 *m_type = internal_forces::ligaments::LIGAMENT_TYPE::LIGAMENT_SPRING_LINEAR;
99}
100
102#ifdef BIORBD_USE_CASADI_MATH
103 *m_Fl = IF_ELSE_NAMESPACE::if_else_zero(
104 IF_ELSE_NAMESPACE::gt(
105 position().length(), characteristics().ligamentSlackLength()),
106 *m_stiffness *
107 (position().length() - characteristics().ligamentSlackLength()));
108#else
109 if (position().length() > characteristics().ligamentSlackLength()) {
110 *m_Fl = *m_stiffness *
111 (position().length() - characteristics().ligamentSlackLength());
112 } else {
113 *m_Fl = 0;
114 }
115#endif
116}
const utils::String & name() const
Return the name of the muscle.
Definition Compound.cpp:48
Class Geometry of the muscle.
Definition Geometry.h:31
Holder of all the path modifiers of a muscle.
Class LigamentSpringLinear is a ligament with same behavior than linear spring defined by: k(l-l0) wi...
virtual void computeFl()
Compute the Force-length of the contractile element.
void setStiffness(const utils::Scalar &stiffness)
Set the ligament stiffness.
std::shared_ptr< utils::Scalar > m_stiffness
stiffness of the ligament
const utils::Scalar & stiffness() const
Return the ligament stiffness.
virtual void setType()
Set type to linear spring like ligament.
LigamentSpringLinear DeepCopy() const
Deep copy of a linear spring like ligament.
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
const utils::Scalar & length(rigidbody::Joints &updatedModel, const rigidbody::GeneralizedCoordinates &Q, bool updateLigamentKinematics=true)
Get the length of the ligament.
Definition Ligament.cpp:152
void DeepCopy(const Ligament &other)
Deep copy of a ligament in new ligament.
Definition Ligament.cpp:93
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
std::shared_ptr< LIGAMENT_TYPE > m_type
The type of the ligament.
Definition Ligament.h:274
static void check(bool cond, const String &message)
Assert that raises the error message if false.
Definition Error.cpp:10
Wrapper around the std::string class with augmented functionality.
Definition String.h:18