Skip to content

Commit 0f5becb

Browse files
authored
Merge pull request #131 from paulWegiel/test_actuators
Tests for actuators
2 parents f870869 + 8411ca7 commit 0f5becb

File tree

11 files changed

+640
-99
lines changed

11 files changed

+640
-99
lines changed

binding/python3/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
from .biorbd import *
22
from ._version import __version__
3-

binding/python3/_version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import biorbd
2+
23
__version__ = biorbd.getVersion().to_string()

include/Actuators/Actuators.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <vector>
55
#include <memory>
66
#include "biorbdConfig.h"
7+
#include "Utils/Scalar.h"
78

89
namespace biorbd {
910
namespace utils {
@@ -122,6 +123,18 @@ class BIORBD_API Actuators
122123
std::shared_ptr<std::vector<bool>> m_isDofSet;///< If DoF all dof are set
123124
std::shared_ptr<bool> m_isClose; ///< If the set is ready
124125

126+
///
127+
/// \brief getTorqueMaxDirection Get the max torque of a specific actuator (interface necessary because of CasADi)
128+
/// \param actuator The actuator to gather from
129+
/// \param Q The Generalized coordinates
130+
/// \param Qdot The Generalized velocity
131+
/// \return The torque max
132+
///
133+
biorbd::utils::Scalar getTorqueMaxDirection(
134+
const std::shared_ptr<Actuator> actuator,
135+
const rigidbody::GeneralizedCoordinates &Q,
136+
const rigidbody::GeneralizedVelocity &Qdot) const;
137+
125138
};
126139

127140
}}

include/biorbdConfig.h.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ inline LINEAR_ALGEBRA_BACKEND currentLinearAlgebraBackend(){
8686
#define DECLARE_GENERALIZED_TORQUE(varname, model) \
8787
casadi::DM varname(model.nbGeneralizedTorque(), 1);\
8888
biorbd::rigidbody::GeneralizedTorque varname##_sym(casadi::MX::sym(#varname, model.nbGeneralizedTorque(), 1));
89+
#define DECLARE_VECTOR(varname, nbElements) \
90+
casadi::DM varname(nbElements, 1);\
91+
biorbd::utils::Vector varname##_sym(casadi::MX::sym(#varname, nbElements, 1));
8992

9093
#define CALL_BIORBD_FUNCTION_1ARG(varname, model, funcname, arg1) \
9194
casadi::Function func_##funcname(#funcname, {arg1##_sym}, {model.funcname(arg1##_sym)}, {#arg1}, {#funcname});\
@@ -118,6 +121,8 @@ inline LINEAR_ALGEBRA_BACKEND currentLinearAlgebraBackend(){
118121
biorbd::rigidbody::GeneralizedAcceleration varname(model);
119122
#define DECLARE_GENERALIZED_TORQUE(varname, model) \
120123
biorbd::rigidbody::GeneralizedTorque varname(model);
124+
#define DECLARE_VECTOR(varname, nbElements) \
125+
biorbd::utils::Vector varname(nbElements);
121126

122127
#define CALL_BIORBD_FUNCTION_1ARG(varname, model, funcname, arg1) \
123128
auto varname = model.funcname(arg1);

src/Actuators/Actuators.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -284,36 +284,36 @@ biorbd::rigidbody::GeneralizedTorque biorbd::actuator::Actuators::torqueMax(
284284
biorbd::rigidbody::GeneralizedTorque maxGeneralizedTorque_all(model);
285285

286286
for (unsigned int i=0; i<model.nbDof(); ++i){
287-
std::shared_ptr<Actuator> GeneralizedTorque_tp;
288-
289287
#ifdef BIORBD_USE_CASADI_MATH
290-
casadi::MX useFirst = casadi::MX::if_else(
291-
casadi::MX::ge(activation[i], 0),
292-
1, 0);
293-
if (!useFirst.is_zero()){
294-
GeneralizedTorque_tp = actuator(i).first;
295-
} else {
296-
GeneralizedTorque_tp = actuator(i).second;
297-
}
288+
maxGeneralizedTorque_all[i] = casadi::MX::if_else(
289+
casadi::MX::ge(activation(i, 0), 0),
290+
getTorqueMaxDirection(actuator(i).first, Q, Qdot),
291+
getTorqueMaxDirection(actuator(i).second, Q, Qdot));
298292
#else
299293
if (activation[i] >= 0) // First
300-
GeneralizedTorque_tp = actuator(i).first;
294+
maxGeneralizedTorque_all[i] = getTorqueMaxDirection(actuator(i).first, Q, Qdot);
301295
else
302-
GeneralizedTorque_tp = actuator(i).second;
296+
maxGeneralizedTorque_all[i] = getTorqueMaxDirection(actuator(i).second, Q, Qdot);
303297
#endif
304-
305-
if (std::dynamic_pointer_cast<ActuatorGauss3p> (GeneralizedTorque_tp))
306-
maxGeneralizedTorque_all[i] = std::static_pointer_cast<ActuatorGauss3p> (GeneralizedTorque_tp)->torqueMax(Q, Qdot);
307-
else if (std::dynamic_pointer_cast<ActuatorConstant> (GeneralizedTorque_tp))
308-
maxGeneralizedTorque_all[i] = std::static_pointer_cast<ActuatorConstant> (GeneralizedTorque_tp)->torqueMax();
309-
else if (std::dynamic_pointer_cast<ActuatorLinear> (GeneralizedTorque_tp))
310-
maxGeneralizedTorque_all[i] = std::static_pointer_cast<ActuatorLinear> (GeneralizedTorque_tp)->torqueMax(Q);
311-
else if (std::dynamic_pointer_cast<ActuatorGauss6p> (GeneralizedTorque_tp))
312-
maxGeneralizedTorque_all[i] = std::static_pointer_cast<ActuatorGauss6p> (GeneralizedTorque_tp)->torqueMax(Q, Qdot);
313-
else
314-
biorbd::utils::Error::raise("Wrong type (should never get here because of previous safety)");
315-
316298
}
317299

318300
return maxGeneralizedTorque_all;
319301
}
302+
303+
biorbd::utils::Scalar biorbd::actuator::Actuators::getTorqueMaxDirection(
304+
const std::shared_ptr<biorbd::actuator::Actuator> actuator,
305+
const biorbd::rigidbody::GeneralizedCoordinates& Q,
306+
const biorbd::rigidbody::GeneralizedVelocity& Qdot) const
307+
{
308+
if (std::dynamic_pointer_cast<ActuatorGauss3p> (actuator))
309+
return std::static_pointer_cast<ActuatorGauss3p> (actuator)->torqueMax(Q, Qdot);
310+
else if (std::dynamic_pointer_cast<ActuatorConstant> (actuator))
311+
return std::static_pointer_cast<ActuatorConstant> (actuator)->torqueMax();
312+
else if (std::dynamic_pointer_cast<ActuatorLinear> (actuator))
313+
return std::static_pointer_cast<ActuatorLinear> (actuator)->torqueMax(Q);
314+
else if (std::dynamic_pointer_cast<ActuatorGauss6p> (actuator))
315+
return std::static_pointer_cast<ActuatorGauss6p> (actuator)->torqueMax(Q, Qdot);
316+
else
317+
biorbd::utils::Error::raise("Wrong type (should never get here because of previous safety)");
318+
319+
}

src/ModelReader.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ void biorbd::Reader::readModelFile(
628628
int int_direction = 0;
629629
double Tmax(-1); bool isTmaxSet = false;
630630
double T0(-1); bool isT0Set = false;
631-
double pente(-1); bool isPenteSet = false;
631+
double slope(-1); bool isSlopeSet = false;
632632
double wmax(-1); bool iswmaxSet = false;
633633
double wc(-1); bool iswcSet = false;
634634
double amin(-1); bool isaminSet = false;
@@ -671,9 +671,9 @@ void biorbd::Reader::readModelFile(
671671
file.read(T0, variable);
672672
isT0Set = true;
673673
}
674-
else if (!property_tag.tolower().compare("pente")){
675-
file.read(pente, variable);
676-
isPenteSet = true;
674+
else if (!property_tag.tolower().compare("pente") || !property_tag.tolower().compare("slope")){
675+
file.read(slope, variable);
676+
isSlopeSet = true;
677677
}
678678
else if (!property_tag.tolower().compare("wmax")){
679679
file.read(wmax, variable);
@@ -732,9 +732,9 @@ void biorbd::Reader::readModelFile(
732732
actuator = new biorbd::actuator::ActuatorConstant(int_direction,Tmax,dofIdx,name);
733733
}
734734
else if (!type.tolower().compare("linear")){
735-
biorbd::utils::Error::check(isDofSet && isDirectionSet && isPenteSet && isT0Set,
735+
biorbd::utils::Error::check(isDofSet && isDirectionSet && isSlopeSet && isT0Set,
736736
"Make sure all parameters are defined");
737-
actuator = new biorbd::actuator::ActuatorLinear(int_direction,T0,pente,dofIdx,name);
737+
actuator = new biorbd::actuator::ActuatorLinear(int_direction,T0,slope,dofIdx,name);
738738
}
739739
else if (!type.tolower().compare("gauss6p")){
740740
biorbd::utils::Error::check(isDofSet && isDirectionSet && isTmaxSet && isT0Set && iswmaxSet && iswcSet && isaminSet &&

test/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,19 @@ add_subdirectory(
4242
# Unit Tests
4343
##############
4444
enable_testing()
45-
file(GLOB TEST_SRC_FILES "${CMAKE_SOURCE_DIR}/test/*.cpp")
45+
46+
set(TEST_SRC_FILES
47+
"${CMAKE_SOURCE_DIR}/test/test_biorbd.cpp"
48+
"${CMAKE_SOURCE_DIR}/test/test_rigidbody.cpp"
49+
"${CMAKE_SOURCE_DIR}/test/test_utils.cpp"
50+
"${CMAKE_SOURCE_DIR}/test/test_actuators.cpp"
51+
)
52+
if(MODULE_MUSCLES)
53+
list(APPEND TEST_SRC_FILES "${CMAKE_SOURCE_DIR}/test/test_muscles.cpp")
54+
endif()
55+
if(MODULE_ACTUATORS)
56+
list(APPEND TEST_SRC_FILES "${CMAKE_SOURCE_DIR}/test/test_actuators.cpp")
57+
endif()
4658
add_executable(${PROJECT_NAME} "${TEST_SRC_FILES}")
4759
add_dependencies(${PROJECT_NAME} ${BIORBD_NAME})
4860

0 commit comments

Comments
 (0)