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

WIP: Revive order of grabbed #1450

Open
wants to merge 40 commits into
base: production
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2198a21
Fix the incorrect computation of self collision for grabbed bodies.
Sep 25, 2024
0cd3346
reduce the duplicated checking of pointer validity. check it when cre…
Sep 24, 2024
a942ee1
use _mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed and _listNon…
Sep 24, 2024
d7b510e
directly return from the function if collision is deteced when bAllLi…
Sep 25, 2024
8fdf9eb
Improve warning message more
Sep 25, 2024
042243f
fix wrong size
Sep 25, 2024
a8839a2
fix typo of pSecondLink. in addition, rename variable to contain 'Ref…
Sep 25, 2024
7841daf
improve comments
Sep 25, 2024
61dc5dc
Resolve conflict while merge production. Conflicts: include/openrave/…
Sep 26, 2024
c3e9253
Merge remote-tracking branch 'origin/production' into fixGrabbedSelfC…
Sep 30, 2024
d8dcfeb
Merge remote-tracking branch 'origin/miscCleanupForGrabbedAPIs' into …
Sep 30, 2024
2bdbdb3
Add missing post processing of check self collision at the very end.
Sep 30, 2024
4645c51
Merge remote-tracking branch 'origin/miscCleanupForGrabbedAPIs' into …
Sep 30, 2024
78088f7
Merge remote-tracking branch 'origin/miscCleanupForGrabbedAPIs' into …
Oct 10, 2024
21b37e5
Merge remote-tracking branch 'origin/miscCleanupForGrabbedAPIs' into …
Oct 17, 2024
bb7cc24
Merge remote-tracking branch 'origin/miscCleanupForGrabbedAPIs' into …
Oct 18, 2024
9270541
Resolve conflict while merge production. Conflicts: src/libopenrave/k…
Oct 19, 2024
2856b8d
Fix compile
Oct 19, 2024
f5a663d
use |
Oct 19, 2024
a67e44c
Revive order of grabbed bodies.
Oct 19, 2024
68a50e0
If the unique id of pOtherGrabbed is >= than the one of this grabbed,…
Oct 19, 2024
16bd21f
Merge remote-tracking branch 'origin/production' into fixGrabbedSelfC…
Oct 21, 2024
1988ca2
Merge remote-tracking branch 'origin/fixGrabbedSelfColCheckAsym' into…
Oct 21, 2024
0ae0e0e
Add kinematics hash checking for map list noncolliding for inter grabbed
Oct 22, 2024
fa2cc0c
No need to check iterator since the code right before already checked it
Oct 22, 2024
e21a2e7
no need of bInvertFirstSecond
Oct 22, 2024
8bf75a0
Swap the order of code, for better readability
Oct 22, 2024
50d81aa
Merge remote-tracking branch 'origin/fixGrabbedSelfColCheckAsym' into…
Oct 22, 2024
e7cd291
return value from here is unused
Oct 25, 2024
05c9441
Update warning message clearer.
Oct 25, 2024
d9f6275
Introduce the rule of indices pair, which is key of map. the first en…
Oct 25, 2024
d8a7d4f
Bump minor version to fix bug of _listNonColidingLinksWhenGrabbed asy…
Oct 25, 2024
ad8983a
Resolve conflict while merge fixGrabbedSelfColCheckAsym. Conflict : k…
Oct 25, 2024
8df8122
Bump patch version: Revive the order of grabbed bodies to avoid less …
Oct 26, 2024
35fc6f9
Merge remote-tracking branch 'origin/production' into fixGrabbedSelfC…
Oct 28, 2024
662bc78
Merge remote-tracking branch 'origin/fixGrabbedSelfColCheckAsym' into…
Oct 28, 2024
b1599de
Resolve conflict while merge production. CMakeLists.txt, docs/source/…
Oct 31, 2024
0a83d66
Merge remote-tracking branch 'origin/fixGrabbedSelfColCheckAsym' into…
Oct 31, 2024
179f48e
Resolve conflict while merge master. Conflict. docs/source/changelog.rst
Nov 3, 2024
d510324
Resolve conflict while merge master. Conflict. docs/source/changelog.rst
Nov 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE )

# Define here the needed parameters
set (OPENRAVE_VERSION_MAJOR 0)
set (OPENRAVE_VERSION_MINOR 157)
set (OPENRAVE_VERSION_MINOR 159)
set (OPENRAVE_VERSION_PATCH 0)
set (OPENRAVE_VERSION ${OPENRAVE_VERSION_MAJOR}.${OPENRAVE_VERSION_MINOR}.${OPENRAVE_VERSION_PATCH})
set (OPENRAVE_SOVERSION ${OPENRAVE_VERSION_MAJOR}.${OPENRAVE_VERSION_MINOR})
Expand Down
12 changes: 12 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
ChangeLog
#########

Version 0.159.0
===============

- Revive the order of grabbed bodies to avoid less deterministic grabbed self collision checking.

Version 0.158.0
===============

- Fix bug of `_listNonColidingLinksWhenGrabbed` asymmetricity which might cause false positive/negative self collision checking and might make it less deterministic.
- Store the link pair for grabbed-grabber collision in `Grabbed` class.
- Store the link pair for inter-grabbed collision in `KinBody` class.

Version 0.157.0
===============

Expand Down
45 changes: 42 additions & 3 deletions include/openrave/kinbody.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
};
Expand Down Expand Up @@ -2485,6 +2488,8 @@ 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;
uint64_t _nextGrabbedBodyUniqueId = 0;
bool _bRestoreOnDestructor;
private:
virtual void _RestoreKinBody(boost::shared_ptr<KinBody> body);
Expand Down Expand Up @@ -2531,6 +2536,8 @@ 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;
uint64_t _nextGrabbedBodyUniqueId = 0;
bool _bRestoreOnDestructor;
bool _bReleased; ///< if true, then body should not be restored
private:
Expand Down Expand Up @@ -3716,10 +3723,14 @@ 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] savedNextGrabbedBodyUniqueId : _nextGrabbedBodyUniqueId 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 uint64_t savedNextGrabbedBodyUniqueId,
const bool bCalledFromClone = false);

/// \brief Save this kinbody's information.
Expand All @@ -3729,6 +3740,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.
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
Expand Down Expand Up @@ -3798,6 +3824,8 @@ 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.
uint64_t _nextGrabbedBodyUniqueId = 0; ///< This indicates the unique id of the next grabbed body. Monotonically increasing, except for the resetting when all grabbed bodies are released, ...etc. Lower unique id means grabbed earlier, and we can identify the order of grabbed bodies through this Id.

private:
mutable std::vector<dReal> _vTempJoints;
Expand Down Expand Up @@ -3833,7 +3861,7 @@ class OPENRAVE_API KinBody : public InterfaceBase
class OPENRAVE_API Grabbed : public UserData, public boost::enable_shared_from_this<Grabbed>
{
public:
Grabbed(KinBodyPtr pGrabbedBody, KinBody::LinkPtr pGrabbingLink);
Grabbed(KinBodyPtr pGrabbedBody, KinBody::LinkPtr pGrabbingLink, const uint64_t uniqueId);
virtual ~Grabbed() {
}

Expand Down Expand Up @@ -3873,11 +3901,22 @@ 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
const uint64_t _uniqueId = 0; ///< The unique id of this Grabbed instance. Lower unique id means grabbed earlier, and we can identify the order of grabbed bodies through this Id.
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.
Expand Down
Loading
Loading