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);
Many thanks in advance for the help.
Andrea