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
Access leg state in Lua
- Thomas Geijtenbeek
- Posts: 451
- Joined: Wed Mar 12, 2014 8:08 am
Re: Access leg state in Lua
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!
Let me know if this helps!
- Nathan Timmers
- Posts: 12
- Joined: Thu Apr 04, 2019 11:10 am
Re: Access leg state in Lua
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?
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?
- Thomas Geijtenbeek
- Posts: 451
- Joined: Wed Mar 12, 2014 8:08 am
Re: Access leg state in Lua
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
- Nathan Timmers
- Posts: 12
- Joined: Thu Apr 04, 2019 11:10 am
Re: Access leg state in Lua
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.
- Thomas Geijtenbeek
- Posts: 451
- Joined: Wed Mar 12, 2014 8:08 am
Re: Access leg state in Lua
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.
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.