37 #include <boost/algorithm/string.hpp>
58 const std::string
LOGNAME =
"planning_scene";
67 bool canTransform(
const std::string& from_frame)
const override
72 bool isFixedFrame(
const std::string& frame)
const override
76 if (Transforms::isFixedFrame(frame))
84 const Eigen::Isometry3d&
getTransform(
const std::string& from_frame)
const override
115 const collision_detection::WorldPtr& world)
123 : world_(world), world_const_(world)
131 robot_model_ = createRobotModel(urdf_model, srdf_model);
154 acm_ = std::make_shared<collision_detection::AllowedCollisionMatrix>(*
getRobotModel()->getSRDF());
165 return moveit::core::RobotModelPtr();
175 if (!
parent_->getName().empty())
182 world_ = std::make_shared<collision_detection::World>(*
parent_->world_);
189 for (
const std::pair<const std::string, CollisionDetectorPtr>& it :
parent_->collision_)
191 const CollisionDetectorPtr& parent_detector = it.second;
193 detector = std::make_shared<CollisionDetector>();
194 detector->alloc_ = parent_detector->alloc_;
195 detector->parent_ = parent_detector;
197 detector->cenv_ = detector->alloc_->allocateEnv(parent_detector->cenv_,
world_);
198 detector->cenv_const_ = detector->cenv_;
200 detector->cenv_unpadded_ = detector->alloc_->allocateEnv(parent_detector->cenv_unpadded_,
world_);
201 detector->cenv_unpadded_const_ = detector->cenv_unpadded_;
208 PlanningScenePtr result = scene->diff();
209 result->decoupleParent();
210 result->setName(scene->getName());
216 return PlanningScenePtr(
new PlanningScene(shared_from_this()));
221 PlanningScenePtr result =
diff();
222 result->setPlanningSceneDiffMsg(msg);
228 cenv_->setLinkPadding(src.getCollisionEnv()->getLinkPadding());
229 cenv_->setLinkScale(src.getCollisionEnv()->getLinkScale());
234 for (std::pair<const std::string, CollisionDetectorPtr>& it :
collision_)
247 if (it != scene.parent_->collision_.end())
253 const std::string&
name = allocator->getName();
259 detector = std::make_shared<CollisionDetector>();
261 detector->alloc_ = allocator;
266 detector->findParent(*
this);
269 detector->cenv_const_ = detector->cenv_;
275 detector->cenv_unpadded_const_ = detector->cenv_unpadded_;
281 detector->cenv_unpadded_const_ = detector->cenv_unpadded_;
289 CollisionDetectorPtr p;
320 "Cannot setActiveCollisionDetector to '%s' -- it has been added to PlanningScene. "
321 "Keeping existing active collision detector '%s'",
331 for (
const std::pair<const std::string, CollisionDetectorPtr>& it :
collision_)
332 names.push_back(it.first);
335 const collision_detection::CollisionEnvConstPtr&
346 return it->second->getCollisionEnv();
349 const collision_detection::CollisionEnvConstPtr&
356 "Could not get CollisionRobotUnpadded named '%s'. "
357 "Returning active CollisionRobotUnpadded '%s' instead",
362 return it->second->getCollisionEnvUnpadded();
371 world_ = std::make_shared<collision_detection::World>(*
parent_->world_);
378 for (std::pair<const std::string, CollisionDetectorPtr>& it :
collision_)
380 if (!it.second->parent_)
381 it.second->findParent(*
this);
383 if (it.second->parent_)
385 it.second->cenv_unpadded_ = it.second->alloc_->allocateEnv(it.second->parent_->cenv_unpadded_,
world_);
386 it.second->cenv_unpadded_const_ = it.second->cenv_unpadded_;
388 it.second->cenv_ = it.second->alloc_->allocateEnv(it.second->parent_->cenv_,
world_);
389 it.second->cenv_const_ = it.second->cenv_;
393 it.second->copyPadding(*
parent_->active_collision_);
394 it.second->cenv_const_ = it.second->cenv_;
411 scene->getTransformsNonConst().setAllTransforms(
scene_transforms_->getAllTransforms());
417 std::vector<const moveit::core::AttachedBody*> attached_objs;
422 scene->setObjectType(attached_obj->getName(),
getObjectType(attached_obj->getName()));
424 scene->setObjectColor(attached_obj->getName(),
getObjectColor(attached_obj->getName()));
429 scene->getAllowedCollisionMatrixNonConst() = *
acm_;
431 collision_detection::CollisionEnvPtr active_cenv = scene->getCollisionEnvNonConst();
434 scene->propogateRobotPadding();
438 for (
const std::pair<const std::string, collision_detection::World::Action>& it : *
world_diff_)
442 scene->world_->removeObject(it.first);
443 scene->removeObjectColor(it.first);
444 scene->removeObjectType(it.first);
449 scene->world_->removeObject(
obj.id_);
450 scene->world_->addToObject(
obj.id_,
obj.pose_,
obj.shapes_,
obj.shape_poses_);
456 scene->world_->setSubframesOfObject(
obj.id_,
obj.subframe_poses_);
535 const std::string& group_name)
const
561 for (collision_detection::CollisionResult::ContactMap::const_iterator it = contacts.begin(); it != contacts.end();
614 acm_ = std::make_shared<collision_detection::AllowedCollisionMatrix>(
parent_->getAllowedCollisionMatrix());
641 scene_msg.name =
name_;
643 scene_msg.is_diff =
true;
648 scene_msg.fixed_frame_transforms.clear();
653 scene_msg.robot_state = moveit_msgs::RobotState();
654 scene_msg.robot_state.is_diff =
true;
657 acm_->getMessage(scene_msg.allowed_collision_matrix);
659 scene_msg.allowed_collision_matrix = moveit_msgs::AllowedCollisionMatrix();
664 scene_msg.object_colors.clear();
671 scene_msg.object_colors[i].id = it->first;
672 scene_msg.object_colors[i].color = it->second;
676 scene_msg.world.collision_objects.clear();
677 scene_msg.world.octomap = octomap_msgs::OctomapWithPose();
681 bool do_omap =
false;
682 for (
const std::pair<const std::string, collision_detection::World::Action>& it : *
world_diff_)
689 if (!std::count_if(scene_msg.robot_state.attached_collision_objects.cbegin(),
690 scene_msg.robot_state.attached_collision_objects.cend(),
691 [&it](
const moveit_msgs::AttachedCollisionObject& aco) {
692 return aco.object.id == it.first &&
693 aco.object.operation == moveit_msgs::CollisionObject::ADD;
696 moveit_msgs::CollisionObject co;
699 co.operation = moveit_msgs::CollisionObject::REMOVE;
700 scene_msg.world.collision_objects.push_back(co);
705 scene_msg.world.collision_objects.emplace_back();
716 for (
const auto& collision_object : scene_msg.world.collision_objects)
718 if (
parent_ &&
parent_->getCurrentState().hasAttachedBody(collision_object.id))
720 moveit_msgs::AttachedCollisionObject aco;
721 aco.object.id = collision_object.id;
722 aco.object.operation = moveit_msgs::CollisionObject::REMOVE;
723 scene_msg.robot_state.attached_collision_objects.push_back(aco);
730 class ShapeVisitorAddToCollisionObject :
public boost::static_visitor<void>
733 ShapeVisitorAddToCollisionObject(moveit_msgs::CollisionObject* obj) :
boost::static_visitor<void>(),
obj_(
obj)
737 void setPoseMessage(
const geometry_msgs::Pose* pose)
742 void operator()(
const shape_msgs::Plane& shape_msg)
const
744 obj_->planes.push_back(shape_msg);
748 void operator()(
const shape_msgs::Mesh& shape_msg)
const
750 obj_->meshes.push_back(shape_msg);
754 void operator()(
const shape_msgs::SolidPrimitive& shape_msg)
const
756 obj_->primitives.push_back(shape_msg);
761 moveit_msgs::CollisionObject*
obj_;
762 const geometry_msgs::Pose*
pose_;
773 collision_obj.id = ns;
774 collision_obj.operation = moveit_msgs::CollisionObject::ADD;
775 ShapeVisitorAddToCollisionObject sv(&collision_obj);
776 for (std::size_t j = 0; j <
obj->shapes_.size(); ++j)
782 sv.setPoseMessage(&p);
783 boost::apply_visitor(sv, sm);
787 if (!collision_obj.primitives.empty() || !collision_obj.meshes.empty() || !collision_obj.planes.empty())
792 for (
const auto& frame_pair :
obj->subframe_poses_)
794 collision_obj.subframe_names.push_back(frame_pair.first);
795 geometry_msgs::Pose p;
797 collision_obj.subframe_poses.push_back(p);
805 collision_objs.clear();
806 const std::vector<std::string>& ids =
world_->getObjectIds();
807 for (
const std::string&
id : ids)
810 collision_objs.emplace_back();
816 const std::string& ns)
const
818 std::vector<moveit_msgs::AttachedCollisionObject> attached_collision_objs;
820 for (moveit_msgs::AttachedCollisionObject& it : attached_collision_objs)
822 if (it.object.id == ns)
824 attached_collision_obj = it;
832 std::vector<moveit_msgs::AttachedCollisionObject>& attached_collision_objs)
const
834 std::vector<const moveit::core::AttachedBody*> attached_bodies;
842 octomap.octomap = octomap_msgs::Octomap();
847 if (map->shapes_.size() == 1)
854 ROS_ERROR_NAMED(
LOGNAME,
"Unexpected number of shapes in octomap collision object. Not including '%s' object",
862 object_colors.clear();
867 object_colors.resize(cmap.size());
868 for (ObjectColorMap::const_iterator it = cmap.begin(); it != cmap.end(); ++it, ++i)
870 object_colors[i].id = it->first;
871 object_colors[i].color = it->second;
877 scene_msg.name =
name_;
878 scene_msg.is_diff =
false;
897 const moveit_msgs::PlanningSceneComponents& comp)
const
899 scene_msg.is_diff =
false;
900 if (comp.components & moveit_msgs::PlanningSceneComponents::SCENE_SETTINGS)
902 scene_msg.name =
name_;
906 if (comp.components & moveit_msgs::PlanningSceneComponents::TRANSFORMS)
909 if (comp.components & moveit_msgs::PlanningSceneComponents::ROBOT_STATE_ATTACHED_OBJECTS)
912 for (moveit_msgs::AttachedCollisionObject& attached_collision_object :
913 scene_msg.robot_state.attached_collision_objects)
917 attached_collision_object.object.type =
getObjectType(attached_collision_object.object.id);
921 else if (comp.components & moveit_msgs::PlanningSceneComponents::ROBOT_STATE)
926 if (comp.components & moveit_msgs::PlanningSceneComponents::ALLOWED_COLLISION_MATRIX)
929 if (comp.components & moveit_msgs::PlanningSceneComponents::LINK_PADDING_AND_SCALING)
935 if (comp.components & moveit_msgs::PlanningSceneComponents::OBJECT_COLORS)
939 if (comp.components & moveit_msgs::PlanningSceneComponents::WORLD_OBJECT_GEOMETRY)
941 else if (comp.components & moveit_msgs::PlanningSceneComponents::WORLD_OBJECT_NAMES)
943 const std::vector<std::string>& ids =
world_->getObjectIds();
944 scene_msg.world.collision_objects.clear();
945 scene_msg.world.collision_objects.reserve(ids.size());
946 for (
const std::string&
id : ids)
949 moveit_msgs::CollisionObject co;
953 scene_msg.world.collision_objects.push_back(co);
958 if (comp.components & moveit_msgs::PlanningSceneComponents::OCTOMAP)
964 out <<
name_ << std::endl;
965 const std::vector<std::string>& ids =
world_->getObjectIds();
966 for (
const std::string&
id : ids)
972 out <<
"* " <<
id << std::endl;
977 out <<
obj->shapes_.size() << std::endl;
978 for (std::size_t j = 0; j <
obj->shapes_.size(); ++j)
986 out << c.r <<
" " << c.g <<
" " << c.b <<
" " << c.a << std::endl;
989 out <<
"0 0 0 0" << std::endl;
993 out <<
obj->subframe_poses_.size() << std::endl;
994 for (
auto& pose_pair :
obj->subframe_poses_)
996 out << pose_pair.first << std::endl;
1001 out <<
"." << std::endl;
1011 if (!in.good() || in.eof())
1017 std::getline(in,
name_);
1020 auto pos = in.tellg();
1024 std::getline(in, line);
1025 }
while (in.good() && !in.eof() && (line.empty() || line[0] !=
'*'));
1026 std::getline(in, line);
1027 boost::algorithm::trim(line);
1030 bool uses_new_scene_format = line.find(
' ') != std::string::npos;
1033 Eigen::Isometry3d pose;
1038 if (!in.good() || in.eof())
1045 std::string object_id;
1046 std::getline(in, object_id);
1047 if (!in.good() || in.eof())
1052 boost::algorithm::trim(object_id);
1061 pose = offset * pose;
1062 world_->setObjectPose(object_id, pose);
1065 unsigned int shape_count;
1067 for (std::size_t i = 0; i < shape_count && in.good() && !in.eof(); ++i)
1081 if (!(in >> r >> g >> b >> a))
1088 world_->addToObject(object_id, shape, pose);
1089 if (r > 0.0f || g > 0.0f || b > 0.0f || a > 0.0f)
1091 std_msgs::ColorRGBA color;
1102 if (uses_new_scene_format)
1105 unsigned int subframe_count;
1106 in >> subframe_count;
1107 for (std::size_t i = 0; i < subframe_count && in.good() && !in.eof(); ++i)
1109 std::string subframe_name;
1110 in >> subframe_name;
1116 subframes[subframe_name] = pose;
1118 world_->setSubframesOfObject(object_id, subframes);
1121 else if (marker ==
".")
1136 double x,
y,
z, rx, ry, rz, rw;
1137 if (!(in >> x >> y >> z))
1142 if (!(in >> rx >> ry >> rz >> rw))
1147 pose = Eigen::Translation3d(x, y, z) * Eigen::Quaterniond(rw, rx, ry, rz);
1153 out << pose.translation().x() <<
" " << pose.translation().y() <<
" " << pose.translation().z() << std::endl;
1154 Eigen::Quaterniond
r(pose.linear());
1155 out <<
r.x() <<
" " <<
r.y() <<
" " <<
r.z() <<
" " <<
r.w() << std::endl;
1162 moveit_msgs::RobotState state_no_attached(state);
1163 state_no_attached.attached_collision_objects.clear();
1177 for (std::size_t i = 0; i < state.attached_collision_objects.size(); ++i)
1179 if (!state.is_diff && state.attached_collision_objects[i].object.operation != moveit_msgs::CollisionObject::ADD)
1182 "The specified RobotState is not marked as is_diff. "
1183 "The request to modify the object '%s' is not supported. Object is ignored.",
1184 state.attached_collision_objects[i].object.id.c_str());
1215 acm_ = std::make_shared<collision_detection::AllowedCollisionMatrix>(
parent_->getAllowedCollisionMatrix());
1217 for (std::pair<const std::string, CollisionDetectorPtr>& it :
collision_)
1219 it.second->parent_.reset();
1226 parent_->getKnownObjectColors(kc);
1232 parent_->getKnownObjectColors(kc);
1233 for (ObjectColorMap::const_iterator it = kc.begin(); it != kc.end(); ++it)
1235 (*object_colors_)[it->first] = it->second;
1241 parent_->getKnownObjectTypes(kc);
1247 parent_->getKnownObjectTypes(kc);
1248 for (ObjectTypeMap::const_iterator it = kc.begin(); it != kc.end(); ++it)
1250 (*object_types_)[it->first] = it->second;
1261 if (!scene_msg.name.empty())
1262 name_ = scene_msg.name;
1264 if (!scene_msg.robot_model_name.empty() && scene_msg.robot_model_name !=
getRobotModel()->
getName())
1270 if (!scene_msg.fixed_frame_transforms.empty())
1278 if (!scene_msg.robot_state.multi_dof_joint_state.joint_names.empty() ||
1279 !scene_msg.robot_state.joint_state.name.empty() || !scene_msg.robot_state.attached_collision_objects.empty())
1283 if (!scene_msg.allowed_collision_matrix.entry_names.empty())
1284 acm_ = std::make_shared<collision_detection::AllowedCollisionMatrix>(scene_msg.allowed_collision_matrix);
1286 if (!scene_msg.link_padding.empty() || !scene_msg.link_scale.empty())
1288 for (std::pair<const std::string, CollisionDetectorPtr>& it :
collision_)
1290 it.second->cenv_->setPadding(scene_msg.link_padding);
1291 it.second->cenv_->setScale(scene_msg.link_scale);
1296 for (
const moveit_msgs::ObjectColor& object_color : scene_msg.object_colors)
1300 for (
const moveit_msgs::CollisionObject& collision_object : scene_msg.world.collision_objects)
1304 if (!scene_msg.world.octomap.octomap.data.empty())
1313 name_ = scene_msg.name;
1315 if (!scene_msg.robot_model_name.empty() && scene_msg.robot_model_name !=
getRobotModel()->
getName())
1325 acm_ = std::make_shared<collision_detection::AllowedCollisionMatrix>(scene_msg.allowed_collision_matrix);
1326 for (std::pair<const std::string, CollisionDetectorPtr>& it :
collision_)
1328 it.second->cenv_->setPadding(scene_msg.link_padding);
1329 it.second->cenv_->setScale(scene_msg.link_scale);
1332 for (
const moveit_msgs::ObjectColor& object_color : scene_msg.object_colors)
1341 for (
const moveit_msgs::CollisionObject& collision_object : world.collision_objects)
1349 if (scene_msg.is_diff)
1357 std::shared_ptr<collision_detection::OccMapTree> om =
1358 std::make_shared<collision_detection::OccMapTree>(map.resolution);
1365 std::stringstream datastream;
1366 if (!map.data.empty())
1368 datastream.write((
const char*)&map.data[0], map.data.size());
1369 om->readData(datastream);
1380 if (map.data.empty())
1383 if (map.id !=
"OcTree")
1385 ROS_ERROR_NAMED(
LOGNAME,
"Received octomap is of type '%s' but type 'OcTree' is expected.", map.id.c_str());
1389 std::shared_ptr<collision_detection::OccMapTree> om =
createOctomap(map);
1390 if (!map.header.frame_id.empty())
1403 const std::vector<std::string>& object_ids =
world_->getObjectIds();
1404 for (
const std::string& object_id : object_ids)
1418 if (map.octomap.data.empty())
1421 if (map.octomap.id !=
"OcTree")
1423 ROS_ERROR_NAMED(
LOGNAME,
"Received octomap is of type '%s' but type 'OcTree' is expected.", map.octomap.id.c_str());
1427 std::shared_ptr<collision_detection::OccMapTree> om =
createOctomap(map.octomap);
1430 Eigen::Isometry3d p;
1441 if (map->shapes_.size() == 1)
1448 if (map->shape_poses_[0].isApprox(
t, std::numeric_limits<double>::epsilon() * 100.0))
1471 if (
object.
object.operation == moveit_msgs::CollisionObject::ADD && !
getRobotModel()->hasLinkModel(
object.link_name))
1473 ROS_ERROR_NAMED(
LOGNAME,
"Unable to attach a body to link '%s' (link not found)",
object.link_name.c_str());
1495 if (
object.
object.operation == moveit_msgs::CollisionObject::ADD ||
1496 object.
object.operation == moveit_msgs::CollisionObject::APPEND)
1502 Eigen::Isometry3d object_pose_in_link;
1503 std::vector<shapes::ShapeConstPtr>
shapes;
1511 if (
object.
object.operation == moveit_msgs::CollisionObject::ADD &&
object.
object.primitives.empty() &&
1512 object.object.meshes.empty() &&
object.object.planes.empty())
1517 object.link_name.c_str());
1518 object_pose_in_link =
robot_state_->getGlobalLinkTransform(link_model).inverse() * obj_in_world->pose_;
1519 shapes = obj_in_world->shapes_;
1520 shape_poses = obj_in_world->shape_poses_;
1521 subframe_poses = obj_in_world->subframe_poses_;
1526 "Attempting to attach object '%s' to link '%s' but no geometry specified "
1527 "and such an object does not exist in the collision world",
1528 object.
object.
id.c_str(),
object.link_name.c_str());
1534 Eigen::Isometry3d header_frame_to_object_pose;
1538 const Eigen::Isometry3d link_to_header_frame =
1539 robot_state_->getGlobalLinkTransform(link_model).inverse() * world_to_header_frame;
1540 object_pose_in_link = link_to_header_frame * header_frame_to_object_pose;
1542 Eigen::Isometry3d subframe_pose;
1543 for (std::size_t i = 0; i <
object.object.subframe_poses.size(); ++i)
1546 std::string
name =
object.object.subframe_names[i];
1547 subframe_poses[
name] = subframe_pose;
1554 object.link_name.c_str(),
object.object.id.c_str());
1558 if (!
object.
object.type.db.empty() || !
object.object.type.key.empty())
1562 if (obj_in_world &&
world_->removeObject(
object.object.id))
1564 if (
object.
object.operation == moveit_msgs::CollisionObject::ADD)
1566 object.
object.
id.c_str());
1569 "You tried to append geometry to an attached object "
1570 "that is actually a world object ('%s'). World geometry is ignored.",
1571 object.
object.
id.c_str());
1575 if (
object.
object.operation == moveit_msgs::CollisionObject::ADD ||
1580 "The robot state already had an object named '%s' attached to link '%s'. "
1581 "The object was replaced.",
1582 object.
object.
id.c_str(),
object.link_name.c_str());
1584 robot_state_->attachBody(
object.
object.
id, object_pose_in_link,
shapes, shape_poses,
object.touch_links,
1585 object.link_name,
object.detach_posture, subframe_poses);
1587 object.link_name.c_str());
1595 object_pose_in_link = ab->
getPose();
1600 trajectory_msgs::JointTrajectory detach_posture =
1601 object.detach_posture.joint_names.empty() ? ab->
getDetachPosture() :
object.detach_posture;
1604 touch_links.insert(std::make_move_iterator(
object.touch_links.begin()),
1605 std::make_move_iterator(
object.touch_links.end()));
1608 robot_state_->attachBody(
object.
object.
id, object_pose_in_link,
shapes, shape_poses, touch_links,
1609 object.link_name, detach_posture, subframe_poses);
1610 ROS_DEBUG_NAMED(
LOGNAME,
"Appended things to object '%s' attached to link '%s'",
object.
object.
id.c_str(),
1611 object.link_name.c_str());
1618 else if (
object.
object.operation == moveit_msgs::CollisionObject::REMOVE)
1621 std::vector<const moveit::core::AttachedBody*> attached_bodies;
1622 if (
object.
object.
id.empty())
1625 object.link_name.empty() ? nullptr :
getRobotModel()->getLinkModel(
object.link_name);
1627 robot_state_->getAttachedBodies(attached_bodies, link_model);
1639 <<
object.link_name <<
", but it is actually attached to "
1641 <<
". Leave the link_name empty or specify the correct link.");
1644 attached_bodies.push_back(body);
1651 const std::string&
name = attached_body->getName();
1652 if (
world_->hasObject(name))
1654 "The collision world already has an object with the same name as the body about to be detached. "
1655 "NOT adding the detached body '%s' to the collision world.",
1656 object.
object.
id.c_str());
1659 const Eigen::Isometry3d& pose = attached_body->getGlobalPose();
1660 world_->addToObject(name, pose, attached_body->getShapes(), attached_body->getShapePoses());
1661 world_->setSubframesOfObject(name, attached_body->getSubframes());
1663 name.c_str(),
object.link_name.c_str());
1668 if (!attached_bodies.empty() ||
object.object.id.empty())
1671 else if (
object.
object.operation == moveit_msgs::CollisionObject::MOVE)
1691 if (
object.operation == moveit_msgs::CollisionObject::ADD ||
object.operation == moveit_msgs::CollisionObject::APPEND)
1695 else if (
object.operation == moveit_msgs::CollisionObject::REMOVE)
1699 else if (
object.operation == moveit_msgs::CollisionObject::MOVE)
1710 Eigen::Translation3d translation(msg.position.x, msg.position.y, msg.position.z);
1711 Eigen::Quaterniond quaternion(msg.orientation.w, msg.orientation.x, msg.orientation.y, msg.orientation.z);
1712 if ((quaternion.x() == 0) && (quaternion.y() == 0) && (quaternion.z() == 0) && (quaternion.w() == 0))
1715 quaternion.setIdentity();
1719 quaternion.normalize();
1721 out = translation * quaternion;
1725 Eigen::Isometry3d& object_pose,
1726 std::vector<shapes::ShapeConstPtr>&
shapes,
1729 if (
object.primitives.size() <
object.primitive_poses.size())
1734 if (
object.meshes.size() <
object.mesh_poses.size())
1739 if (
object.planes.size() <
object.plane_poses.size())
1745 const int num_shapes =
object.primitives.size() +
object.meshes.size() +
object.planes.size();
1746 shapes.reserve(num_shapes);
1747 shape_poses.reserve(num_shapes);
1751 bool switch_object_pose_and_shape_pose =
false;
1752 if (num_shapes == 1)
1755 switch_object_pose_and_shape_pose =
true;
1760 &switch_object_pose_and_shape_pose](
shapes::Shape*
s,
const geometry_msgs::Pose& pose_msg) {
1763 Eigen::Isometry3d pose;
1765 if (!switch_object_pose_and_shape_pose)
1766 shape_poses.emplace_back(std::move(pose));
1769 shape_poses.emplace_back(std::move(object_pose));
1775 auto treat_shape_vectors = [&
append](
const auto& shape_vector,
1776 const auto& shape_poses_vector,
1777 const std::string& shape_type) {
1778 if (shape_vector.size() > shape_poses_vector.size())
1781 <<
" does not match number of poses "
1782 "in collision object message. Assuming identity.");
1783 for (std::size_t i = 0; i < shape_vector.size(); ++i)
1785 if (i >= shape_poses_vector.size())
1788 geometry_msgs::Pose identity;
1789 identity.orientation.w = 1.0;
1797 for (std::size_t i = 0; i < shape_vector.size(); ++i)
1801 treat_shape_vectors(
object.primitives,
object.primitive_poses, std::string(
"primitive_poses"));
1802 treat_shape_vectors(
object.meshes,
object.mesh_poses, std::string(
"meshes"));
1803 treat_shape_vectors(
object.planes,
object.plane_poses, std::string(
"planes"));
1815 if (
object.primitives.empty() &&
object.meshes.empty() &&
object.planes.empty())
1822 if (
object.operation == moveit_msgs::CollisionObject::ADD &&
world_->hasObject(
object.id))
1823 world_->removeObject(
object.
id);
1826 Eigen::Isometry3d header_to_pose_transform;
1827 std::vector<shapes::ShapeConstPtr>
shapes;
1831 const Eigen::Isometry3d object_frame_transform = world_to_object_header_transform * header_to_pose_transform;
1833 world_->addToObject(
object.
id, object_frame_transform,
shapes, shape_poses);
1835 if (!
object.type.key.empty() || !
object.type.db.empty())
1840 Eigen::Isometry3d subframe_pose;
1841 for (std::size_t i = 0; i <
object.subframe_poses.size(); ++i)
1844 std::string
name =
object.subframe_names[i];
1845 subframes[
name] = subframe_pose;
1847 world_->setSubframesOfObject(
object.
id, subframes);
1853 if (
object.
id.empty())
1859 if (!
world_->removeObject(
object.id))
1862 "Tried to remove world object '" <<
object.
id <<
"', but it does not exist in this scene.");
1874 if (
world_->hasObject(
object.id))
1876 if (!
object.primitives.empty() || !
object.meshes.empty() || !
object.planes.empty())
1877 ROS_WARN_NAMED(
LOGNAME,
"Move operation for object '%s' ignores the geometry specified in the message.",
1881 Eigen::Isometry3d header_to_pose_transform;
1885 const Eigen::Isometry3d object_frame_transform = world_to_object_header_transform * header_to_pose_transform;
1886 world_->setObjectPose(
object.
id, object_frame_transform);
1908 const std::string& frame_id)
const
1910 if (!frame_id.empty() && frame_id[0] ==
'/')
1919 const Eigen::Isometry3d& t2 =
getWorld()->getTransform(frame_id, frame_found);
1932 if (!frame_id.empty() && frame_id[0] ==
'/')
1937 if (
getWorld()->knowsTransform(frame_id))
1948 return parent_->hasObjectType(object_id);
1956 ObjectTypeMap::const_iterator it =
object_types_->find(object_id);
1961 return parent_->getObjectType(object_id);
1962 static const object_recognition_msgs::ObjectType EMPTY;
1970 (*object_types_)[object_id] = type;
1983 parent_->getKnownObjectTypes(kc);
1986 kc[it->first] = it->second;
1995 return parent_->hasObjectColor(object_id);
2003 ObjectColorMap::const_iterator it =
object_colors_->find(object_id);
2008 return parent_->getObjectColor(object_id);
2009 static const std_msgs::ColorRGBA EMPTY;
2017 parent_->getKnownObjectColors(kc);
2020 kc[it->first] = it->second;
2025 if (object_id.empty())
2032 (*object_colors_)[object_id] = color;
2095 kinematic_constraints::KinematicConstraintSetPtr ks(
2120 static const moveit_msgs::Constraints EMP_CONSTRAINTS;
2126 static const moveit_msgs::Constraints EMP_CONSTRAINTS;
2131 const std::string& group,
bool verbose)
const
2139 const std::string& group,
bool verbose)
const
2160 const moveit_msgs::RobotTrajectory& trajectory,
const std::string& group,
bool verbose,
2161 std::vector<std::size_t>* invalid_index)
const
2163 static const moveit_msgs::Constraints EMP_CONSTRAINTS;
2164 static const std::vector<moveit_msgs::Constraints> EMP_CONSTRAINTS_VECTOR;
2165 return isPathValid(start_state, trajectory, EMP_CONSTRAINTS, EMP_CONSTRAINTS_VECTOR, group,
verbose, invalid_index);
2169 const moveit_msgs::RobotTrajectory& trajectory,
2170 const moveit_msgs::Constraints& path_constraints,
const std::string& group,
2171 bool verbose, std::vector<std::size_t>* invalid_index)
const
2173 static const std::vector<moveit_msgs::Constraints> EMP_CONSTRAINTS_VECTOR;
2174 return isPathValid(start_state, trajectory, path_constraints, EMP_CONSTRAINTS_VECTOR, group,
verbose, invalid_index);
2178 const moveit_msgs::RobotTrajectory& trajectory,
2179 const moveit_msgs::Constraints& path_constraints,
2180 const moveit_msgs::Constraints& goal_constraints,
const std::string& group,
2181 bool verbose, std::vector<std::size_t>* invalid_index)
const
2183 std::vector<moveit_msgs::Constraints> goal_constraints_vector(1, goal_constraints);
2184 return isPathValid(start_state, trajectory, path_constraints, goal_constraints_vector, group,
verbose, invalid_index);
2188 const moveit_msgs::RobotTrajectory& trajectory,
2189 const moveit_msgs::Constraints& path_constraints,
2190 const std::vector<moveit_msgs::Constraints>& goal_constraints,
const std::string& group,
2191 bool verbose, std::vector<std::size_t>* invalid_index)
const
2196 t.setRobotTrajectoryMsg(
start, trajectory);
2201 const moveit_msgs::Constraints& path_constraints,
2202 const std::vector<moveit_msgs::Constraints>& goal_constraints,
const std::string& group,
2203 bool verbose, std::vector<std::size_t>* invalid_index)
const
2207 invalid_index->clear();
2211 for (std::size_t i = 0; i < n_wp; ++i)
2215 bool this_state_valid =
true;
2217 this_state_valid =
false;
2219 this_state_valid =
false;
2221 this_state_valid =
false;
2223 if (!this_state_valid)
2226 invalid_index->push_back(i);
2233 if (i + 1 == n_wp && !goal_constraints.empty())
2236 for (
const moveit_msgs::Constraints& goal_constraint : goal_constraints)
2249 invalid_index->push_back(i);
2258 const moveit_msgs::Constraints& path_constraints,
2259 const moveit_msgs::Constraints& goal_constraints,
const std::string& group,
2260 bool verbose, std::vector<std::size_t>* invalid_index)
const
2262 std::vector<moveit_msgs::Constraints> goal_constraints_vector(1, goal_constraints);
2263 return isPathValid(trajectory, path_constraints, goal_constraints_vector, group, verbose, invalid_index);
2267 const moveit_msgs::Constraints& path_constraints,
const std::string& group,
2268 bool verbose, std::vector<std::size_t>* invalid_index)
const
2270 static const std::vector<moveit_msgs::Constraints> EMP_CONSTRAINTS_VECTOR;
2271 return isPathValid(trajectory, path_constraints, EMP_CONSTRAINTS_VECTOR, group, verbose, invalid_index);
2275 bool verbose, std::vector<std::size_t>* invalid_index)
const
2277 static const moveit_msgs::Constraints EMP_CONSTRAINTS;
2278 static const std::vector<moveit_msgs::Constraints> EMP_CONSTRAINTS_VECTOR;
2279 return isPathValid(trajectory, EMP_CONSTRAINTS, EMP_CONSTRAINTS_VECTOR, group, verbose, invalid_index);
2283 std::set<collision_detection::CostSource>& costs,
double overlap_fraction)
const
2285 getCostSources(trajectory, max_costs, std::string(), costs, overlap_fraction);
2289 const std::string& group_name, std::set<collision_detection::CostSource>& costs,
2290 double overlap_fraction)
const
2296 std::set<collision_detection::CostSource> cs;
2297 std::set<collision_detection::CostSource> cs_start;
2299 for (std::size_t i = 0; i < n_wp; ++i)
2308 if (cs.size() <= max_costs)
2314 for (std::set<collision_detection::CostSource>::iterator it = cs.begin(); i < max_costs; ++it, ++i)
2323 std::set<collision_detection::CostSource>& costs)
const
2329 const std::string& group_name,
2330 std::set<collision_detection::CostSource>& costs)
const
2343 const std::vector<std::string>& objects =
getWorld()->getObjectIds();
2344 std::vector<const moveit::core::AttachedBody*> attached_bodies;
2348 out <<
"-----------------------------------------\n";
2349 out <<
"PlanningScene Known Objects:\n";
2350 out <<
" - Collision World Objects:\n ";
2351 for (
const std::string&
object : objects)
2353 out <<
"\t- " <<
object <<
"\n";
2356 out <<
" - Attached Bodies:\n";
2359 out <<
"\t- " << attached_body->getName() <<
"\n";
2361 out <<
"-----------------------------------------\n";