Biomech-Sim-Toolbox 1
Toolbox for movement simulation and analysis
|
The class for defining an optimal control of musculoskeletal. More...
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) | |
The class for defining an optimal control of musculoskeletal.
function Collocation | ( | in | model, |
in | nNodes, | ||
in | Euler, | ||
in | logfile, | ||
in | plotLog | ||
) |
Constructor setting default Collocation options.
model | Model 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) |
obj | Collocation class object |
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).
obj | Collocation class object |
fh | Function handle: Method defined in Collocation |
cmin | Double array: Lower bound on constraint |
cmax | Double array: Upper bound on constraint |
varargin | (optional) Input parameter for function handle |
function addObjective | ( | in | obj, |
in | fh, | ||
in | weight, | ||
in | varargin | ||
) |
Function adding objective term to the optimization problem.
The objective terms are summed up in objective function using the function and weights which are defined as input.
obj | Collocation class object |
fh | Function handle: Method defined in the Collocation class folder |
weight | Double: Weight of the objective term in the objective function |
varargin | (optional) Input parameter for function handle |
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).
obj | Collocation class object |
name | String: Name of variable |
xmin | Double, vector or matrix: Lower bounds |
xmax | Double, vector or matrix: Upper bounds |
xinit | (optional) Vector or matrix: Initial guess |
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:
obj | Collocation class object |
X | Double matrix: State vector (i.e. result) of the problem |
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.
obj | Collocation class object |
option | String parsing the demanded output |
X | Double array: State vector containing at least speed of the movement |
targetMotion | Double: target motion of the center of mass |
function computeJpattern | ( | in | obj | ) |
Function computing the jacobian pattern.
obj | Collocation class object |
|
virtual |
Function to compute constraint violations at state vector X.
obj | Collocation class object |
X | Double array: State vector with variables that are optimized |
c | Double array: Constraint violations at state vector X |
Reimplemented from Problem.
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.
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double 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 |
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:
obj | Collocation class object |
option | String: Parsing the demanded output |
X | Double array: State vector containing at least 'states' and 'controls' of the model and speed and duration of the periodic movement |
radius | Double: Radius of the circle |
|
inherited |
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.
obj | Collocation class object |
option | String parsing the demanded output |
X | Double array: State vector containing at least speed of the movement |
targetDuration | Double: target duration to reach |
function dynamicConstraints | ( | in | obj, |
in | option, | ||
in | X | ||
) |
Computes constaint violation demanding dynamic equilibrium.
obj | Collocation class object |
option | String parsing the demanded output |
X | Double array: State vector containing at least 'states' and 'controls' of the model and speed and duration of the periodic movement |
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.
obj | Collocation class object |
option | String parsing the demanded output |
X | Double array: State vector containing at least 'states' and 'controls' of the model and 'duration' of movement |
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.
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double 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) |
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.
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double 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) |
function effortTermTorques | ( | in | obj, |
in | option, | ||
in | X, | ||
in | exponent, | ||
in | speedWeighting | ||
) |
Matlab function to compute effort of the torques from states vector.
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double 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) |
function equilibriumConstraints | ( | in | obj, |
in | option, | ||
in | X | ||
) |
Matlab function to compute dynamic constraint for standing.
It ensures equilibrium at node 1.
obj | Collocation class object |
option | String parsing the demanded output |
X | Double array: State vector containing at least 'states' and 'controls' of the model and speed and duration of the periodic movement |
function equilibriumConstraintsCPOffset | ( | in | obj, |
in | option, | ||
in | X | ||
) |
Matlab function to compute dynamic constraint for standing with a vertical offset of the contact points.
obj | Collocation class object |
option | String parsing the demanded output |
X | Double array: State vector containing at least 'states' and 'controls' of the model and speed and duration of the periodic movement |
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:
By default, the following variables will automatically be extracted if you do not overwrite the respective fields in settings:
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:
obj | Collocation class object |
X | Double 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:
|
simVarTable | Table: Summarizing all simulated, tracked and optionally additional data which was requested. The three different data kinds are saved in the following columns:
|
function fromStandingConstraint | ( | in | obj, |
in | option, | ||
in | X | ||
) |
Matlab function to find walking/running from standing.
obj | Collocation class object |
option | String parsing the demanded output |
X | Double array: State vector containing at least 'states' and 'controls' of the model and speed and duration of the periodic movement |
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.
obj | Collocation object |
X | Double matrix: State vector (i.e. result) of the problem |
totalCEPower | Double: Total mechanical work of the muscle fibres in W |
powers | Double array: CE power output in W of each muscle and time point (Model.nMus x Collocation.nNodes) |
function getComMotion | ( | in | obj, |
in | X | ||
) |
Computes center of mass motion.
obj | Collocation class object |
X | Double array: State vector containing at least speed of the movement |
function getComMotionDeriv | ( | in | obj, |
in | X | ||
) |
Function to compute center of mass motion.
obj | Collocation class object |
X | Double array: State vector containing at least speed of the movement |
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:
obj | Collocation object |
X | Double 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) |
metCost | Double: Metabolic Cost of movement in J/m/kg |
metRate | Double: Metabolic Rate of movement in W/kg |
CoT | Double: Cost of transport of movement in 1 |
metCostPerMus | Double vector: Metabolic Cost of movement in J/m/kg (obj.model.nMus x 1) |
dmetCostdX | Double vector: Derivative of metCost w.r.t to X (size of X) |
dmetRatedX | Double vector: Derivative of metRate w.r.t to X (size of X) |
dCoTdX | Double vector: Derivative of metRate w.r.t to X (size of X) |
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:
obj | Collocation class object |
X | Double matrix: State vector (i.e. result) of the problem |
simVar | Table: 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. |
modelName | For metabolic rate: name of the model that should be used |
simVar | Table: Input table with an additional column "sim" containing the simulated data for this X. |
function getStepLength | ( | in | obj, |
in | X, | ||
in | name | ||
) |
Computes step length.
obj | Collocation class object |
X | Double array: State vector containing at least speed of the movement |
name | Optional: left or right |
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:
obj | Collocation object |
X | Double matrix: State vector (i.e. result) of the problem |
t_stim | Double matrix: Activation Time (nMus x nNodesDur) |
|
virtual |
Function computing gradient at state vector X.
obj | Collocation class object |
X | Double array: State vector with variables that are optimized |
g | Double array: Gradient vector at state vector X |
Reimplemented from Problem.
function headStabTerm | ( | in | obj, |
in | option, | ||
in | X | ||
) |
Matlab function to compute Veerkamp's HeadStab.
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'states' and 'dur' of the model |
function impactTerm | ( | in | obj, |
in | option, | ||
in | X | ||
) |
Matlab function to compute Veerkamp's FGImpact.
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'states' and 'dur' of the model |
function initObjectives | ( | in | obj | ) |
Function initializing the objective functions.
obj | Collocation class object |
function get isPeriodic | ( | in | obj | ) |
Function returning isPeriodic parameter.
obj | Collocation class object |
isPer | Bool: see Collocation.isPeriodic |
function get isSymmetric | ( | in | obj | ) |
Function returning isSymmetric parameter.
obj | Collocation class object |
isSym | Bool: see Collocation.isSymmetric |
|
virtual |
Function to compute jacobian at state vector X.
obj | Collocation class object |
X | Double array: State vector with variables that are optimized |
J | Sparse matrix: Jacobian at state vector X |
Reimplemented from Problem.
|
virtual |
Function providing the jacobian pattern.
obj | Collocation class object |
J | Double matrix: Pattern of jacobian matrix |
Reimplemented from Problem.
function jointAccelerationTerm | ( | in | obj, |
in | option, | ||
in | X | ||
) |
Matlab function to compute effort of the muscles from states vector.
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'states' of the model |
function kneeExtTerm | ( | in | obj, |
in | option, | ||
in | X | ||
) |
Matlab function to compute Veerkamp's KneeExt.
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'states' of the model |
function makeinitialguess | ( | in | obj, |
in | init | ||
) |
Function to define an initial guess.
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.
obj | Collocation class object |
init | String: Parsing the demanded initialguess OR Double vector: X which fits exactly the size of the current problem (no tests and no resampling) |
|
staticinherited |
Helperfunction to compare matrices and mind maximum abs error.
Used for derivativetest()
function get nNodesDur | ( | in | obj | ) |
Function returning nNodesDur parameter.
obj | Collocation class object |
isPer | Bool: see Collocation.isPeriodic |
|
virtual |
Function computing objective value at state vector X.
obj | Collocation class object |
X | Double array: State vector with variables that are optimized |
f | Double array: Objective value at state vector X |
Reimplemented from Problem.
function passiveMomentTerm | ( | in | obj, |
in | option, | ||
in | X, | ||
in | exponent | ||
) |
Collocation function to compute effort of the torques from states vector.
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'states' of the model |
exponent | (optional) Positive integer: Exponent of passive moments (default: 2) |
function periodicityConstraint | ( | in | obj, |
in | option, | ||
in | X, | ||
in | sym | ||
) |
Computes constaint violation demanding periodic movement.
obj | Collocation class object |
option | String parsing the demanded output |
X | Double array: State vector containing at least 'states' and 'controls' of the model and speed and duration of the periodic movement |
sym | Boolean if movement is symmetric (half period is optimized) or not |
function plotlog | ( | in | obj, |
in | X | ||
) |
Function plotting stick figure, objective values and constraint violations.
obj | Collocation class object |
X | Double array: State vector with variables that are optimized |
|
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.
tables | Cell 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:
|
meanTablesOut | Cell 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. |
|
static |
Function to plot the content of multiple simulation variable tables.
Usage:
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.
tables | Cell 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:
|
plotStance | (optional) Boolean: If true and if the tables contain rows of type "standing", the stance phase(s) will be plotted. (default: false) |
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:
obj | Collocation class object |
X | Double 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) |
function printlog | ( | in | obj | ) |
Function logging objective value and constraint violations.
obj | Collocation class object |
function regTerm | ( | in | obj, |
in | option, | ||
in | X | ||
) |
Computes differences between collocation nodes to ensure smoothness.
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'states' and 'controls' of the model |
|
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().
obj | Collocation class object |
X | Double 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:
|
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. |
conString | String: Formated text to be printed in the console containing problem informations |
texString | String: Formated LaTeX text containing problem informations and tikz code for the figures. |
simVarTable | Table: Summarizing all data which was reported (see Collocation.extractData() for details) |
Reimplemented from Problem.
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
obj | Collocation class object |
X | Double array: State vector containing at least 'speed' |
foot | left ('l') or right (default, 'r') |
contact_names | [2 x n] cell containing all the contact names in the |
|
static |
Function for resampling state vector for makeinitialguess.
x | Matrix with initial guess |
N | Number of collocation nodes |
xrep | Matrix with resampled initial guess |
function setPlotLim | ( | in | values | ) |
Helperfunction setting the limits for objective and constraints plot.
values | Double matrix: Values plotted (sum is first term) (nEvaluations x nTerms) |
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.
obj | Collocation class object |
option | String parsing the demanded output |
X | Double array: State vector containing at least speed of the movement |
targetSpeed | Double: target speed to reach |
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').
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'states' and 'dur' of the model |
data | TrackingData: All rows with type 'acc' will be tracked |
weight | (optional) String: Defines the weighting of the squared difference. The following options exist:
|
output | Objective values for input option 'objval' or vector with gradient for input option 'gradient' |
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').
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'states' of the model |
data | TrackingData: All rows with type 'angle' will be tracked |
output | Objective values for input option 'objval' or vector with gradient |
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
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'duration' of the model |
data | TrackingData: The row with type 'duration' will be tracked. It assumes that there is only one row. |
output | Objective values for input option 'objval' or vector with gradient for input option 'gradient' |
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').
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'states' of the model |
data | TrackingData: All rows with type 'GRF' will be tracked |
output | Objective values for input option 'objval' or vector with gradient for input option 'gradient' |
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').
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'states' of the model |
data | TrackingData: All rows with type 'gyro' will be tracked |
weight | (optional) String: Defines the weighting of the squared difference. The following options exist:
|
output | Objective values for input option 'objval' or vector with gradient for input option 'gradient' |
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').
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'states' of the model |
data | TrackingData: All rows with type 'marker' will be tracked |
output | Objective values for input option 'objval' or vector with gradient |
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
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'speed' of the model |
data | TrackingData: All rows with type 'speed' will be tracked |
output | Objective values for input option 'objval' or vector with gradient for input option 'gradient' |
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').
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'states' of the model |
data | TrackingData: All rows with type 'translation' will be tracked |
output | Objective values for input option 'objval' or vector with gradient for input option 'gradient' |
function trackTranslationsAndAngles | ( | in | obj, |
in | option, | ||
in | X, | ||
in | data | ||
) |
Computes difference between simulated and measured translations and angles in one term.
obj | Collocation class object |
option | String parsing the demanded output: 'objval' or 'gradient' (or 'init' for initialization) |
X | Double array: State vector containing at least 'states' of the model |
data | TrackingData: All rows with type 'angle' or 'translation' will be tracked |
output | Objective values for input option 'objval' or vector with gradient for input option 'gradient' |
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).
obj | Collocation class object |
option | String parsing the demanded output |
X | Double array: State vector containing at least states, speed and duration of the movement |
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:
No resampling is applied.
obj | Collocation class object |
X | Double matrix: State vector (i.e. result) of the problem |
filename | String: 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. |
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:
obj | Collocation class object |
X | Double 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
|
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. |
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.
obj | Collocation class object |
X | Double matrix: State vector (i.e. result) of the problem |
filename | String: Filename which is used to save the OpenSim files |
radius | Double: 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) |
|
inherited |
Double array: Lower bound of constaints.
|
inherited |
Double array: Upper bound of constraints.
|
private |
Struct array: Constraints.
|
private |
String: Midpoint euler 'ME' or backward euler 'BE' or semi-implicit euler 'SIE'.
|
private |
Struct: Indices for position of variables in state vector X.
|
inherited |
Struct: Intial guess for x.
|
private |
Bool: True if the periodicityConstraint() was used.
|
private |
Bool: True if the periodicityConstraint() was used and there sym is true.
|
private |
Double: Number of non-zero entries in jacobian pattern.
|
private |
Double matrix: Jacobian pattern.
|
private |
Struct: Information for logging objectives and constrained violations.
|
inherited |
String: Name of result file.
|
private |
Double: Total number of constraints.
|
private |
Double: Number of collocation nodes.
|
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).
|
private |
Double: Number of variables that are optimized.
|
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.
|
private |
Struct array: Ojective terms.
|
private |
Bool: If true, plot log in call of Collocation.objfun() (stick figure, objective, constrains) (default: 0)
|
inherited |
Double array: Lower bound of state vector.
|
inherited |
Double array: Upper bound of state vector.