1#define BIORBD_API_EXPORTS
3#include "InternalForces/Ligaments/Ligaments.h"
5#include "InternalForces/Ligaments/Ligament.h"
6#include "InternalForces/Ligaments/LigamentConstant.h"
7#include "InternalForces/Ligaments/LigamentSpringLinear.h"
8#include "InternalForces/Ligaments/LigamentSpringSecondOrder.h"
9#include "RigidBody/GeneralizedCoordinates.h"
10#include "RigidBody/GeneralizedTorque.h"
11#include "RigidBody/GeneralizedVelocity.h"
12#include "RigidBody/Joints.h"
13#include "Utils/Error.h"
14#include "Utils/Matrix.h"
16using namespace BIORBD_NAMESPACE;
20 std::make_shared<std::vector<
39 for (
size_t i = 0; i < other.
m_ligaments->size(); ++i) {
41 internal_forces::ligaments::LIGAMENT_TYPE::LIGAMENT_CONSTANT) {
43 std::make_shared<internal_forces::ligaments::LigamentConstant>(
48 internal_forces::ligaments::LIGAMENT_TYPE::LIGAMENT_SPRING_LINEAR) {
50 std::make_shared<internal_forces::ligaments::LigamentSpringLinear>(
55 internal_forces::ligaments::LIGAMENT_TYPE::
56 LIGAMENT_SPRING_SECOND_ORDER) {
57 (*m_ligaments)[i] = std::make_shared<
69 idx <
nbLigaments(),
"Idx asked is higher than number of ligaments");
70 return *(*m_ligaments)[idx];
76 idx <
nbLigaments(),
"Idx asked is higher than number of ligaments");
77 return *(*m_ligaments)[idx];
83 if (ligamentTp.
type() ==
84 internal_forces::ligaments::LIGAMENT_TYPE::LIGAMENT_CONSTANT) {
86 std::make_shared<internal_forces::ligaments::LigamentConstant>(
90 internal_forces::ligaments::LIGAMENT_TYPE::LIGAMENT_SPRING_LINEAR) {
92 std::make_shared<internal_forces::ligaments::LigamentSpringLinear>(
96 internal_forces::ligaments::LIGAMENT_TYPE::LIGAMENT_SPRING_SECOND_ORDER) {
98 std::make_shared<internal_forces::ligaments::LigamentSpringSecondOrder>(
106std::vector<utils::String>
108 std::vector<utils::String> names;
133 bool updateLigamentKinematics) {
146#ifdef BIORBD_USE_CASADI_MATH
150 "When using Casadi, this method must set updateKin to true. ") +
151 "Alternatively, you can call ligamentsJointTorque with the pre-updated "
160 updateKin >= 2 ? &Q :
nullptr, updateKin >= 2 ? &Qdot :
nullptr);
171 bool updateLigamentKinematics) {
182#ifdef BIORBD_USE_CASADI_MATH
186 "When using Casadi, this method must set updateKin to true. ") +
187 "Alternatively, you can call ligamentsJointTorque with the pre-updated "
196 updateKin >= 2 ? &Q :
nullptr, updateKin >= 2 ? &Qdot :
nullptr);
204 bool updateLigamentKinematics) {
208 forces(
static_cast<unsigned int>(j)) =
209 ((*m_ligaments)[j]->force(updatedModel, Q, updateLigamentKinematics));
219#ifdef BIORBD_USE_CASADI_MATH
223 "When using Casadi, this method must set updateKin to true. ") +
224 "Alternatively, you can call ligamentForces with the pre-updated "
233 updateKin >= 2 ? &Q :
nullptr);
243 bool updateLigamentKinematics) {
247 forces(
static_cast<unsigned int>(j)) = ((*m_ligaments)[j]->force(
248 updatedModel, Q, Qdot, updateLigamentKinematics));
259#ifdef BIORBD_USE_CASADI_MATH
263 "When using Casadi, this method must set updateKin to true. ") +
264 "Alternatively, you can call ligamentForces with the pre-updated "
273 updateKin >= 2 ? &Q :
nullptr, updateKin >= 2 ? &Qdot :
nullptr);
291 static_cast<unsigned int>(j),
294 static_cast<unsigned int>(model.
nbDof())) =
295 (*m_ligaments)[j]->position().jacobianLength();
303 bool updateLigamentKinematics) {
312#ifdef BIORBD_USE_CASADI_MATH
316 "When using Casadi, this method must set updateKin to true. ") +
317 "Alternatively, you can call ligamentsLengthJacobian with the "
318 "pre-updated model.");
326 updateKin >= 2 ? &Q :
nullptr);
335std::vector<std::shared_ptr<internal_forces::ligaments::Ligament>>&
340const std::vector<std::shared_ptr<internal_forces::ligaments::Ligament>>&
348 if (!nameToFind.compare((*
m_ligaments)[i]->name())) {
349 return static_cast<int>(i);
360 ligament(j).updateOrientations(updatedModel, Q, Qdot);
368#ifdef BIORBD_USE_CASADI_MATH
375 updateKin ? &Q :
nullptr, updateKin ? &Qdot :
nullptr);
383 ligament(j).updateOrientations(updatedModel, Q);
390#ifdef BIORBD_USE_CASADI_MATH
397 updateKin ? &Q :
nullptr);
403 std::vector<std::vector<utils::Vector3d>>& ligamentPointsInGlobal,
404 std::vector<utils::Matrix>& jacoPointsInGlobal,
408 ligamentPointsInGlobal[j], jacoPointsInGlobal[j], Qdot);
413 std::vector<std::vector<utils::Vector3d>>& ligamentPointsInGlobal,
414 std::vector<utils::Matrix>& jacoPointsInGlobal) {
417 ligamentPointsInGlobal[j], jacoPointsInGlobal[j]);
Class LigamentSpringSecondOrder is a ligament with same behavior than second order spring defined by:...
Base class of all ligament.
LIGAMENT_TYPE type() const
Return the type of the ligament.
void updateLigaments(rigidbody::Joints &updatedModel, const rigidbody::GeneralizedCoordinates &Q)
Update all the ligaments (positions, jacobian, etc.).
int ligamentID(const utils::String &name)
Return the ligament index.
std::shared_ptr< std::vector< std::shared_ptr< Ligament > > > m_ligaments
Holder for ligament groups.
utils::Vector ligamentForces(rigidbody::Joints &updatedModel, const rigidbody::GeneralizedCoordinates &Q, bool updateLigamentKinematics=true)
Compute and return the ligament forces.
rigidbody::GeneralizedTorque ligamentsJointTorque(const utils::Vector &F)
Compute the ligament joint torque.
Ligaments()
Construct ligaments.
std::vector< std::shared_ptr< Ligament > > & ligaments()
Returns all the ligaments. It sorts the ligaments by group.
utils::Matrix ligamentsLengthJacobian() const
Return the previously computed ligament length jacobian.
void addLigament(const Ligament &ligament)
Add a ligament to the set of ligaments.
Ligaments DeepCopy() const
Deep copy of ligaments.
Ligament & ligament(size_t idx)
Returns a specific ligament sorted by ligaments().
std::vector< utils::String > ligamentNames() const
ligamentNames Return the names for all the ligament ordered by their respective name
utils::Matrix computeLigamentsLengthJacobian(const rigidbody::Joints &model) const
Assemble the ligament length jacobian using the provided model.
size_t nbLigaments() const
Return the total number of ligament.
virtual ~Ligaments()
Destroy class properly.
Class GeneralizedCoordinates.
Class GeneralizedVelocity.
This is the core of the musculoskeletal model in biorbd.
size_t nbDof() const
Return the number of degrees of freedom (DoF).
Joints & UpdateKinematicsCustom(const GeneralizedCoordinates *Q=nullptr, const GeneralizedVelocity *Qdot=nullptr, const rigidbody::GeneralizedAcceleration *Qddot=nullptr)
Update the kinematic variables such as body velocities and accelerations in the model to reflect the ...
static void raise(const String &message)
Throw an error message.
static void check(bool cond, const String &message)
Assert that raises the error message if false.
A wrapper for the Eigen::MatrixXd.
Wrapper around the std::string class with augmented functionality.
Wrapper of the Eigen VectorXd.