Skip to main content

GroundContactPersonalization.m


% This function is part of the NMSM Pipeline, see file for full license.
%
%
%
% (struct, struct) -> (struct)
% Runs all Ground Contact Personalization stages from inputs and params.


function results = GroundContactPersonalization(inputs, params)
inputs = prepareGroundContactPersonalizationInputs(inputs);
% Optionally initializes the resting spring length.
if params.restingSpringLengthInitialization
inputs = initializeRestingSpringLength(inputs);
end
for surface = 1:length(inputs.surfaces)
[inputs.surfaces{surface}.experimentalGroundReactionMoments, ...
inputs.surfaces{surface}.experimentalMomentCenter] = ...
replaceMomentsAboutMidfootSuperior(inputs.surfaces{surface}, ...
inputs);
inputs.surfaces{surface}.experimentalGroundReactionMomentsSlope = ...
calcBSplineDerivative(inputs.surfaces{surface}.time, ...
inputs.surfaces{surface}.experimentalGroundReactionMoments, 2, ...
inputs.surfaces{surface}.splineNodes);
end
% Run each task as outlined in XML settings file.
for task = 1:length(params.tasks)
inputs = optimizeGroundContactPersonalizationTask(inputs, params, ...
task);
end

results = inputs;
end

% (struct, struct) -> (2D Array of double)
% Replace parsed experimental ground reaction moments about midfoot
% superior marker projected onto floor
function [replacedMoments, momentCenter] = ...
replaceMomentsAboutMidfootSuperior(surface, inputs)
replacedMoments = ...
zeros(size(surface.experimentalGroundReactionMoments));
for i = 1:size(replacedMoments, 2)
newCenter = surface.midfootSuperiorPosition(:, i);
newCenter(2) = inputs.restingSpringLength;
replacedMoments(:, i) = ...
surface.experimentalGroundReactionMoments(:, i) + ...
cross((surface.electricalCenter(:, i) - newCenter), ...
surface.experimentalGroundReactionForces(:, i));
momentCenter = repmat(newCenter, 1, 101);
end
end