Page 1 of 1

Extracting contact force

Posted: Mon Jan 27, 2020 4:29 am
by aoiferyan
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!

Re: Extracting contact force

Posted: Mon Jan 27, 2020 8:10 am
by tgeijten
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!

Re: Extracting contact force

Posted: Mon Feb 03, 2020 4:37 am
by aoiferyan
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

Re: Extracting contact force

Posted: Mon Feb 03, 2020 4:44 am
by tgeijten
That really depends on what type of Controller you are using -- can you provide me a bit more detail on that?

Re: Extracting contact force

Posted: Mon Feb 03, 2020 5:48 am
by aoiferyan
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:
SC.JPG
SC.JPG (17.7 KiB) Viewed 1052 times
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?

Re: Extracting contact force

Posted: Mon Feb 03, 2020 7:45 am
by tgeijten
The following code works for me (using the model from the tutorials, your body names may be different):

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
Let me know if this helps!

Re: Extracting contact force

Posted: Thu Feb 20, 2020 4:49 am
by aoiferyan
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!

Re: Extracting contact force

Posted: Thu Feb 20, 2020 5:13 am
by tgeijten
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?