Extracting contact force

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
Aoife Ryan
Posts: 10
Joined: Tue Sep 24, 2019 3:23 am

Extracting contact force

Post by Aoife Ryan » Mon Jan 27, 2020 4:29 am

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!

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

Re: Extracting contact force

Post by Thomas Geijtenbeek » Mon Jan 27, 2020 8:10 am

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!

User avatar
Aoife Ryan
Posts: 10
Joined: Tue Sep 24, 2019 3:23 am

Re: Extracting contact force

Post by Aoife Ryan » Mon Feb 03, 2020 4:37 am

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

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

Re: Extracting contact force

Post by Thomas Geijtenbeek » Mon Feb 03, 2020 4:44 am

That really depends on what type of Controller you are using -- can you provide me a bit more detail on that?

User avatar
Aoife Ryan
Posts: 10
Joined: Tue Sep 24, 2019 3:23 am

Re: Extracting contact force

Post by Aoife Ryan » Mon Feb 03, 2020 5:48 am

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 1054 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?

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

Re: Extracting contact force

Post by Thomas Geijtenbeek » Mon Feb 03, 2020 7:45 am

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!

User avatar
Aoife Ryan
Posts: 10
Joined: Tue Sep 24, 2019 3:23 am

Re: Extracting contact force

Post by Aoife Ryan » Thu Feb 20, 2020 4:49 am

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!

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

Re: Extracting contact force

Post by Thomas Geijtenbeek » Thu Feb 20, 2020 5:13 am

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?

POST REPLY