% This function is part of the NMSM Pipeline, see file for full license.
%
% This function sets up the input variables and mex files (or parallel
% matlab function) for the main function of design optimization
%
% (struct, struct) -> (struct, struct)
% Inputs for the main function are setup
function [output, inputs] = DesignOptimization(inputs, params)
inputs = makeTreatmentOptimizationInputs(inputs, params);
initializeMexOrMatlabParallelFunctions(inputs.mexModel);
if strcmp(inputs.controllerType, 'synergy_driven')
inputs = setupMuscleSynergies(inputs);
end
if inputs.enableExternalTorqueControl
inputs = setupExternalTorqueControls(inputs);
end
output = computeDesignOptimizationMainFunction(inputs, params);
end
function inputs = setupMuscleSynergies(inputs)
inputs.splineSynergyActivations = spaps(inputs.initialGuess.time, ...
inputs.initialGuess.control(:, inputs.numCoordinates + 1 : ...
inputs.numCoordinates + inputs.numSynergies)', 0.0000001);
inputs.synergyLabels = inputs.initialGuess.controlLabels(:, ...
inputs.numCoordinates + 1 : inputs.numCoordinates + inputs.numSynergies);
end
function inputs = setupExternalTorqueControls(inputs)
if size(inputs.initialGuess.control, 2) ~= length(inputs.maxControl)
inputs.initialGuess.control = [inputs.initialGuess.control ...
zeros(size(inputs.initialGuess.control, 1), ...
inputs.numExternalTorqueControls)];
end
end