1#define BIORBD_API_EXPORTS
3#include "InternalForces/Muscles/Muscle.h"
5#include "InternalForces/Compound.h"
6#include "InternalForces/Muscles/Characteristics.h"
7#include "InternalForces/Muscles/MuscleGeometry.h"
8#include "InternalForces/Muscles/MusclesEnums.h"
9#include "InternalForces/Muscles/StateDynamics.h"
10#include "InternalForces/Muscles/StateDynamicsBuchanan.h"
11#include "InternalForces/Muscles/StateDynamicsDeGroote.h"
12#include "InternalForces/PathModifiers.h"
13#include "RigidBody/GeneralizedCoordinates.h"
14#include "RigidBody/GeneralizedVelocity.h"
15#include "RigidBody/Joints.h"
16#include "Utils/Error.h"
18using namespace BIORBD_NAMESPACE;
23 std::make_shared<internal_forces::muscles::MUSCLE_TYPE>(
24 internal_forces::muscles::MUSCLE_TYPE::NO_MUSCLE_TYPE)),
27 m_state(std::make_shared<internal_forces::muscles::
State>()) {
39 std::make_shared<internal_forces::muscles::MUSCLE_TYPE>(
40 internal_forces::muscles::MUSCLE_TYPE::NO_MUSCLE_TYPE)),
44 m_state(std::make_shared<internal_forces::muscles::
State>()) {}
55 std::make_shared<internal_forces::muscles::MUSCLE_TYPE>(
56 internal_forces::muscles::MUSCLE_TYPE::NO_MUSCLE_TYPE)),
60 m_state(std::make_shared<internal_forces::muscles::
State>(dynamicState)) {
73 std::make_shared<internal_forces::muscles::MUSCLE_TYPE>(
74 internal_forces::muscles::MUSCLE_TYPE::NO_MUSCLE_TYPE)),
78 m_state(std::make_shared<internal_forces::muscles::
State>()) {}
104 std::make_shared<internal_forces::muscles::MUSCLE_TYPE>(
105 internal_forces::muscles::MUSCLE_TYPE::NO_MUSCLE_TYPE)),
108 m_state(std::make_shared<internal_forces::muscles::
State>()) {
113 "Multiple wrapping objects is not implemented yet");
135 *
m_type = internal_forces::muscles::MUSCLE_TYPE::NO_MUSCLE_TYPE;
154 std::vector<utils::Vector3d> &musclePointsInGlobal,
161 std::vector<utils::Vector3d> &musclePointsInGlobal,
181 bool updateMuscleParameters) {
182 if (updateMuscleParameters)
191 bool updateMuscleParameters) {
192 if (updateMuscleParameters)
195 return position().musculoTendonLength();
202 bool updateMuscleParameters) {
203 if (updateMuscleParameters)
211 bool alreadyNormalized)
const {
212 std::shared_ptr<internal_forces::muscles::StateDynamics> state_copy =
213 std::dynamic_pointer_cast<internal_forces::muscles::StateDynamics>(
216 state_copy !=
nullptr,
217 "The muscle " +
name() +
" is not a dynamic muscle");
218 return state_copy->timeDerivativeActivation(
227const std::vector<utils::Vector3d> &
231 bool updateMuscleParameters) {
232 if (updateMuscleParameters)
238const std::vector<utils::Vector3d> &
244 const utils::Scalar &forceMax) {
261 if (emg.
type() == internal_forces::muscles::STATE_TYPE::BUCHANAN) {
262 m_state = std::make_shared<internal_forces::muscles::StateDynamicsBuchanan>(
264 }
else if (emg.
type() == internal_forces::muscles::STATE_TYPE::DE_GROOTE) {
265 m_state = std::make_shared<internal_forces::muscles::StateDynamicsDeGroote>(
267 }
else if (emg.
type() == internal_forces::muscles::STATE_TYPE::DYNAMIC) {
268 m_state = std::make_shared<internal_forces::muscles::StateDynamics>(
273 " is not a valid type for setState");
const utils::String & name() const
Return the name of the muscle.
void DeepCopy(const Compound &other)
Deep copy of a compound.
std::shared_ptr< utils::Scalar > m_force
The last computed force.
Compound()
Construct muscle compound.
std::shared_ptr< internal_forces::PathModifiers > m_pathChanger
The set of path modifiers.
Holder of all the path modifiers of a muscle.
size_t nbWraps() const
Return the total number of wrapping objects in the set.
Class Holds that muscle characteristics.
Class muscle geometry of the muscle.
void updateKinematics(rigidbody::Joints &updatedModel, const Characteristics &characteristics, const rigidbody::GeneralizedCoordinates *Q=nullptr, const rigidbody::GeneralizedVelocity *Qdot=nullptr)
Updates the position and dynamic elements of the muscles.
Base class of all muscle.
void setState(const State &emg)
Set the dynamic state.
std::shared_ptr< Characteristics > m_characteristics
The muscle characteristics.
Characteristics & characteristics() const
Return the muscle characteristics.
virtual ~Muscle()
Destroy class properly.
Muscle()
Construct a muscle.
std::shared_ptr< State > m_state
The dynamic state.
const utils::Scalar & activationDot(const State &state, bool alreadyNormalized=false) const
Return the activation time derivative.
void setCharacteristics(const Characteristics &characteristics)
Set the muscle characteristics.
virtual void setType()
Set the type of muscle.
virtual void computeForce(const State &emg)
Computer the forces from a specific emg.
std::shared_ptr< internal_forces::muscles::MuscleGeometry > m_position
The geometry (position of the nodes) of the muscle.
const utils::Scalar & musculoTendonLength(rigidbody::Joints &updatedModel, const rigidbody::GeneralizedCoordinates &Q, bool updateMuscleParameters=true)
Return the musculo tendon length.
const utils::Scalar & length(rigidbody::Joints &updatedModel, const rigidbody::GeneralizedCoordinates &Q, bool updateMuscleParameters=true)
Get the length of the muscle.
std::shared_ptr< MUSCLE_TYPE > m_type
The type of the muscle.
const internal_forces::muscles::MuscleGeometry & position() const
Return the position of all the points attached to the muscle (0 being the origin).
const std::vector< utils::Vector3d > & musclesPointsInGlobal() const
Return the previously computed muscle points in global reference frame.
const State & state() const
Return the dynamic state.
virtual utils::Scalar getForceFromActivation(const State &emg)=0
Function allowing modification of the way the multiplication is done in computeForce(EMG).
void setForceIsoMax(const utils::Scalar &forceMax)
Set the maximal isometric force.
MUSCLE_TYPE type() const
Return the type of the muscle.
const std::vector< utils::Vector3d > & musclesPointsInGlobal(rigidbody::Joints &updatedModel, const rigidbody::GeneralizedCoordinates &Q, bool updateMuscleParameters=true)
Return the muscle points in global reference frame.
const utils::Scalar & velocity(rigidbody::Joints &updatedModel, const rigidbody::GeneralizedCoordinates &Q, const rigidbody::GeneralizedVelocity &Qdot, bool updateMuscleParameters=true)
Return the velocity of the muscle.
void DeepCopy(const Muscle &other)
Deep copy of a muscle in new muscle.
void setPosition(const internal_forces::muscles::MuscleGeometry &positions)
Set the position of all the points attached to the muscle (0 being the origin).
void updateOrientations(rigidbody::Joints &updatedModel, const rigidbody::GeneralizedCoordinates &Q)
Update the position of the origin and insertion positions of the muscle.
Time derivative of activation as described by Buchanan (https://www.sciencedirect....
EMG with the capability to compute the time derivative.
EMG with the capability to compute the time derivative.
EMG holder to interact with the muscle.
STATE_TYPE type() const
Return the state type.
Class GeneralizedCoordinates.
Class GeneralizedVelocity.
This is the core of the musculoskeletal model in biorbd.
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.