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

Bullet discrete contact testing #425

Merged
merged 6 commits into from
Jan 21, 2020
Merged

Conversation

aclegg3
Copy link
Contributor

@aclegg3 aclegg3 commented Jan 10, 2020

Motivation and Context

Discrete contact testing is useful for a variety of tasks including agent/object placement and collision filter functions. This PR introduces the first step: binary contact testing for a specific object with the collision world.

Includes Simulator.cpp wrapper and python bindings for simulator.py.

This infra can later be extended to include a configurable contact distance threshold and collection of contact points, normals, friction directions, contact distances, and colliding object pair identifiers.

How Has This Been Tested

C++ CI test for object/object and object/scene contact results.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@aclegg3 aclegg3 self-assigned this Jan 10, 2020
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jan 10, 2020
@codecov-io
Copy link

codecov-io commented Jan 17, 2020

Codecov Report

Merging #425 into master will decrease coverage by 1.41%.
The diff coverage is 78.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #425      +/-   ##
==========================================
- Coverage   57.68%   56.27%   -1.42%     
==========================================
  Files         176      156      -20     
  Lines        8225     6804    -1421     
  Branches       84       84              
==========================================
- Hits         4745     3829     -916     
+ Misses       3480     2975     -505
Flag Coverage Δ
#CPP 50.06% <78.33%> (-3.87%) ⬇️
#JavaScript 10% <ø> (ø) ⬆️
#Python 78.8% <ø> (ø) ⬆️
Impacted Files Coverage Δ
src/esp/io/json.h 100% <ø> (+30%) ⬆️
src/esp/scene/SemanticScene.h 30.76% <ø> (+16.48%) ⬆️
src/esp/scene/Mp3dSemanticScene.cpp 0.85% <0%> (ø) ⬆️
src/esp/assets/GenericInstanceMeshData.cpp 0% <0%> (ø) ⬆️
src/esp/assets/Attributes.cpp 36.46% <100%> (ø) ⬆️
src/esp/io/json.cpp 80.64% <100%> (+5.64%) ⬆️
src/tests/PhysicsTest.cpp 100% <100%> (ø) ⬆️
src/esp/physics/bullet/BulletRigidObject.cpp 63.77% <100%> (+0.27%) ⬆️
src/esp/physics/PhysicsManager.cpp 46.01% <100%> (+0.23%) ⬆️
src/esp/scene/test/GibsonSceneTest.cpp 60.6% <25%> (-11.4%) ⬇️
... and 48 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d1b9c1...405caf5. Read the comment docs.

@@ -346,6 +346,13 @@ Magnum::Quaternion Simulator::getRotation(const int objectID,
return Magnum::Quaternion();
}

bool Simulator::contactTest(const int objectID, const int sceneID) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we expose the physics manager instead of forwarding? It would simplify Simulator and avoid having to add forwarding code every time a new API is added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We've talked about this in the past. At that time the motivation was:

  1. make C++ the primary API (implement functions in Simulator class in C++)
  2. make physics functions callable from sim.function() instead of needing sim.physicsManager.function() for ease of use.

Copy link
Contributor

Choose a reason for hiding this comment

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

For 2. you could grab a physicsManager reference and just call physicsManager.function(). But sounds reasonable to have everything go through Simulator.

Non-blocking: it would be nice to not have all the forwarding logic in Simulator.cpp. Maybe via multiple inheritance or an include.

@@ -285,6 +285,9 @@ def apply_force(self, force, relative_position, object_id, scene_id=0):
def apply_torque(self, torque, object_id, scene_id=0):
self._sim.apply_torque(torque, object_id, scene_id)

def contact_test(self, object_id, scene_id=0):
Copy link
Contributor

@bigbike bigbike Jan 18, 2020

Choose a reason for hiding this comment

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

If it is an internal test, I am wondering why we need to expose it on the python side?

I took a look at the other bindings above it, e.g., apply_torque, get_rotation, add_object. They are reasonable and very necessary to be exposed here. But this one is different. I would like to hear from you first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. This function name may be misleading. It is not a unit test, but a discrete collision check. I'm happy to rename it if that is a problem.

There are actually a couple of applications for this functionality on the python side.

Examples include:

  • 3D step filter function (check if agent collides with env after moving)
  • Scene generation and 3D Agent placement (rejection sampling for contact free placement)

@@ -346,6 +346,13 @@ Magnum::Quaternion Simulator::getRotation(const int objectID,
return Magnum::Quaternion();
}

bool Simulator::contactTest(const int objectID, const int sceneID) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For 2. you could grab a physicsManager reference and just call physicsManager.function(). But sounds reasonable to have everything go through Simulator.

Non-blocking: it would be nice to not have all the forwarding logic in Simulator.cpp. Maybe via multiple inheritance or an include.

@aclegg3 aclegg3 merged commit 7e30a68 into master Jan 21, 2020
@aclegg3 aclegg3 deleted the bullet-discrete-collision-checking branch January 21, 2020 20:09
Ram81 pushed a commit to Ram81/habitat-web-sim that referenced this pull request Dec 10, 2020
* Introduced basic contact results callback struct

* Add discrete contact testing for rigid bodies and a C++ test

* Add contact testing functionality to Simulator.cpp and python bindings for simulator.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants