% This function is part of the NMSM Pipeline, see file for full license.
%
% Cost associated to penalizing differences in activation time constants,
% activation nonlinearity, and EMG scaling factors from user selected set
% point. Additionally, a cost associated to minimizing passive force is
% calculated.
%
% (struct, struct, 3D matrix, struct) -> (struct)
% calculates the cost for changes in paramters from user selected set point
function cost = calcAllDeviationPenaltyCosts(values, ...
experimentalData, passiveForce, cost)
% Penalize difference of tact from set point
cost.activationTimePenalty = calcDeviationCostTerm( ...
values.activationTimeConstants / 100, ...
experimentalData.errorCenters(2), experimentalData.maxAllowableErrors(2));
% Penalize difference of Anonlin from set point
cost.activationNonlinearityPenalty = calcDeviationCostTerm( ...
values.activationNonlinearityConstants, experimentalData.errorCenters(3), ...
experimentalData.maxAllowableErrors(3));
% Penalize difference of lMo values from pre-calibrated values
cost.optimalFiberLengthPenalty = calcDeviationCostTerm( ...
experimentalData.optimalFiberLength .* ...
values.optimalFiberLengthScaleFactors - experimentalData.optimalFiberLength, ...
experimentalData.errorCenters(4), experimentalData.maxAllowableErrors(4));
% Penalize difference of tendonSlackLength values from pre-calibrated values
cost.tendonSlackLengthPenalty = calcDeviationCostTerm( ...
experimentalData.tendonSlackLength .* ...
values.tendonSlackLengthScaleFactors - experimentalData.tendonSlackLength, ...
experimentalData.errorCenters(5), experimentalData.maxAllowableErrors(5));
% Penalize difference of EMGScale from set point
cost.emgScalePenalty = calcDeviationCostTerm( ...
values.emgScaleFactors, experimentalData.errorCenters(6), ...
experimentalData.maxAllowableErrors(6));
% Minimize passive force
cost.minPassiveForce = calcDeviationCostTerm(passiveForce, ...
experimentalData.errorCenters(8), experimentalData.maxAllowableErrors(8));
end