Access leg state in Lua

SCONE is a software tool for predictive simulations of biomechanical movement. It uses OpenSim for modeling and simulation, and performs optimization using various control strategies, including feed-forward control, proprioceptic feedback control, and bal
POST REPLY
User avatar
Nathan Timmers
Posts: 12
Joined: Thu Apr 04, 2019 11:10 am

Access leg state in Lua

Post by Nathan Timmers » Mon Mar 02, 2020 4:12 am

Hi Thomas,

I was wondering if it is possible to access the leg state in Lua, because the leg is not a body that you can access.
The reason of asking is that I want a specific part of my code to work only during certain phases of the gait.

Kind regards,
Nathan

User avatar
Thomas Geijtenbeek
Posts: 451
Joined: Wed Mar 12, 2014 8:08 am

Re: Access leg state in Lua

Post by Thomas Geijtenbeek » Mon Mar 02, 2020 1:57 pm

The leg state is something that's calculated in GaitStateController and not available in other controllers. You could, however, compute your own state based on the ground reaction force and the relative sagittal position. Alternatively, you can make your controller part of a ConditionalController in GaitStateController, which then automatically gets activated only during specific states. See the file data/ControllerGH2010.scone for details on how that works.

Let me know if this helps!

User avatar
Nathan Timmers
Posts: 12
Joined: Thu Apr 04, 2019 11:10 am

Re: Access leg state in Lua

Post by Nathan Timmers » Tue Mar 03, 2020 12:58 am

Computing my own state is indeed what I did first and that works great, but I thought that it would be nice if it could be accessed.

Making the controller part of the GaitStateController is a nice way of implementing as well. Just one thing I was wandering, are the global variables declared in that controller file accessible through other Lua scripts? Or are the Lua files executed through different processes on the processor?

User avatar
Thomas Geijtenbeek
Posts: 451
Joined: Wed Mar 12, 2014 8:08 am

Re: Access leg state in Lua

Post by Thomas Geijtenbeek » Tue Mar 03, 2020 6:31 am

Lua scripts that run in separate ScriptController or ScriptMeasure instances indeed do not have access to each other's data -- this is done so that everything is modular and without side effects. So far, I haven't seen a use case for which this would be necessary, but I'm always open to suggestions ;)

User avatar
Nathan Timmers
Posts: 12
Joined: Thu Apr 04, 2019 11:10 am

Re: Access leg state in Lua

Post by Nathan Timmers » Tue Mar 03, 2020 8:50 am

I was thinking more in terms of separate ScriptControllers during different phases of the gait. Do they also not have any access to each other's data? I am not sure whether I really need it, but just out of curiosity so that I know what is possible.

User avatar
Thomas Geijtenbeek
Posts: 451
Joined: Wed Mar 12, 2014 8:08 am

Re: Access leg state in Lua

Post by Thomas Geijtenbeek » Tue Mar 03, 2020 12:00 pm

Each ScriptController has its own data, and can't access data from other ScriptControllers.

On a side note, the upcoming release (1.4.0) will support the use of multiple lua files in a single script trough 'require', so that may be useful too.

POST REPLY