Skip to main content

computeTrackingOptimizationMainFunction.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% This function sets up GPOPS-II to run Tracking Optimization.
%
% (struct) -> (struct, struct)
% Assigns optimal control settings and runs Tracking Optimization


function output = computeTrackingOptimizationMainFunction(inputs, params)
bounds = setupProblemBounds(inputs, params);
guess = setupCommonOptimalControlInitialGuess(inputs);
setup = setupCommonOptimalControlSolverSettings(inputs, ...
bounds, guess, params, ...
@computeTrackingOptimizationContinuousFunction, ...
@computeTrackingOptimizationEndpointFunction);
checkInitialGuess(guess, inputs, ...
@computeTrackingOptimizationContinuousFunction);
solution = gpops2(setup);
solution = solution.result.solution;
solution.auxdata = inputs;
if inputs.optimizeSynergyVectors
solution.phase.parameter = solution.parameter;
end
output = computeTrackingOptimizationContinuousFunction(solution);
output.solution = solution;
end

function bounds = setupProblemBounds(inputs, params)
bounds = setupCommonOptimalControlBounds(inputs, params);
% setup parameter bounds
if strcmp(inputs.controllerType, 'synergy_driven')
if inputs.optimizeSynergyVectors
bounds.parameter.lower = -0.5 * ones(1, length(inputs.minParameter));
bounds.parameter.upper = 0.5 * ones(1, length(inputs.minParameter));
end
end
end