Dear experts of OpenSim and Moco,
I'm learning OpenSim MOCO with the latest OpenSim. I'm interested in predicting gait motions using a osim model with contact bodies. I found an example of 2Dwalking and examing it in Python environment.
Then I have a question. This sample creates gaitTrackingSolution using MocoTracking, and solution variable is reused as a guess in gaitPrediction with MocoStudy. But is it possible to recreate the gaitTrackingSolution from osim, sto files of states and controls?
For example, I have a_model.osim with a_states.sto and a_control.sto files. How can I recreate a Moco's solution variable.
Here attached file is my python script converted from Matlab sample code.
Any suggestions are helpful.
Thank you and Best,
Hide
Recreate Moco solution from osim, sto files of states and control
- Hide Kimpara
- Posts: 135
- Joined: Mon Sep 19, 2016 5:12 am
Recreate Moco solution from osim, sto files of states and control
- Attachments
-
- example2DWalking_Predict.py.txt
- (15.81 KiB) Downloaded 87 times
Tags:
- Nicholas Bianco
- Posts: 1048
- Joined: Thu Oct 04, 2012 8:09 pm
Re: Recreate Moco solution from osim, sto files of states and control
Hi Hide,
There's a few options you can use through the MocoTrajectory class. You can use one of the constructors directly to create a new MocoTrajectory. Or, if you have an existing MocoTrajectory (e.g., from MocoCasADiSolver::createGuess()), then you can use insertStatesTrajectory() and insertControlsTrajectory() to insert states and controls from another source (my recommended approach). There is also createFromStatesControlsTables(), but this isn't as well used/tested as the other options.
-Nick
There's a few options you can use through the MocoTrajectory class. You can use one of the constructors directly to create a new MocoTrajectory. Or, if you have an existing MocoTrajectory (e.g., from MocoCasADiSolver::createGuess()), then you can use insertStatesTrajectory() and insertControlsTrajectory() to insert states and controls from another source (my recommended approach). There is also createFromStatesControlsTables(), but this isn't as well used/tested as the other options.
-Nick
- Hide Kimpara
- Posts: 135
- Joined: Mon Sep 19, 2016 5:12 am
Re: Recreate Moco solution from osim, sto files of states and control
Thank you, Nick!
createFromStatesControlsTables works for me. (I also tried insertStatesTrajectory with MocoTrajectory, but only state labels are registered without matrix part)
Now I enjoy running example2DWalking. When I increase speed to 4 m/s, the model is running.
I will try to use other MocoGoal options.
Best,
Hide
createFromStatesControlsTables works for me. (I also tried insertStatesTrajectory with MocoTrajectory, but only state labels are registered without matrix part)
Code: Select all
single_state = osim.TimeSeriesTable('gaitTracking_solution_singleStride_states.sto')
single_contl = osim.TimeSeriesTable('gaitTracking_solution_singleStride_controls.sto')
problemRep = osim.MocoProblemRep()
mocoTraj = osim.MocoTrajectory().createFromStatesControlsTables(problemRep, single_state, single_contl)
I will try to use other MocoGoal options.
Best,
Hide
- Nicholas Bianco
- Posts: 1048
- Joined: Thu Oct 04, 2012 8:09 pm
Re: Recreate Moco solution from osim, sto files of states and control
Hi Hide,
Great! Glad you found a working solution.
(I realize now that insertStatesTrajectory() was a bad suggestion: it will only work if the MocoTrajectory already contains an existing time vector. It's not designed to build a trajectory for scratch.)
-Nick
Great! Glad you found a working solution.
(I realize now that insertStatesTrajectory() was a bad suggestion: it will only work if the MocoTrajectory already contains an existing time vector. It's not designed to build a trajectory for scratch.)
-Nick