45 #include <urdf_parser/urdf_parser.h>
48 #include <gtest/gtest.h>
52 #include <boost/filesystem.hpp>
65 acm_ = std::make_shared<collision_detection::AllowedCollisionMatrix>(
robot_model_->getLinkModelNames(),
true);
67 std::map<std::string, std::vector<collision_detection::CollisionSphere>> link_body_decompositions;
68 cenv_ = std::make_shared<DefaultCEnvType>(
robot_model_, link_body_decompositions);
78 moveit::core::TransformsPtr
ftf_;
81 collision_detection::CollisionEnvPtr
cenv_;
83 collision_detection::AllowedCollisionMatrixPtr
acm_;
95 cenv_->checkSelfCollision(req, res,
robot_state, *acm_);
110 cenv_->checkSelfCollision(req, res1,
robot_state, *acm_);
111 std::map<std::string, double> torso_val;
112 torso_val[
"torso_lift_joint"] = .15;
115 cenv_->checkSelfCollision(req, res1,
robot_state, *acm_);
116 cenv_->checkSelfCollision(req, res1,
robot_state, *acm_);
132 Eigen::Isometry3d offset = Eigen::Isometry3d::Identity();
133 offset.translation().x() = .01;
135 robot_state.updateStateWithLinkAt(
"base_link", Eigen::Isometry3d::Identity());
136 robot_state.updateStateWithLinkAt(
"base_bellow_link", offset);
138 acm_->setEntry(
"base_link",
"base_bellow_link",
false);
139 cenv_->checkSelfCollision(req, res1,
robot_state, *acm_);
142 acm_->setEntry(
"base_link",
"base_bellow_link",
true);
143 cenv_->checkSelfCollision(req, res2,
robot_state, *acm_);
146 robot_state.updateStateWithLinkAt(
"r_gripper_palm_link", Eigen::Isometry3d::Identity());
147 robot_state.updateStateWithLinkAt(
"l_gripper_palm_link", offset);
149 acm_->setEntry(
"r_gripper_palm_link",
"l_gripper_palm_link",
false);
150 cenv_->checkSelfCollision(req, res3,
robot_state, *acm_);
164 Eigen::Isometry3d offset = Eigen::Isometry3d::Identity();
165 offset.translation().x() = .01;
167 robot_state.updateStateWithLinkAt(
"base_link", Eigen::Isometry3d::Identity());
168 robot_state.updateStateWithLinkAt(
"base_bellow_link", offset);
170 robot_state.updateStateWithLinkAt(
"r_gripper_palm_link", Eigen::Isometry3d::Identity());
171 robot_state.updateStateWithLinkAt(
"l_gripper_palm_link", offset);
173 acm_->setEntry(
"base_link",
"base_bellow_link",
false);
174 acm_->setEntry(
"r_gripper_palm_link",
"l_gripper_palm_link",
false);
177 cenv_->checkSelfCollision(req, res,
robot_state, *acm_);
186 cenv_->checkSelfCollision(req, res,
robot_state, *acm_);
196 acm_ = std::make_shared<collision_detection::AllowedCollisionMatrix>(robot_model_->getLinkModelNames(),
false);
197 cenv_->checkSelfCollision(req, res,
robot_state, *acm_);
199 EXPECT_LE(res.
contacts.size(), 10u);
213 Eigen::Isometry3d pos1 = Eigen::Isometry3d::Identity();
214 Eigen::Isometry3d pos2 = Eigen::Isometry3d::Identity();
216 pos1.translation().x() = 5.0;
217 pos2.translation().x() = 5.01;
219 robot_state.updateStateWithLinkAt(
"r_gripper_palm_link", pos1);
220 robot_state.updateStateWithLinkAt(
"l_gripper_palm_link", pos2);
222 acm_->setEntry(
"r_gripper_palm_link",
"l_gripper_palm_link",
false);
225 cenv_->checkSelfCollision(req, res,
robot_state, *acm_);
228 ASSERT_EQ(res.
contacts.begin()->second.size(), 1u);
230 for (collision_detection::CollisionResult::ContactMap::const_iterator it = res.
contacts.begin();
236 pos1 = Eigen::Isometry3d(Eigen::Translation3d(3.0, 0.0, 0.0) * Eigen::Quaterniond::Identity());
237 pos2 = Eigen::Isometry3d(Eigen::Translation3d(3.0, 0.0, 0.0) * Eigen::Quaterniond(0.965, 0.0, 0.258, 0.0));
239 robot_state.updateStateWithLinkAt(
"r_gripper_palm_link", pos1);
240 robot_state.updateStateWithLinkAt(
"l_gripper_palm_link", pos2);
243 cenv_->checkSelfCollision(req, res2,
robot_state, *acm_);
245 ASSERT_EQ(res2.
contacts.size(), 1u);
246 ASSERT_EQ(res2.
contacts.begin()->second.size(), 1u);
248 for (collision_detection::CollisionResult::ContactMap::const_iterator it = res2.
contacts.begin();
254 pos1 = Eigen::Isometry3d(Eigen::Translation3d(3.0, 0.0, 0.0) * Eigen::Quaterniond::Identity());
255 pos2 = Eigen::Isometry3d(Eigen::Translation3d(3.0, 0.0, 0.0) * Eigen::Quaterniond(
M_PI / 4.0, 0.0,
M_PI / 4.0, 0.0));
257 robot_state.updateStateWithLinkAt(
"r_gripper_palm_link", pos1);
258 robot_state.updateStateWithLinkAt(
"l_gripper_palm_link", pos2);
261 cenv_->checkSelfCollision(req, res2,
robot_state, *acm_);
272 acm_ = std::make_shared<collision_detection::AllowedCollisionMatrix>(robot_model_->getLinkModelNames(),
true);
278 Eigen::Isometry3d pos1 = Eigen::Isometry3d::Identity();
279 pos1.translation().x() = 1.0;
281 robot_state.updateStateWithLinkAt(
"r_gripper_palm_link", pos1);
282 cenv_->checkSelfCollision(req, res,
robot_state, *acm_);
289 cenv_->checkRobotCollision(req, res,
robot_state, *acm_);
293 cenv_->getWorld()->removeObject(
"box");
295 const auto identity = Eigen::Isometry3d::Identity();
296 std::vector<shapes::ShapeConstPtr>
shapes;
299 poses.push_back(identity);
300 std::set<std::string> touch_links;
301 trajectory_msgs::JointTrajectory empty_state;
303 robot_state.attachBody(std::make_unique<moveit::core::AttachedBody>(
304 robot_state.getLinkModel(
"r_gripper_palm_link"),
"box", identity,
shapes, poses, touch_links, empty_state));
307 cenv_->checkSelfCollision(req, res,
robot_state, *acm_);
313 touch_links.insert(
"r_gripper_palm_link");
314 shapes[0] = std::make_shared<shapes::Box>(.1, .1, .1);
316 robot_state.attachBody(std::make_unique<moveit::core::AttachedBody>(
317 robot_state.getLinkModel(
"r_gripper_palm_link"),
"box", identity,
shapes, poses, touch_links, empty_state));
320 cenv_->checkSelfCollision(req, res,
robot_state, *acm_);
323 pos1.translation().x() = 1.01;
327 cenv_->checkRobotCollision(req, res,
robot_state, *acm_);
330 acm_->setEntry(
"coll",
"r_gripper_palm_link",
true);
332 cenv_->checkRobotCollision(req, res,
robot_state, *acm_);
336 TEST(DistanceFieldCollisionDetectionPadding, Sphere)
338 geometry_msgs::Pose origin;
339 origin.orientation.w = 1.0;
345 auto world = std::make_shared<collision_detection::World>();
346 world->addToObject(
"box", Eigen::Isometry3d::Identity(), std::make_shared<shapes::Box>(.02, .02, .02),
347 Eigen::Isometry3d::Identity());
352 std::map<std::string, std::vector<collision_detection::CollisionSphere>>(),
370 cenv.checkRobotCollision(req, res,
robot_state, acm);
374 world->setObjectPose(
"box", Eigen::Isometry3d::Identity() * Eigen::Translation3d(0, 0, 0.08));
375 cenv.checkRobotCollision(req, res,
robot_state, acm);
376 EXPECT_TRUE(res.
collision) <<
"Collision should be detected when box is in padding area of base";
379 world->setObjectPose(
"box", Eigen::Isometry3d::Identity() * Eigen::Translation3d(0, 0, 0.1));
380 cenv.checkRobotCollision(req, res,
robot_state, acm);
381 EXPECT_FALSE(res.
collision) <<
"No collision should be reported when box is outside of padding area";
385 int main(
int argc,
char** argv)
387 testing::InitGoogleTest(&argc, argv);
388 return RUN_ALL_TESTS();