Hi Nick,
I'm trying to implement something similar to this (basically providing a lowly weighted goal to keep the pelvis level), but with the Pelvis and in Python. I'm wondering whether the bindings to use a rotation table are available in Python?
I managed to create a rotation table using (I think this is right?):
Code: Select all
import opensim as osim
#Create rotation time series table
rotTable = osim.TimeSeriesTableRotation()
#Set column labels for pelvis bodyset
rotLabels = osim.StdVectorString()
rotLabels.append('/bodyset/pelvis')
rotTable.setColumnLabels(rotLabels)
#Create a zero rotation value
zeroRot = osim.Rotation()
zeroRot.setToZero()
#Set the data to zeros
#Use length of reference kinematic data as a reference
nrows = len(osim.TimeSeriesTable('refQ.sto').getIndependentColumn())
for ii in range(nrows):
#Get an opensim row vector rotation with a zero value
row = osim.RowVectorRotation(1,zeroRot)
#Append to the table
rotTable.appendRow(ii,row)
#Set the time data
for ii in range(nrows):
rotTable.setIndependentValueAtIndex(ii,osim.TimeSeriesTable('refQ.sto').getIndependentColumn()[ii])
I then create and add the goal:
Code: Select all
#Create goal
pelvisGoal = osim.MocoOrientationTrackingGoal('pelvisOrientation',0.1)
#Set path to pelvis frame
framePaths = osim.StdVectorString()
framePaths.append('/bodyset/pelvis')
pelvisGoal.setFramePaths(framePaths)
#Add rotation table of zeros to goal
pelvisGoal.setRotationReference(rotTable)
But this generates an error:
Code: Select all
TypeError: in method 'MocoOrientationTrackingGoal_setRotationReference', argument 2 of type 'OpenSim::TimeSeriesTable_< OpenSim::Rotation > const &'
It seems like my rotation table is of the wrong type for using 'setRotationReference.' It is an object of type:
Code: Select all
<opensim.common.TimeSeriesTableRotation; proxy of <Swig Object of type 'std::shared_ptr< OpenSim::TimeSeriesTable_< SimTK::Rotation_< double > > > *' at 0x00000192A19C6C00> >
Am I missing a step or potentially consturcting things wrong here? I tried to use the approach you mentioned in having a states reference file with all zero values (to specify a neutral pelvis), but I keep getting a 'nan' result as the pelvisGoal output so there is clearly another issue in how I'm implementing that approach.
Aaron