MocoAccelerationTrackingGoal & MocoAngularVelocityTrackingGoal Failing to Transfer Reference DataTable to Solver

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
Owen Pearl
Posts: 5
Joined: Thu Oct 01, 2020 7:58 am

MocoAccelerationTrackingGoal & MocoAngularVelocityTrackingGoal Failing to Transfer Reference DataTable to Solver

Post by Owen Pearl » Tue Sep 27, 2022 11:22 am

Hi,

My name is Owen. I hope you are all doing well!

I have been messing around with tracking some higher order terms through the MATLAB scripting environment with MOCO's API, and haven't been able to find a file type/format or TimeSeriesTableVec3 that either the MocoAccelerationTrackingGoal or the MocoAngularVelocityTrackingGoal can load without running into the following error:

Java exception occurred:
java.lang.RuntimeException: Invalid Argument. DataTable 'that' has zero
rows/columns.
Thrown at DataTable.h:178 in DataTable_().


I have tried using the SetAccelerationReferenceFile with .trc files formatted to read properly as a TimeSeriesTableVec3, as well as .sto files that are formatted other ways. I have also tried to manually create a TimeSeriesTableVec3 to make sure that the column labels are correct and there isn't any issue on the file reading side.

In both circumstances (loading the .trc and loading the manual TimeSeriesTableVec3), somewhere in the transition the solver drops the ball on transferring the references and they end up empty. Could you possibly provide an example file or .sto for which the formatting of the acceleration and angular velocity references can load properly via MATLAB? I also find that the documentation on these goals is quite vague, since I haven't seen another context besides marker files where a file is read directly into a vec3 table. The documentation also doesn't specifically say it has to be able to do that either, or whether there can be one column per 3 entries, etc. More details on the formatting will probably be necessary here so users can implement those methods properly.

Let me know if you need more info or if you have a sufficient understanding of the predicament.

Thanks so much for the help :D
Owen

Code snippet just so people understand what I am describing above:
accelTracking = org.opensim.modeling.MocoAccelerationTrackingGoal('accel_tracking');
accelTracking.setAccelerationReference(accelTimeSeriesTableVec3);
accelTracking.setWeight(10);
problem.addGoal(accelTracking);

angVelTracking = org.opensim.modeling.MocoAngularVelocityTrackingGoal('angvel_tracking');
angVelTracking.setAngularVelocityReference(angvelTimeSeriesTableVec3);
angVelTracking.setWeight(10);
problem.addGoal(angVelTracking);

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

Re: MocoAccelerationTrackingGoal & MocoAngularVelocityTrackingGoal Failing to Transfer Reference DataTable to Solver

Post by Nicholas Bianco » Tue Sep 27, 2022 12:05 pm

Hi Owen,

Could you try setting the 'frame_paths' property (using setFramePaths, as in this example). Leaving 'frame_paths' empty should select all the columns in the data by default, but I suspect there might be a bug here.

-Nick

User avatar
Owen Pearl
Posts: 5
Joined: Thu Oct 01, 2020 7:58 am

Re: MocoAccelerationTrackingGoal & MocoAngularVelocityTrackingGoal Failing to Transfer Reference DataTable to Solver

Post by Owen Pearl » Tue Sep 27, 2022 1:58 pm

Nick,

Thank you so much for the super speedy reply and for pointing to that helpful example. I followed the example more closely and got things working. I think the issue was that my pathing was a bit strange because I was trying to access a PhysicalOffsetFrame in a weld joint rather than in a body.

So, in the end it is appearing the setReferenceFile methods are working as desired :) I'll follow up on this later when I stress test it. If my current understanding is correct that means that a provided reference file would have to be in a format similar to what is normally done for markers files.

Thanks again so much for the help! Regardless, your comment helped me get things working properly so I really appreciate it.

Sincerely,
Owen

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

Re: MocoAccelerationTrackingGoal & MocoAngularVelocityTrackingGoal Failing to Transfer Reference DataTable to Solver

Post by Nicholas Bianco » Wed Sep 28, 2022 9:30 am

Hi Owen,

You're welcome!
If my current understanding is correct that means that a provided reference file would have to be in a format similar to what is normally done for markers files.
Not sure exactly what you mean, but as long as the columns in the reference file have labels that match paths to components in the model that have body accelerations, then you should be fine.

-Nick

User avatar
Mikayla Schneider
Posts: 6
Joined: Mon Aug 30, 2021 5:35 pm

Re: MocoAccelerationTrackingGoal & MocoAngularVelocityTrackingGoal Failing to Transfer Reference DataTable to Solver

Post by Mikayla Schneider » Tue Apr 02, 2024 1:56 pm

Hello! Thank you all so much for your hard work on Moco.

I am joining this thread because I have a very similar question and Owen's setup of the problem was very clear. However, I am a step further behind Owen and am struggling to figure out the format for acceleration reference data. I am trying to create fabricated zero acceleration reference data to constrain the motion of a torso but have not been able to create a .sto or .trc file that is accepted by the "setAccelerationReferenceFile" command.

Below is a snippet of my code. I am trying to add an IMU frame at zero offset and (0,0,0) reference coordinate system and then track fabricated reference data that is essentially an acceleration of (0,0,0) for the entire time series. I also looked at the forum thread from Grace M titled "Fabricating and tracking IMU signals," which is where I got the basic format for the "imu_tracking.sto" file that I also attached (the .txt ending is only so I could save it and upload here). The error I am currently getting is pasted below-- essentially DataType:Quaternion is not recognized. If you have any advice on how to format acceleration reference data or an example file, that would be greatly appreciated.


% Acceleration Tracking
addIMUFrame(model, 'torso', Vec3(0, 0, 0), Vec3(0, 0, 0));
imuFramePaths = StdVectorString();
imuFramePaths.add('/bodyset/torso/torso_imu_offset');
OpenSenseUtilities().addModelIMUs(model, imuFramePaths);
model.initSystem();

tracking = MocoAccelerationTrackingGoal('acceleration_tracking');
tracking.setFramePaths(imuFramePaths);
tracking.setAccelerationReference("imu_tracking.sto");
tracking.setGravityOffset(false);
tracking.setExpressAccelerationsInTrackingFrames(false);
problem.addGoal(tracking);


Java exception occurred:
java.lang.RuntimeException: Datatype 'Quaternion ' is not supported.
Thrown at STOFileAdapter.cpp:77 in createSTOFileAdapterForReading().

at org.opensim.modeling.opensimMocoJNI.MocoSolver_resetProblem(Native Method)

at org.opensim.modeling.MocoSolver.resetProblem(MocoSolver.java:72)
Attachments
imu_tracking.sto.txt
(4.48 KiB) Downloaded 82 times

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

Re: MocoAccelerationTrackingGoal & MocoAngularVelocityTrackingGoal Failing to Transfer Reference DataTable to Solver

Post by Nicholas Bianco » Wed Apr 03, 2024 9:46 am

Hi Mikayla,

You're trying to use MocoAccelerationTrackingGoal which accepts a TimeSeriesTableVec3, so tables constructed using type Quaternion won't be supported (the format from the other thread by Grace M was probably for MocoOrientationTrackingGoal, which does support Quaternion types).

Try constructing a TimeSeriesTableVec3 for your reference zero acceleration (i.e., columns of Vec3 types) and try that instead.

-Nick

POST REPLY