Hi Thomas,
Just wondering if there is a way to extract a contact force for use in a script controller. I see in the LuaBody documentation that you can add a contact force, I wondered could I do the opposite and find the value of one already there?
Thanks!
Extracting contact force
- Thomas Geijtenbeek
- Posts: 461
- Joined: Wed Mar 12, 2014 8:08 am
Re: Extracting contact force
Hi Aoife,
You can use the function contact_force() to get the current contact force applied to a body. I just checked and noticed the documentation was incorrect for this function -- I'll fix that immediately.
Let me know if this works!
You can use the function contact_force() to get the current contact force applied to a body. I just checked and noticed the documentation was incorrect for this function -- I'll fix that immediately.
Let me know if this works!
- Aoife Ryan
- Posts: 10
- Joined: Tue Sep 24, 2019 3:23 am
Re: Extracting contact force
Thanks for that Thomas. Just wondering when pulling contact forces for the lower limbs, does the controller retrieve all of the right side contact forces and then all of the left side contact forces or does it alternate from right to left or vice versa?
Thanks for all your help so far,
Aoife
Thanks for all your help so far,
Aoife
- Thomas Geijtenbeek
- Posts: 461
- Joined: Wed Mar 12, 2014 8:08 am
Re: Extracting contact force
That really depends on what type of Controller you are using -- can you provide me a bit more detail on that?
- Aoife Ryan
- Posts: 10
- Joined: Tue Sep 24, 2019 3:23 am
Re: Extracting contact force
I'm using a script controller and attempting to update model parameters using a simple feedback loop.
Also, when I try to call on a contact force (rightpedalcontactforce = R_foot:conact_force()) in the controller I get the error message:
I have tried calling on both the body of interest and the contact geometry associated with it, the same error message appearing in both cases. Do you have any idea how I might fix this?
Also, when I try to call on a contact force (rightpedalcontactforce = R_foot:conact_force()) in the controller I get the error message:
I have tried calling on both the body of interest and the contact geometry associated with it, the same error message appearing in both cases. Do you have any idea how I might fix this?
- Thomas Geijtenbeek
- Posts: 461
- Joined: Wed Mar 12, 2014 8:08 am
Re: Extracting contact force
The following code works for me (using the model from the tutorials, your body names may be different):
Let me know if this helps!
Code: Select all
function init( model, par )
-- find the body from which to get the contact force
right_foot = model:find_body( "calcn_r" )
...
end
function update( model )
-- get the actual contact force
local force = right_foot:contact_force()
scone.debug( "force: " .. force.y )
...
end
- Aoife Ryan
- Posts: 10
- Joined: Tue Sep 24, 2019 3:23 am
Re: Extracting contact force
Thanks for your help with the contact forces, that was very helpful. I am currently working that all right right side contact forces are pulled first, followed by left side contact forces. Could you confirm that this is correct?
Thanks!
Thanks!
- Thomas Geijtenbeek
- Posts: 461
- Joined: Wed Mar 12, 2014 8:08 am
Re: Extracting contact force
Hi Aoife,
I'm not sure what you mean by "first" -- you can fetch the contact forces in any order you want. Can you elaborate?
I'm not sure what you mean by "first" -- you can fetch the contact forces in any order you want. Can you elaborate?