Biorbd
Release_1.13.0
Toggle main menu visibility
Loading...
Searching...
No Matches
State.cpp
1
#define BIORBD_API_EXPORTS
2
#include "InternalForces/Muscles/State.h"
3
4
#include "Utils/Error.h"
5
6
using namespace
BIORBD_NAMESPACE;
7
internal_forces::muscles::State::State
(
8
const
utils::Scalar&
excitation
,
9
const
utils::Scalar&
activation
)
10
:
m_stateType
(std::make_shared<internal_forces::muscles::STATE_TYPE>()),
11
m_excitation
(std::make_shared<utils::Scalar>(
excitation
)),
12
m_excitationNorm
(std::make_shared<utils::Scalar>(0)),
13
m_activation
(std::make_shared<utils::Scalar>(
activation
)) {
14
setType
();
15
}
16
17
internal_forces::muscles::State::State
(
18
const
internal_forces::muscles::State
& other)
19
:
m_stateType
(other.
m_stateType
),
20
m_excitation
(other.
m_excitation
),
21
m_excitationNorm
(std::make_shared<utils::Scalar>(0)),
22
m_activation
(other.
m_activation
) {}
23
24
internal_forces::muscles::State::~State
() {
25
// dtor
26
}
27
28
internal_forces::muscles::State
internal_forces::muscles::State::DeepCopy
()
29
const
{
30
internal_forces::muscles::State
copy;
31
copy.
DeepCopy
(*
this
);
32
return
copy;
33
}
34
35
void
internal_forces::muscles::State::DeepCopy
(
36
const
internal_forces::muscles::State
& other) {
37
*
m_stateType
= *other.
m_stateType
;
38
*
m_excitation
= *other.
m_excitation
;
39
*
m_excitationNorm
= *other.
m_excitationNorm
;
40
*
m_activation
= *other.
m_activation
;
41
}
42
43
void
internal_forces::muscles::State::setExcitation
(
44
const
utils::Scalar& val,
45
bool
turnOffWarnings) {
46
#ifdef BIORBD_USE_CASADI_MATH
47
*
m_excitation
= val;
48
#else
49
if
(val < 0) {
50
if
(!turnOffWarnings) {
51
utils::Error::warning
(
52
0,
"Excitation can't be lower than 0, 0 is used then"
);
53
}
54
*
m_excitation
= 0;
55
}
else
{
56
*
m_excitation
= val;
57
}
58
#endif
59
}
60
61
const
utils::Scalar&
internal_forces::muscles::State::excitation
()
const
{
62
return
*
m_excitation
;
63
}
64
65
const
utils::Scalar&
internal_forces::muscles::State::normalizeExcitation
(
66
const
internal_forces::muscles::State
& emgMax,
67
bool
turnOffWarnings) {
68
#ifndef BIORBD_USE_CASADI_MATH
69
if
(!turnOffWarnings) {
70
utils::Error::warning
(
71
*
m_excitation
< emgMax.
excitation
(),
72
"Excitation is higher than maximal excitation."
);
73
}
74
#endif
75
*
m_excitationNorm
= *
m_excitation
/ emgMax.
excitation
();
76
77
return
*
m_excitationNorm
;
78
}
79
80
void
internal_forces::muscles::State::setExcitationNorm
(
81
const
utils::Scalar& val) {
82
*
m_excitationNorm
= val;
83
}
84
85
const
utils::Scalar&
internal_forces::muscles::State::excitationNorm
()
const
{
86
return
*
m_excitationNorm
;
87
}
88
89
void
internal_forces::muscles::State::setActivation
(
90
const
utils::Scalar& val,
91
bool
turnOffWarnings) {
92
#ifdef BIORBD_USE_CASADI_MATH
93
*
m_activation
= val;
94
#else
95
if
(val < 0) {
96
if
(!turnOffWarnings) {
97
utils::Error::warning
(
98
0,
99
"Activation is "
+
utils::String::to_string
(val) +
100
" but can't be lower than 0, 0 is used then"
);
101
}
102
*
m_activation
= 0;
103
}
else
if
(val > 1) {
104
if
(!turnOffWarnings) {
105
utils::Error::warning
(
106
0,
107
"Activation "
+
utils::String::to_string
(val) +
108
" but can't be higher than 1, 1 is used then"
);
109
}
110
*
m_activation
= 1;
111
}
else
{
112
*
m_activation
= val;
113
}
114
#endif
115
}
116
117
const
utils::Scalar&
internal_forces::muscles::State::activation
()
const
{
118
return
*
m_activation
;
119
}
120
121
internal_forces::muscles::STATE_TYPE
internal_forces::muscles::State::type
()
122
const
{
123
return
*
m_stateType
;
124
}
125
126
void
internal_forces::muscles::State::setType
() {
127
*
m_stateType
= internal_forces::muscles::STATE_TYPE::SIMPLE_STATE;
128
}
BIORBD_NAMESPACE::internal_forces::muscles::State
EMG holder to interact with the muscle.
Definition
State.h:17
BIORBD_NAMESPACE::internal_forces::muscles::State::setExcitationNorm
void setExcitationNorm(const utils::Scalar &val)
Force set the normalized excitation.
Definition
State.cpp:80
BIORBD_NAMESPACE::internal_forces::muscles::State::~State
virtual ~State()
Destroy class properly.
Definition
State.cpp:24
BIORBD_NAMESPACE::internal_forces::muscles::State::DeepCopy
State DeepCopy() const
Deep copy of state.
Definition
State.cpp:28
BIORBD_NAMESPACE::internal_forces::muscles::State::m_stateType
std::shared_ptr< STATE_TYPE > m_stateType
The state type.
Definition
State.h:127
BIORBD_NAMESPACE::internal_forces::muscles::State::setActivation
virtual void setActivation(const utils::Scalar &val, bool turnOffWarnings=false)
Set the muscle activation.
Definition
State.cpp:89
BIORBD_NAMESPACE::internal_forces::muscles::State::setExcitation
virtual void setExcitation(const utils::Scalar &val, bool turnOffWarnings=false)
Set the muscle excitation.
Definition
State.cpp:43
BIORBD_NAMESPACE::internal_forces::muscles::State::m_activation
std::shared_ptr< utils::Scalar > m_activation
The muscle activation.
Definition
State.h:131
BIORBD_NAMESPACE::internal_forces::muscles::State::excitationNorm
const utils::Scalar & excitationNorm() const
Return the previously normalized excitation.
Definition
State.cpp:85
BIORBD_NAMESPACE::internal_forces::muscles::State::excitation
const utils::Scalar & excitation() const
Return the muscle excitation.
Definition
State.cpp:61
BIORBD_NAMESPACE::internal_forces::muscles::State::m_excitationNorm
std::shared_ptr< utils::Scalar > m_excitationNorm
The normalized excitation.
Definition
State.h:130
BIORBD_NAMESPACE::internal_forces::muscles::State::normalizeExcitation
const utils::Scalar & normalizeExcitation(const State &emgMax, bool turnOffWarnings=false)
Compute and return the normalized excitation.
Definition
State.cpp:65
BIORBD_NAMESPACE::internal_forces::muscles::State::m_excitation
std::shared_ptr< utils::Scalar > m_excitation
The muscle excitation.
Definition
State.h:128
BIORBD_NAMESPACE::internal_forces::muscles::State::activation
const utils::Scalar & activation() const
Return the muscle activation.
Definition
State.cpp:117
BIORBD_NAMESPACE::internal_forces::muscles::State::State
State(const utils::Scalar &excitation=0, const utils::Scalar &activation=0)
Construct a state.
Definition
State.cpp:7
BIORBD_NAMESPACE::internal_forces::muscles::State::type
STATE_TYPE type() const
Return the state type.
Definition
State.cpp:121
BIORBD_NAMESPACE::internal_forces::muscles::State::setType
virtual void setType()
Set the type to simple_state.
Definition
State.cpp:126
BIORBD_NAMESPACE::utils::Error::warning
static void warning(bool cond, const String &message)
Non-blocking assert that displays the error message if false.
Definition
Error.cpp:16
BIORBD_NAMESPACE::utils::String::to_string
static String to_string(double val)
Overload of the to_string C++11 function to allow for X-digits precision.
Definition
String.cpp:92
src
InternalForces
Muscles
State.cpp
Generated by
1.18.0