Page 1 of 1

showMotion()

Posted: Thu May 02, 2024 9:52 am
by ben_snbd_2002
Hello everyone,
does anyone of you have experience with the function 'showMotion()'? My plan is to collect the coordinate data in a matrix, turn it into a TimeSeriesTable and use showMotion to visualize the Motion. On Doxygen it only tells you that the storage should contain all the generalized coordinates but I don't which coordinates to include, only those of the bodies or those of all components? Also, I don't know how to structure the matrix, so that the function works. If anyone can help me there it would be much appreciated
Thanks in advance

Re: showMotion()

Posted: Thu May 02, 2024 3:45 pm
by kernalnet
Hi, if you intend to visualize the coordinates only, the IK output file would be enough.

Code: Select all

import opensim as osim

# set path to the required files/folders
model_path = '...'
IK_path = '...'
geometry_path = '...'

osim.ModelVisualizer.addDirToGeometrySearchPaths(geometry_path)

model = osim.Model(model_path)
newModel = model.clone()
newModel.set_ForceSet(osim.ForceSet())
table = osim.TimeSeriesTable(IK_path)

viz = osim.VisualizerUtilities()
viz.showMotion(newModel, table)
Here I removed muscles just for simplicity. You can use a state file (e.g. CMC output) or create a new table and put all the required values with appropriate labels (model.getStateVariableNames()).

Hope this helps.

Re: showMotion()

Posted: Fri May 03, 2024 3:23 am
by ben_snbd_2002
Thank you so much for your reply. It is probably a dumb question but how do I get the IK File?

Re: showMotion()

Posted: Fri May 03, 2024 3:29 am
by kernalnet
I meant your motion file; for instance the output of Inverse Kinematics tool.

Re: showMotion()

Posted: Fri May 03, 2024 12:57 pm
by ben_snbd_2002
Thank you
And do you know how I can change the Unit of the angles to degree?

Re: showMotion()

Posted: Fri May 03, 2024 1:55 pm
by kernalnet
SimbodyEngine::convertRadiansToDegrees may help:

Code: Select all

model.initSystem()
if table.getTableMetaDataString('inDegrees') == 'no':
    model.getSimbodyEngine().convertRadiansToDegrees(table)
But simbody-visualizer works with both units.

Re: showMotion()

Posted: Fri May 03, 2024 1:58 pm
by aymanh
Hello,

There's a line in the header of sto (and mot) files that specifies whether the angles are in degrees or radians. Motion files are assumed to have rotational coordinates in degrees (inDegrees=yes) so you can set it to match the data in the file. For OpenSim use the .mot and .sto are interchangeable except that the latter may have more flexibility and more meta data in the header.

Hope this helps,
-Ayman