forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore behavior of Box shapes in BulletModel.
Updating Bullet to 2.87 introduced a fix that caused sub-epsilon differences in the vertices returned by `btBoxShape::getVertex()`. SNOPT exhibits different behavior when run with constraints that use the slightly different set of vertices introduced by the fix. We were only using `btBoxShape` when adding boxes to the collision model (the collision shape that was stored in the model was always a `btConvexHullShape` due to an (unrelated?) issue with collision normals in `btBoxShape`). It was basically a lazy way to convert box dimensions to vertex coordinates. This PR explicitly converts the box dimensions to vertex coordinates and locks down the behavior we expect when creating a `btCollisionShape` from a `DrakeShapes::Box`.
- Loading branch information
Andrés Valenzuela
committed
Apr 17, 2018
1 parent
9c7040b
commit a186f87
Showing
4 changed files
with
82 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "drake/multibody/collision/bullet_model.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "drake/common/eigen_types.h" | ||
#include "drake/multibody/shapes/geometry.h" | ||
|
||
namespace drake { | ||
namespace multibody { | ||
namespace collision { | ||
namespace { | ||
GTEST_TEST(BulletModelTest, newBulletBoxShapeTest) { | ||
// Verifies that BulletModel::newBulletBoxShape() returns a pointer to a | ||
// btConvexHullShape instance that satisfies the following criteria: | ||
// - contains 8 points | ||
// - the coordinates of those points are bit-wise equal to the permutations | ||
// of the positive and negative half-extents of the box in a specified | ||
// order. | ||
const Vector3<double> half_extents{0.01, 0.04, 0.09}; | ||
// clang-format off | ||
std::vector<Vector3<double>> expected_vertices{ | ||
{ half_extents(0), half_extents(1), half_extents(2)}, | ||
{-half_extents(0), half_extents(1), half_extents(2)}, | ||
{ half_extents(0), -half_extents(1), half_extents(2)}, | ||
{-half_extents(0), -half_extents(1), half_extents(2)}, | ||
{ half_extents(0), half_extents(1), -half_extents(2)}, | ||
{-half_extents(0), half_extents(1), -half_extents(2)}, | ||
{ half_extents(0), -half_extents(1), -half_extents(2)}, | ||
{-half_extents(0), -half_extents(1), -half_extents(2)}, | ||
}; | ||
// clang-format on | ||
const int expected_num_vertices = static_cast<int>(expected_vertices.size()); | ||
std::unique_ptr<btCollisionShape> bt_shape = | ||
BulletModel::newBulletBoxShape(DrakeShapes::Box{2 * half_extents}, true); | ||
const auto bt_convex_hull_shape = | ||
dynamic_cast<btConvexHullShape*>(bt_shape.get()); | ||
|
||
// Lock down implementation as btConvexHullShape as we'll need that to check | ||
// the vertices below. | ||
ASSERT_NE(bt_convex_hull_shape, nullptr); | ||
|
||
// Check the number of vertices. | ||
ASSERT_EQ(bt_convex_hull_shape->getNumVertices(), expected_num_vertices); | ||
|
||
// Check that the vertices have the expected values. We intentionally use a | ||
// tolerance of zero here because the results of queries on BulletModel may be | ||
// used in solving nonlinear optimization problems, where sub-epsilon | ||
// differences can lead to different results. We use EXPECT_NEAR rather than | ||
// EXPECT_EQ because EXPECT_NEAR's error message is more informative in this | ||
// case. | ||
for (int i = 0; i < expected_num_vertices; ++i) { | ||
btVector3 bullet_vertex; | ||
bt_convex_hull_shape->getVertex(i, bullet_vertex); | ||
EXPECT_NEAR(bullet_vertex.x(), expected_vertices[i].x(), 0.0); | ||
EXPECT_NEAR(bullet_vertex.y(), expected_vertices[i].y(), 0.0); | ||
EXPECT_NEAR(bullet_vertex.z(), expected_vertices[i].z(), 0.0); | ||
} | ||
} | ||
} // namespace | ||
} // namespace collision | ||
} // namespace multibody | ||
} // namespace drake |