I have started by building a script using ChatGPT (as I'm not very familiar with the scripting tools in Opensim):
Code: Select all
import opensim as osim
# Load your OpenSim model
model = osim.Model("path/to/your/model.osim")
# Create a Storage object to read in the .mot file
storage = osim.Storage("path/to/your/model_outputs.mot")
# Get the number of bodies in the model
num_bodies = model.getNumBodies()
# Loop through each time step in the .mot file
for i in range(storage.getSize()):
# Set the model state to the current time step
time = storage.getTime(i)
state = model.initSystem()
osim.TimeSeriesTableUtilities.setAllValues(state, storage.getRowAtIndex(i))
# Loop through all bodies in the model and get their global angular velocities
for j in range(num_bodies):
body = model.getBodySet().get(j)
ang_vel = body.getAngularVelocityInGround(state)
print("Time = {}, Body {}: global angular velocity = {}".format(time, j+1, ang_vel))
Code: Select all
time = storage.getTime(i)
Code: Select all
osim.TimeSeriesTableUtilities.setAllValues(state, storage.getRowAtIndex(i))
Any feedback on how to modify the existing script, or perhaps use a different script entirely, would be much appreciated!