Moco result inconsistent with the set kinematics

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
Xinguo Fang
Posts: 1
Joined: Wed Jul 14, 2021 8:40 am

Moco result inconsistent with the set kinematics

Post by Xinguo Fang » Thu Aug 05, 2021 10:16 pm

Hi there,

I was trying to use moco to solve the muscle activation of an arm model with 50 muscles.

Code: Select all

import opensim as osim

inverse = osim.MocoInverse()

# Construct a ModelProcessor and set it on the tool. The default
# muscles in the model are replaced with optimization-friendly
# DeGrooteFregly2016Muscles, and adjustments are made to the default muscle
# parameters.
modelProcessor = osim.ModelProcessor(r'C:\Users\fxgcy\PycharmProjects\OpenSim Moco\MOBL_ARMS_fixed_41.osim')
modelProcessor.append(osim.ModOpIgnoreTendonCompliance())
modelProcessor.append(osim.ModOpReplaceMusclesWithDeGrooteFregly2016())
# Only valid for DeGrooteFregly2016Muscles.
modelProcessor.append(osim.ModOpIgnorePassiveFiberForcesDGF())
# Only valid for DeGrooteFregly2016Muscles.
modelProcessor.append(osim.ModOpScaleActiveFiberForceCurveWidthDGF(1.5))
modelProcessor.append(osim.ModOpAddReserves(1.0))
inverse.setModel(modelProcessor)

# Construct a TableProcessor of the coordinate data and pass it to the
# inverse tool. TableProcessors can be used in the same way as
# ModelProcessors by appending TableOperators to modify the base table.
# A TableProcessor with no operators, as we have here, simply returns the
# base table.
inverse.setKinematics(osim.TableProcessor(r'C:\Users\fxgcy\PycharmProjects\OpenSim Moco\bicep_curl.sto'))
# Initial time, final time, and mesh interval.
inverse.set_initial_time(0.00)
inverse.set_final_time(6.75)
inverse.set_mesh_interval(0.01)
# By default, Moco gives an error if the kinematics contains extra columns.
# Here, we tell Moco to allow (and ignore) those extra columns.
inverse.set_kinematics_allow_extra_columns(True)
# Solve the problem and write the solution to a Storage file.
solution = inverse.solve()
solution.getMocoSolution().write(r'C:\Users\fxgcy\PycharmProjects\OpenSim Moco\MoBL_ARMS_MocoInverse_solution.sto')
There were some optimization errors but I can still get the result.

[error] Model unable to assemble: SimTK Exception thrown at Optimizer.h:133:
Value out of range in OptimizerSystem Constructor: expected 1 <= number of parameters <= 2.14748e+09 but number of parameters=0..Model relaxing constraints and trying again.
[error] Model unable to assemble with relaxed constraints: SimTK Exception thrown at Optimizer.h:133:
Value out of range in OptimizerSystem Constructor: expected 1 <= number of parameters <= 2.14748e+09 but number of parameters=0.


When I tried to input the moco solution to the Forward Dynamics tool in opensim, the simulation result was very far-off from the kinematics that I set in the code. I tried to use a simpler model (arm26). But the forward dynamic simulation was still very inconsistent with the motion file that I set.

So I am wondering that if there's anything wrong with the optimizer or they way I'm using it.

Thanks in advance!

User avatar
Nicholas Bianco
Posts: 980
Joined: Thu Oct 04, 2012 8:09 pm

Re: Moco result inconsistent with the set kinematics

Post by Nicholas Bianco » Sat Aug 07, 2021 6:16 pm

Hi Xinguo,

The errors you're seeing are unrelated to the optimizer Moco uses (i.e., IPOPT), but are warning messages related to the Model's assembly step which enforces kinematic constraints in the model. You may see these errors when using MocoInverse, since the kinematics are prescribed exactly, meaning the model can't make small adjustments to satisfy the model constraints so the constraints must be slightly relaxed. As such, MocoInverse assumes that the kinematics you provide meet any kinematic constraints in the model.

It is unlikely. that the output of a direct collocation problem will produce a stable forward simulation due to the build up of small numerical errors. Stable forward simulations usually require some sort of feedback control to work properly. You're probably not doing anything wrong.

-Nick

User avatar
Sina Tabeiy
Posts: 8
Joined: Thu Sep 05, 2019 4:15 am

Re: Moco result inconsistent with the set kinematics

Post by Sina Tabeiy » Wed May 17, 2023 4:26 am

Dear Nick,

Thank you for your answer. I have almost the same problem. My goal is to use MocoInverse to get the muscle activation and also MocoTrack to get the initial state of the model to use them in forward dynamics tool as the controls and initial state, respectively.
I costumized the the exmpleMocoInverse.m and exampleMocoTrack.m files, in the example 3DWalking folder of Moco resources, to match the data and model I whish to examine. I could run exampleMocoTrack completely; however, MocoInverse took almost 2 hrs (on a 16-core laptop) and I stopped the process to use the muscle activation sto file in forward dynamics. I run fwrd dynamics but the model went crazy.
Now, I have 2 questions; first: did I follow the correct path to supply the requisites (controls nd initial state) of fwrd dynamics toolbox? And second: you said "Stable forward simulations usually require some sort of feedback control to work properly." How can I mke a correct feedback control to run forward dynamics properly?

Many thanks,
Sina

User avatar
Nicholas Bianco
Posts: 980
Joined: Thu Oct 04, 2012 8:09 pm

Re: Moco result inconsistent with the set kinematics

Post by Nicholas Bianco » Thu May 18, 2023 12:01 pm

Hi Sina,

Are you using MocoTrack with a foot-ground contact model? If you want to run forward dynamics after Moco, you'll need to first get a stable tracking solution with foot-ground contact.

Best,
Nick

POST REPLY