Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Treatment Optimization parse space separated lists #348

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ function plotTreatmentOptimizationGroundReactions(trackedDataFile, ...
if trackedDataTime(1) ~= 0
trackedDataTime = trackedDataTime - trackedDataTime(1);
end
trackedDataTime = trackedDataTime / trackedDataTime(end);
% trackedDataTime = trackedDataTime / trackedDataTime(end);
for j = 1 : numel(modelDataFiles)
modelDataStorage = Storage(modelDataFiles(j));
modelData{j} = storageToDoubleMatrix(modelDataStorage)';
@@ -56,7 +56,7 @@ function plotTreatmentOptimizationGroundReactions(trackedDataFile, ...
if modelDataTime{j} ~= 0
modelDataTime{j} = modelDataTime{j} - modelDataTime{j}(1);
end
modelDataTime{j} = modelDataTime{j} / modelDataTime{j}(end);
% modelDataTime{j} = modelDataTime{j} / modelDataTime{j}(end);
end

experimentalMomentIndices = contains(trackedDataLabels, ["_m", "M"]);
@@ -120,10 +120,10 @@ function plotTreatmentOptimizationGroundReactions(trackedDataFile, ...
end
nexttile(subplotNumber);
hold on
plot(trackedDataTime*100, trackedData(:, i), LineWidth=2, ...
plot(trackedDataTime, trackedData(:, i), LineWidth=2, ...
Color = colors(1));
for j = 1 : numel(modelDataFiles)
plot(modelDataTime{j}*100, modelData{j}(:, i), LineWidth=2, ...
plot(modelDataTime{j}, modelData{j}(:, i), LineWidth=2, ...
Color = colors(j+1));
end
hold off
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ function plotTreatmentOptimizationJointLoads(trackedDataFile, ...
if trackedDataTime(1) ~= 0
trackedDataTime = trackedDataTime - trackedDataTime(1);
end
trackedDataTime = trackedDataTime / trackedDataTime(end);
% trackedDataTime = trackedDataTime / trackedDataTime(end);
% Crop data to get rid of edge effects
trackedDataTime = trackedDataTime(1:end-1);
trackedData = trackedData(1:end-1, :);
@@ -58,7 +58,7 @@ function plotTreatmentOptimizationJointLoads(trackedDataFile, ...
if modelDataTime{j} ~= 0
modelDataTime{j} = modelDataTime{j} - modelDataTime{j}(1);
end
modelDataTime{j} = modelDataTime{j} / modelDataTime{j}(end);
% modelDataTime{j} = modelDataTime{j} / modelDataTime{j}(end);
% Crop data to get rid of edge effects
modelDataTime{j} = modelDataTime{j}(1:end-1);
modelData{j} = modelData{j}(1:end-1, :);
@@ -102,9 +102,9 @@ function plotTreatmentOptimizationJointLoads(trackedDataFile, ...
end
nexttile(subplotNumber);
hold on
plot(trackedDataTime*100, trackedData(:, i), LineWidth=2, Color = colors(1));
plot(trackedDataTime, trackedData(:, i), LineWidth=2, Color = colors(1));
for j = 1 : numel(modelDataFiles)
plot(modelDataTime{j}*100, modelData{j}(:, i), LineWidth=2, Color = colors(j+1));
plot(modelDataTime{j}, modelData{j}(:, i), LineWidth=2, Color = colors(j+1));
end
hold off
if contains(jointLoadLabels(i), "moment")
7 changes: 7 additions & 0 deletions src/core/parse/parseRcnlConstraintTermSet.m
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@
currentTerm = tree{term};
end
% Find general cost term elements
tempTerm = struct();
tempTerm.type = getTextFromField(getFieldByNameOrError( ...
currentTerm, 'type'));
[isValid, isPath] = isTypeValid(tempTerm.type, toolName, controllerType);
@@ -57,6 +58,9 @@
% Find other cost term elements
termElements = fieldnames(currentTerm);
for element = 1:length(termElements)
if strcmp(termElements{element}, "Attributes")
continue
end
if isempty(intersect(termElements{element}, ["type" ...
"is_enabled" "max_error" "min_error"]))
contents = getTextFromField(getFieldByNameOrError( ...
@@ -67,6 +71,9 @@
contents = false;
elseif ~isnan(str2double(contents))
contents = str2double(contents);
elseif any(isspace(convertStringsToChars(contents)))
contents = parseSpaceSeparatedList(currentTerm, ...
termElements{element});
end
tempTerm.(termElements{element}) = contents;
end
9 changes: 8 additions & 1 deletion src/core/parse/parseRcnlCostTermSet.m
Original file line number Diff line number Diff line change
@@ -55,6 +55,10 @@
% Find other cost term elements
termElements = fieldnames(currentTerm);
for element = 1:length(termElements)

if strcmp(termElements{element}, "Attributes")
continue
end
if isempty(intersect(termElements{element}, ["type" ...
"is_enabled" "max_allowable_error" "error_center"]))
contents = getTextFromField(getFieldByNameOrError( ...
@@ -65,10 +69,13 @@
contents = false;
elseif ~isnan(str2double(contents))
contents = str2double(contents);
elseif any(isspace(convertStringsToChars(contents)))
contents = parseSpaceSeparatedList(currentTerm, ...
termElements{element});
end
costTerms{term}.(termElements{element}) = contents;
end
end
end
end
end

34 changes: 34 additions & 0 deletions src/core/parse/parseTreatmentOptimizationInputs.m
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@
inputs = parseOptimalControlSolverSettings(tree, inputs);
inputs.costTerms = parseRcnlCostTermSetHelper( ...
getFieldByNameOrError(tree, 'RCNLCostTermSet'));
inputs.costTerms = splitListTerms(inputs.costTerms);
if isequal(mexext, 'mexw64')
inputs.calculateAngularMomentum = any(all([ ...
strcmp(cellfun(@(term) term.type, inputs.costTerms, ...
@@ -74,6 +75,8 @@
[inputs.path, inputs.terminal] = parseRcnlConstraintTermSetHelper( ...
getFieldByNameOrError(tree, 'RCNLConstraintTermSet'), ...
inputs.controllerType, inputs.toolName);
inputs.path = splitListTerms(inputs.path);
inputs.terminal = splitListTerms(inputs.terminal);
end

function inputs = parseBasicInputs(tree)
@@ -125,3 +128,34 @@
end
end

function splitTerms = splitListTerms(originalTerms)
splitTerms = {};
listTypes = ["coordinate_list", "load_list", "muscle_list", ...
"force_list", "moment_list", "marker_list", "controller_list", ...
"synergy_group_list"];
unlistTypes = ["coordinate", "load", "muscle", ...
"force", "moment", "marker", "controller", "synergy_group"];
for i = 1 : length(originalTerms)
termElements = fieldnames(originalTerms{i});
hasBeenSplit = false;
for element = 1:length(termElements)
typeIndex = find(termElements{element} == listTypes, 1);
if ~isempty(typeIndex)
newTermTemplate = originalTerms{i};
newTermTemplate = rmfield(newTermTemplate, termElements{element});
elementsList = convertCharsToStrings(split(originalTerms{i} ...
.(termElements{element})));
for j = 1 : length(elementsList)
newTerm = newTermTemplate;
newTerm.(unlistTypes(typeIndex)) = ...
convertStringsToChars(elementsList(j));
splitTerms{end + 1} = newTerm;
end
hasBeenSplit = true;
end
end
if ~hasBeenSplit
splitTerms{end + 1} = originalTerms{i};
end
end
end