Skip to main content

parseTrackingOptimizationSettingsTree.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% This function parses the settings tree resulting from xml2struct of the
% Tracking Optimizatoin settings XML file.
%
% (struct) -> (struct, struct)
% returns the input values for Tracking Optimization


function [inputs, params, resultsDirectory] = ...
parseTrackingOptimizationSettingsTree(settingsTree)
inputs = getTreatmentOptimizationInputs(settingsTree);
inputs = getDesignVariableBounds(settingsTree, inputs);
params = getParams(settingsTree);
inputs = modifyModelForces(inputs);
end

function inputs = getDesignVariableBounds(tree, inputs)
designVariableTree = getFieldByNameOrError(tree, ...
'RCNLDesignVariableBoundsTerms');
jointPositionsMultiple = getFieldByNameOrError(designVariableTree, ...
'joint_positions_multiple');
if(isstruct(jointPositionsMultiple))
inputs.statePositionsMultiple = getDoubleFromField(jointPositionsMultiple);
end
jointVelocitiesMultiple = getFieldByNameOrError(designVariableTree, ...
'joint_velocities_multiple');
if(isstruct(jointVelocitiesMultiple))
inputs.stateVelocitiesMultiple = getDoubleFromField(jointVelocitiesMultiple);
end
jointAccelerationsMultiple = getFieldByNameOrError(designVariableTree, ...
'joint_accelerations_multiple');
if(isstruct(jointAccelerationsMultiple))
inputs.stateAccelerationsMultiple = ...
getDoubleFromField(jointAccelerationsMultiple);
end
jointJerkMultiple = getFieldByNameOrError(designVariableTree, ...
'joint_jerks_multiple');
if(isstruct(jointJerkMultiple))
inputs.controlJerksMultiple = getDoubleFromField(jointJerkMultiple);
end
if strcmp(inputs.controllerType, 'synergy_driven')
maxControlSynergyActivations = getFieldByNameOrError(designVariableTree, ...
'synergy_activations_max');
if(isstruct(maxControlSynergyActivations))
inputs.maxControlSynergyActivations = ...
getDoubleFromField(maxControlSynergyActivations);
end
maxParameterSynergyWeights = getFieldByNameOrError(designVariableTree, ...
'synergy_weights_max');
if(isstruct(maxParameterSynergyWeights))
inputs.maxParameterSynergyWeights = ...
getDoubleFromField(maxParameterSynergyWeights);
end
else
maxControlTorques = getFieldByNameOrError(designVariableTree, ...
'torque_controls_max');
if(isstruct(maxControlTorques))
inputs.maxControlTorquesMultiple = getDoubleFromField(maxControlTorques);
end
end
inputs.toolName = "TrackingOptimization";
end

function params = getParams(tree)
params.solverSettings = getOptimalControlSolverSettings(...
getTextFromField(getFieldByName(tree, 'optimal_control_settings_file')));
end