37#include <gtest/gtest.h>
49#include <urdf_parser/urdf_parser.h>
50#include <geometric_shapes/shape_operations.h>
56 double joint2 = -0.785;
57 double joint4 = -2.356;
58 double joint6 = 1.571;
59 double joint7 = 0.785;
80 acm_ = std::make_shared<collision_detection::AllowedCollisionMatrix>(
robot_model_->getLinkModelNames(),
false);
82 acm_->setEntry(
"panda_link0",
"panda_link1",
true);
83 acm_->setEntry(
"panda_link1",
"panda_link2",
true);
84 acm_->setEntry(
"panda_link2",
"panda_link3",
true);
85 acm_->setEntry(
"panda_link3",
"panda_link4",
true);
86 acm_->setEntry(
"panda_link4",
"panda_link5",
true);
87 acm_->setEntry(
"panda_link5",
"panda_link6",
true);
88 acm_->setEntry(
"panda_link6",
"panda_link7",
true);
89 acm_->setEntry(
"panda_link7",
"panda_hand",
true);
90 acm_->setEntry(
"panda_hand",
"panda_rightfinger",
true);
91 acm_->setEntry(
"panda_hand",
"panda_leftfinger",
true);
92 acm_->setEntry(
"panda_rightfinger",
"panda_leftfinger",
true);
93 acm_->setEntry(
"panda_link5",
"panda_link7",
true);
94 acm_->setEntry(
"panda_link6",
"panda_hand",
true);
112 collision_detection::CollisionEnvPtr
c_env_;
114 collision_detection::AllowedCollisionMatrixPtr
acm_;
122 ASSERT_TRUE(robot_model_ok_);
130 c_env_->checkSelfCollision(req, res, *robot_state_, *acm_);
138 robot_state_->setToDefaultValues();
139 robot_state_->update();
143 c_env_->checkSelfCollision(req, res, *robot_state_, *acm_);
153 shapes::Shape* shape =
new shapes::Box(.1, .1, .1);
154 shapes::ShapeConstPtr shape_ptr(shape);
156 Eigen::Isometry3d pos1 = Eigen::Isometry3d::Identity();
157 pos1.translation().z() = 0.3;
158 c_env_->getWorld()->addToObject(
"box", shape_ptr, pos1);
160 c_env_->checkSelfCollision(req, res, *robot_state_, *acm_);
164 c_env_->checkRobotCollision(req, res, *robot_state_, *acm_);
168 c_env_->getWorld()->moveObject(
"box", pos1);
169 c_env_->checkRobotCollision(req, res, *robot_state_, *acm_);
173 c_env_->getWorld()->moveObject(
"box", pos1);
186 shapes::Shape* shape =
new shapes::Box(.4, .4, .4);
187 shapes::ShapeConstPtr shape_ptr(shape);
189 Eigen::Isometry3d pos1 = Eigen::Isometry3d::Identity();
190 pos1.translation().z() = 0.3;
191 c_env_->getWorld()->addToObject(
"box", shape_ptr, pos1);
192 c_env_->checkRobotCollision(req, res, *robot_state_, *acm_);
206 c_env_->checkRobotCollision(req, res, *robot_state_, *acm_);
211 shapes::Shape* shape =
new shapes::Box(0.1, 0.1, 0.1);
212 shapes::ShapeConstPtr shape_ptr(shape);
214 Eigen::Isometry3d pos{ Eigen::Isometry3d::Identity() };
215 pos.translation().x() = 0.43;
216 pos.translation().y() = 0;
217 pos.translation().z() = 0.55;
218 c_env_->getWorld()->addToObject(
"box", shape_ptr, pos);
220 c_env_->setLinkPadding(
"panda_hand", 0.08);
221 c_env_->checkRobotCollision(req, res, *robot_state_, *acm_);
225 c_env_->setLinkPadding(
"panda_hand", 0.0);
226 c_env_->checkRobotCollision(req, res, *robot_state_, *acm_);
242 double joint2 = 0.15;
243 double joint4 = -3.0;
244 double joint5 = -0.8;
245 double joint7 = -0.785;
252 c_env_->checkSelfCollision(req, res, state1, *acm_);
257 double joint_5_other = 0.8;
264 c_env_->checkSelfCollision(req, res, state2, *acm_);
269 RCLCPP_INFO(
getLogger(),
"Continuous to continuous collisions are not supported yet, therefore fail here.");
291 double joint_2{ 0.05 };
292 double joint_4{ -1.6 };
297 c_env_->checkRobotCollision(req, res, state1, state2, *acm_);
302 shapes::Shape* shape =
new shapes::Box(0.1, 0.1, 0.1);
303 shapes::ShapeConstPtr shape_ptr(shape);
305 Eigen::Isometry3d pos{ Eigen::Isometry3d::Identity() };
306 pos.translation().x() = 0.43;
307 pos.translation().y() = 0;
308 pos.translation().z() = 0.55;
309 c_env_->getWorld()->addToObject(
"box", shape_ptr, pos);
311 c_env_->checkRobotCollision(req, res, state1, *acm_);
315 c_env_->checkRobotCollision(req, res, state2, *acm_);
319 c_env_->checkRobotCollision(req, res, state1, state2, *acm_);
327 testing::InitGoogleTest(&argc, argv);
328 return RUN_ALL_TESTS();
moveit::core::RobotStatePtr robot_state_
moveit::core::RobotModelPtr robot_model_
collision_detection::CollisionEnvPtr c_env_
collision_detection::AllowedCollisionMatrixPtr acm_
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)
moveit::core::RobotModelPtr loadTestingRobotModel(const std::string &package_name, const std::string &urdf_relative_path, const std::string &srdf_relative_path)
Loads a robot model given a URDF and SRDF file in a package.
rclcpp::Logger getLogger(const std::string &name)
Creates a namespaced logger.
Representation of a collision checking request.
bool verbose
Flag indicating whether information about detected collisions should be reported.
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)
rclcpp::Logger getLogger()
void setToHome(moveit::core::RobotState &panda_state)
Brings the panda robot in user defined home position.
TEST_F(CollisionDetectionEnvTest, InitOK)
Correct setup testing.