Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip grab saver for unjointed bodies #1484

Merged
merged 9 commits into from
Jan 31, 2025
6 changes: 3 additions & 3 deletions src/libopenrave/kinbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4807,7 +4807,7 @@ void KinBody::_ComputeInternalInformation()
else {
// NOTE: possibly try to choose roots that do not involve mimic joints. ikfast might have problems
// dealing with very complex formulas
LinkPtr plink0 = joint.GetFirstAttached(), plink1 = joint.GetSecondAttached();
const LinkPtr& plink0 = joint.GetFirstAttached(), plink1 = joint.GetSecondAttached();
if( vlinkdepths[plink0->GetIndex()] < vlinkdepths[plink1->GetIndex()] ) {
parentlinkindex = plink0->GetIndex();
}
Expand Down Expand Up @@ -4929,7 +4929,7 @@ void KinBody::_ComputeInternalInformation()
stringstream ss;
ss << GetName() << " closedloop found: ";
FOREACH(itlinkindex,*itclosedloop) {
LinkPtr plink = _veclinks.at(*itlinkindex);
const LinkPtr& plink = _veclinks.at(*itlinkindex);
ss << plink->GetName() << "(" << plink->GetIndex() << ") ";
}
RAVELOG_VERBOSE(ss.str());
Expand Down Expand Up @@ -4974,7 +4974,7 @@ void KinBody::_ComputeInternalInformation()

// breadth first search for rigid links
for(size_t icurlink = 0; icurlink<vattachedlinks.size(); ++icurlink) {
LinkPtr plink=_veclinks.at(vattachedlinks[icurlink]);
const LinkPtr& plink = _veclinks.at(vattachedlinks[icurlink]);
FOREACHC(itjoint, _vecjoints) {
if( (*itjoint)->IsStatic() ) {
if(((*itjoint)->GetFirstAttached() == plink)&& !!(*itjoint)->GetSecondAttached() &&(find(vattachedlinks.begin(),vattachedlinks.end(),(*itjoint)->GetSecondAttached()->GetIndex()) == vattachedlinks.end())) {
Expand Down
22 changes: 17 additions & 5 deletions src/libopenrave/kinbodygrab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,29 @@ Grabbed::Grabbed(KinBodyPtr pGrabbedBody, KinBody::LinkPtr pGrabbingLink)
_pGrabbedBody = pGrabbedBody;
_pGrabbingLink = pGrabbingLink;
_pGrabbingLink->GetRigidlyAttachedLinks(_vAttachedToGrabbingLink);

// If the grabbing body has no joints, then it is effectively a rigid body.
// When calculating non-colliding links, we exclude all links rigidly attached to the grabbing link.
// Since for fully rigid bodies _all_ links are attached, we effectively exclude all links.
// We can therefore skip the non-colliding calculation, along with generating the associated state savers.
KinBodyPtr pGrabber(pGrabbingLink->GetParent());
if (pGrabber->GetJoints().size() + pGrabber->GetPassiveJoints().size() == 0) {
// This body is fully rigid: all links are excluded from the non colliding link set, so just flag that the list is valid (empty) and return.
_listNonCollidingIsValid = true;
return;
}

// if this body is not rigid, then we need to save the current state of the grabber/grabbee so that we can roll back to it when computing the non-colliding links
_listNonCollidingIsValid = false;
const bool bDisableRestoreOnDestructor = true; // This is very important! These saver are used only in ComputeListNonCollidingLinks and we don't want to restore on destructor.
static const int saverOptions = KinBody::Save_LinkTransformation | KinBody::Save_LinkEnable | KinBody::Save_JointLimits;
_CreateSaverForGrabbedAndGrabber(_pGrabbedSaver,
pGrabbedBody,
KinBody::Save_LinkTransformation|KinBody::Save_LinkEnable|KinBody::Save_JointLimits,
saverOptions,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone tries to set velocity of a currently grabbed kinbody, should we reject it because its velocity is determined by the grabbing link? If such guarantee exists that body's velocity doesn't get modified while being grabbed, it is fine to not save at the time of grabbing and restore at the time of releasing. @rdiankov @rschlaikjer

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be okay if velocity is not saved..

bDisableRestoreOnDestructor);

KinBodyPtr pGrabber = RaveInterfaceCast<KinBody>(_pGrabbingLink->GetParent());
_CreateSaverForGrabbedAndGrabber(_pGrabberSaver,
pGrabber,
KinBody::Save_LinkTransformation|KinBody::Save_LinkEnable|KinBody::Save_JointLimits|KinBody::Save_LinkVelocities, // Need to save link velocities of the grabber since will be used for computing link velocities of the grabbed bodies.
saverOptions,
bDisableRestoreOnDestructor);
} // end Grabbed

Expand Down Expand Up @@ -162,7 +174,7 @@ void Grabbed::ComputeListNonCollidingLinks()
KinBodyPtr pGrabbedBody(_pGrabbedBody);
KinBodyPtr pGrabber = RaveInterfaceCast<KinBody>(_pGrabbingLink->GetParent());
KinBody::KinBodyStateSaverPtr pCurrentGrabbedSaver, pCurrentGrabberSaver;
const int defaultSaveOptions = KinBody::Save_LinkTransformation|KinBody::Save_LinkEnable|KinBody::Save_LinkVelocities|KinBody::Save_JointLimits;
const int defaultSaveOptions = KinBody::Save_LinkTransformation|KinBody::Save_LinkEnable|KinBody::Save_JointLimits;
const bool bDisableRestoreOnDestructor = false;
_CreateSaverForGrabbedAndGrabber(pCurrentGrabbedSaver, pGrabbedBody, defaultSaveOptions, bDisableRestoreOnDestructor);
_CreateSaverForGrabbedAndGrabber(pCurrentGrabberSaver, pGrabber, defaultSaveOptions, bDisableRestoreOnDestructor);
Expand Down