Biomech-Sim-Toolbox 1
Toolbox for movement simulation and analysis
Loading...
Searching...
No Matches
Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
ModelTest Class Reference

Abstract test class to test the class Model. More...

Inheritance diagram for ModelTest:
Gait2d_osimTest Gait2dcTest Gait3dTest

Public Member Functions

Tests: ModelTest
function derivativetest_Dynamics (in testCase)
 Function to test the derivatives of Model.getDynamics()
 
function derivativetest_GRF (in testCase)
 Function to test the derivatives of Model.getGRF()
 
function derivativetest_Moments (in testCase)
 Function to test the derivatives of Model.getJointmoments()
 
function derivativetest_SimuAccGyro_Acc (in testCase)
 Function to test the acc derivatives of Model.simuAccGyro()
 
function derivativetest_SimuAccGyro_Gyro (in testCase)
 Function to test the gyro derivatives of odel.simuAccGyro()
 
function test_speedOfMex (in testCase)
 Function for testing the speed of the MEX function.
 
function test_speedOfSimuAccGyro (in testCase)
 Function for testing the speed of Model.simuAccGyro().
 
function test_memory (in testCase)
 Function for testing memory use of the MEX function.
 
function test_dynamics (in testCase)
 Function for testing the correctness of the dynamic model.
 
function test_showStickNeutral (in testCase)
 Function for testing showStick()
 
function test_simulateFreefall (in testCase)
 Function to simulate freefall.
 

Public Attributes

Property model
 Model object.
 

Protected Member Functions

function doTest_derivativetest_SimuAccGyro (in testCase, in iCom)
 Function with test content to test Model.simuAccGyro()
 
function generateRandType (in testCase, in type, in isState)
 Function to generate a vector with random numbers of a specific type (e.g.
 
function halfstim (in testCase, in t)
 Helperfunction for muscle stimulation function for 50% muscle stimulation.
 
function matcompare (in testCase, in value, in valueRef, in kind, in namesDim1, in namesDim2)
 Function to verify the derivative outcomes.
 
function nostim (in testCase, in t)
 Helperfunction for muscle stimulation function for passive simulation.
 
function step (in testCase, in stimfun, in x0, in trange, in nsteps, in options)
 Function to solve implicit differential equation for simulaton.
 

Static Protected Member Functions

static function fsolve1 (in fun, in x0, in options)
 Function to solves f(x)=0 using Newton's method.
 

Protected Attributes

Constant Property COMMANDS = {'Acc', 'Gyro'}
 Names of different test conditions.
 
Property data
 Data for tracking tests.
 
Property grf_xc
 Used in test_grf() to keep the previous result as initial guess.
 
Constant Property TOL_DERIVATIVETEST = 10
 Tolerance to pass derivative tests: maxerror/value < tol.
 
Constant Property TOL_S = 10
 Tolerance to pass tests for Model.simuAccGyro()
 

Detailed Description

Abstract test class to test the class Model.

Tests:

Member Function Documentation

◆ derivativetest_Dynamics()

function derivativetest_Dynamics ( in  testCase)

Function to test the derivatives of Model.getDynamics()

Gait2dc

Example output:

Derivatives for Dynamics
dfdx: Max. difference is: 0.0001211260 (3450.3251510427 vs. 3450.3250299167) at 'dofs: hip_flexion_l: equations of motion from Autolev'(idx:16) and 's: Glutei_l'(idx:28)
dfdxdot: Max. difference is: 0.0000023285 ( -0.0212161829 vs. -0.0212185114) at 'dofs: hip_flexion_l: equations of motion from Autolev'(idx:16) and 'qdot: pelvis_ty'(idx:11)
dfdu: Max. difference is: 0.0000068123 (-152.4926607122 vs. -152.4926675245) at 'muscles: Rectus_l: activation dynamics: da/dt - (u-a)(c1*u + c2) = 0'(idx:46) and 'Rectus_l'(idx:12)

Gait3d

Example output:

Derivatives for Dynamics
dfdx: Max. difference is: 0.0027930663 (-46136.0346080336 vs. -46136.0318149673) at 'muscles: add_brev_l: contraction dynamics: f = Fsee - Fce - Fpee'(idx:122) and 's: add_brev_l'(idx:122)
dfdxdot: Max. difference is: 0.0010051358 (-494.0920577725 vs. -494.0930629083) at 'muscles: per_long_r: contraction dynamics: f = Fsee - Fce - Fpee'(idx:106) and 's: per_long_r'(idx:106)
dfdu: Max. difference is: 0.0000086362 (350.9248257347 vs. 350.9248170985) at 'muscles: glut_max3_l: activation dynamics: da/dt - rate * (u-a) = 0'(idx:223) and 'glut_max3_l'(idx:65)

◆ derivativetest_GRF()

function derivativetest_GRF ( in  testCase)

Function to test the derivatives of Model.getGRF()

Gait2dc

Example output:

Derivatives for GRF
dGRFdx: Max. difference is: 0.0000000055 ( -0.0688392154 vs. -0.0688392099) at 'right Mz'(idx:6) and 'Fy: toe_r'(idx:58)

Gait3d

Example output:

Derivatives for GRF
dGRFdx: Max. difference is: 0.0000000187 ( -0.9337272476 vs. -0.9337272289) at 'left My'(idx:11) and 'zc: CPL_l'(idx:337)

◆ derivativetest_Moments()

function derivativetest_Moments ( in  testCase)

Function to test the derivatives of Model.getJointmoments()

Gait2dc

Example output:

Derivatives for Moments
dMdx: Max. difference is: 0.0120983138 (41480.6475985067 vs. 41480.6355001929) at 'hip_flexion_l'(idx:7) and 's: Glutei_l'(idx:28)
dMdu: Max. difference is: 0.0000000000 ( 0.0000000000 vs. 0.0000000000) at 'pelvis_tx'(idx:1) and 'Iliopsoas_r'(idx:1)

Gait3d

Example output:

Derivatives for Moments
dMdx: Max. difference is: 0.1738820117 (-350944.6392260600 vs. -350944.8131080717) at 'hip_flexion_r'(idx:7) and 'q: hip_flexion_r'(idx:7)
dMdu: Max. difference is: 0.0000000000 ( 0.0000000000 vs. 0.0000000000) at 'pelvis_tx'(idx:1) and 'Iliopsoas_r'(idx:1)

◆ derivativetest_SimuAccGyro_Acc()

function derivativetest_SimuAccGyro_Acc ( in  testCase)

Function to test the acc derivatives of Model.simuAccGyro()

Gait2dc

Example output:

Derivatives for Acc
dsdq: Max. difference is: 0.0000000227 ( 1.7175791416 vs. 1.7175791189) at '4'(idx:4) and 'hip_flexion_r'(idx:4)
dsdqd: Max. difference is: 0.0000000229 ( -0.8737816552 vs. -0.8737816781) at '4'(idx:4) and 'pelvis_tilt'(idx:3)
dsdqdd: Max. difference is: 0.0000000271 ( 0.2436197648 vs. 0.2436197377) at '4'(idx:4) and 'pelvis_tx'(idx:1)

Gait3d

Example output:

Derivatives for Acc
dsdq: Max. difference is: 0.0000016256 ( 1.7379826469 vs. 1.7379810213) at '10'(idx:7) and 'pelvis_tilt'(idx:1)
dsdqd: Max. difference is: 0.0000000929 ( -1.5895990794 vs. -1.5895991723) at '10'(idx:7) and 'hip_rotation_l'(idx:16)
dsdqdd: Max. difference is: 0.0000000209 ( 0.0951314259 vs. 0.0951314050) at '5'(idx:4) and 'pelvis_list'(idx:2)

◆ derivativetest_SimuAccGyro_Gyro()

function derivativetest_SimuAccGyro_Gyro ( in  testCase)

Function to test the gyro derivatives of odel.simuAccGyro()

Gait2dc

Example output:

Derivatives for Gyro
dsdq: Max. difference is: 0.0000000000 ( 0.0000000000 vs. 0.0000000000) at '1'(idx:1) and 'pelvis_tx'(idx:1)
dsdqd: Max. difference is: 0.0000000061 ( 1.0000000000 vs. 0.9999999939) at '4'(idx:4) and 'pelvis_tilt'(idx:3)
dsdqdd: Max. difference is: 0.0000000000 ( 0.0000000000 vs. 0.0000000000) at '1'(idx:1) and 'pelvis_tx'(idx:1)

Gait3d

Example output:

Derivatives for Gyro
dsdq: Max. difference is: 0.0000000843 ( 0.6910369209 vs. 0.6910368366) at '3'(idx:2) and 'hip_adduction_r'(idx:8)
dsdqd: Max. difference is: 0.0000000081 ( 0.8115557434 vs. 0.8115557515) at '5'(idx:4) and 'hip_rotation_r'(idx:9)
dsdqdd: Max. difference is: 0.0000000000 ( 0.0000000000 vs. 0.0000000000) at '2'(idx:1) and 'pelvis_tilt'(idx:1)

◆ doTest_derivativetest_SimuAccGyro()

function doTest_derivativetest_SimuAccGyro ( in  testCase,
in  iCom 
)
protected

Function with test content to test Model.simuAccGyro()

◆ fsolve1()

static function fsolve1 ( in  fun,
in  x0,
in  options 
)
staticprotected

Function to solves f(x)=0 using Newton's method.

Parameters
fun
x0
options
Return values
x
f
info
iterations

◆ generateRandType()

function generateRandType ( in  testCase,
in  type,
in  isState 
)
protected

Function to generate a vector with random numbers of a specific type (e.g.

q or u)

Usage:

x = testCase.generateRandType('States');
u = testCase.generateRandType('Controls');
q = testCase.generateRandType('q', 1);
M = testCase.generateRandType('torque', 0);
Parameters
testCase
typeString: Either 'States' or 'Controls' or a type which has to be identical to the type specified in model.states or in model.controls
isState(optional) Boolean: Needed if type is not 'States' or 'Controls'. If true, the type is in the model.states. Otherwise we search in the model.controls.
Return values
randTypeDouble vector: Vector containing uniformly sampled random numbers of that type in the interval [xmin, xmax] which is specified in model.states or model.controls

◆ halfstim()

function halfstim ( in  testCase,
in  t 
)
protected

Helperfunction for muscle stimulation function for 50% muscle stimulation.

Todo:
Does it make sense to use 0.5 for all? We should differentiate between muscle exctitation and torques
Parameters
testCase
t
Return values
u

◆ matcompare()

function matcompare ( in  testCase,
in  value,
in  valueRef,
in  kind,
in  namesDim1,
in  namesDim2 
)
protected

Function to verify the derivative outcomes.

Parameters
testCase
valueArray or Matrix: Derivatives of Model class
valueRefArray or Matrix: Reference derivatives
kindString: Name of derivative (e.g. dfdx)
namesDim1(optional) Cell array with strings: Names defining the first dimension of the value
namesDim2(optional) Cell array with strings: Names defining the second dimension of the value

◆ nostim()

function nostim ( in  testCase,
in  t 
)
protected

Helperfunction for muscle stimulation function for passive simulation.

Parameters
testCase
t
Return values
u

◆ step()

function step ( in  testCase,
in  stimfun,
in  x0,
in  trange,
in  nsteps,
in  options 
)
protected

Function to solve implicit differential equation for simulaton.

Solves the implicit differential equation fmin <= f(x,dx/dt,u) <= fmax using the midpoint Euler method, with constant stepsize, and Newton iteration.

Parameters
testCase
stimfunA function u = fun(t) to stimulate the muscles.
x0Initial system state.
trange[starttime enddtime]
nstepsHow many time steps to take.
optionsStruct with fields:
  • tol: Tolerance
  • maxiterations: Maximum number of Newton iterations
Return values
toutVector of time points (ntimes x 1).
xoutSolution vectors (nstates x ntimes).
info0: success, -1: maximum number of iterations exceeded.
nevalNumber of evaluations.

◆ test_dynamics()

function test_dynamics ( in  testCase)

Function for testing the correctness of the dynamic model.

Free fall dynamics test: This test shows the correctness of the dynamic model f = f(x,xdot,u,M) = 0. Therefore, the model is put in a freefall acceleration state, so residuals should be zero when acceleration is -g for DOF 5 and zero elsewhere. Moreover, the joint moments of the model in its neutral position are computed and should be zero.

Gait2dc

Dynamics violations:

Joint moments:

GRFs:

Gait3d

Dynamics violations:

Joint moments:

GRFs:

◆ test_memory()

function test_memory ( in  testCase)

Function for testing memory use of the MEX function.

This tests the memory usage of the multibody dynamics. The MEX function is executed 500000 times with random inputs, and the resulting memory usage is plotted.

This function is only working at Windows!

Gait2dc

Gait3d

Todo:
Add error checking

◆ test_showStickNeutral()

function test_showStickNeutral ( in  testCase)

Function for testing showStick()

This tests plots a stick figure for the neutral position of the model.

Gait2dc

Gait3d

Todo:
Add error checking

◆ test_simulateFreefall()

function test_simulateFreefall ( in  testCase)

Function to simulate freefall.

The model is placed in a neutral position. We drop the model on the ground. This is done twice, once with passive muscles and once with muscles that are 50% activated. It uses the implicit midpoint Euler method (van den Bogert et al., 2011) with a step size of 10 ms.

The second simulation (with activated muscles) is then repeated with a step size of 1 ms. The results are compared with the 10 ms stepsize.

Gait2dc

Example outpu:

Running test_simulateFreefall:
1. Running passive freefall simulation...
Number of time steps: 400
Number of function evaluations: 2572
2. Running active freefall simulation...
Number of time steps: 400
Number of function evaluations: 2285
3. Running active freefall simulation with smaller steps...
Number of time steps: 4000
Number of function evaluations: 16259

Gait3d

Example output:

Running test_simulateFreefall:
1. Running passive freefall simulation...
Number of time steps: 400
Number of function evaluations: 3120
2. Running active freefall simulation...
Number of time steps: 1
Number of function evaluations: 1129
3. Running active freefall simulation with smaller steps...
Number of time steps: 4000
Number of function evaluations: 17836
Todo:
The second simulation is not solving for 3D. And switching from Windows to Linux caused that also the first simulation is not solving. A difference in the compilers maybe caused this...

◆ test_speedOfMex()

function test_speedOfMex ( in  testCase)

Function for testing the speed of the MEX function.

This tests the execution time of the multibody dynamics, without and with derivatives. The MEX function is executed 1000 times with random inputs, and the resulting time is divided by 1000.

Gait2dc

Example output:

Speed test
Evaluation of dynamics function without derivatives: 1.100 ms
Evaluation of dynamics function with derivatives: 0.831 ms

Gait3d

Example output:

Speed test
Evaluation of dynamics function without derivatives: 3.340 ms
Evaluation of dynamics function with derivatives: 4.998 ms
Todo:
Add error checking

◆ test_speedOfSimuAccGyro()

function test_speedOfSimuAccGyro ( in  testCase)

Function for testing the speed of Model.simuAccGyro().

This tests the execution time of Model.simuAccGyro(), without and with derivatives. The simuAccGyro() is executed 1000 times with random inputs, and the resulting time is divided by 1000.

Gait2dc

Example output for 3 (acc x, acc y, acc z) times 7 (trunk, legs, feet) IMU signals:

Speed test of SimuAccGyro()
Evaluation of dynamics function without Jacobians: 1.714 ms
Evaluation of dynamics function with Jacobians: 3.047 ms

Gait3d

Example output for 6 (all acc and gyro) times 7 (trunk, legs, feet) IMU signals::

Speed test of simuAccGyro()
Evaluation of dynamics function without Jacobians: 4.066 ms
Evaluation of dynamics function with Jacobians: 26.996 ms
Todo:
Add error checking

Member Data Documentation

◆ COMMANDS

Constant Property COMMANDS = {'Acc', 'Gyro'}
protected

Names of different test conditions.

◆ data

Property data
protected

Data for tracking tests.

◆ grf_xc

Property grf_xc
protected

Used in test_grf() to keep the previous result as initial guess.

◆ model

Property model

Model object.

◆ TOL_DERIVATIVETEST

Constant Property TOL_DERIVATIVETEST = 10
protected

Tolerance to pass derivative tests: maxerror/value < tol.

◆ TOL_S

Constant Property TOL_S = 10
protected

Tolerance to pass tests for Model.simuAccGyro()


The documentation for this class was generated from the following file: