37 #include <gtest/gtest.h>
38 #include <rclcpp/rclcpp.hpp>
51 #include <urdf_parser/urdf_parser.h>
52 #include <geometric_shapes/shape_operations.h>
56 static const rclcpp::Logger TEST_LOGGER = rclcpp::get_logger(
"collision_detection.bullet_test");
62 double joint2 = -0.785;
63 double joint4 = -2.356;
64 double joint6 = 1.571;
65 double joint7 = 0.785;
81 acm_ = std::make_shared<collision_detection::AllowedCollisionMatrix>(*
robot_model_->getSRDF());
99 collision_detection::CollisionEnvPtr
cenv_;
101 collision_detection::AllowedCollisionMatrixPtr
acm_;
111 shapes::ShapePtr static_box = std::make_shared<shapes::Box>(1, 1, 1);
112 Eigen::Isometry3d static_box_pose;
113 static_box_pose.setIdentity();
115 std::vector<shapes::ShapeConstPtr> obj1_shapes;
117 std::vector<cb::CollisionObjectType> obj1_types;
118 obj1_shapes.push_back(static_box);
119 obj1_poses.push_back(static_box_pose);
120 obj1_types.push_back(cb::CollisionObjectType::USE_SHAPE_TYPE);
122 cb::CollisionObjectWrapperPtr cow_1 = std::make_shared<cb::CollisionObjectWrapper>(
129 shapes::ShapePtr moving_box = std::make_shared<shapes::Box>(0.2, 0.2, 0.2);
130 Eigen::Isometry3d moving_box_pose;
132 moving_box_pose.setIdentity();
135 std::vector<shapes::ShapeConstPtr> obj2_shapes;
137 std::vector<cb::CollisionObjectType> obj2_types;
138 obj2_shapes.push_back(moving_box);
139 obj2_poses.push_back(moving_box_pose);
140 obj2_types.push_back(cb::CollisionObjectType::USE_SHAPE_TYPE);
142 cb::CollisionObjectWrapperPtr cow_2 = std::make_shared<cb::CollisionObjectWrapper>(
152 shapes::ShapePtr static_box = std::make_shared<shapes::Box>(0.3, 0.3, 0.3);
153 Eigen::Isometry3d static_box_pose;
154 static_box_pose.setIdentity();
156 std::vector<shapes::ShapeConstPtr> obj1_shapes;
158 std::vector<cb::CollisionObjectType> obj1_types;
159 obj1_shapes.push_back(static_box);
160 obj1_poses.push_back(static_box_pose);
161 obj1_types.push_back(cb::CollisionObjectType::USE_SHAPE_TYPE);
163 cb::CollisionObjectWrapperPtr cow_1 = std::make_shared<cb::CollisionObjectWrapper>(
170 std::vector<shapes::ShapeConstPtr> obj2_shapes;
172 std::vector<cb::CollisionObjectType> obj2_types;
174 obj1_poses.push_back(static_box_pose);
175 obj1_types.push_back(cb::CollisionObjectType::USE_SHAPE_TYPE);
177 Eigen::Isometry3d s_pose;
178 s_pose.setIdentity();
180 std::string kinect =
"package://moveit_resources_panda_description/meshes/collision/hand.stl";
181 auto s = std::shared_ptr<shapes::Shape>{ shapes::createMeshFromResource(kinect) };
182 obj2_shapes.push_back(s);
183 obj2_types.push_back(cb::CollisionObjectType::CONVEX_HULL);
184 obj2_poses.push_back(s_pose);
186 cb::CollisionObjectWrapperPtr cow_2 = std::make_shared<cb::CollisionObjectWrapper>(
192 std::vector<collision_detection::Contact>& result_vector, Eigen::Isometry3d& start_pos,
193 Eigen::Isometry3d& end_pos)
209 checker.
contactTest(result, request,
nullptr,
false);
211 for (
const auto& contacts_all : result.
contacts)
213 for (
const auto& contact : contacts_all.second)
215 result_vector.push_back(contact);
231 double joint2 = 0.15;
232 double joint4 = -3.0;
233 double joint5 = -0.8;
234 double joint7 = -0.785;
241 cenv_->checkSelfCollision(req, res, state1, *acm_);
246 double joint_5_other = 0.8;
253 cenv_->checkSelfCollision(req, res, state2, *acm_);
257 RCLCPP_INFO(TEST_LOGGER,
"Continuous to continuous collisions are not supported yet, therefore fail here.");
277 double joint_2{ 0.05 };
278 double joint_4{ -1.6 };
283 cenv_->checkRobotCollision(req, res, state1, state2, *acm_);
288 shapes::Shape* shape =
new shapes::Box(0.1, 0.1, 0.1);
289 shapes::ShapeConstPtr shape_ptr(shape);
291 Eigen::Isometry3d pos{ Eigen::Isometry3d::Identity() };
292 pos.translation().x() = 0.43;
293 pos.translation().y() = 0;
294 pos.translation().z() = 0.55;
295 cenv_->getWorld()->addToObject(
"box", shape_ptr, pos);
297 cenv_->checkRobotCollision(req, res, state1, *acm_);
301 cenv_->checkRobotCollision(req, res, state2, *acm_);
305 cenv_->checkRobotCollision(req, res, state1, state2, *acm_);
309 for (
auto& contact_pair : res.
contacts)
326 TEST(ContinuousCollisionUnit, BulletCastBVHCollisionBoxBoxUnit)
329 std::vector<collision_detection::Contact> result_vector;
331 Eigen::Isometry3d start_pos, end_pos;
332 start_pos.setIdentity();
333 start_pos.translation().x() = -2;
334 end_pos.setIdentity();
335 end_pos.translation().x() = 2;
339 runTest(checker, result, result_vector, start_pos, end_pos);
342 EXPECT_NEAR(result_vector[0].depth, -0.6, 0.001);
343 EXPECT_NEAR(result_vector[0].percent_interpolation, 0.6, 0.001);
346 TEST(ContinuousCollisionUnit, BulletCastMeshVsBox)
351 Eigen::Isometry3d start_pos, end_pos;
352 start_pos.setIdentity();
353 start_pos.translation().x() = -1.9;
354 end_pos.setIdentity();
355 end_pos.translation().x() = 1.9;
358 std::vector<collision_detection::Contact> result_vector;
360 runTest(checker, result, result_vector, start_pos, end_pos);
365 int main(
int argc,
char** argv)
367 testing::InitGoogleTest(&argc, argv);
368 return RUN_ALL_TESTS();
moveit::core::RobotModelPtr robot_model_
collision_detection::CollisionEnvPtr cenv_
moveit::core::RobotStatePtr robot_state_
collision_detection::AllowedCollisionMatrixPtr acm_
void setCollisionObjectsTransform(const std::string &name, const Eigen::Isometry3d &pose)
Set a single static collision object's tansform.
void setContactDistanceThreshold(double contact_distance)
Set the contact distance threshold for which collision should be considered through expanding the AAB...
void setActiveCollisionObjects(const std::vector< std::string > &names)
Set which collision objects are active.
A bounding volume hierarchy (BVH) implementation of a tesseract contact manager.
void setCastCollisionObjectsTransform(const std::string &name, const Eigen::Isometry3d &pose1, const Eigen::Isometry3d &pose2)
Set a single cast (moving) collision object's tansforms.
void contactTest(collision_detection::CollisionResult &collisions, const collision_detection::CollisionRequest &req, const collision_detection::AllowedCollisionMatrix *acm, bool self) override
Perform a contact test for all objects.
void addCollisionObject(const CollisionObjectWrapperPtr &cow) override
Add a tesseract collision object to the manager.
Representation of a robot's state. This includes position, velocity, acceleration and effort.
void update(bool force=false)
Update all transforms.
void setToDefaultValues()
Set all joints to their default positions. The default position is 0, or if that is not within bounds...
void setJointPositions(const std::string &joint_name, const double *position)
Type
The types of bodies that are considered for collision.
@ ROBOT_LINK
A link on the robot.
@ WORLD_OBJECT
A body in the environment.
std::vector< T, Eigen::aligned_allocator< T > > AlignedVector
Vec3fX< details::Vec3Data< double > > Vector3d
moveit::core::RobotModelPtr loadTestingRobotModel(const std::string &robot_name)
Loads a robot from moveit_resources.
Representation of a collision checking request.
bool contacts
If true, compute contacts. Otherwise only a binary collision yes/no is reported.
std::size_t max_contacts
Overall maximum number of contacts to compute.
Representation of a collision checking result.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW void clear()
Clear a previously stored result.
bool collision
True if collision was found, false otherwise.
std::size_t contact_count
Number of contacts returned.
int main(int argc, char **argv)
void addCollisionObjectsMesh(cb::BulletCastBVHManager &checker)
TEST(ContinuousCollisionUnit, BulletCastBVHCollisionBoxBoxUnit)
void runTest(cb::BulletCastBVHManager &checker, collision_detection::CollisionResult &result, std::vector< collision_detection::Contact > &result_vector, Eigen::Isometry3d &start_pos, Eigen::Isometry3d &end_pos)
void setToHome(moveit::core::RobotState &panda_state)
Brings the panda robot in user defined home position.
TEST_F(BulletCollisionDetectionTester, DISABLED_ContinuousCollisionSelf)
Continuous self collision checks are not supported yet by the bullet integration.
void addCollisionObjects(cb::BulletCastBVHManager &checker)