39 #include <moveit_msgs/GetPlanningScene.h> 40 #include <moveit_msgs/ApplyPlanningScene.h> 63 moveit_msgs::GetPlanningScene::Request request;
64 moveit_msgs::GetPlanningScene::Response response;
65 std::vector<std::string> result;
66 request.components.components = request.components.WORLD_OBJECT_NAMES;
71 for (std::size_t i = 0; i < response.scene.world.collision_objects.size(); ++i)
72 if (!response.scene.world.collision_objects[i].type.key.empty())
73 result.push_back(response.scene.world.collision_objects[i].id);
77 for (std::size_t i = 0; i < response.scene.world.collision_objects.size(); ++i)
78 result.push_back(response.scene.world.collision_objects[i].id);
84 double maxz,
bool with_type, std::vector<std::string>& types)
86 moveit_msgs::GetPlanningScene::Request request;
87 moveit_msgs::GetPlanningScene::Response response;
88 std::vector<std::string> result;
89 request.components.components = request.components.WORLD_OBJECT_GEOMETRY;
92 ROS_WARN_NAMED(
"planning_scene_interface",
"Could not call planning scene service to get object names");
96 for (std::size_t i = 0; i < response.scene.world.collision_objects.size(); ++i)
98 if (with_type && response.scene.world.collision_objects[i].type.key.empty())
100 if (response.scene.world.collision_objects[i].mesh_poses.empty() &&
101 response.scene.world.collision_objects[i].primitive_poses.empty())
104 for (std::size_t j = 0; j < response.scene.world.collision_objects[i].mesh_poses.size(); ++j)
105 if (!(response.scene.world.collision_objects[i].mesh_poses[j].position.x >= minx &&
106 response.scene.world.collision_objects[i].mesh_poses[j].position.x <= maxx &&
107 response.scene.world.collision_objects[i].mesh_poses[j].position.y >= miny &&
108 response.scene.world.collision_objects[i].mesh_poses[j].position.y <= maxy &&
109 response.scene.world.collision_objects[i].mesh_poses[j].position.z >= minz &&
110 response.scene.world.collision_objects[i].mesh_poses[j].position.z <= maxz))
115 for (std::size_t j = 0; j < response.scene.world.collision_objects[i].primitive_poses.size(); ++j)
116 if (!(response.scene.world.collision_objects[i].primitive_poses[j].position.x >= minx &&
117 response.scene.world.collision_objects[i].primitive_poses[j].position.x <= maxx &&
118 response.scene.world.collision_objects[i].primitive_poses[j].position.y >= miny &&
119 response.scene.world.collision_objects[i].primitive_poses[j].position.y <= maxy &&
120 response.scene.world.collision_objects[i].primitive_poses[j].position.z >= minz &&
121 response.scene.world.collision_objects[i].primitive_poses[j].position.z <= maxz))
128 result.push_back(response.scene.world.collision_objects[i].id);
130 types.push_back(response.scene.world.collision_objects[i].type.key);
136 std::map<std::string, geometry_msgs::Pose>
getObjectPoses(
const std::vector<std::string>& object_ids)
138 moveit_msgs::GetPlanningScene::Request request;
139 moveit_msgs::GetPlanningScene::Response response;
140 std::map<std::string, geometry_msgs::Pose> result;
141 request.components.components = request.components.WORLD_OBJECT_GEOMETRY;
144 ROS_WARN_NAMED(
"planning_scene_interface",
"Could not call planning scene service to get object names");
148 for (std::size_t i = 0; i < response.scene.world.collision_objects.size(); ++i)
150 if (std::find(object_ids.begin(), object_ids.end(), response.scene.world.collision_objects[i].id) !=
153 if (response.scene.world.collision_objects[i].mesh_poses.empty() &&
154 response.scene.world.collision_objects[i].primitive_poses.empty())
156 if (!response.scene.world.collision_objects[i].mesh_poses.empty())
157 result[response.scene.world.collision_objects[i].id] =
158 response.scene.world.collision_objects[i].mesh_poses[0];
160 result[response.scene.world.collision_objects[i].id] =
161 response.scene.world.collision_objects[i].primitive_poses[0];
167 std::map<std::string, moveit_msgs::CollisionObject>
getObjects(
const std::vector<std::string>& object_ids)
169 moveit_msgs::GetPlanningScene::Request request;
170 moveit_msgs::GetPlanningScene::Response response;
171 std::map<std::string, moveit_msgs::CollisionObject> result;
172 request.components.components = request.components.WORLD_OBJECT_GEOMETRY;
175 ROS_WARN_NAMED(
"planning_scene_interface",
"Could not call planning scene service to get object geometries");
179 for (std::size_t i = 0; i < response.scene.world.collision_objects.size(); ++i)
181 if (object_ids.empty() ||
182 std::find(object_ids.begin(), object_ids.end(), response.scene.world.collision_objects[i].id) !=
185 result[response.scene.world.collision_objects[i].id] = response.scene.world.collision_objects[i];
191 std::map<std::string, moveit_msgs::AttachedCollisionObject>
194 moveit_msgs::GetPlanningScene::Request request;
195 moveit_msgs::GetPlanningScene::Response response;
196 std::map<std::string, moveit_msgs::AttachedCollisionObject> result;
197 request.components.components = request.components.ROBOT_STATE_ATTACHED_OBJECTS;
201 "Could not call planning scene service to get attached object geometries");
205 for (std::size_t i = 0; i < response.scene.robot_state.attached_collision_objects.size(); ++i)
207 if (object_ids.empty() ||
208 std::find(object_ids.begin(), object_ids.end(),
209 response.scene.robot_state.attached_collision_objects[i].object.id) != object_ids.end())
211 result[response.scene.robot_state.attached_collision_objects[i].object.id] =
212 response.scene.robot_state.attached_collision_objects[i];
220 moveit_msgs::ApplyPlanningScene::Request request;
221 moveit_msgs::ApplyPlanningScene::Response response;
222 request.scene = planning_scene;
225 ROS_WARN_NAMED(
"planning_scene_interface",
"Failed to call ApplyPlanningScene service");
228 return response.success;
232 const std::vector<moveit_msgs::ObjectColor>& object_colors)
const 235 planning_scene.world.collision_objects = collision_objects;
236 planning_scene.object_colors = object_colors;
238 for (
size_t i = 0; i < planning_scene.object_colors.size(); ++i)
240 if (planning_scene.object_colors[i].id.empty() && i < collision_objects.size())
241 planning_scene.object_colors[i].id = collision_objects[i].id;
246 planning_scene.is_diff =
true;
253 moveit_msgs::CollisionObject object;
254 for (std::size_t i = 0; i < object_ids.size(); ++i)
256 object.id = object_ids[i];
257 object.operation =
object.REMOVE;
258 planning_scene.world.collision_objects.push_back(
object);
260 planning_scene.is_diff =
true;
288 double maxx,
double maxy,
double maxz,
290 std::vector<std::string>& types)
295 std::map<std::string, geometry_msgs::Pose>
301 std::map<std::string, moveit_msgs::CollisionObject>
307 std::map<std::string, moveit_msgs::AttachedCollisionObject>
315 moveit_msgs::PlanningScene ps;
316 ps.robot_state.is_diff =
true;
318 ps.world.collision_objects.reserve(1);
319 ps.world.collision_objects.push_back(collision_object);
324 const std_msgs::ColorRGBA& object_color)
326 moveit_msgs::PlanningScene ps;
327 ps.robot_state.is_diff =
true;
329 ps.world.collision_objects.reserve(1);
330 ps.world.collision_objects.push_back(collision_object);
331 moveit_msgs::ObjectColor oc;
332 oc.id = collision_object.id;
333 oc.color = object_color;
334 ps.object_colors.push_back(oc);
339 const std::vector<moveit_msgs::ObjectColor>& object_colors)
341 moveit_msgs::PlanningScene ps;
342 ps.robot_state.is_diff =
true;
344 ps.world.collision_objects = collision_objects;
345 ps.object_colors = object_colors;
347 for (
size_t i = 0; i < ps.object_colors.size(); ++i)
349 if (ps.object_colors[i].id.empty() && i < collision_objects.size())
350 ps.object_colors[i].id = collision_objects[i].id;
360 moveit_msgs::PlanningScene ps;
361 ps.robot_state.is_diff =
true;
363 ps.robot_state.attached_collision_objects.reserve(1);
364 ps.robot_state.attached_collision_objects.push_back(collision_object);
369 const std::vector<moveit_msgs::AttachedCollisionObject>& collision_objects)
371 moveit_msgs::PlanningScene ps;
372 ps.robot_state.is_diff =
true;
374 ps.robot_state.attached_collision_objects = collision_objects;
384 const std::vector<moveit_msgs::ObjectColor>& object_colors)
const void removeCollisionObjects(const std::vector< std::string > &object_ids) const
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
std::map< std::string, geometry_msgs::Pose > getObjectPoses(const std::vector< std::string > &object_ids)
bool applyCollisionObject(const moveit_msgs::CollisionObject &collision_object)
Apply collision object to the planning scene of the move_group node synchronously. Other PlanningSceneMonitors will NOT receive the update unless they subscribe to move_group's monitored scene.
std::vector< std::string > getKnownObjectNames(bool with_type)
static const std::string GET_PLANNING_SCENE_SERVICE_NAME
void publish(const boost::shared_ptr< M > &message) const
#define ROS_WARN_NAMED(name,...)
bool applyCollisionObjects(const std::vector< moveit_msgs::CollisionObject > &collision_objects, const std::vector< moveit_msgs::ObjectColor > &object_colors=std::vector< moveit_msgs::ObjectColor >())
Apply collision objects to the planning scene of the move_group node synchronously. Other PlanningSceneMonitors will NOT receive the update unless they subscribe to move_group's monitored scene. If object_colors do not specify an id, the corresponding object id from collision_objects is used.
bool call(MReq &req, MRes &res)
ros::ServiceClient apply_planning_scene_service_
std::map< std::string, moveit_msgs::CollisionObject > getObjects(const std::vector< std::string > &object_ids=std::vector< std::string >())
Get the objects identified by the given object ids list. If no ids are provided, return all the known...
void addCollisionObjects(const std::vector< moveit_msgs::CollisionObject > &collision_objects, const std::vector< moveit_msgs::ObjectColor > &object_colors=std::vector< moveit_msgs::ObjectColor >()) const
Add collision objects to the world via /planning_scene. Make sure object.operation is set to object...
std::vector< std::string > getKnownObjectNamesInROI(double minx, double miny, double minz, double maxx, double maxy, double maxz, bool with_type, std::vector< std::string > &types)
PlanningSceneInterfaceImpl * impl_
static const std::string APPLY_PLANNING_SCENE_SERVICE_NAME
std::map< std::string, geometry_msgs::Pose > getObjectPoses(const std::vector< std::string > &object_ids)
Get the poses from the objects identified by the given object ids list.
PlanningSceneInterface(const std::string &ns="")
bool applyAttachedCollisionObjects(const std::vector< moveit_msgs::AttachedCollisionObject > &attached_collision_objects)
Apply attached collision objects to the planning scene of the move_group node synchronously. Other PlanningSceneMonitors will NOT receive the update unless they subscribe to move_group's monitored scene.
bool applyPlanningScene(const moveit_msgs::PlanningScene &ps)
Update the planning_scene of the move_group node with the given ps synchronously. Other PlanningScene...
PlanningSceneInterfaceImpl(const std::string &ns="")
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::ServiceClient planning_scene_service_
std::map< std::string, moveit_msgs::AttachedCollisionObject > getAttachedObjects(const std::vector< std::string > &object_ids=std::vector< std::string >())
Get the attached objects identified by the given object ids list. If no ids are provided, return all the attached objects.
bool applyAttachedCollisionObject(const moveit_msgs::AttachedCollisionObject &attached_collision_object)
Apply attached collision object to the planning scene of the move_group node synchronously. Other PlanningSceneMonitors will NOT receive the update unless they subscribe to move_group's monitored scene.
std::vector< std::string > getKnownObjectNames(bool with_type=false)
Get the names of all known objects in the world. If with_type is set to true, only return objects tha...
void removeCollisionObjects(const std::vector< std::string > &object_ids) const
Remove collision objects from the world via /planning_scene.
bool applyPlanningScene(const moveit_msgs::PlanningScene &planning_scene)
std::vector< std::string > getKnownObjectNamesInROI(double minx, double miny, double minz, double maxx, double maxy, double maxz, bool with_type, std::vector< std::string > &types)
Get the names of known objects in the world that are located within a bounding region (specified in t...
~PlanningSceneInterface()
ros::NodeHandle node_handle_
void addCollisionObjects(const std::vector< moveit_msgs::CollisionObject > &collision_objects, const std::vector< moveit_msgs::ObjectColor > &object_colors) const
std::map< std::string, moveit_msgs::AttachedCollisionObject > getAttachedObjects(const std::vector< std::string > &object_ids)
std::map< std::string, moveit_msgs::CollisionObject > getObjects(const std::vector< std::string > &object_ids)
ros::Publisher planning_scene_diff_publisher_
robot_model::RobotModelConstPtr robot_model_