% This function is part of the NMSM Pipeline, see file for full license.
%
% This function calculates the difference between the inverse dynamic
% moments and the muscle produced moments with the aid of an external
% torque controller for the specified coordinate. Applicable only if the
% model is synergy driven and if an external torque controller is present.
%
% (struct, struct, 2D matrix, Array of string) -> (Array of number)
%
function pathTerm = ...
calcMuscleActuatedMomentsWithExternalAidPathConstraints(params, ...
modeledValues, externalControlTorques, coordinate)
indx1 = find(strcmp(convertCharsToStrings(params.inverseDynamicMomentLabels), ...
[coordinate '_moment']));
indx2 = find(strcmp(params.surrogateModelCoordinateNames, ...
coordinate));
indx3 = find(strcmp(params.externalControlTorqueNames, ...
coordinate));
pathTerm = modeledValues.inverseDynamicMoments(:, indx1) - ...
(modeledValues.muscleJointMoments(:, indx2) + ...
externalControlTorques(:, indx3));
end