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.
User avatar
Nicholas Bianco
Posts: 1003
Joined: Thu Oct 04, 2012 8:09 pm

Re: Orientation Tracking Setup

Post by Nicholas Bianco » Tue Dec 12, 2023 10:38 am

Hi Nick,

The you wrote the file 'TFAB_02_SSWlk08_Pelvis_Quat.sto' with type TimeSeriesTableQuaternion, but now you are trying to load it in again as a regular TimeSeriesTable on this line:

Code: Select all

pelvisTable = TimeSeriesTable('TFAB_02_SSWlk08_Pelvis_Quat.sto');
Either load it as a TimeSeriesTableQuaternion directly, or save the file as a TimeSeriesTable and pack it to a Quaternion type as you are doing now.

Best,
Nick

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

Re: Orientation Tracking Setup

Post by Nicholas Vandenberg » Wed Dec 13, 2023 10:49 am

Hey Nick,

Yup that makes a lot of sense. I've updated to the following:

Code: Select all

pelvisGoal = MocoOrientationTrackingGoal('pelvisGoal',20);
pelvisTable = TimeSeriesTableQuaternion('TFAB_02_SSWlk08_Pelvis_Quat.sto');
pelvisGoal.setRotationReference(pelvisTable);
pel_paths = StdVectorString();
pel_paths.add('/bodyset/pelvis');
pelvisGoal.setFramePaths(pel_paths);
problem.addGoal(pelvisGoal);
which at least gets me sorta started, I'm running into some kind of Frame error now though.
Screenshot 2023-12-12 110321.png
Screenshot 2023-12-12 110321.png (15.18 KiB) Viewed 1003 times
Is there some way that I'm setting up the orientation tracking incorrectly? I tried referencing the code that Ross shared which utilizes a MocoOrientationTrackingGoal to maintain an upright torso, but that's using a states reference as opposed to the rotation reference I'm trying to implement. Am I missing a syntax change?

Thanks,
Nick

User avatar
Ross Miller
Posts: 372
Joined: Tue Sep 22, 2009 2:02 pm

Re: Orientation Tracking Setup

Post by Ross Miller » Wed Dec 13, 2023 11:46 am

My response won't be very helpful sorry, but just some background: the reason I used setStateReference instead of setRotationReference was because I could never figure out how to get setRotationReference to work. I wanted to minimize the angular motion of the torso in the global frame, but because the torso angles aren't states in the model, I couldn't do that with MocoTrack. Using setRotationReference in MocoOrientationTrackingGoal seemed like the most straightforward approach (just create a file with all the torso rotations set to zero) but the code wouldn't run. I don't remember if I got the same error Nick is reporting, was several years ago. So instead I made a state reference file that had all the pelvis and lumbar angles (states) set to zero, which indirectly gives torso angles of zero in the global frame, and that worked (the code ran).

Nick, what does your .sto file for the rotation references look like? The documentation says "The column labels of the provided reference must be paths to frames in the model, e.g. /bodyset/torso". Does it have that? It's unclear to me how that would be used to specify quaternions (or Euler angles or whatever) since they are 4-D (seems like there should be four columns, not one). Maybe the "states" vs. "rotations" distinction is the issue here? In your model I assume the pelvis angles are states.

Ross

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

Re: Orientation Tracking Setup

Post by Nicholas Bianco » Wed Dec 13, 2023 12:03 pm

Hi Nick,

That should work. Is it possible the pelvis body has a different name in your model, or is at a different path (e.g., '/pelvis'). The error here is more related to OpenSim modeling than Moco.

If you don't mind sending over your model I could take a closer look.

-Nick

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

Re: Orientation Tracking Setup

Post by Nicholas Vandenberg » Wed Dec 13, 2023 12:29 pm

Ross,
Thanks for your response and for sharing your Moco work on here, it's been extremely helpful as I've been working on my own projects and I greatly appreciate it. That makes a lot of sense with the way you set up your goal, and yes the pelvis angles are states in my model. Unfortunately I forgot I cant upload .sto's (see pic), but my rotation reference only has a time column and a 'pelvis' column that has a 4 number array. Since I created it as a quaternion table I assumed it was formatted correctly, but I could be mistaken?
Pel_Quat_RotRef.png
Pel_Quat_RotRef.png (47.19 KiB) Viewed 958 times
Nick,
That makes sense, and along with Ross' response it may be something I need to change in the conversion code to output as 'bodyset/pelvis' instead of simply 'pelvis' for the correct referencing. I've included the model I've been using though.
TFAB02_AMCOI01_11Con.osim
(670.91 KiB) Downloaded 76 times
Thanks to you both,
Nick

User avatar
Ross Miller
Posts: 372
Joined: Tue Sep 22, 2009 2:02 pm

Re: Orientation Tracking Setup

Post by Ross Miller » Wed Dec 13, 2023 2:58 pm

I think the header in the file probably just needs to say bodyset/pelvis

You can thank Brian, Nick, and Chris for most of the code I paste here, they indirectly wrote ~ half of it!

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

Re: Orientation Tracking Setup

Post by Nicholas Vandenberg » Wed Dec 13, 2023 3:24 pm

Yeah, just tried that out and that was all it needed. Got it running now, we'll see how it does!

Thanks again everyone!

POST REPLY