-
Notifications
You must be signed in to change notification settings - Fork 342
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
Fix bugs for grabbed self col checking due to asymmetricity and unordered-ness. #1438
base: production
Are you sure you want to change the base?
Changes from all commits
2198a21
0cd3346
a942ee1
d7b510e
8fdf9eb
042243f
a8839a2
7841daf
61dc5dc
c3e9253
d8dcfeb
2bdbdb3
4645c51
78088f7
21b37e5
bb7cc24
9270541
2856b8d
f5a663d
16bd21f
0ae0e0e
fa2cc0c
e21a2e7
8bf75a0
e7cd291
05c9441
d9f6275
d8a7d4f
35fc6f9
b1599de
179f48e
f6f4f50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2438,6 +2438,9 @@ class OPENRAVE_API KinBody : public InterfaceBase | |||||||||||||||||||||||||||
typedef boost::shared_ptr<KinBodyInfo> KinBodyInfoPtr; | ||||||||||||||||||||||||||||
typedef boost::shared_ptr<KinBodyInfo const> KinBodyInfoConstPtr; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/// \brief Alias for list of non-colliding link pairs, mostly used for Grabbed checking. | ||||||||||||||||||||||||||||
using ListNonCollidingLinkPairs = std::list<std::pair<KinBody::LinkConstPtr, KinBody::LinkConstPtr> >; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/// \brief Saved data for Grabbed used in KinBodyStateSaver and KinBodyStateSaverRef | ||||||||||||||||||||||||||||
/// When KinBody::Grab, KinBody::Release, ...etc are called, new Grabbed instance is created in KinBody and the original ptr for the original Grabbed instance is swapped. | ||||||||||||||||||||||||||||
/// Thus, the original information of Grabbed instance is unchanged and holding the ptr of it as pGrabbed is enough for the saver. | ||||||||||||||||||||||||||||
|
@@ -2446,7 +2449,7 @@ class OPENRAVE_API KinBody : public InterfaceBase | |||||||||||||||||||||||||||
struct SavedGrabbedData | ||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||
GrabbedPtr pGrabbed; ///< pointer of original Grabbed instance, which originally in KinBody's _grabbedBodiesByEnvironmentIndex. | ||||||||||||||||||||||||||||
std::list<KinBody::LinkConstPtr> listNonCollidingLinksWhenGrabbed; ///< copied values of Grabbed's _listNonCollidingLinksWhenGrabbed. See also the documentation of Grabbed class. | ||||||||||||||||||||||||||||
ListNonCollidingLinkPairs listNonCollidingGrabbedGrabberLinkPairsWhenGrabbed; ///< copied values of Grabbed's _listNonCollidingGrabbedGrabberLinkPairsWhenGrabbed. See also the documentation of Grabbed class. | ||||||||||||||||||||||||||||
std::set<int> setGrabberLinkIndicesToIgnore; ///< copied values of Grabbed's _setGrabberLinkIndicesToIgnore. See also the documentation of Grabbed class. | ||||||||||||||||||||||||||||
bool listNonCollidingIsValid = false; ///< copied values of Grabbed's _listNonCollidingIsValid. See also the documentation of Grabbed class. | ||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
|
@@ -2485,6 +2488,7 @@ class OPENRAVE_API KinBody : public InterfaceBase | |||||||||||||||||||||||||||
std::vector<dReal> _vdoflastsetvalues; | ||||||||||||||||||||||||||||
std::vector<dReal> _vMaxVelocities, _vMaxAccelerations, _vMaxJerks, _vDOFWeights, _vDOFLimits[2], _vDOFResolutions; | ||||||||||||||||||||||||||||
std::unordered_map<int, SavedGrabbedData> _grabbedDataByEnvironmentIndex; | ||||||||||||||||||||||||||||
std::unordered_map<uint64_t, ListNonCollidingLinkPairs> _mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed; | ||||||||||||||||||||||||||||
bool _bRestoreOnDestructor; | ||||||||||||||||||||||||||||
private: | ||||||||||||||||||||||||||||
virtual void _RestoreKinBody(boost::shared_ptr<KinBody> body); | ||||||||||||||||||||||||||||
|
@@ -2531,6 +2535,7 @@ class OPENRAVE_API KinBody : public InterfaceBase | |||||||||||||||||||||||||||
std::vector<dReal> _vdoflastsetvalues; | ||||||||||||||||||||||||||||
std::vector<dReal> _vMaxVelocities, _vMaxAccelerations, _vMaxJerks, _vDOFWeights, _vDOFLimits[2], _vDOFResolutions; | ||||||||||||||||||||||||||||
std::unordered_map<int, SavedGrabbedData> _grabbedDataByEnvironmentIndex; | ||||||||||||||||||||||||||||
std::unordered_map<uint64_t, ListNonCollidingLinkPairs> _mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed; | ||||||||||||||||||||||||||||
bool _bRestoreOnDestructor; | ||||||||||||||||||||||||||||
bool _bReleased; ///< if true, then body should not be restored | ||||||||||||||||||||||||||||
private: | ||||||||||||||||||||||||||||
|
@@ -3716,10 +3721,12 @@ class OPENRAVE_API KinBody : public InterfaceBase | |||||||||||||||||||||||||||
/// \param[in] savedBody : saved KinBody inside of saver. | ||||||||||||||||||||||||||||
/// \param[in] options : SaveParameters inside of saver. | ||||||||||||||||||||||||||||
/// \param[in] savedGrabbedBodiesByEnvironmentIndex : _grabbedBodiesByEnvironmentIndex held in saver. | ||||||||||||||||||||||||||||
/// \param[in] savedMapListNonCollidingInterGrabbedLinkPairsWhenGrabbed : _mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed held in saver. | ||||||||||||||||||||||||||||
/// \param[in] bCalledFromClone : true this is called from clone, e.g. called from _RestoreGrabbedBodiesForClone. false if Assumes that this is called from _RestoreKinBody of saver classes. | ||||||||||||||||||||||||||||
void _RestoreGrabbedBodiesFromSavedData(const KinBody& savedBody, | ||||||||||||||||||||||||||||
const int options, | ||||||||||||||||||||||||||||
const std::unordered_map<int, SavedGrabbedData>& savedGrabbedDataByEnvironmentIndex, | ||||||||||||||||||||||||||||
const std::unordered_map<uint64_t, ListNonCollidingLinkPairs>& savedMapListNonCollidingInterGrabbedLinkPairsWhenGrabbed, | ||||||||||||||||||||||||||||
const bool bCalledFromClone = false); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/// \brief Save this kinbody's information. | ||||||||||||||||||||||||||||
|
@@ -3729,6 +3736,21 @@ class OPENRAVE_API KinBody : public InterfaceBase | |||||||||||||||||||||||||||
/// Ensures that _vAllPairsShortestPaths is initialized if it is not already | ||||||||||||||||||||||||||||
void _EnsureAllPairsShortestPaths() const; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/// \brief Check if IsListNonCollidingLinksValid is true for the Grabbed instance with the given envBodyIndex. | ||||||||||||||||||||||||||||
/// \param[int] envBodyIndex : env body index. | ||||||||||||||||||||||||||||
bool _IsListNonCollidingLinksValidFromEnvironmentBodyIndex(const int envBodyIndex) const; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/// \brief Compute environment body indices pair. pack the two bodies' envBodyIndices (32bit int) into one environment body indices pair (uint64_t). | ||||||||||||||||||||||||||||
/// Here, environment body indices pair is uint64_t, which higher 32bits are for body2 envBodyIndex, and which lower 32bits are for body1 envBodyIndex. | ||||||||||||||||||||||||||||
/// Note that index1 < index2. | ||||||||||||||||||||||||||||
Comment on lines
+3743
to
+3745
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @snozawa Are there any particular reasons why you chose to force the caller to give correct ordering of indices instead of letting the function |
||||||||||||||||||||||||||||
static uint64_t _ComputeEnvironmentBodyIndicesPair(const uint64_t index1, const uint64_t index2); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/// \brief Extract the first body's environmentBodyIndex from environment body indices pair. | ||||||||||||||||||||||||||||
static int _GetFirstEnvironmentBodyIndexFromPair(const uint64_t pair); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/// \brief Extract the first body's environmentBodyIndex from environment body indices pair. | ||||||||||||||||||||||||||||
static int _GetSecondEnvironmentBodyIndexFromPair(const uint64_t pair); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
std::string _name; ///< name of body | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
std::vector<JointPtr> _vecjoints; ///< \see GetJoints | ||||||||||||||||||||||||||||
|
@@ -3798,6 +3820,7 @@ class OPENRAVE_API KinBody : public InterfaceBase | |||||||||||||||||||||||||||
mutable std::string __hashKinematicsGeometryDynamics; ///< hash serializing kinematics, dynamics and geometry properties of the KinBody | ||||||||||||||||||||||||||||
int64_t _lastModifiedAtUS=0; ///< us, linux epoch, last modified time of the kinbody when it was originally loaded from the environment. | ||||||||||||||||||||||||||||
int64_t _revisionId = 0; ///< the webstack revision for this loaded kinbody | ||||||||||||||||||||||||||||
std::unordered_map<uint64_t, ListNonCollidingLinkPairs> _mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed; ///< map of list of link pairs. This is computed when grabbed bodies are grabbed, and at taht time, two grabbed bodies are not touching each other. Since these links are not colliding at the time of grabbing, they should remain non-colliding with the grabbed body throughout. If, while grabbing, they collide with the grabbed body at some point, CheckSelfCollision should return true. It is important to note that the enable state of a link does *not* affect its membership of this list. Each pair in the list should be [Grabbed1-link, Grabbed2-link]. Note that this does not contain link pairs of [Grabbed-link, Grabber-link], c.f. Grabbed::_listNonCollidingGrabbedGrabberLinkPairsWhenGrabbed. Note that the key of this map is 'environment body indices pair', which lower 32bits are for the first KinBody's envBodyIndex, and which higher 32bits are for the second KinBody's envBodyIndex. The first envBodyIndex should be always smaller than the second envBodyIndex to simplify searching. Please also see _ComputeEnvironmentBodyIndicesPair. | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
private: | ||||||||||||||||||||||||||||
mutable std::vector<dReal> _vTempJoints; | ||||||||||||||||||||||||||||
|
@@ -3873,11 +3896,21 @@ class OPENRAVE_API Grabbed : public UserData, public boost::enable_shared_from_t | |||||||||||||||||||||||||||
// Member Variables | ||||||||||||||||||||||||||||
KinBodyWeakPtr _pGrabbedBody; ///< the body being grabbed | ||||||||||||||||||||||||||||
KinBody::LinkPtr _pGrabbingLink; ///< the link used for grabbing _pGrabbedBody. Its transform (as well as the transforms of other links rigidly attached to _pGrabbingLink) relative to the grabbed body remains constant until the grabbed body is released. | ||||||||||||||||||||||||||||
std::list<KinBody::LinkConstPtr> _listNonCollidingLinksWhenGrabbed; ///< list of links of the grabber that are not touching the grabbed body *at the time of grabbing*. Since these links are not colliding with the grabbed body at the time of grabbing, they should remain non-colliding with the grabbed body throughout. If, while grabbing, they collide with the grabbed body at some point, CheckSelfCollision should return true. It is important to note that the enable state of a link does *not* affect its membership of this list. | ||||||||||||||||||||||||||||
KinBody::ListNonCollidingLinkPairs _listNonCollidingGrabbedGrabberLinkPairsWhenGrabbed; ///< list of link pairs of the grabber that are not touching the grabbed body *at the time of grabbing*. Since these links are not colliding with the grabbed body at the time of grabbing, they should remain non-colliding with the grabbed body throughout. If, while grabbing, they collide with the grabbed body at some point, CheckSelfCollision should return true. It is important to note that the enable state of a link does *not* affect its membership of this list. Each pair in the list should be [Grabbed-link, Grabber-link]. Note that this does not contain link pairs from two grabbed bodies, c.f. KinBody::_mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed. | ||||||||||||||||||||||||||||
Transform _tRelative; ///< the relative transform between the grabbed body and the grabbing link. tGrabbingLink*tRelative = tGrabbedBody. | ||||||||||||||||||||||||||||
std::set<int> _setGrabberLinkIndicesToIgnore; ///< indices to the links of the grabber whose collisions with the grabbed bodies should be ignored. | ||||||||||||||||||||||||||||
rapidjson::Document _rGrabbedUserData; ///< user-defined data to be updated when kinbody grabs and releases objects | ||||||||||||||||||||||||||||
private: | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/// \brief push inter-grabbed-bodies non colliding link pairs to grabber. | ||||||||||||||||||||||||||||
/// \param[out] pGrabber : updated grabber. | ||||||||||||||||||||||||||||
/// \param[out] pchecker : collision checker | ||||||||||||||||||||||||||||
/// \param[in] grabbedBody, otherGrabbedBody : grabbed body by this class, and other grabbed body to check. | ||||||||||||||||||||||||||||
void _PushNonCollidingLinkPairsForGrabbedBodies(KinBodyPtr& pGrabber, | ||||||||||||||||||||||||||||
CollisionCheckerBasePtr& pchecker, | ||||||||||||||||||||||||||||
const KinBody& grabbedBody, | ||||||||||||||||||||||||||||
const KinBody& otherGrabbedBody); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
bool _listNonCollidingIsValid = false; ///< a flag indicating whether the current _listNonCollidingLinksWhenGrabbed is valid or not. | ||||||||||||||||||||||||||||
std::vector<KinBody::LinkPtr> _vAttachedToGrabbingLink; ///< vector of all links that are rigidly attached to _pGrabbingLink | ||||||||||||||||||||||||||||
KinBody::KinBodyStateSaverPtr _pGrabberSaver; ///< statesaver that saves the snapshot of the grabber at the time Grab is called. The saved state will be used (i.e. restored) temporarily when computation of _listNonCollidingLinksWhenGrabbed is necessary. | ||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.