Page 1 of 1

GeneralContactSubsystem

Posted: Wed Jun 19, 2024 9:13 am
by andreabraschi
Hi all,

I have a Simbody question:

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

Re: GeneralContactSubsystem

Posted: Fri Jul 26, 2024 10:12 am
by nbianco
Hi Andrea,

I don't think that the GeneralContactSubsystem::getContacts() method is returning what you mean by "the location of the different points of contact between 2 ContactGeometry objects". Rather, it returns an array of Simbody Contact objects, which is something different.

I think you want to use ContactGeometry directly to determine whether or not two bodies are in contact. You could look at the source code for HuntCrossleyForce in Simbody to see how forces are calculated. There's really only one true contact point for this model, as you will see.

Best,
Nick