create Moco guess from previous solution

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
POST REPLY
User avatar
Christian Greve
Posts: 40
Joined: Mon Jun 13, 2016 11:14 pm

create Moco guess from previous solution

Post by Christian Greve » Tue Jul 04, 2023 9:17 am

Dear Moco community,

I am trying to use a guess file from a previous MocoStudy solution but encounter the following problem/error message:

RuntimeError: std::exception in 'void OpenSim::MocoCasADiSolver::setGuess(OpenSim::MocoTrajectory)': The trajectory and provided problem are not compatible. The following state(s) are in the trajectory but not the problem:
/jointset/Ankle_l/ankle_pfdf_l/speed
/jointset/Ankle_l/ankle_pfdf_l/value
/jointset/Ankle_r/ankle_pfdf_r/speed
/jointset/Ankle_r/ankle_pfdf_r/value
Thrown at MocoTrajectory.cpp:1028 in MocoTrajectory::isCompatible()().

I am using a MocoInverse instant to prescribe kinematics. The MocoInverse is then translated into a MocoStudy where I add EMG tracking goals.....when setting the guess file with a previous solution it generates the error message.

Are the values and speeds not in the problem because I am using MocoInverse to prescribe kinematics? Do you have a suggestion how I can use a previous solution as guess file for my MocoStudy?

Thanks and kind regards

Christian

User avatar
Edward Syrett
Posts: 34
Joined: Mon Jan 14, 2019 11:04 am

Re: create Moco guess from previous solution

Post by Edward Syrett » Wed Jul 05, 2023 5:45 am

Hey there,
So from what I can tell, you are bringing in the guess, including the ankle kinematics into your problem. But it seems your problem does not use the ankle kinematics. So that is why you are getting this error. Are you intentionally not using them as part of your problem? If you are intending to use them, you need to add them into your problem. If not, you can remove the ankle kinematics from your guess with something like the following code (Matlab):

Code: Select all

guess = solver.createGuess();
prevSolution = MocoTrajectory('insert your previous solution here');
StatesTable = prevSolution.exportToStatesTable();
StatesTable.removeColumn('/jointset/Ankle_l/ankle_pfdf_l/speed');
StatesTable.removeColumn('/jointset/Ankle_l/ankle_pfdf_l/value');
StatesTable.removeColumn('/jointset/Ankle_r/ankle_pfdf_r/speed');
StatesTable.removeColumn('/jointset/Ankle_r/ankle_pfdf_r/value');
guess.insertStatesTrajectory(StatesTable, true);
ControlsTable = prevSolution.exportToControlsTable();
guess.insertControlsTrajectory(ControlsTable, true);
solver.setGuess(guess);
I've used similar code when I am removing certain muscle states from my problem (like when I use an able-bodied solution as a guess for an amputee problem). Hope this helps.

Dan

POST REPLY