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

The class for defining an optimal control of musculoskeletal. More...

Inheritance diagram for Collocation:
Problem handle Collocation_Exo Collocation_NN Collocation_stoch

Public Member Functions

function addConstraint (in obj, in fh, in cmin, in cmax, in varargin)
 Function adding constraint to the optimization problem.
 
function addObjective (in obj, in fh, in weight, in varargin)
 Function adding objective term to the optimization problem.
 
function addOptimVar (in obj, in name, in xmin, in xmax, in xinit)
 Function adding optimization variables to the state vector.
 
function checkXScaling (in obj, in X)
 Matlab function to check the scaling withing X.
 
function Collocation (in model, in nNodes, in Euler, in logfile, in plotLog)
 Constructor setting default Collocation options.
 
function comFixConstraint (in obj, in option, in X, in targetMotion)
 Function to compute constraint violation of center of mass motion.
 
function computeJpattern (in obj)
 Function computing the jacobian pattern.
 
function confun (in obj, in X)
 Function to compute constraint violations at state vector X.
 
function cotTerm (in obj, in option, in X, in name, in epsilon, in exponent)
 Collocation function to compute cost of transport of the muscles from states vector.
 
function curveConstraint_pelvis213 (in obj, in option, in X, in radius)
 Function to compute the periodicity constraint for curved running.
 
function derivativetest (in obj, in xr)
 Function to test the whole problem which was defined.
 
function durationConstraint (in obj, in option, in X, in targetDuration)
 Computes constraint violation demanding periodic movement.
 
function dynamicConstraints (in obj, in option, in X)
 Computes constaint violation demanding dynamic equilibrium.
 
function dynamicsFirstNodeConstraint (in obj, in option, in X)
 Matlab function to constrain the first node.
 
function effortTermMuscles (in obj, in option, in X, in weigthsType, in exponent, in speedWeighting)
 Matlab function to compute effort of the muscles from states vector.
 
function effortTermMusclesAct (in obj, in option, in X, in weigthsType, in exponent, in speedWeighting)
 Matlab function to compute effort of the muscles from states vector.
 
function effortTermTorques (in obj, in option, in X, in exponent, in speedWeighting)
 Matlab function to compute effort of the torques from states vector.
 
function equilibriumConstraints (in obj, in option, in X)
 Matlab function to compute dynamic constraint for standing.
 
function equilibriumConstraintsCPOffset (in obj, in option, in X)
 Matlab function to compute dynamic constraint for standing with a vertical offset of the contact points.
 
function extractData (in obj, in X, in settings, in variableTable, in getFullCycle)
 Function to extract simulated and tracked data of the problem.
 
function fromStandingConstraint (in obj, in option, in X)
 Matlab function to find walking/running from standing.
 
function getCEPower (in obj, in X)
 Function to compute the CE Power over the whole movemenent.
 
function getComMotion (in obj, in X)
 Computes center of mass motion.
 
function getComMotionDeriv (in obj, in X)
 Function to compute center of mass motion.
 
function getMetabolicCost (in obj, in X, in name, in getCont, in epsilon, in exponent)
 Function to calculate metabolic cost of a movement.
 
function getSimData (in obj, in X, in simVar, in modelName)
 Matlab function to extract simulated variables.
 
function getStepLength (in obj, in X, in name)
 Computes step length.
 
function getStimTime (in obj, in X)
 Collocation function to calculate the stimulation time for one gait cycle.
 
function gradient (in obj, in X)
 Function computing gradient at state vector X.
 
function headStabTerm (in obj, in option, in X)
 Matlab function to compute Veerkamp's HeadStab.
 
function impactTerm (in obj, in option, in X)
 Matlab function to compute Veerkamp's FGImpact.
 
function initObjectives (in obj)
 Function initializing the objective functions.
 
function get isPeriodic (in obj)
 Function returning isPeriodic parameter.
 
function get isSymmetric (in obj)
 Function returning isSymmetric parameter.
 
function jacobian (in obj, in X)
 Function to compute jacobian at state vector X.
 
function jacstructure (in obj)
 Function providing the jacobian pattern.
 
function jointAccelerationTerm (in obj, in option, in X)
 Matlab function to compute effort of the muscles from states vector.
 
function kneeExtTerm (in obj, in option, in X)
 Matlab function to compute Veerkamp's KneeExt.
 
function makeinitialguess (in obj, in init)
 Function to define an initial guess.
 
function get nNodesDur (in obj)
 Function returning nNodesDur parameter.
 
function objfun (in obj, in X)
 Function computing objective value at state vector X.
 
function passiveMomentTerm (in obj, in option, in X, in exponent)
 Collocation function to compute effort of the torques from states vector.
 
function periodicityConstraint (in obj, in option, in X, in sym)
 Computes constaint violation demanding periodic movement.
 
function plotlog (in obj, in X)
 Function plotting stick figure, objective values and constraint violations.
 
function plotStickSlider (in obj, in X, in subTrans, in showStickOpt, in markerTable)
 Matlab function to create plot stick figure with slider.
 
function printlog (in obj)
 Function logging objective value and constraint violations.
 
function regTerm (in obj, in option, in X)
 Computes differences between collocation nodes to ensure smoothness.
 
function report (in obj, in X, in settings, in style, in resultFilename)
 Computes function to report a current state vector of the problem.
 
function resampleInitialContact (in obj, in X, in foot, in contact_names)
 Resamples X so that the Heelstrike is at the first node.
 
function setPlotLim (in values)
 Helperfunction setting the limits for objective and constraints plot.
 
function shift_index (in X_tmp, in amount)
 
function showSingleStick (in es, in ignoredArg)
 
function speedConstraint (in obj, in option, in X, in targetSpeed)
 Computes constraint violation demanding periodic movement.
 
function trackAcc (in obj, in option, in X, in data, in weight)
 Matlab function to track accelerometer data.
 
function trackAngles (in obj, in option, in X, in data)
 Computes difference between simulated and measured angles.
 
function trackDuration (in obj, in option, in X, in data)
 Matlab function to track duration of the gait cycle.
 
function trackGRF (in obj, in option, in X, in data)
 Matlab function to track ground reaction forces.
 
function trackGyro (in obj, in option, in X, in data, in weight)
 Matlab function to track gyroscope data.
 
function trackMarker (in obj, in option, in X, in data)
 Computes difference between simulated and measured marker data.
 
function trackSpeed (in obj, in option, in X, in data)
 Matlab function to track speed of the gait cycle.
 
function trackTranslations (in obj, in option, in X, in data)
 Computes difference between simulated and measured translations.
 
function trackTranslationsAndAngles (in obj, in option, in X, in data)
 Computes difference between simulated and measured translations and angles in one term.
 
function translationSpeedConstraint (in obj, in option, in X)
 Computes constraint based on speed and translation.
 
function writeMotionToOsim (in obj, in X, in filename, in variableTable, in rangeNodes, in t0)
 Function to write motion from a solution X to OpenSim files.
 
function writeMovie (in obj, in X, in filename, in fps, in subTrans, in showStickOpt, in makeGIF, in playSpeed, in markerTable, in rangeNodes)
 Matlab function to create a movie of a simulation result.
 
function writeMovieCurvedRunning (in obj, in X, in filename, in radius, in fps, in showStickOpt, in makeGIF)
 Matlab function to create a movie of a simulation result for curved running.
 

Static Public Member Functions

static function matcompare (in a, in b)
 Helperfunction to compare matrices and mind maximum abs error.
 
function plotMeanSimVarTable (in tables, in style)
 Computes function to plot the mean and SD of multiple simulation variable tables.
 
function plotMultSimVarTables (in tables, in style, in plotStance)
 Function to plot the content of multiple simulation variable tables.
 
static function resampleX (in x, in N)
 Function for resampling state vector for makeinitialguess.
 

Public Attributes

Property c_lb
 Double array: Lower bound of constaints.
 
Property c_ub
 Double array: Upper bound of constraints.
 
Property initialguess
 Struct: Intial guess for x.
 
Property model
 Model: Object of class Model.m.
 
Property name
 String: Name of result file.
 
Property X_lb
 Double array: Lower bound of state vector.
 
Property X_ub
 Double array: Upper bound of state vector.
 

Private Attributes

Property constraintTerms
 Struct array: Constraints.
 
Property Euler
 String: Midpoint euler 'ME' or backward euler 'BE' or semi-implicit euler 'SIE'.
 
Property idx
 Struct: Indices for position of variables in state vector X.
 
Property isPeriodic
 Bool: True if the periodicityConstraint() was used.
 
Property isSymmetric
 Bool: True if the periodicityConstraint() was used and there sym is true.
 
Property Jnnz
 Double: Number of non-zero entries in jacobian pattern.
 
Property Jpattern
 Double matrix: Jacobian pattern.
 
Property log
 Struct: Information for logging objectives and constrained violations.
 
Property nConstraints
 Double: Total number of constraints.
 
Property nNodes
 Double: Number of collocation nodes.
 
Property nNodesDur
 Double: Number of collocation nodes which define the duration of the simulation.
 
Property nVars
 Double: Number of variables that are optimized.
 
Property objectiveInit
 Struct: Contains values extracted during initialization of objective functions.
 
Property objectiveTerms
 Struct array: Ojective terms.
 
Property plotLog
 Bool: If true, plot log in call of Collocation.objfun() (stick figure, objective, constrains) (default: 0)
 

Detailed Description

The class for defining an optimal control of musculoskeletal.

Author
Eva Dorschky, Marlies Nitschke
Date
November, 2017
Examples
/home/runner/work/BioMAC-Sim-Toolbox/BioMAC-Sim-Toolbox/ExampleScripts/+IntroductionExamples/script2D.m, and /home/runner/work/BioMAC-Sim-Toolbox/BioMAC-Sim-Toolbox/ExampleScripts/+IntroductionExamples/scriptPlotting.m.

Constructor & Destructor Documentation

◆ Collocation()

function Collocation ( in  model,
in  nNodes,
in  Euler,
in  logfile,
in  plotLog 
)

Constructor setting default Collocation options.

Parameters
modelModel class object
nNodes(optional) Double: Number of collocation nodes
Euler(optional) String: Discretization method: backward euler 'BE' or midpoint euler 'ME' or semi-implicit euler 'SIE
logfile(optional) String: Logfile including the path. The input can be skipped with an empty string.
plotLog(optional) Bool: If true, plot log in call of Collocation.objfun() (stick figure, objective, constrains) (default: 0)
Return values
objCollocation class object

Member Function Documentation

◆ addConstraint()

function addConstraint ( in  obj,
in  fh,
in  cmin,
in  cmax,
in  varargin 
)

Function adding constraint to the optimization problem.

The constraints are called by the name of the function handle. The upper and lower bounds of the constraints can be set to zero for equalitiy constraints. The constraints can be a vector or a matrix to define constraints at a single or mulitple collocation nodes. (nconstraintspernode x 1|.nNodes).

problem.addConstraint(@dynamicConstraints,repmat(model.init.fmin,1,N),repmat(model.init.fmax,1,N))
problem.addConstraint(@periodicityConstraint,zeros(model.nStates+model.nControls,1),zeros(model.nStates+model.nControls,1),sym)
Property model
Model: Object of class Model.m.
Definition: Collocation.m:20
function periodicityConstraint(in obj, in option, in X, in sym)
Computes constaint violation demanding periodic movement.
function dynamicConstraints(in obj, in option, in X)
Computes constaint violation demanding dynamic equilibrium.
static double zeros[MAXSTATES]
Definition: gait10dof18musc.c:45
Parameters
objCollocation class object
fhFunction handle: Method defined in Collocation
cminDouble array: Lower bound on constraint
cmaxDouble array: Upper bound on constraint
varargin(optional) Input parameter for function handle

◆ addObjective()

function addObjective ( in  obj,
in  fh,
in  weight,
in  varargin 
)

Function adding objective term to the optimization problem.

Todo:
check if xmin, xmax, xinit have the correct size

The objective terms are summed up in objective function using the function and weights which are defined as input.

problem.addObjective(@regTerm,W.reg)
problem.addObjective(@effortTerm,W.effort,'volumeweighted',2)
problem.addObjective(@trackGRF,W.track,trackingData)
problem.addObjective(@trackAngles,W.track,trackingData)
function trackGRF(in obj, in option, in X, in data)
Matlab function to track ground reaction forces.
function trackAngles(in obj, in option, in X, in data)
Computes difference between simulated and measured angles.
function regTerm(in obj, in option, in X)
Computes differences between collocation nodes to ensure smoothness.
Parameters
objCollocation class object
fhFunction handle: Method defined in the Collocation class folder
weightDouble: Weight of the objective term in the objective function
varargin(optional) Input parameter for function handle

◆ addOptimVar()

function addOptimVar ( in  obj,
in  name,
in  xmin,
in  xmax,
in  xinit 
)

Function adding optimization variables to the state vector.

Variables that should be optimized can be added to the collocation problem. The 'name' how the variables are called in the objective functions/ constraints need to be defined as first input, e.g. X(obj.idx.(name)). The lower and upper bounds xmin < x < xmax need to be defined as second and third input. Moreover, an initial guess for x can be defined. If no initial guess is provided, the mid point between the lower and upper bound is used.

The variables can be a vector or a matrix defining the variables at multiple collocation nodes (nvarspernode x 1|Collocation.nNodes|Collocation.nNodes+1).

problem.addOptimVar('states',repmat(model.states.xmin,1,N+1),repmat(model.states.xmax,1,N+1));
problem.addOptimVar('controls',repmat(model.controls.xmin,1,N+1),repmat(model.controls.xmax,1,N+1));
problem.addOptimVar('dur',0.1,1);
problem.addOptimVar('speed',targetspeed,targetspeed);
Parameters
objCollocation class object
nameString: Name of variable
xminDouble, vector or matrix: Lower bounds
xmaxDouble, vector or matrix: Upper bounds
xinit(optional) Vector or matrix: Initial guess

◆ checkXScaling()

function checkXScaling ( in  obj,
in  X 
)

Matlab function to check the scaling withing X.

It plots the ranges (min and max) of the absolute values in X for each type of states and controls. This function can be used to check whether the scaling of the states and controls

The function can be called using:

result.problem.checkXScaling(result.X);
Parameters
objCollocation class object
XDouble matrix: State vector (i.e. result) of the problem

◆ comFixConstraint()

function comFixConstraint ( in  obj,
in  option,
in  X,
in  targetMotion 
)

Function to compute constraint violation of center of mass motion.

This function was never actually used. If you would like to, make sure that it is tested before.

Parameters
objCollocation class object
optionString parsing the demanded output
XDouble array: State vector containing at least speed of the movement
targetMotionDouble: target motion of the center of mass

◆ computeJpattern()

function computeJpattern ( in  obj)

Function computing the jacobian pattern.

Parameters
objCollocation class object

◆ confun()

function confun ( in  obj,
in  X 
)
virtual

Function to compute constraint violations at state vector X.

Parameters
objCollocation class object
XDouble array: State vector with variables that are optimized
Return values
cDouble array: Constraint violations at state vector X

Reimplemented from Problem.

◆ cotTerm()

function cotTerm ( in  obj,
in  option,
in  X,
in  name,
in  epsilon,
in  exponent 
)

Collocation function to compute cost of transport of the muscles from states vector.

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states', 'controls', 'dur', and 'speed' of the model
name(optional) name of the model to be used, defaults to lichtwark
epsilon(optional) level of nonlinearity, defaults to 10^-3
exponent(optional) Positive integer: Exponent of energy rate in optimization

◆ curveConstraint_pelvis213()

function curveConstraint_pelvis213 ( in  obj,
in  option,
in  X,
in  radius 
)

Function to compute the periodicity constraint for curved running.

It ensures a perdiodic movement on a circle with a specifc radius. It was defined for our 3D model with the pelvis rotation sequence 213.

It uses the following equations:

  • \( c = \vert\vert v \vert\vert \cdot T \)
  • \( \theta = 2 \arcsin \left( \frac{c}{2r} \right) \)
Parameters
objCollocation class object
optionString: Parsing the demanded output
XDouble array: State vector containing at least 'states' and 'controls' of the model and speed and duration of the periodic movement
radiusDouble: Radius of the circle

◆ derivativetest()

function derivativetest ( in  obj,
in  xr 
)
inherited

Function to test the whole problem which was defined.

◆ durationConstraint()

function durationConstraint ( in  obj,
in  option,
in  X,
in  targetDuration 
)

Computes constraint violation demanding periodic movement.

Parameters
objCollocation class object
optionString parsing the demanded output
XDouble array: State vector containing at least speed of the movement
targetDurationDouble: target duration to reach

◆ dynamicConstraints()

function dynamicConstraints ( in  obj,
in  option,
in  X 
)

Computes constaint violation demanding dynamic equilibrium.

Parameters
objCollocation class object
optionString parsing the demanded output
XDouble array: State vector containing at least 'states' and 'controls' of the model and speed and duration of the periodic movement

◆ dynamicsFirstNodeConstraint()

function dynamicsFirstNodeConstraint ( in  obj,
in  option,
in  X 
)

Matlab function to constrain the first node.

It ensures the dynamics at the first node: f(x[1], (x[2]-x[1])/h, u[1]) = 0 without the constraints for qdot for the pelvis

This constraint can be used when no periodicity constraint is used.

Parameters
objCollocation class object
optionString parsing the demanded output
XDouble array: State vector containing at least 'states' and 'controls' of the model and 'duration' of movement

◆ effortTermMuscles()

function effortTermMuscles ( in  obj,
in  option,
in  X,
in  weigthsType,
in  exponent,
in  speedWeighting 
)

Matlab function to compute effort of the muscles from states vector.

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'controls' of the model
weigthsType(optional) String parsing weights
exponent(optional) Positive integer: Exponent of muscle controls (default: 3)
speedWeighting(optional) Boolean: If true, the objective will be divided by norm(speed)^exponent. (default: false)

◆ effortTermMusclesAct()

function effortTermMusclesAct ( in  obj,
in  option,
in  X,
in  weigthsType,
in  exponent,
in  speedWeighting 
)

Matlab function to compute effort of the muscles from states vector.

This function is using the muscle activation whereas Collocation.effortTermMusclesAct() is using the neural excitation.

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states' of the model
weigthsType(optional) String parsing weights
exponent(optional) Positive integer: Exponent of muscle activation (default: 3)
speedWeighting(optional) Boolean: If true, the objective will be divided by norm(speed)^exponent. (default: false)

◆ effortTermTorques()

function effortTermTorques ( in  obj,
in  option,
in  X,
in  exponent,
in  speedWeighting 
)

Matlab function to compute effort of the torques from states vector.

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'controls' of the model
exponent(optional) Positive integer: Exponent of torque controls (default: 2)
speedWeighting(optional) Boolean: If true, the objective will be divided by norm(speed)^exponent. (default: false)

◆ equilibriumConstraints()

function equilibriumConstraints ( in  obj,
in  option,
in  X 
)

Matlab function to compute dynamic constraint for standing.

It ensures equilibrium at node 1.

Parameters
objCollocation class object
optionString parsing the demanded output
XDouble array: State vector containing at least 'states' and 'controls' of the model and speed and duration of the periodic movement

◆ equilibriumConstraintsCPOffset()

function equilibriumConstraintsCPOffset ( in  obj,
in  option,
in  X 
)

Matlab function to compute dynamic constraint for standing with a vertical offset of the contact points.

Parameters
objCollocation class object
optionString parsing the demanded output
XDouble array: State vector containing at least 'states' and 'controls' of the model and speed and duration of the periodic movement

◆ extractData()

function extractData ( in  obj,
in  X,
in  settings,
in  variableTable,
in  getFullCycle 
)

Function to extract simulated and tracked data of the problem.

Using the fields of settings, you can specify which simulated data will be extracted. For each type, you define the names. The fieldname corresponds to the type of the variable. You do not have to use all of the fields! Just use the ones you need.

Example entries for all possible fields of settings:

settings.translation = {'pelvis_tx', 'pelvis_ty'};
settings.angle = {'hip_flexion_r','knee_angle_r', 'ankle_angle_r'};
settings.qdot = {'hip_flexion_r','knee_angle_r', 'ankle_angle_r'};
settings.moment = {'hip_flexion_r','knee_angle_r', 'ankle_angle_r'};
settings.torque = {'arm_flex_r', 'arm_add_r', 'arm_rot_r', 'elbow_flex_r', 'pro_sup_r'};
settings.GRF = {'GRF_x_r', 'GRF_y_r'};
settings.CoP = {'CoP_x_r'};
settings.acc = accTable; % variables table specifying acc with at least the columns: type, name, unit, segment, position, direction
settings.gyro = gyroTable; % variables table specifying gyro with at least the columns: type, name, unit, segment, position, direction
settings.marker = markerTable; % variables table specifying markers with at least the columns: type, name, unit, segment, position, direction
settings.u = {'Iliopsoas_r', 'Glutei_r', 'Hamstrings_r', 'Rectus_r', 'Vasti_r', 'Gastroc_r', 'Soleus_r', 'TibialisAnt_r'};
settings.a = settings.u;
settings.s = settings.u;
settings.sdot = settings.u;
settings.LMTU = settings.u;
settings.LCE = settings.u;
settings.LSEE = settings.u;
settings.LdotMTU = settings.u;
settings.LdotCE = settings.u;
settings.LdotSEEE = settings.u;
settings.muscleForce = settings.u;
settings.CEForce = settings.u;
settings.musclePower = settings.u;
settings.CEPower = settings.u;
settings.SEEPower = settings.u;
settings.muscleMetRate = settings.u;
settings.jointPower = {'hip_flexion_r','knee_angle_r', 'ankle_angle_r'};
settings.CoM = {'CoM_x', 'CoM_y'};
settings.footAngle = {'angle_r', 'angle_l' };
settings.standing = {'standing_r', 'standing_l'};
settings.duration = 1;
Property name
String: Name of result file.
Definition: Problem.m:18

By default, the following variables will automatically be extracted if you do not overwrite the respective fields in settings:

  • translation: all
  • angle: all joint angles of both sides (no global orientation)
  • moment: all joint moments of both sides
  • GRF: all of both sides
  • a and u:
    • 2D: all of both sides
    • 3D: in totla 16 largest muscles of both sides

The function will further extract all tracked variables which are defined in settings.

Additionally, you can use the input variableTable to specify a variable table with additional (reference) data which was not tracked. You can for example use the variables table in a TrackingData object:

variableTable = trackingdata.variables;
Parameters
objCollocation class object
XDouble matrix: State vector (i.e. result) of the problem
settings(optional) Struct: Describing which data should be extracted (see details above; use empty to skip)
variableTable(optional) Table: Additional reference data with the data beeing in the columns 'mean' and 'var'. (default: empty)
getFullCycle(optional) Boolean: Defines if a full gait cycle should be constructed for symmetric simulations:
  • 0: requested variable names for the half cycle
  • 1: requested variable names for the entire cycle by using symmetry
Return values
simVarTableTable: Summarizing all simulated, tracked and optionally additional data which was requested. The three different data kinds are saved in the following columns:
  • simulated data: 'sim'
  • tracked data: 'mean' and 'var'
  • additional data: 'mean_extra' and 'var_extra'

◆ fromStandingConstraint()

function fromStandingConstraint ( in  obj,
in  option,
in  X 
)

Matlab function to find walking/running from standing.

Todo:
Generalize this function and remove hard coded indices. E.g. we do not assume fixed indices for the states. The function should also work for 2D.
Parameters
objCollocation class object
optionString parsing the demanded output
XDouble array: State vector containing at least 'states' and 'controls' of the model and speed and duration of the periodic movement

◆ getCEPower()

function getCEPower ( in  obj,
in  X 
)

Function to compute the CE Power over the whole movemenent.

Computes the CE power according to Ton's paper:

A. J. van den Bogert, M. Hupperets, H. Schlarb, and B. Krabbe. Predictive musculoskeletal simulation using optimal control: effects of added limb mass on energy cost and kinematics of walking and running. Proceedings of the Institution of Mechanical Engineers, Part P: Journal of Sports Engineering and Technology, 226(2):123{133, 2012.

His old implementation was used as basis for this implementation.

We do only take the simulated motion into account, i.e. we do not multiply the output times two for symmetric simulations.

Todo:
Implement powerd. There were multiple implementations of it. See comments. Add a description for the outcome powerd and rename it!
Parameters
objCollocation object
XDouble matrix: State vector (i.e. result) of the problem
Return values
totalCEPowerDouble: Total mechanical work of the muscle fibres in W
powersDouble array: CE power output in W of each muscle and time point (Model.nMus x Collocation.nNodes)

◆ getComMotion()

function getComMotion ( in  obj,
in  X 
)

Computes center of mass motion.

Parameters
objCollocation class object
XDouble array: State vector containing at least speed of the movement

◆ getComMotionDeriv()

function getComMotionDeriv ( in  obj,
in  X 
)

Function to compute center of mass motion.

Parameters
objCollocation class object
XDouble array: State vector containing at least speed of the movement

◆ getMetabolicCost()

function getMetabolicCost ( in  obj,
in  X,
in  name,
in  getCont,
in  epsilon,
in  exponent 
)

Function to calculate metabolic cost of a movement.

Function to calculate the metabolic cost of a movement using Umberger's model. Ross Miller's code was also used as a reference.

See also the metabolic cost paper: A Koelewijn, E Dorschky, A van den Bogert; A metabolic energy expenditure model with a continuous first derivative and its application to predictive simulations of gait. Computer Methods in Biomechanics and Biomedical Engineering 21(4):1-11, 2018.

This function does only return the energy of the present movement. => We did not multiplied by two for symmetric movements here. Since metCost is computed from mean energy expenditure, it would be false to multiply the metCost by 2 for symmetric movements!!!

To get the cost of a result, you can call:

[metCost, ~, metCostPerMus, metRate, CoT] = result.problem.getMetabolicCost(result.X);
Todo:
Agree for one method to define (compute or extract) speed!
Parameters
objCollocation object
XDouble matrix: State vector (i.e. result) of the problem
name(optional) String: name of the model to be used default is umberger, other options are minetti, margaria, houdijk, bhargava, uchida, lichtwark, kim
getCont(optional) Boolean: If true, get the continuous version which is needed if we use the output for simulation. (default: 0)
epsilon(optional) Double: Amount of nonlinearity in continuous model it should be specified if a continuous model is used
exponent(optional) integer: could be used to calculate square, cube or nth power of metabolic cost. Only used for derivatives. (default: 1)
Return values
metCostDouble: Metabolic Cost of movement in J/m/kg
metRateDouble: Metabolic Rate of movement in W/kg
CoTDouble: Cost of transport of movement in 1
metCostPerMusDouble vector: Metabolic Cost of movement in J/m/kg (obj.model.nMus x 1)
dmetCostdXDouble vector: Derivative of metCost w.r.t to X (size of X)
dmetRatedXDouble vector: Derivative of metRate w.r.t to X (size of X)
dCoTdXDouble vector: Derivative of metRate w.r.t to X (size of X)

◆ getSimData()

function getSimData ( in  obj,
in  X,
in  simVar,
in  modelName 
)

Matlab function to extract simulated variables.

Warning: This function was not tested completely!

Currently, this function can return simulated data for the following data types:

  • translation
  • angle
  • qdot
  • moment
  • GRF
  • CoP
  • marker
  • acc
  • gyro
  • a
  • s
  • LMTU
  • LCE
  • LSEE
  • LdotMTU
  • LdotCE
  • LdotSEE
  • muscleForce
  • CEForce
  • u
  • speed
  • duration
  • footAngle
  • musclePower
  • CEPower
  • SEEPower
  • torque
  • sdot
  • muscleMetRate
  • CoM
  • jointPower
Todo:
Check which unit is requested and convert the data if needed. However this is currently only done for angles which are automatically converted into degrees if the unit is 'deg'.
Todo:
Use model.GRFNAMES instead of hard coded indices. Eventally change the names in GRFNAMES
Todo:
Check again if we use always the correct discretization method. If we use BE, shouldn't we use states(idxSimVar, 2:nNodes+1) and controls(idxSimVar, 2:nNodes+1)?
Parameters
objCollocation class object
XDouble matrix: State vector (i.e. result) of the problem
simVarTable: Information on variables from which we want to get the simulated data. This table has to contain the columns: type, name, and for IMU also position and direction.
modelNameFor metabolic rate: name of the model that should be used
Return values
simVarTable: Input table with an additional column "sim" containing the simulated data for this X.

◆ getStepLength()

function getStepLength ( in  obj,
in  X,
in  name 
)

Computes step length.

Parameters
objCollocation class object
XDouble array: State vector containing at least speed of the movement
nameOptional: left or right

◆ getStimTime()

function getStimTime ( in  obj,
in  X 
)

Collocation function to calculate the stimulation time for one gait cycle.

The stimulation time is a variable that is necessary for some of the metabolic models, because the energy expenditure is dependent on the stimulation time. This function calculates the stimulation time at the beginning of the gait cycle by looping to the gait cycle once.

To get the cost of a result, you can call:

t_stim = problem.getStimTime(X);
Parameters
objCollocation object
XDouble matrix: State vector (i.e. result) of the problem
Return values
t_stimDouble matrix: Activation Time (nMus x nNodesDur)

◆ gradient()

function gradient ( in  obj,
in  X 
)
virtual

Function computing gradient at state vector X.

Parameters
objCollocation class object
XDouble array: State vector with variables that are optimized
Return values
gDouble array: Gradient vector at state vector X

Reimplemented from Problem.

◆ headStabTerm()

function headStabTerm ( in  obj,
in  option,
in  X 
)

Matlab function to compute Veerkamp's HeadStab.

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states' and 'dur' of the model

◆ impactTerm()

function impactTerm ( in  obj,
in  option,
in  X 
)

Matlab function to compute Veerkamp's FGImpact.

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states' and 'dur' of the model

◆ initObjectives()

function initObjectives ( in  obj)

Function initializing the objective functions.

Parameters
objCollocation class object

◆ isPeriodic()

function get isPeriodic ( in  obj)

Function returning isPeriodic parameter.

Todo:
What if symmetric and not symmetric movement is loaded?
Todo:
: current hack without changing Model Class, is there a better way to make sure that always the right model is initialized?
Todo:
What if symmetric and not symmetric movement is loaded?
Todo:
: current hack without changing Model Class, is there a better way to make sure that always the right model is initialized?
Parameters
objCollocation class object
Return values
isPerBool: see Collocation.isPeriodic

◆ isSymmetric()

function get isSymmetric ( in  obj)

Function returning isSymmetric parameter.

Parameters
objCollocation class object
Return values
isSymBool: see Collocation.isSymmetric

◆ jacobian()

function jacobian ( in  obj,
in  X 
)
virtual

Function to compute jacobian at state vector X.

Parameters
objCollocation class object
XDouble array: State vector with variables that are optimized
Return values
JSparse matrix: Jacobian at state vector X

Reimplemented from Problem.

◆ jacstructure()

function jacstructure ( in  obj)
virtual

Function providing the jacobian pattern.

Parameters
objCollocation class object
Return values
JDouble matrix: Pattern of jacobian matrix

Reimplemented from Problem.

◆ jointAccelerationTerm()

function jointAccelerationTerm ( in  obj,
in  option,
in  X 
)

Matlab function to compute effort of the muscles from states vector.

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states' of the model

◆ kneeExtTerm()

function kneeExtTerm ( in  obj,
in  option,
in  X 
)

Matlab function to compute Veerkamp's KneeExt.

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states' of the model

◆ makeinitialguess()

function makeinitialguess ( in  obj,
in  init 
)

Function to define an initial guess.

Todo:
check if cmin and cmax have the correct size

The initial guess is initialized by adding the state variables. This function can be used to overwrite the initial guess, e.g. by loading an initial guess of a previous result. The input parameter 'init' can be used to define how the initial guess should be computed. If init = 'mid', the midpoint between the lower and upper bounds of the state vector X are used. If init = 'random', X is intialized by drawing random values from a uniform distribution between the lower and upper bound. If init contains the path to a result file, the result file is loaded. If neccessary, the result is resampled to the size of the current collocation problem.

problem.makeinitialguess('mid');
Parameters
objCollocation class object
initString: Parsing the demanded initialguess OR Double vector: X which fits exactly the size of the current problem (no tests and no resampling)

◆ matcompare()

static function matcompare ( in  a,
in  b 
)
staticinherited

Helperfunction to compare matrices and mind maximum abs error.

Used for derivativetest()

◆ nNodesDur()

function get nNodesDur ( in  obj)

Function returning nNodesDur parameter.

Parameters
objCollocation class object
Return values
isPerBool: see Collocation.isPeriodic

◆ objfun()

function objfun ( in  obj,
in  X 
)
virtual

Function computing objective value at state vector X.

Parameters
objCollocation class object
XDouble array: State vector with variables that are optimized
Return values
fDouble array: Objective value at state vector X

Reimplemented from Problem.

◆ passiveMomentTerm()

function passiveMomentTerm ( in  obj,
in  option,
in  X,
in  exponent 
)

Collocation function to compute effort of the torques from states vector.

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states' of the model
exponent(optional) Positive integer: Exponent of passive moments (default: 2)

◆ periodicityConstraint()

function periodicityConstraint ( in  obj,
in  option,
in  X,
in  sym 
)

Computes constaint violation demanding periodic movement.

Parameters
objCollocation class object
optionString parsing the demanded output
XDouble array: State vector containing at least 'states' and 'controls' of the model and speed and duration of the periodic movement
symBoolean if movement is symmetric (half period is optimized) or not

◆ plotlog()

function plotlog ( in  obj,
in  X 
)

Function plotting stick figure, objective values and constraint violations.

Parameters
objCollocation class object
XDouble array: State vector with variables that are optimized

◆ plotMeanSimVarTable()

function plotMeanSimVarTable ( in  tables,
in  style 
)
static

Computes function to plot the mean and SD of multiple simulation variable tables.

The function computes and plots the mean and variance for each column of tables.

When plotting IMU and marker data separate subplots are created for different directions and positions.

The function is not yet able to plot stance phases.

Collocation.plotMeanSimVarTable({simVarTable1, simVarTable2; simVarTable3, simVarTable4}, style);
The class for defining an optimal control of musculoskeletal.
Definition: Collocation.m:14
function plotMeanSimVarTable(in tables, in style)
Computes function to plot the mean and SD of multiple simulation variable tables.
Note
The function is currently assuming that tracking and reference data is identical over all tables within each column and is therefore only plotting the tracking and reference data of the first row.
Parameters
tablesCell matrix: Each entry is a simVarTable containing a full gait cycle returned from Collocation.report or Collocation.extractData. The results in dimension 1 can for example be from another subject and in dimension 2 from another condition, e.g., walking with an exoskeleton.
style(optional) Struct: Style of the figure containing the fields:
  • figureSize
  • xLabelFontSize
  • yLabelFontSize
  • xTickFontSize
  • yTickFontSize
  • legendFontSize
  • lineWidth
  • trackColor
  • extraColor
  • trackFaceAlpha
  • extraFaceAlpha
  • subFigSettings
If a field is not defined, default values specified in the description of plotVarType() will be used. Use empty to skip the input.
Return values
meanTablesOutCell vector: SimVarTables reflecting the mean of each column in tables. The simulated means and variances are saved in the table columns 'sim' and 'simVar', respectively. The columns 'mean', 'var', 'mean_extra', and 'var_extra' reflect the tracking and reference data which is currently assumed to be equal for all tables within one column.

◆ plotMultSimVarTables()

function plotMultSimVarTables ( in  tables,
in  style,
in  plotStance 
)
static

Function to plot the content of multiple simulation variable tables.

Usage:

Collocation.plotMultSimVarTables({simVarTable1, simVarTable2; simVarTable3, simVarTable4}, style);
function plotMultSimVarTables(in tables, in style, in plotStance)
Function to plot the content of multiple simulation variable tables.

It is also possible to plot simVarTables with different content.

When plotting IMU and marker data separate subplots are created for different directions and positions.

Parameters
tablesCell matrix: Each entry is a simVarTable containing a full gait cycle returned from Collocation.report or Collocation.extractData. The results in dimension 1 can for example be from another subject and in dimension 2 from another condition, e.g., walking with an exoskeleton.
style(optional) Struct: Style of the figure containing the fields:
  • figureSize
  • xLabelFontSize
  • yLabelFontSize
  • xTickFontSize
  • yTickFontSize
  • legendFontSize
  • lineWidth
  • trackColor
  • extraColor
  • trackFaceAlpha
  • extraFaceAlpha
  • standingRightColor
  • standingLeftColor
  • standingFaceAlpha
  • subFigSettings
If a field is not defined, default values specified in the description of plotVarType() will be used. Use empty to skip the input.
plotStance(optional) Boolean: If true and if the tables contain rows of type "standing", the stance phase(s) will be plotted. (default: false)

◆ plotStickSlider()

function plotStickSlider ( in  obj,
in  X,
in  subTrans,
in  showStickOpt,
in  markerTable 
)

Matlab function to create plot stick figure with slider.

Uses Model::showStick() to plot the result.

If you are adding more content to the plot, it will take noticable more time to initialize the figure. Be patient!

Example usage:

markerTable = result.problem.objectiveTerms(1).varargin{1}.variables; % assuming trackMarker is your first objective
result.problem.plotStickSlider(result.X, 0, {1, 0, 1, 0}, markerTable);
function trackMarker(in obj, in option, in X, in data)
Computes difference between simulated and measured marker data.
Parameters
objCollocation class object
XDouble matrix: State vector (i.e. result or initial guess) of the problem
subTrans(optional) Bool: Subtract the horizontal translation of the pelvis from the movement. (default: false)
showStickOpt(optional) Cell: Cell with optional input for model.showStick. Cell can contain all possible input options after ''range''. (default: empty cell)
markerTable(optional) Table: Variables table specifying markers with at least the columns: type, name, segment, position, direction to call Model.showMarker. If the column "mean" is also give, it will be plotted as reference. (default: empty table)

◆ printlog()

function printlog ( in  obj)

Function logging objective value and constraint violations.

Parameters
objCollocation class object

◆ regTerm()

function regTerm ( in  obj,
in  option,
in  X 
)

Computes differences between collocation nodes to ensure smoothness.

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states' and 'controls' of the model

◆ report()

function report ( in  obj,
in  X,
in  settings,
in  style,
in  resultFilename 
)
virtual

Computes function to report a current state vector of the problem.

It calls extractData() (see for details) to obtain the simulated data.

If you want to plot a static solution with one node (e.g. standing), you can still compare this to extra data using settings.variableTable. However, the variables table has to be resampled to 100 nodes before calling report().

Parameters
objCollocation class object
XDouble matrix: State vector (i.e. result) of the problem
settings(optional) Struct: Settings defining what to report. Additionally to the fields specified in extractData(), it supports the following fields:
  • variableTable (see extractData())
  • plotObjectives (boolean, default: 1)
  • plotConstraints (boolean, default: 1)
  • plotStick (boolean, default: 1)
  • plotInitialGuess (boolean, default: 0)
  • plotStance (boolean, default: 0)
(use empty to skip)
style(optional) Struct: Settings defining the style for reporting. See plotVarType() for details. (use empty to skip)
resultFilename(optional) String: Filename (without extension) to save Matlab figures and to save figures as tikz standalone.
Return values
conStringString: Formated text to be printed in the console containing problem informations
texStringString: Formated LaTeX text containing problem informations and tikz code for the figures.
simVarTableTable: Summarizing all data which was reported (see Collocation.extractData() for details)

Reimplemented from Problem.

◆ resampleInitialContact()

function resampleInitialContact ( in  obj,
in  X,
in  foot,
in  contact_names 
)

Resamples X so that the Heelstrike is at the first node.

Naive implementation that only considers one Heelstrike per foot

Todo:
Implement symmetric case, 3d-Curved running (?)
Parameters
objCollocation class object
XDouble array: State vector containing at least 'speed'
footleft ('l') or right (default, 'r')
contact_names[2 x n] cell containing all the contact names in the

◆ resampleX()

static function resampleX ( in  x,
in  N 
)
static

Function for resampling state vector for makeinitialguess.

Parameters
xMatrix with initial guess
NNumber of collocation nodes
Return values
xrepMatrix with resampled initial guess

◆ setPlotLim()

function setPlotLim ( in  values)

Helperfunction setting the limits for objective and constraints plot.

Parameters
valuesDouble matrix: Values plotted (sum is first term) (nEvaluations x nTerms)

◆ shift_index()

function shift_index ( in  X_tmp,
in  amount 
)

◆ showSingleStick()

function showSingleStick ( in  es,
in  ignoredArg 
)

◆ speedConstraint()

function speedConstraint ( in  obj,
in  option,
in  X,
in  targetSpeed 
)

Computes constraint violation demanding periodic movement.

Parameters
objCollocation class object
optionString parsing the demanded output
XDouble array: State vector containing at least speed of the movement
targetSpeedDouble: target speed to reach

◆ trackAcc()

function trackAcc ( in  obj,
in  option,
in  X,
in  data,
in  weight 
)

Matlab function to track accelerometer data.

Supports data in millimeter per second squared ('mm/s^2') and meter per second squared ('m/s^2').

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states' and 'dur' of the model
dataTrackingData: All rows with type 'acc' will be tracked
weight(optional) String: Defines the weighting of the squared difference. The following options exist:
  • 'varOverTrials' (default) for nTrials > 1:
    \( \frac{\left(y_{i}[k]- \hat{y}_{i}[k] \right)^2}{\sigma^2_{y,i}[k]} \), where \( \sigma^2_{y,i}[k] \) is the variance over all trials of signal i for the time point k (given in the data table).
  • 'varOverTrials' (default) for nTrials = 1:
    \( \frac{\left(y_{i}[k]- \hat{y}_{i}[k] \right)^2}{1} \) , where no weighting is performed as the variance over one trial would be zero.
  • 'varOverTime':
    \( \frac{\left(y_{i}[k]- \hat{y}_{i}[k] \right)^2}{\sigma^2_{y,i}} \) , where \( \sigma^2_{y,i} \) is the variance over all time points of signal i.
  • 'minMaxSquared':
    \( \frac{\left(y_{i}[k]- \hat{y}_{i}[k] \right)^2}{\left(max(y_i)-min(y_i) \right)^2 } \) , where the range of signal i over all time points is computed.
Return values
outputObjective values for input option 'objval' or vector with gradient for input option 'gradient'

◆ trackAngles()

function trackAngles ( in  obj,
in  option,
in  X,
in  data 
)

Computes difference between simulated and measured angles.

Supports data in radian ('rad') and degree ('deg').

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states' of the model
dataTrackingData: All rows with type 'angle' will be tracked
Return values
outputObjective values for input option 'objval' or vector with gradient

◆ trackDuration()

function trackDuration ( in  obj,
in  option,
in  X,
in  data 
)

Matlab function to track duration of the gait cycle.

Computes difference between simulated and measured duration

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'duration' of the model
dataTrackingData: The row with type 'duration' will be tracked. It assumes that there is only one row.
Return values
outputObjective values for input option 'objval' or vector with gradient for input option 'gradient'

◆ trackGRF()

function trackGRF ( in  obj,
in  option,
in  X,
in  data 
)

Matlab function to track ground reaction forces.

Computes difference between simulated and measured ground reaction forces. Supports data in bodyweight ('BW'), bodyweight percentage ('BW'), and newton ('N').

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states' of the model
dataTrackingData: All rows with type 'GRF' will be tracked
Return values
outputObjective values for input option 'objval' or vector with gradient for input option 'gradient'

◆ trackGyro()

function trackGyro ( in  obj,
in  option,
in  X,
in  data,
in  weight 
)

Matlab function to track gyroscope data.

Supports data in rad per second ('rad/s') and degree per second ('deg/s').

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states' of the model
dataTrackingData: All rows with type 'gyro' will be tracked
weight(optional) String: Defines the weighting of the squared difference. The following options exist:
  • 'varOverTrials' (default) for nTrials > 1:
    \( \frac{\left(y_{i}[k]- \hat{y}_{i}[k] \right)^2}{\sigma^2_{y,i}[k]} \), where \( \sigma^2_{y,i}[k] \) is the variance over all trials of signal i for the time point k (given in the data table).
  • 'varOverTrials' (default) for nTrials = 1:
    \( \frac{\left(y_{i}[k]- \hat{y}_{i}[k] \right)^2}{1} \) , where no weighting is performed as the variance over one trial would be zero.
  • 'varOverTime':
    \( \frac{\left(y_{i}[k]- \hat{y}_{i}[k] \right)^2}{\sigma^2_{y,i}} \) , where \( \sigma^2_{y,i} \) is the variance over all time points of signal i.
  • 'minMaxSquared':
    \( \frac{\left(y_{i}[k]- \hat{y}_{i}[k] \right)^2}{\left(max(y_i)-min(y_i) \right)^2 } \) , where the range of signal i over all time points is computed.
Return values
outputObjective values for input option 'objval' or vector with gradient for input option 'gradient'

◆ trackMarker()

function trackMarker ( in  obj,
in  option,
in  X,
in  data 
)

Computes difference between simulated and measured marker data.

Supports data in millimeter ('mm') and meter ('m').

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states' of the model
dataTrackingData: All rows with type 'marker' will be tracked
Return values
outputObjective values for input option 'objval' or vector with gradient

◆ trackSpeed()

function trackSpeed ( in  obj,
in  option,
in  X,
in  data 
)

Matlab function to track speed of the gait cycle.

Computes difference between simulated and measured duration

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'speed' of the model
dataTrackingData: All rows with type 'speed' will be tracked
Return values
outputObjective values for input option 'objval' or vector with gradient for input option 'gradient'

◆ trackTranslations()

function trackTranslations ( in  obj,
in  option,
in  X,
in  data 
)

Computes difference between simulated and measured translations.

Supports data in meter ('m') and millimeter ('mm').

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states' of the model
dataTrackingData: All rows with type 'translation' will be tracked
Return values
outputObjective values for input option 'objval' or vector with gradient for input option 'gradient'

◆ trackTranslationsAndAngles()

function trackTranslationsAndAngles ( in  obj,
in  option,
in  X,
in  data 
)

Computes difference between simulated and measured translations and angles in one term.

Parameters
objCollocation class object
optionString parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization)
XDouble array: State vector containing at least 'states' of the model
dataTrackingData: All rows with type 'angle' or 'translation' will be tracked
Return values
outputObjective values for input option 'objval' or vector with gradient for input option 'gradient'

◆ translationSpeedConstraint()

function translationSpeedConstraint ( in  obj,
in  option,
in  X 
)

Computes constraint based on speed and translation.

Constraint: deltaTranslation/duration - speed = 0

If two entries of type speed are contained in X, it assumes the first one to be forward (x-direction) and the second one to be sideward (z-direction).

Parameters
objCollocation class object
optionString parsing the demanded output
XDouble array: State vector containing at least states, speed and duration of the movement

◆ writeMotionToOsim()

function writeMotionToOsim ( in  obj,
in  X,
in  filename,
in  variableTable,
in  rangeNodes,
in  t0 
)

Function to write motion from a solution X to OpenSim files.

Saves the motion to the following files:

  1. <filename>_kinematics.mot containing the joint angles
  2. <filename>_kinematics_subTrans.mot containing the joint angles while subtracting x and z translation
  3. <filename>_kinetics_GRFs.mot containing GRFs
  4. <filename>_kinetics_activation.sto containing muscle activation
  5. <filename>_kinetics_moments.sto containing moments
  6. <filename>_kinetics_force.sto containing muscle forces
  7. <filename>_kinetics_controls.xml containing controls
  8. Optional: <filename>_markers.trc containing marker positions of markerTable specified
  9. Optional: <filename>_IMUs.csv containing IMU data of varTable (format definition of APDM)

No resampling is applied.

Parameters
objCollocation class object
XDouble matrix: State vector (i.e. result) of the problem
filenameString: Filename which is used to save the OpenSim files
variableTable(optional) Table: Variables table specifying markers or IMUs with at least the columns: type, name, segment, position, direction to call Model.simuMarker or Model.simuAccGyro. Can be skipped when empty.
rangeNodes(optional) Array: Specifying first and last node which should be exported. This might not work well for symmetric motions which are automatically mirrored.
t0(optional) Double: Time at first time point which should be used to start the time vector. If this value is not given, the time vector will start at 0.

◆ writeMovie()

function writeMovie ( in  obj,
in  X,
in  filename,
in  fps,
in  subTrans,
in  showStickOpt,
in  makeGIF,
in  playSpeed,
in  markerTable,
in  rangeNodes 
)

Matlab function to create a movie of a simulation result.

Uses Model::showStick() to plot the result.

Whether the optimal solution is converged is not checked.

Example usage:

markerTable = result.problem.objectiveTerms(1).varargin{1}.variables; % assuming trackMarker is your first objective
result.problem.writeMovie(result.X, result.filename, [], 0, {1, 0, 1, 0}, 1, 0, markerTable)
Parameters
objCollocation class object
XDouble matrix: State vector (i.e. result) of the problem
filename(optional) String: Filename which is used to save the OpenSim files. Use an empty char array '' to not save a file.
fps(optional) Double: Desired frame rate (frames per second) To skip the input, you can use []. (default: 5)
subTrans(optional) Bool: Subtract the horizontal translation of the pelvis from the movement. To skip the input, you can use []. (default: false)
showStickOpt(optional) Cell: Cell with optional input for model.showStick. Cell can contain all possible input options after ''range''. (default: empty cell)
makeGIF(optional) Bool: If true, a gif will be saved. Otherwise an avi will be saved. (default: 0=avi)
playSpeed(Optional) Double: If specified, the real duration of the simulated motion will be taken into account with
  • playSpeed == 1: duration of movie reflects the duration of motion
  • playSpeed < 1: slow motion (e.g. 0.5 => half the playback speed and double the duration)
  • playSpeed > 1: fast motion (e.g. 2 => double the playback speed and half the duration) (default: 0: fps nodes are displayed per second and duration is not taken into account) Attention: The duration of the movie will not be equal to the duration of the motion since the function is plotting the motion till node nNodes and not till nNodes+1.
markerTable(optional) Table: Variables table specifying markers with at least the columns: type, name, segment, position, direction to call Model.showMarker. If the column "mean" is also give, it will be plotted as reference. (default: empty table)
rangeNodes(optional) Array: Specifying first and last node which should be used for the movie. This might not work well for symmetric motions which are automatically mirrored.

◆ writeMovieCurvedRunning()

function writeMovieCurvedRunning ( in  obj,
in  X,
in  filename,
in  radius,
in  fps,
in  showStickOpt,
in  makeGIF 
)

Matlab function to create a movie of a simulation result for curved running.

This function writes movies for simulations which used Collocation::curveConstraint_pelvis213() instead of Collocation::periodicityConstraint().

Whether the optimal solution is converged is not checked.

Parameters
objCollocation class object
XDouble matrix: State vector (i.e. result) of the problem
filenameString: Filename which is used to save the OpenSim files
radiusDouble: Radius in m
fps(optional) Double: Desired frame rate (frames per second) To skip the input, you can use []. (default: 5)
showStickOpt(optional) Cell: Cell with optional input for model.showStick. Cell can contain all possible input options after ''range''. (default: empty cell)
makeGIF(optional) Bool: If true, a gif will be saved. Otherwise an avi will be saved. (default: 0=avi)

Member Data Documentation

◆ c_lb

Property c_lb
inherited

Double array: Lower bound of constaints.

◆ c_ub

Property c_ub
inherited

Double array: Upper bound of constraints.

◆ constraintTerms

Property constraintTerms
private

Struct array: Constraints.

◆ Euler

Property Euler
private

String: Midpoint euler 'ME' or backward euler 'BE' or semi-implicit euler 'SIE'.

◆ idx

Property idx
private

Struct: Indices for position of variables in state vector X.

◆ initialguess

Property initialguess
inherited

Struct: Intial guess for x.

◆ isPeriodic

Property isPeriodic
private

Bool: True if the periodicityConstraint() was used.

◆ isSymmetric

Property isSymmetric
private

Bool: True if the periodicityConstraint() was used and there sym is true.

◆ Jnnz

Property Jnnz
private

Double: Number of non-zero entries in jacobian pattern.

◆ Jpattern

Property Jpattern
private

Double matrix: Jacobian pattern.

◆ log

Property log
private

Struct: Information for logging objectives and constrained violations.

◆ model

Property model

Model: Object of class Model.m.

◆ name

Property name
inherited

String: Name of result file.

◆ nConstraints

Property nConstraints
private

Double: Total number of constraints.

◆ nNodes

Property nNodes
private

Double: Number of collocation nodes.

◆ nNodesDur

Property nNodesDur
private

Double: Number of collocation nodes which define the duration of the simulation.

If Collocation.isPeriodic is true, it is Collocation.nNodes+1 since we are simulating an additional node. If Collocation.isPeriodic is false, it is Collocation.nNodes since we do not simulate an additional node. This has to be taken into account when specifying the duration of the simulation as h=T/(nNodesDur-1).

◆ nVars

Property nVars
private

Double: Number of variables that are optimized.

◆ objectiveInit

Property objectiveInit
private

Struct: Contains values extracted during initialization of objective functions.

This is used to avoid the extraction in every call of the objective in each iteration thus to improve performance. Since it is a transient property it will not be saved when saving the object.

◆ objectiveTerms

Property objectiveTerms
private

Struct array: Ojective terms.

◆ plotLog

Property plotLog
private

Bool: If true, plot log in call of Collocation.objfun() (stick figure, objective, constrains) (default: 0)

◆ X_lb

Property X_lb
inherited

Double array: Lower bound of state vector.

◆ X_ub

Property X_ub
inherited

Double array: Upper bound of state vector.


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