access some of the states of the leg in a lua script

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
chang wang
Posts: 8
Joined: Thu Mar 21, 2024 7:54 am

access some of the states of the leg in a lua script

Post by chang wang » Mon Nov 04, 2024 7:54 am

Hi, how can I access some of the states of the leg in a lua script, such as gait phase, load, etc.? I recently tried to implement Song's article[1] in SCONE again and found that I can't go to fully implement it according to GaitStateConreoller, so I would like to implement it using lua script, thanks a lot.
[1] S. Song,H. Geyer, A neural circuitry that emphasizes spinal feedback generates diverse behaviours of human locomotion, The Journal of Physiology,doi: 10.1113/JP270228.

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

Re: access some of the states of the leg in a lua script

Post by Thomas Geijtenbeek » Tue Nov 05, 2024 2:40 am

The states are computed in the GaitStateController, so if you'd like the additional states from the Song controller then you'd have to implement the state transitions yourself.

Please note that you can still use normal ReflexController instances as children of your ScriptController (just like with the GaitStateController). You can enable/disable them depending on the state computed in your Lua script. For more information, see:

https://scone.software/doku.php?id=ref:lua_controller

User avatar
chang wang
Posts: 8
Joined: Thu Mar 21, 2024 7:54 am

Re: access some of the states of the leg in a lua script

Post by chang wang » Tue Nov 05, 2024 3:47 am

tgeijten wrote:
Tue Nov 05, 2024 2:40 am
The states are computed in the GaitStateController, so if you'd like the additional states from the Song controller then you'd have to implement the state transitions yourself.

Please note that you can still use normal ReflexController instances as children of your ScriptController (just like with the GaitStateController). You can enable/disable them depending on the state computed in your Lua script. For more information, see:

https://scone.software/doku.php?id=ref:lua_controller
Yes, but I read the user documentation and found that the leg loads are not accessible in the lua script. Thanks for answering my question.

User avatar
chang wang
Posts: 8
Joined: Thu Mar 21, 2024 7:54 am

Re: access some of the states of the leg in a lua script

Post by chang wang » Tue Nov 05, 2024 3:59 am

tgeijten wrote:
Tue Nov 05, 2024 2:40 am
The states are computed in the GaitStateController, so if you'd like the additional states from the Song controller then you'd have to implement the state transitions yourself.

Please note that you can still use normal ReflexController instances as children of your ScriptController (just like with the GaitStateController). You can enable/disable them depending on the state computed in your Lua script. For more information, see:

https://scone.software/doku.php?id=ref:lua_controller
Can you please see if I'm doing the right thing? Thank you very much.
In the two-dimensional case,
calcn_l = model:find_body( "calcn_l" )
grf.y = calcn_l:contact_force()
load_l = grf.y/gravity

User avatar
chang wang
Posts: 8
Joined: Thu Mar 21, 2024 7:54 am

Re: access some of the states of the leg in a lua script

Post by chang wang » Tue Nov 05, 2024 4:37 am

tgeijten wrote:
Tue Nov 05, 2024 2:40 am
The states are computed in the GaitStateController, so if you'd like the additional states from the Song controller then you'd have to implement the state transitions yourself.

Please note that you can still use normal ReflexController instances as children of your ScriptController (just like with the GaitStateController). You can enable/disable them depending on the state computed in your Lua script. For more information, see:

https://scone.software/doku.php?id=ref:lua_controller
Thanks a lot, I just found the source code for scone on github, found the relevant calculations, and implemented and verified the results in a lua script.

calcn_l = model:find_body( "calcn_l" )
grf_test = calcn_l:contact_force()
model_bw = model:mass() * math.sqrt(model:gravity().x^2 + model:gravity().y^2 + model:gravity().z^2)
leg_load_0 = math.sqrt(grf_test.x^2 + grf_test.y^2 + grf_test.z^2)
leg_load = leg_load_0 / model_bw

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

Re: access some of the states of the leg in a lua script

Post by Thomas Geijtenbeek » Tue Nov 05, 2024 5:29 am

Great, that looks correct.

Please note that you can also simply use grf_test:length() and gravity():length() to the lengths of these vectors.

User avatar
chang wang
Posts: 8
Joined: Thu Mar 21, 2024 7:54 am

Re: access some of the states of the leg in a lua script

Post by chang wang » Tue Nov 05, 2024 6:05 am

tgeijten wrote:
Tue Nov 05, 2024 5:29 am
Great, that looks correct.

Please note that you can also simply use grf_test:length() and gravity():length() to the lengths of these vectors.
I have another question why my calculated and analyzed windows are not equal?
calcn_l = model:find_body( "calcn_l" )
foot_com = calcn_l:com_pos().x
model_com = model:com_pos().x
pelvis_com = target_body:com_pos().x
leg_sagittal_pos_0 = foot_com - model_com
leg_sagittal_pos_1 = foot_com - pelvis_com

User avatar
chang wang
Posts: 8
Joined: Thu Mar 21, 2024 7:54 am

Re: access some of the states of the leg in a lua script

Post by chang wang » Tue Nov 05, 2024 6:14 am

1
Attachments
1730811887647.png
1730811887647.png (49.26 KiB) Viewed 266 times

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

Re: access some of the states of the leg in a lua script

Post by Thomas Geijtenbeek » Wed Nov 06, 2024 8:55 am

I looked into it, and it appears that "target_body" in your example is actually the torso and not the pelvis. If I replace target_body with the pelvis body, the sagittal positions become identical to those from the GaitStateController.

POST REPLY