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

Add Cone as a collision shape #639

Merged
merged 9 commits into from
Jun 13, 2024
Merged

Conversation

bperseghetti
Copy link
Member

@bperseghetti bperseghetti commented May 15, 2024

🦟 Bug fix

Summary

This helps add the missing cone geometry for primitive/basic parametric shapes:

conetopple
cone

And is also valuable for visualizations of emitters/source that typically have conic-based spread as seen in this acoustic attack on an IMU by showing the affected area:

drone_attack

Associated PRs:

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

Squashing commits to make requested target of main with backports to
harmonic.

Signed-off-by: Benjamin Perseghetti <[email protected]>
dartsim/src/SDFFeatures.cc Outdated Show resolved Hide resolved
dartsim/src/ShapeFeatures.cc Show resolved Hide resolved
dartsim/src/ShapeFeatures.cc Show resolved Hide resolved
Signed-off-by: Benjamin Perseghetti <[email protected]>
@bperseghetti bperseghetti requested a review from ahcorde May 16, 2024 19:23
Comment on lines 356 to 360
meshMgr->CreateCone(
coneMeshName,
_geometry.ConeShape()->Radius(),
_geometry.ConeShape()->Length(),
3, 40);
Copy link
Member Author

Choose a reason for hiding this comment

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

@azeey @scpeters @ahcorde I set these values as they seemed to be "reasonable" tradeoff between increased computation and avoiding "lumpy" cones that can't roll. I think the problem really stems from the implementation in gz-common though, it would be nice if segments were actually a function of arc length or surface area so you get consistent segment sizes. IE the bounded area of each segment by the top vertex ring set is much much much smaller than the area bounded by the ringset adjacent to the bottom cap. I think maybe changing that here to be calculated from a segment area and number of rings instead of number of segments and number of rings would make a lot more sense: https://github.com/gazebosim/gz-common/blob/27f7017c5c1b1fd2ba9c603e92b694f98417175d/graphics/src/MeshManager.cc#L1242-L1313

Copy link
Contributor

Choose a reason for hiding this comment

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

Can the number of rings be set to 0? I would think the rolling issue is affected by the number of segments, but not rings.

Regarding the idea of making segments be a function of the arc length, I think we can do that here---if the rings can be set to 0, segments could be a simple function of the radius.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, and even for visualization I was thinking it might not be bad to have less segments with the same logic but just implemented in the gz-common I showed earlier? I guess, is there ever a case where we would desire more than one ring? I would feel like having the input to the mesh function just be number of segments might be enough for all cases?

Copy link
Contributor

Choose a reason for hiding this comment

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

is there ever a case where we would desire more than one ring?

I can't think of one. The unit_cone which is created in gz::common::MeshManager is used in gz::rendering for the cone in the transform tool. That's the only place I see it used. And for that, I don't think we need more than one ring (0 if you don't count the base circle). Maybe someone That being said, is changing the API worth the hassle?

Copy link
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

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

I've updated some shape tests in 71d883e (feel free to cherry-pick) to include the cone (just by duplicating cylinder and search/replace s/ylinder/one/), and I'm seeing a test failure in dart related to casting to the ConeShape. I commented on the dartsim ShapeFeatures.cc file where I think the problem comes from.

Perhaps we could create a CustomConeShape that inherits from CustomMeshShape, so we can cast to CustomConeShape instead of dart::dynamics::ConeShape?


const dart::dynamics::ShapePtr &shape = shapeInfo->node->getShape();

if (dynamic_cast<dart::dynamics::ConeShape *>(shape.get()))
Copy link
Member

Choose a reason for hiding this comment

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

I believe this cast is failing because we are actually using a MeshShape instead of a ConeShape

Signed-off-by: Steve Peters <[email protected]>
@bperseghetti
Copy link
Member Author

I've updated some shape tests in 71d883e (feel free to cherry-pick) to include the cone (just by duplicating cylinder and search/replace s/ylinder/one/), and I'm seeing a test failure in dart related to casting to the ConeShape. I commented on the dartsim ShapeFeatures.cc file where I think the problem comes from.

Perhaps we could create a CustomConeShape that inherits from CustomMeshShape, so we can cast to CustomConeShape instead of dart::dynamics::ConeShape?

Cherry-picked and pushed.
You have a test implementation of that method?

@scpeters
Copy link
Member

scpeters commented Jun 3, 2024

Cherry-picked and pushed. You have a test implementation of that method?

not yet; I was just tinkering with it and since the CustomMeshShape constructor wants a gz::common::Mesh, I think we would need a factory function to return a gz::common::Mesh to use in the CustomMeshShape initializer. I'll tinker a bit more

@scpeters
Copy link
Member

Cherry-picked and pushed. You have a test implementation of that method?

not yet; I was just tinkering with it and since the CustomMeshShape constructor wants a gz::common::Mesh, I think we would need a factory function to return a gz::common::Mesh to use in the CustomMeshShape initializer. I'll tinker a bit more

ok, I think I've gotten most of the tests fixed, except for bullet-featherstone, which complains about the bounding box size being larger due to the collision margin parameter, which we should discuss directly

@bperseghetti
Copy link
Member Author

Cherry-picked and pushed. You have a test implementation of that method?

not yet; I was just tinkering with it and since the CustomMeshShape constructor wants a gz::common::Mesh, I think we would need a factory function to return a gz::common::Mesh to use in the CustomMeshShape initializer. I'll tinker a bit more

ok, I think I've gotten most of the tests fixed, except for bullet-featherstone, which complains about the bounding box size being larger due to the collision margin parameter, which we should discuss directly

Thanks, cherry-picked!

@scpeters
Copy link
Member

the following patch will fix tests by reducing the bullet-featherstone margin to 0, but I'm not sure if that will cause problems with contact simulation

diff --git a/bullet-featherstone/src/SDFFeatures.cc b/bullet-featherstone/src/SDFFeatures.cc
index 82fe6744..3ad3b3f5 100644
--- a/bullet-featherstone/src/SDFFeatures.cc
+++ b/bullet-featherstone/src/SDFFeatures.cc
@@ -970,6 +970,7 @@ bool SDFFeatures::AddSdfCollision(
     const auto height = static_cast<btScalar>(cone->Length());
     shape =
       std::make_unique<btConeShapeZ>(radius, height);
+    shape->setMargin(0.0);
   }
   else if (const auto *cylinder = geom->CylinderShape())
   {
diff --git a/bullet-featherstone/src/ShapeFeatures.cc b/bullet-featherstone/src/ShapeFeatures.cc
index c4702764..038ad835 100644
--- a/bullet-featherstone/src/ShapeFeatures.cc
+++ b/bullet-featherstone/src/ShapeFeatures.cc
@@ -247,6 +247,7 @@ Identity ShapeFeatures::AttachConeShape(
   const auto height = static_cast<btScalar>(_height);
   auto shape =
     std::make_unique<btConeShapeZ>(radius, height);
+  shape->setMargin(0.0);
 
   auto identity = this->AddCollision(
     CollisionInfo{

@bperseghetti
Copy link
Member Author

bperseghetti commented Jun 12, 2024

the following patch will fix tests by reducing the bullet-featherstone margin to 0, but I'm not sure if that will cause problems with contact simulation

diff --git a/bullet-featherstone/src/SDFFeatures.cc b/bullet-featherstone/src/SDFFeatures.cc
index 82fe6744..3ad3b3f5 100644
--- a/bullet-featherstone/src/SDFFeatures.cc
+++ b/bullet-featherstone/src/SDFFeatures.cc
@@ -970,6 +970,7 @@ bool SDFFeatures::AddSdfCollision(
     const auto height = static_cast<btScalar>(cone->Length());
     shape =
       std::make_unique<btConeShapeZ>(radius, height);
+    shape->setMargin(0.0);
   }
   else if (const auto *cylinder = geom->CylinderShape())
   {
diff --git a/bullet-featherstone/src/ShapeFeatures.cc b/bullet-featherstone/src/ShapeFeatures.cc
index c4702764..038ad835 100644
--- a/bullet-featherstone/src/ShapeFeatures.cc
+++ b/bullet-featherstone/src/ShapeFeatures.cc
@@ -247,6 +247,7 @@ Identity ShapeFeatures::AttachConeShape(
   const auto height = static_cast<btScalar>(_height);
   auto shape =
     std::make_unique<btConeShapeZ>(radius, height);
+  shape->setMargin(0.0);
 
   auto identity = this->AddCollision(
     CollisionInfo{

BTW, I do have your personal github as one of my remotes for that repo so you can always just push to the branch and I can fetch/cherry-pick anything in. 😃

But i'll just apply this diff for now anyhow.

Signed-off-by: Benjamin Perseghetti <[email protected]>
@bperseghetti
Copy link
Member Author

@scpeters thanks once again, I applied your patch, I think it just needs CI approval.

bperseghetti and others added 2 commits June 13, 2024 00:23
Co-authored-by: Steve Peters <[email protected]>
Signed-off-by: Benjamin Perseghetti <[email protected]>
@scpeters scpeters changed the title Adding cone primitives. Add Cone as a collision shape Jun 13, 2024
Copy link
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

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

thanks for working on this! I'm going to merge now to support further testing of the gz-sim PR. We can come back to adjust the bullet collision margin if necessary

@scpeters scpeters dismissed ahcorde’s stale review June 13, 2024 17:14

the request changes have been applied

@scpeters scpeters merged commit 4f1b1df into gazebosim:main Jun 13, 2024
6 checks passed
bperseghetti added a commit to rudislabs/gz-physics that referenced this pull request Jun 18, 2024
@bperseghetti bperseghetti deleted the pr-cone-main branch June 21, 2024 01:20
bperseghetti added a commit to rudislabs/gz-physics that referenced this pull request Jun 21, 2024
bperseghetti added a commit to rudislabs/gz-physics that referenced this pull request Jun 21, 2024
azeey pushed a commit that referenced this pull request Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏛️ ionic Gazebo Ionic
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants