Hi all,
I was wondering if anyone has tried visualising results obtained using OpenSim 4.0?
I have control and state files computed using my own optimal control approach in conjunction with OpenSim 4.0.
I have tried to use StatesTrajectory to load the states storage file but I'm unsure how to convert it into a time-varying state variable and then run the visualiser to view the motion of the model (as well as the activity of the model). Currently, I've resorted to plot my positions and activations using MATLAB and exporting it as an .avi, which suits my purpose but having a function that takes in either both a control and/or state file would be handy in the future.
Note, I'm running most of my simulations using the MATLAB API.
Thanks in advance!
Adrian
Visualising OpenSim 4.0 results
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Visualising OpenSim 4.0 results
You might be able to create the StatesTrajectory using `StatesTrajectory.createFromStatesStorage()`, and then you can visualize individual states with `model.getVisualizer().show(statesTraj.get(i))`.
- Adrian Lai
- Posts: 46
- Joined: Tue Mar 13, 2012 11:33 am
Re: Visualising OpenSim 4.0 results
Hi Chris,
Thanks for the reply.
I was able to create the StateTrajectory using createFromStatesStorage() but when I tried to visualise the individual states, I get the following error. I tried different values but I get the same error. Any ideas?
Thanks for the reply.
I was able to create the StateTrajectory using createFromStatesStorage() but when I tried to visualise the individual states, I get the following error. I tried different values but I get the same error. Any ideas?
Code: Select all
osimModel.getVisualizer().show(stateSimulate.get(0))
Java exception occurred:
java.lang.RuntimeException: min = 0 max = 4294967295 index = 0
In file
c:\users\adriannew\dropbox\opensim\my_repositories\opensim_4.0_source_code\opensim\simulation\StatesTrajectory.h:174
In function 'get'
at org.opensim.modeling.opensimSimulationJNI.StatesTrajectory_get(Native
Method)
at org.opensim.modeling.StatesTrajectory.get(StatesTrajectory.java:47)
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: Visualising OpenSim 4.0 results
The message indicates that the exception is thrown on line 174 of StatesTrajectory.h (https://github.com/opensim-org/opensim- ... ory.h#L174):
The error message states "min = 0 max = 4294967295", but I think the size of the StatesTrajectory is actually zero (subtracting 1 and converting to an unsigned would give 2^32 - 1 = 4294967296). Does stateSimulate.size() return 0?
Code: Select all
OPENSIM_THROW(IndexOutOfRange, index, 0,
static_cast<unsigned>(m_states.size() - 1));
- Adrian Lai
- Posts: 46
- Joined: Tue Mar 13, 2012 11:33 am
Re: Visualising OpenSim 4.0 results
Yes, it returns 0. Am I creating the StateTrajectory incorrectly?Does stateSimulate.size() return 0?
Code: Select all
stateStorage = Storage('tugOfWar_states.sto');
stateSimulate = StatesTrajectory();
stateSimulate.createFromStatesStorage(osimModel,stateStorage);
Code: Select all
stateSimulate.createFromStatesStorage(osimModel,'tugOfWar_states.sto');
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: Visualising OpenSim 4.0 results
Hm, not sure about this; your code looks okay to me. Based on the doxygen (http://myosin.sourceforge.net/1987/clas ... 0b662882f3), the allowMissingColumns argument will be false so it should throw an exception "if there are continuous state variables in the Model for which there is no column in the Storage". If no exception is thrown when calling createFromStatesStorage(), then it seems like there can't be any missing columns (and, unless your model has zero states, you should get a non-empty trajectory). Perhaps there's an issue with the MATLAB bindings? I see there's a Python test for StatesTrajectory (https://github.com/opensim-org/opensim- ... jectory.py) but no analogous test for MATLAB.