% This function is part of the NMSM Pipeline, see file for full license.
%
% This function calculates the terminal constraint for verification
% optimization
%
% (struct, struct, struct) -> (Array of number)
% Returns terminal constraint
function event = calcVerificationOptimizationTerminalConstraint(inputs, params)
inputs.phase.state = [inputs.phase.initialstate; inputs.phase.finalstate];
inputs.phase.time = [inputs.phase.initialtime; inputs.phase.finaltime];
inputs.phase.control = ones(size(inputs.phase.time,1),length(params.minControl));
values = getVerificationOptimizationValueStruct(inputs.phase, params);
modeledValues = calcTorqueBasedModeledValues(values, params);
event = [];
for i = 1:length(params.terminal)
constraintTerm = params.terminal{i};
if constraintTerm.isEnabled
switch constraintTerm.type
case "state_position_periodicity"
event = cat(2, event, ...
calcStatePositionPeriodicity(values.statePositions, ...
params.coordinateNames, ...
constraintTerm.coordinate));
case "state_velocity_periodicity"
event = cat(2, event, ...
calcStateVelocityPeriodicity(values.stateVelocities, ...
params.coordinateNames, ...
constraintTerm.coordinate));
case "root_segment_residual_load_periodicity"
event = cat(2, event, ...
calcRootSegmentResidualsPeriodicity(...
modeledValues.inverseDynamicMoments, ...
params.inverseDynamicMomentLabels, ...
constraintTerm.load));
case "external_force_periodicity"
event = cat(2, event, ...
calcExternalForcesPeriodicity(...
modeledValues.groundReactionsLab.forces, ...
params.contactSurfaces, ...
constraintTerm.force));
case "external_moment_periodicity"
event = cat(2, event, ...
calcExternalMomentsPeriodicity(...
modeledValues.groundReactionsLab.moments, ...
params.contactSurfaces, ...
constraintTerm.moment));
otherwise
throw(MException('', ['Constraint term type ' ...
constraintTerm.type ' does not exist for this tool.']))
end
end
end
end