Orientation Tracking Setup

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
POST REPLY
User avatar
Nicholas Vandenberg
Posts: 71
Joined: Wed Jan 20, 2021 12:47 pm

Orientation Tracking Setup

Post by Nicholas Vandenberg » Thu Aug 24, 2023 12:25 pm

Hi all,

I recently started working with some IMU data that I'm trying to use with Moco, the good news being that there's a ton of data available but it's a bit like drinking out of a fire hose. The Xsens system we're using gives a ton of information and I've been able to adapt some conversion code from the native MVNX files to kinematics .mot files. However, (and this seems silly to say) I can only pull joint angle data from the MVN model joints which leaves gaps in various OpenSim model DOFs that don't have data to track (i.e., pelvis_tilt/list/rotation); resulting in solutions that aren't super great.

I have a question regarding the MocoOrientationTrackingGoal. I've used a variant of this goal in the past to assign a states trajectory for reference for the torso orientation. The description of this goal says that it can also take a trajectory in quaternion format, representing the orientation reference data which is provided in an array for all of the MVN model segments in each captured frame.
IMU_data_frames.png
IMU_data_frames.png (50.3 KiB) Viewed 1702 times
I'm wondering if it's as straightforward as building a TimeSeriesTable of the quaternion data and adding a Pelvis_Orientation tracking goal to my problem? Or am I missing something else?

Thanks!
Nick

User avatar
Nicholas Bianco
Posts: 1041
Joined: Thu Oct 04, 2012 8:09 pm

Re: Orientation Tracking Setup

Post by Nicholas Bianco » Fri Aug 25, 2023 10:17 am

Hi Nick,

Yes, that should work! It's been a while since I wrote that cost term, so hopefully everything works as expected.

One quick thing: you might run into issues with the Matlab bindings not supporting a TimeSeriesTable of Quaternion or Rotation objects. I believe we fixed that recently, but let me know if it still doesn't work.

Best,
Nick

User avatar
Nicholas Vandenberg
Posts: 71
Joined: Wed Jan 20, 2021 12:47 pm

Re: Orientation Tracking Setup

Post by Nicholas Vandenberg » Mon Aug 28, 2023 11:27 am

Hey Nick,

I've tried working it up, pretty sure I've pulled the right section to construct the table itself and wrote up the goal:
Pel_OTG_code.png
Pel_OTG_code.png (11.85 KiB) Viewed 1657 times
Is this what you were referring to about the table not being supported? I tried it with the TableProcessor after trying just the TimeSeriesTableQuaternion and normal TimeSeriesTable.
Pel_OTG_err.png
Pel_OTG_err.png (14.32 KiB) Viewed 1657 times
If it's helpful I also included the .mot file that I made with the orientation data. I'm not sure if the issue is the type of table I'm trying to make or the data I'm trying to put in it.

Best,
Nick
Attachments
TFAB_02_SSWlk04_Xsens_PelQuat.mot
(43.44 KiB) Downloaded 76 times

User avatar
Nicholas Bianco
Posts: 1041
Joined: Thu Oct 04, 2012 8:09 pm

Re: Orientation Tracking Setup

Post by Nicholas Bianco » Mon Aug 28, 2023 11:48 am

Hey Nick,

You can't load that data directly into a TimeSeriesTableQuaternion, since it's currently just a table of "scalar" columns. But you can load the data into a TimeSeriesTable, and then "pack" it into a table of quaternions.

Code: Select all

pelvisTable = TimeSeriesTable('TFAB_02_SSWlk04_Xsens_PelQuat.mot');

% The "pack" method will take each 4 consecutive columns and pack them into a Quaternion object. It will choose a % column name based on a common prefix across all columns.
pelvisTableQuaternion = pelvisTable.pack();

% If you know the suffixes for each group of 4 columns, you can specify them during the pack operation.
suffixes = StdVectorString();
suffixes.add("_e0");
suffixes.add("_e1");
suffixes.add("_e2");
suffixes.add("_e3");
pelvisTableQuaternion = pelvisTable.pack(suffixes);
-Nick

User avatar
Nicholas Vandenberg
Posts: 71
Joined: Wed Jan 20, 2021 12:47 pm

Re: Orientation Tracking Setup

Post by Nicholas Vandenberg » Mon Aug 28, 2023 12:04 pm

That makes sense, thanks! I've got that worked in now but I'm getting an error about too many output arguments when I use the pack function?

User avatar
Nicholas Bianco
Posts: 1041
Joined: Thu Oct 04, 2012 8:09 pm

Re: Orientation Tracking Setup

Post by Nicholas Bianco » Mon Aug 28, 2023 12:06 pm

Could you post a screenshot of the error message?

User avatar
Nicholas Vandenberg
Posts: 71
Joined: Wed Jan 20, 2021 12:47 pm

Re: Orientation Tracking Setup

Post by Nicholas Vandenberg » Mon Aug 28, 2023 12:08 pm

Here's the error I'm seeing
Pel_OTG_err.png
Pel_OTG_err.png (3.33 KiB) Viewed 1616 times

User avatar
Nicholas Bianco
Posts: 1041
Joined: Thu Oct 04, 2012 8:09 pm

Re: Orientation Tracking Setup

Post by Nicholas Bianco » Mon Aug 28, 2023 12:10 pm

Ah, sorry -- you need to use the method "packQuaternion".

Code: Select all

pelvisTableQuaternion = pelvisTable.packQuaternion();

User avatar
Nicholas Vandenberg
Posts: 71
Joined: Wed Jan 20, 2021 12:47 pm

Re: Orientation Tracking Setup

Post by Nicholas Vandenberg » Mon Aug 28, 2023 12:18 pm

Gotcha, that makes sense. I'm seeing this now, is it because there's header info or something? Not sure what's still missing.
Attachments
Pel_OTG_err.png
Pel_OTG_err.png (10.8 KiB) Viewed 1598 times

User avatar
Nicholas Bianco
Posts: 1041
Joined: Thu Oct 04, 2012 8:09 pm

Re: Orientation Tracking Setup

Post by Nicholas Bianco » Mon Aug 28, 2023 12:29 pm

You need to provide column labels that have a common pattern so that OpenSim can auto-detect how to pack and name the columns. For quaternions, you could have column labels that end with "_e#", where # = 0, 1, 2, 3. For example: "pelvis_e0", "pelvis_e1", "pelvis_e2", "pelvis_e3". Then you can provide these suffixes (as in the example code above), or let OpenSim try to auto-detect (which it should be able to do after renaming).

POST REPLY