Page 1 of 1

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

Posted: Mon Nov 04, 2024 7:54 am
by wangchang
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.

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

Posted: Tue Nov 05, 2024 2:40 am
by tgeijten
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

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

Posted: Tue Nov 05, 2024 3:47 am
by wangchang
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.

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

Posted: Tue Nov 05, 2024 3:59 am
by wangchang
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

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

Posted: Tue Nov 05, 2024 4:37 am
by wangchang
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

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

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

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

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

Posted: Tue Nov 05, 2024 6:05 am
by wangchang
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

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

Posted: Tue Nov 05, 2024 6:14 am
by wangchang
1

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

Posted: Wed Nov 06, 2024 8:55 am
by tgeijten
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.