Coordinate driven force application

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
Evan Dooley
Posts: 33
Joined: Sun Nov 24, 2019 11:17 am

Coordinate driven force application

Post by Evan Dooley » Tue Mar 08, 2022 11:01 am

Hello,

I was wondering if anyone has any experience (or recommendations) about a way to use coordinate information to drive a force in your model. I want to try and apply a force to the model on a coordinate that is different from the coordinate I am tracking.

Looking around, I found "ExpressionBasedCoordinateForce" but this only allows the force applied be a function of the coordinate the force is applied to. The same thing happens with "CoordinateLimitForce". "ExpressionBasedPointToPointForce" only uses the distance between the points in the expression.

Ultimately, I am trying to simulate different assistance forces in Moco that are patterned with the gait cycle of the person. We can reliably determine where the person is in the gait cycle by different joint angles, and I want to try and only apply force relative to portions of the gait cycle.

Any advice or ideas would be greatly appreciated.

Thanks,
Evan

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

Re: Coordinate driven force application

Post by Nicholas Bianco » Wed Mar 09, 2022 1:01 pm

Hi Evan,

Unfortunately there's no force component to do what you're asking. It sounds like you need some sort of controller, but I don't think that type of controller exists in OpenSim, and Moco doesn't support controllers at the moment anyway.

If you're tracking kinematic data you should know the time point when the model is in a certain configuration where you want to apply a force. Unless I'm not understanding your problem correctly?

-Nick

User avatar
Evan Dooley
Posts: 33
Joined: Sun Nov 24, 2019 11:17 am

Re: Coordinate driven force application

Post by Evan Dooley » Wed Mar 09, 2022 1:12 pm

Thanks Nick.

I was also thinking about using knowledge of where the kinematics should be to time when forces should be applied, and then write and external loads file to do that. However, I am trying to let the simulation be loose enough that the motion could vary a little bit to react to the applied force, so the timings for the future events may differ from those known at the start.

I appreciate your insight, as always.

Best,
Evan

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

Re: Coordinate driven force application

Post by Nicholas Bianco » Wed Mar 09, 2022 1:54 pm

Ah, gotcha. That would definitely be cool and useful to my research as well. But yeah, not sure when we'll support such a thing.

User avatar
Aaron Fox
Posts: 289
Joined: Sun Aug 06, 2017 10:54 pm

Re: Coordinate driven force application

Post by Aaron Fox » Wed Mar 09, 2022 3:07 pm

Hi Evan,

I'm not exactly sure whether this will fit your needs, but it might provide some guidance on how to get there. In this project - https://simtk.org/projects/gh-caps-sims - I modified the expression based coordinate force to take the input of two coordinates in the calculation of the force it applies. This wasn't too difficult, it was just a matter of having the force connect to the two coordinates, rather than one to write the expression. You could equally just re-write this to only use the secondary coordinate in the force calculations.

Aaron

User avatar
Evan Dooley
Posts: 33
Joined: Sun Nov 24, 2019 11:17 am

Re: Coordinate driven force application

Post by Evan Dooley » Mon Mar 14, 2022 10:41 am

Hi Aaron,

This is awesome! I've been working on implementing it and noticed in the function "ShoulderCapsulorrhaphySims_3_CreateModels" you call a model file that has the DualEBCF object already in the force list, then it looks like you use your own method to update the parameters of the object and write it to an XML OSIM file then use that file to generate your model in Matlab.

For other force objects we can call things like newforce = CoordinateLimitForce(); then update the parameters as newforce.setCoordinate('knee_angle') etc. Is there anyway to access the DualEBCF object from Matlab? Or is this further implementation that would need to be done on the C++ level of the plugin?

Thanks for your help!

Best,
Evan

User avatar
Aaron Fox
Posts: 289
Joined: Sun Aug 06, 2017 10:54 pm

Re: Coordinate driven force application

Post by Aaron Fox » Mon Mar 14, 2022 3:19 pm

Hi Evan,

I think the 'shortcut' approach I used is the only way to work with plugins in Matlab unless you rebuild OpenSim from source with your plugins included. That wasn't something I was going to put the effort in for the use of a simple plugin like this, so I figured using the XML functionality to help do the leg-work was the most suitable way to go about it.

Aaron

User avatar
Evan Dooley
Posts: 33
Joined: Sun Nov 24, 2019 11:17 am

Re: Coordinate driven force application

Post by Evan Dooley » Tue Mar 15, 2022 8:06 am

Cool! That totally makes sense. For my application, I think that implementing it in the XML also makes the most sense, especially at the start.

Thanks for your help. I've got this for the citation: https://pubmed.ncbi.nlm.nih.gov/33241584/ , let me know if you would prefer something else. The readme has the paper citation left as a todo.

Best,
Evan

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

Re: Coordinate driven force application

Post by Ross Miller » Tue Mar 15, 2022 8:29 am

To my knowledge, building the application from the source code is the only way to get something like this accessible from Matlab. The XML approach is a great solution, I didn't know that worked without a rebuild.

I do as much as possible in XML but mostly just because I'm not very good with C++.

It would be great if there was "ExpressionBasedCostFunction" that we could enter via XML!

Ross

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

Re: Coordinate driven force application

Post by Nicholas Bianco » Wed Mar 16, 2022 10:22 am

Hey guys,

To confirm Ross and Aaron's thoughts: yes, you would need to modify the OpenSim "bindings", the code that converts C++ to scripting languages, and then rebuild the source to access the class in Matlab.

Ross, I've been thinking about an ExpressionBasedCostFunction! I don't see any reason why it wouldn't work.

-Nick

POST REPLY