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: 11
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: 800
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

POST REPLY