GeneralContactSubsystem

Simbody is useful for internal coordinate and coarse grained molecule modeling, large scale mechanical models like skeletons, and anything else that can be modeled as bodies interconnected by joints, acted upon by forces, and restricted by constraints.
POST REPLY
User avatar
Andrea Braschi
Posts: 14
Joined: Thu Mar 11, 2021 2:42 am

GeneralContactSubsystem

Post by Andrea Braschi » Wed Jun 19, 2024 10:05 am

Hi all,

I have posted the following post on the OpenSim forum, before realising that this migh be the appropriate forum:

I am trying to write a custom HuntCrossleyForce class that can potentially output the location of the different points of contact between 2 ContactGeometry objects. I have seen in the Simbody implementation of the HuntCrossleyForce (https://github.com/simbody/simbody/blob ... yForce.cpp, line 103) that this is possible via the GeneralContactSubsystem object which has the getContacts method that, according to the corresponding header file, gives you "a list of all contacts between bodies in a contact set.". Am I wrong? However, I am struggling to use such method. I get an error at runtime. I was wondering if someone is familiar with the overall class itself or has had any experience with getting the list of contact at a given state?

Currently, this is the implementation that I am doing based on the instructions that are found in the source code and header file:

Code: Select all

const State& s = model.initSystem();

// Create a GeneralContactSubsystem
model.realizeDynamics(s);
SimTK::MultibodySystem& system = model.updMultibodySystem();
std::cout << "\n" + s.getSystemStage().getName();
GeneralContactSubsystem contact = GeneralContactSubsystem(system);


// Add body1
ContactSetIndex setIndex = contact.createContactSet();
contact.addBody(setIndex, mobilizedBody, simTK_sphere, sphere1_transform);


// Add body2
//ContactSetIndex secondIndex = contact.createContactSet();
contact.addBody(setIndex, _mobilizedBody, _simTK_sphere, sphere2_transform);


// Get Contacts
if (!contact.isInSystem())
	std::cout << "\nContact isn't in system";
const Array_<Contact>& contacts = contact.getContacts(s, setIndex);
I believe I have created the GeneralContactSubsystem class correctly as I am able to use all the other methods of it. Anyone can spot some clear mistake in the use of the getContacts method?

Many thanks in advance for the help.

Andrea

User avatar
Michael Sherman
Posts: 807
Joined: Fri Apr 01, 2005 6:05 pm

Re: GeneralContactSubsystem

Post by Michael Sherman » Mon Jun 24, 2024 6:15 pm

Hi, Andrea.

The entire System (including all its Subsystems) needs to be built before any computations are done. It looks like you are adding a Subsystem later, would be good to get that sorted out (might not be the problem but could cause trouble). Also, the GeneralContactSubsystem is old and superseded by the ContactTracker and CompliantContact subsystems (the old one should still work though). Take a look at ExampleContactPlayground. Switching to the more recent code might get you what you need.

Regards,
Sherm

User avatar
Andrea Braschi
Posts: 14
Joined: Thu Mar 11, 2021 2:42 am

Re: GeneralContactSubsystem

Post by Andrea Braschi » Thu Jul 11, 2024 2:44 am

Hi Sherm,

many thanks for getting back to me and apologies for my slow reply.

The main reason why I was playing around with the GeneralContactSubsystem is because I saw that implemented in the HuntCrossleyForce source code. Furthermore, I liked the getContacts method that I could potentially use to extract the point of force application.

However, having a first look, it seems that the getContactForce() method from the ContactForce class will do the job equally!

Thanks for letting me know the newer versions of the contact subsystem objects and how these should be implemented to get them to work! I will keep you updated as I get on.

Best,
Andrea

POST REPLY