Grabbing with force feedback #2615
-
Hi everybody, I'm currently trying to implement grabbing with force feedback inside my plugin and I'm having difficulties. I currently tried 2 methods :
In both of these solution, I get the problem that the Custom grabberThis class makes it easier to grab and ungrab. It is based on the void TrexGrabbingTool::createConstraint()
{
// Add the collision models
this->m_mappers.first.setCollisionModel(this->m_colPair.first.get());
this->m_mappers.second.setCollisionModel(this->m_colPair.second.get());
// Get the mechanical models
auto mmodel1 = this->m_mappers.first.createMapping();
auto mmodel2 = this->m_mappers.second.createMapping();
// Create the constraint
this->m_constraint = sofa::core::objectmodel::New<Constraint>(mmodel1, mmodel2);
this->m_constraint->setName(this->m_name);
this->m_constraint->clear(1);
this->m_mappers.first.resize(1);
this->m_mappers.second.resize(1);
// Get the distance
const double d0 = this->m_intersection->getContactDistance() + this->m_colPair.first->getProximity() +
this->m_colPair.second->getProximity();
// Get the elements
InstrumentColModel::Element elem1((this->m_instrumentIsFirst ? this->m_grabOutput.elem.first : this->m_grabOutput.elem.second));
GrabbableColModel::Element elem2((this->m_instrumentIsFirst ? this->m_grabOutput.elem.second : this->m_grabOutput.elem.first));
int index1 = elem1.getIndex();
int index2 = elem2.getIndex();
SReal r1 = 0.;
SReal r2 = 0.;
// Create mapping for first point
auto pts_instrument = this->m_instrumentIsFirst ? this->m_grabOutput.point[0] : this->m_grabOutput.point[1];
index1 = this->m_mappers.first.addPointB(pts_instrument, index1, r1);
// Create mapping for second point
auto pts_grabbable = this->m_instrumentIsFirst ? this->m_grabOutput.point[1] : this->m_grabOutput.point[0];
index2 = this->m_mappers.second.addPointB(pts_grabbable, index2, r2);
double distance = d0 + r1 + r2;
// Update the mappers
this->m_mappers.first.update();
this->m_mappers.first.updateXfree();
this->m_mappers.second.update();
this->m_mappers.second.updateXfree();
// Add contacts to the constraint
this->m_constraint->addContact(this->m_grabOutput.normal, pts_instrument, pts_grabbable, distance, index1, index2, pts_instrument, pts_grabbable, 0, this->m_grabOutput.id);
// Add the constraint to the simulation
this->m_context->addObject(this->m_constraint);
}
void TrexGrabbingTool::removeConstraint()
{
// Resize the mappers
this->m_mappers.first.resize(0);
this->m_mappers.second.resize(0);
// Remove the constraint from the simulation
this->m_context->removeObject(this->m_constraint);
} Custom ContactManagerCurrently, the implementation of the std::string TrexContactManager::getContactResponse(sofa::core::CollisionModel *model1, sofa::core::CollisionModel *model2)
{
/// Get the tags from the models
sofa::core::objectmodel::TagSet tags = this->getTags(model1, model2);
/// If a contact is between an instrument and a grabbable model, return a StickContact
if ((tags.includes(this->m_tagsTrex) && this->d_grabbing.getValue()(0)) ||
(tags.includes(this->m_tagsDummy) && this->d_grabbing.getValue()(1)))
{
return "StickContactConstraint";
}
else
{
return this->response.getValue().getSelectedItem();
}
} Questions
UsingSofa: v21.06 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
Hey @BrunoB81HK As I wrote you in our private emails preceding your post, this is a very interesting ContactManager that you are looking at. It would interest many devs in the community. I never implemented myself a custom contact manager. I hope other devs can help. @younesssss maybe ? |
Beta Was this translation helpful? Give feedback.
-
Hey @BrunoB81HK Sorry for our latency. Second, you are pointing out a second issue : [ERROR] [MechanicalObject(#13#01%3$69!%$!)] Invalid vOp operation 1 (null(V_DERIV),0(0),null(V_DERIV),100) this can also be observed in other scene with the mouse mode (MouseManager) "attach objects with a bilateral constraint" aka Thanks a lot for your efforts and your report Bruno-Pier ! |
Beta Was this translation helpful? Give feedback.
Hey @BrunoB81HK
Sorry for our latency.
EDIT
The issue you noticed regarding the weird behavior of the constraint, especially in some space direction is actually not due to the
BilateralInteractionConstraint
iteself, but as pointed out by @younesssss by the fact that theLCPConstraintSolver
is built and optimized for contacts, aka Unilateral constraints. The GenericConstraintSolver should be used when other constraints than UnilateralInteractionConstraint are used.Second, you are pointing out a second issue :
[ERROR] [MechanicalObject(#13#01%3$69!%$!)] Invalid vOp operation 1 (null(V_DERIV),0(0),null(V_DERIV),100)
this can also be observed in other scene with the mouse mode (MouseManage…