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
Gait2d_osimTest Class Reference

Test class to test the class Gait2d_osim. More...

Inheritance diagram for Gait2d_osimTest:
ModelTest

Public Member Functions

Tests: Gait3dTest
function test_grf (in testCase)
 Function for testing the ground reaction force model.
 
function derivativetest_Fkin (in testCase)
 Function to test the derivatives of Gait3d.getFkin()
 
function test_Fkin (in testCase)
 Function for testing the forward kinematic model Gait3d.getFkin().
 
function test_isometric (in testCase)
 Function for testing the isometric joint moments.
 
function test_s_static_upright_acc (in testCase)
 Function to test the simulated acc signal for static standing.
 
function test_s_static_upright_gyro (in testCase)
 Function to test the simulated gyro signal for static standing.
 
function test_s_hip_flexion_acc (in testCase)
 Function to test the simulated acc signal for hip flexion.
 
function test_s_pelvis_rotation_acc (in testCase)
 Function to test the simulated acc signal for pelvis rotation

 
function test_s_hip_flexion_gyro (in testCase)
 Function to test the simulated gyro signal for hip flexion.
 
function test_s_pelvis_rotation_gyro (in testCase)
 Function to test the simulated acc signal for pelvis rotation

 
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 grfoptions
 Struct: Options for Ipopt for test_grf()
 
Property grftmp
 Struct: Temporary storage for test_grf()
 
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 grfconfun (in testCase, in X)
 Subfunction for GRF testing.
 
function grfjacobian (in testCase, in X)
 Subfunction for GRF testing.
 
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 maxmom (in testCase, in x, in idof, in direction)
 Function to find the maximal moment for a joint.
 
function moments (in testCase, in idof)
 Function to generate active and passive joint moment curves.
 
function nostim (in testCase, in t)
 Helperfunction for muscle stimulation function for passive simulation.
 
function setup_Test_Random (in testCase, in iCom)
 Function to setup the data.
 
function solvegrf (in testCase, in y, in vy, in vx)
 Subfunction for GRF testing.
 
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

Test class to test the class Gait2d_osim.

Run single test selected by name:

testCase = Gait2d_osimTest;
testCase.model = Gait2d_osim('gait10dof18musc.osim');
res = run(testCase, 'derivativetest_Dynamics');
The class describes the Gait2d_osim model.
Definition: Gait2d_osim.m:18
Test class to test the class Gait2d_osim.
Definition: Gait2d_osimTest.m:47
Property model
Model object.
Definition: ModelTest.m:38

Overview:

Testname/Tag Derivative Freefall Isometric Memory Speed Neutral getDynamics getFkin getGRF getJointmoments getMuscleforces simuAccGyro showStick
derivativetest_Dynamics x x
derivativetest_SimuAccGyro_Acc x x
derivativetest_SimuAccGyro_Gyro x x
derivativetest_Moments x x
derivativetest_GRF x x
derivativetest_Fkin x x
test_simulateFreefall x x
test_showStickNeutral x x
test_dynamics x x x
test_memory x x
test_speedOfSimuAccGyro x x
test_speedOfMex x x
test_s_hip_flexion_gyro x
test_s_pelvis_rotation_gyro x
test_s_hip_flexion_acc x x
test_s_pelvis_rotation_acc x x
test_s_static_upright_acc x x
test_s_static_upright_gyro x x
test_isometric x x x x
test_Fkin x x
test_grf x

Member Function Documentation

◆ derivativetest_Dynamics()

function derivativetest_Dynamics ( in  testCase)
inherited

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_Fkin()

function derivativetest_Fkin ( in  testCase)

Function to test the derivatives of Gait3d.getFkin()

Example output:

Derivatives for Fkin
dFKdq: Max. difference is: 0.0000000514 ( 0.1216789450 vs. 0.1216788936) at 'femur_r: R21'(idx:19) and 'pelvis_tilt'(idx:1)
dFKdotdq: Max. difference is: 0.0000001331 ( 0.9619361218 vs. 0.9619359886) at 'radius_r: R12'(idx:173) and 'elbow_flex_r'(idx:27)
Todo:
Add error checking

◆ derivativetest_GRF()

function derivativetest_GRF ( in  testCase)
inherited

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)
inherited

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)
inherited

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)
inherited

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 
)
protectedinherited

Function with test content to test Model.simuAccGyro()

◆ fsolve1()

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

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 
)
protectedinherited

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

◆ grfconfun()

function grfconfun ( in  testCase,
in  X 
)
protected

Subfunction for GRF testing.

Parameters
testCase
X
Return values
c

◆ grfjacobian()

function grfjacobian ( in  testCase,
in  X 
)
protected

Subfunction for GRF testing.

Parameters
testCase
X
Return values
J

◆ halfstim()

function halfstim ( in  testCase,
in  t 
)
protectedinherited

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 
)
protectedinherited

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

◆ maxmom()

function maxmom ( in  testCase,
in  x,
in  idof,
in  direction 
)
protected

Function to find the maximal moment for a joint.

Function to find the maximal moment for a joint with the model in posture given by x while muscles are required to be in equilibrium contraction state.

Parameters
testCase
xposture of the model
idofwhich joint moment we want to maximize
direction+1 for max moment, -1 for min moment
Return values
Mthe maximum moment
xthe system state that produces the max moment (can be used as initial guess for next function call)

◆ moments()

function moments ( in  testCase,
in  idof 
)
protected

Function to generate active and passive joint moment curves.

Parameters
testCase
idof
Return values
angles
pasmom
actmax
actmin

◆ nostim()

function nostim ( in  testCase,
in  t 
)
protectedinherited

Helperfunction for muscle stimulation function for passive simulation.

Parameters
testCase
t
Return values
u

◆ setup_Test_Random()

function setup_Test_Random ( in  testCase,
in  iCom 
)
protected

Function to setup the data.

Parameters
testCase
iCom
Return values
testCase

◆ solvegrf()

function solvegrf ( in  testCase,
in  y,
in  vy,
in  vx 
)
protected

Subfunction for GRF testing.

Function to solves grf by search for static equilibrium in contact variables

Parameters
testCase
y
vy
vx
Return values
Fx
Fy
x

◆ step()

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

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)
inherited

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_Fkin()

function test_Fkin ( in  testCase)

Function for testing the forward kinematic model Gait3d.getFkin().

This test sequentially animates the kinematic degrees of freedom. First, the model is placed in a neutral position. Then each degree of freedom is animated. After that the Jacobian dFk/dq is computed i.e., the deritive of every segment position and orientation with respect to each kinematic degree of freedom. The result is compared to finite differences and the sparsity of the jacobian is plotted.

Todo:
Add error checking
Todo:
Would be nice to do this interactively with slider GUI like in Opensim

◆ test_grf()

function test_grf ( in  testCase)

Function for testing the ground reaction force model.

This test evaluates the contact model. To test the vertical force, the model is put in a series of positions with different hip height. The vertical ground reaction force at the heel is plotted as a function of hip height. The result (left side of Figure) shows the total force-deformation relationship of the contact model, i.e. deformation of the contact point relative to the foot, and the interaction between the foot and ground. To test the horizontal force, the model is put in three of these hip positions, and the horizontal velocity is varied. The resulting horizontal force is simulated and shown on the right side of the Figure.

Todo:
Add error checking

◆ test_isometric()

function test_isometric ( in  testCase)

Function for testing the isometric joint moments.

Todo:
Add error checking

◆ test_memory()

function test_memory ( in  testCase)
inherited

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_s_hip_flexion_acc()

function test_s_hip_flexion_acc ( in  testCase)

Function to test the simulated acc signal for hip flexion.

Simulates the acceleration signal at calcn_r for hip flexion with 100 r/s. The expected acceleration is computed based on the radius (computed from positions of segments) and known rotational velocity.

◆ test_s_hip_flexion_gyro()

function test_s_hip_flexion_gyro ( in  testCase)

Function to test the simulated gyro signal for hip flexion.

Simulates the gyropscope signal at calcn_r for hip flexion with 100 r/s.

◆ test_s_pelvis_rotation_acc()

function test_s_pelvis_rotation_acc ( in  testCase)

Function to test the simulated acc signal for pelvis rotation

Simulates the acceleration signal at calcn_r for pelvis rotation around 45 Deg and a hip flexion rate of 100 rad/s. The expected acceleration is computed based on the radius (computed from positions of segments), the known hip rotation and known rotational velocity.

◆ test_s_pelvis_rotation_gyro()

function test_s_pelvis_rotation_gyro ( in  testCase)

Function to test the simulated acc signal for pelvis rotation

Simulates the acceleration signal at calcn_r for pelvis rotation around 45 Deg and a hip flexion rate of 100 rad/s. The expected gyroscope signal is computed based on the known hip rotation and known rotational velocity.

◆ test_s_static_upright_acc()

function test_s_static_upright_acc ( in  testCase)

Function to test the simulated acc signal for static standing.

Tests that the acceleration at calcn_r is equal to gravity during static standing.

◆ test_s_static_upright_gyro()

function test_s_static_upright_gyro ( in  testCase)

Function to test the simulated gyro signal for static standing.

Tests that the gyropscope signal at calcn_r is equal to 0 during static standing.

◆ test_showStickNeutral()

function test_showStickNeutral ( in  testCase)
inherited

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)
inherited

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)
inherited

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)
inherited

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'}
protectedinherited

Names of different test conditions.

◆ data

Property data
protectedinherited

Data for tracking tests.

◆ grf_xc

Property grf_xc
protectedinherited

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

◆ grfoptions

Property grfoptions

Struct: Options for Ipopt for test_grf()

◆ grftmp

Property grftmp

Struct: Temporary storage for test_grf()

◆ model

Property model
inherited

Model object.

◆ TOL_DERIVATIVETEST

Constant Property TOL_DERIVATIVETEST = 10
protectedinherited

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

◆ TOL_S

Constant Property TOL_S = 10
protectedinherited

Tolerance to pass tests for Model.simuAccGyro()


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