Page 1 of 1

Problem in appending actuators with Matlab

Posted: Tue Apr 14, 2020 2:42 am
by chantlw
Hi OpenSim community,
I encountered a problem when scripting with Matlab.

The problem arised from the CMCTool. For my previous projects, I normally initiated a simulation by reading in a default XML setup file and modifying inputs via API (as suggested by the developers group). This worked out fine for Inverse Kinematcs and Analysis tools. However, the same pipeline reported the following errors for the CMCTool:


CMC.computeControls: t = 0
SimTK Exception thrown at interiorpointoptimizer.cpp:264:
Optimizer failed: Ipopt: Infeasible problem detected (status 2)
OPTIMIZATION FAILED...


CMC.computeControls: ERROR- Optimizer could not find a solution.
Unable to find a feasible solution at time = 0.
Model cannot generate the forces necessary to achieve the target acceleration.
Possible issues: 1. not all model degrees-of-freedom are actuated,
2. there are tracking tasks for locked coordinates, and/or
3. there are unnecessary control constraints on reserve/residual actuators.




After looking into the details I found that the problem was likely attributed to the failure of appending reversed actuactors to the model. It appeared that additional force set could not be added by the "setForceSetFiles" method, the same issue that I believed many other users have had before.

Could anyone show me the correct Matlab lines (or entries) to append actuators to the model in OpenSim 4.0 and Matlab 64-bit?



Belowed I attached a part of my Matlab script for your reference:

Code: Select all

scaledModel = strcat('.\',ModelFileName);

model = Model(scaledModel);
model.initSystem();

defaultELfile = strcat('.\testing_EL.xml');
GRFdata = strcat('.\',Subject{ren},Point{k},'_kinetics.mot');
ELsetupfile = strcat('.\',Subject{ren},Point{k},'_EL.xml');
generalCMCFile = strcat('.\testing_CMC.xml');
outputIKFile = strcat('.\',Subject{ren},Point{k},'_IK.mot');
outputName = strcat(Subject(ren),Point(k));
taskFile = strcat('.\gait2392_CMC_Tasks.xml');
actuatorFile = strcat('.\gait2392_CMC_Actuators.xml');


cmcTool = CMCTool();

actuator = ArrayStr(actuatorFile)


cmcTool.setModel(model);
cmcTool.setDesiredKinematicsFileName(outputIKFile);
cmcTool.setTaskSetFileName(taskFile);
cmcTool.setName(outputName);
cmcTool.setForceSetFiles(actuator);
cmcTool.setExternalLoadsFileName(defaultELfile);
cmcTool.getExternalLoads.setDataFileName(GRFdata);

cmcTool.run();

Your help will be appreciated.

Re: Problem in appending actuators with Matlab

Posted: Thu Oct 28, 2021 3:01 pm
by ajyoder
I've got a solution

I hit the same bug when executing static optimization via the Analyze tool in the MATLAB API v4.3, i.e. actuators not being appended

Specifically, if I printed the setup XML from MATLAB right before executing AnalyzeTool.run(), it would run and solve just fine in the GUI, with the appended reserve actuators present in the force output file, however if I let it run in MATLAB, it failed due to missing reserve actuators which are needed to support the feet/pelvis - they are not listed in output, despite the setForceSetFiles('reserve_actuator_file.xml') method of AnalyzeTool

Instead, you can pull the ForceSet of the model, and manually append each reserve actuator object

Code: Select all

%% Work-around for setForceSetFiles() of AnalyzeTool not being honored at execution in 4.0API
model = Model('modelfile.osim');

so_actuators = ForceSet('reserve_actuator_file.xml');
forceset = model.updForceSet;
for fi=(1:so_actuators.getSize)-1
   forceset.cloneAndAppend(so_actuators.get(fi))
end
modelFileName_actuated = strrep(modelFileName,'.osim','_actuators.osim');
model.print(modelFileName_actuated)

analyze.setModel(model)
analyze.setModelFilename(modelFileName_actuated)