Creating SimTK Rotations from Numpy arrays
Posted: Thu Feb 15, 2024 5:38 am
Hi there,
Using the OpenSim API through python scripting, how can I create a SimTK Rotation from a numpy array matrix?
More generally - I am trying to update the transform of an IMU PhysicalOffsetFrame associated with a body in my model (so I can manually apply my own calibrations, rather than rely on OpenSim's built-in IMUPlacer tool).
My code looks like this so far:
I get an error message which says I have the wrong number or type of argument for creating a new rotation, and that I need a SimTK Rotation, or Mat33, or Quaternion, but I don't know how to create these in python, without reading in quaternion tables from an data file.
Thanks for any help,
Mhairi
Using the OpenSim API through python scripting, how can I create a SimTK Rotation from a numpy array matrix?
More generally - I am trying to update the transform of an IMU PhysicalOffsetFrame associated with a body in my model (so I can manually apply my own calibrations, rather than rely on OpenSim's built-in IMUPlacer tool).
My code looks like this so far:
Code: Select all
import opensim as osim
import numpy as np
model = osim.Model(model_file)
IMU_frame = model.getBodySet().get('thorax').getComponent('thorax_imu')
rotation_array = np.array([[1, 0, 0],[0, 1, 0],[0, 0, 1]]) # Create an example numpy array
osim_rotation = osim.Rotation(rotation_array) # Create an opensim rotation (this doesn't work)
transform = osim.Transform(osim_rotation) # Create an opensim transform from the rotation
IMU_frame.setOffsetTransform(transform) # Update the IMU frame transform
Thanks for any help,
Mhairi