11 #include <shape_msgs/Mesh.h> 13 #include <moveit_msgs/PlanningSceneComponents.h> 14 #include <moveit_msgs/ApplyPlanningScene.h> 15 #include <moveit_msgs/GetPlanningScene.h> 17 #include <moveit_msgs/AttachedCollisionObject.h> 19 #include <geometry_msgs/Point.h> 30 void setEmptyPoseMsg(geometry_msgs::Pose& pose)
32 pose.position.x = 0.0;
33 pose.position.y = 0.0;
34 pose.position.z = 0.0;
35 pose.orientation.w= 0.0;
36 pose.orientation.x= 0.0;
37 pose.orientation.y= 0.0;
38 pose.orientation.z= 0.0;
41 geometry_msgs::Point reversePointMsg(
const geometry_msgs::Point& p)
43 geometry_msgs::Point rp;
55 const std::vector <moveit_msgs::CollisionObject> &add_cos,
56 const std::vector <moveit_msgs::CollisionObject> &remove_cos,
57 const std::vector <moveit_msgs::AttachedCollisionObject> &attach_objs,
58 const std::vector <moveit_msgs::AttachedCollisionObject> &detach_objs,
59 planning_scene::PlanningScenePtr s)
61 s = base_scene->diff();
63 for(
auto add_co : add_cos)
65 add_co.operation = moveit_msgs::CollisionObject::ADD;
66 assert(s->processCollisionObjectMsg(add_co));
69 for(
auto remove_co : remove_cos)
71 remove_co.operation = moveit_msgs::CollisionObject::REMOVE;
72 assert(s->processCollisionObjectMsg(remove_co));
75 for(
auto ato : attach_objs)
77 ato.object.operation = moveit_msgs::CollisionObject::ADD;
78 assert(s->processAttachedCollisionObjectMsg(ato));
81 for(
auto rto : detach_objs)
83 rto.object.operation = moveit_msgs::CollisionObject::REMOVE;
84 assert(s->processAttachedCollisionObjectMsg(rto));
89 const std::vector <moveit_msgs::CollisionObject> &add_cos,
90 const std::vector <moveit_msgs::CollisionObject> &remove_cos,
91 const std::vector <moveit_msgs::AttachedCollisionObject> &attach_objs,
92 const std::vector <moveit_msgs::AttachedCollisionObject> &detach_objs)
94 planning_scene::PlanningScenePtr scene = base_scene->diff();
100 const std::string& world_frame,
101 const choreo_msgs::AssemblySequencePickNPlace& as_pnp,
102 std::vector<std::vector<planning_scene::PlanningScenePtr>>& planning_scenes_transition,
103 std::vector<std::vector<planning_scene::PlanningScenePtr>>& planning_scenes_subprocess)
110 std::vector <moveit_msgs::CollisionObject> pick_cos;
111 std::vector <moveit_msgs::CollisionObject> place_cos;
113 std::map <std::string, moveit_msgs::CollisionObject> pick_support_surfaces;
114 std::map <std::string, moveit_msgs::CollisionObject> place_support_surfaces;
116 int overall_process_num = as_pnp.sequenced_elements.size();
117 planning_scenes_transition.resize(overall_process_num);
118 planning_scenes_subprocess.resize(overall_process_num);
122 const robot_model::JointModelGroup *eef = moveit_model->getEndEffector(
PICKNPLACE_EEF_NAME);
124 const std::string &ik_link = eef->getEndEffectorParentGroup().second;
129 geometry_msgs::Pose empty_pose;
130 setEmptyPoseMsg(empty_pose);
133 for(
const std::string &pn : as_pnp.pick_support_surface_file_names)
136 as_pnp.file_path + pn,
142 for(
const std::string &pn : as_pnp.place_support_surface_file_names)
145 as_pnp.file_path + pn,
151 for(
const auto &se : as_pnp.sequenced_elements)
156 se.file_path + se.pick_element_geometry_file_name,
163 se.file_path + se.place_element_geometry_file_name,
168 assert(se.order_id == pick_cos.size() - 1 && se.order_id == place_cos.size() - 1);
171 assert(pick_cos.size() == as_pnp.sequenced_elements.size());
172 assert(place_cos.size() == as_pnp.sequenced_elements.size());
180 if (!planning_scene_client.waitForExistence())
182 ROS_ERROR_STREAM(
"[Process Planning] cannot connect with get planning scene server...");
185 moveit_msgs::GetPlanningScene srv;
186 srv.request.components.components =
187 moveit_msgs::PlanningSceneComponents::ROBOT_STATE
188 | moveit_msgs::PlanningSceneComponents::WORLD_OBJECT_GEOMETRY;
190 if (!planning_scene_client.call(srv))
196 root_scene->getCurrentStateNonConst().setToDefaultValues();
197 root_scene->getCurrentStateNonConst().update();
198 root_scene->setPlanningSceneDiffMsg(srv.response.scene);
203 for(
int i = 0; i < as_pnp.sequenced_elements.size(); i++)
205 pick_cos[i].operation = pick_cos[i].ADD;
206 assert(root_scene->processCollisionObjectMsg(pick_cos[i]));
209 moveit_msgs::AttachedCollisionObject last_attached_co;
211 for(
int i=0; i < as_pnp.sequenced_elements.size(); i++)
213 const auto& se = as_pnp.sequenced_elements[i];
214 assert(i == se.order_id);
217 planning_scene::PlanningScenePtr last_place_scene = 0==i ? root_scene : planning_scenes_subprocess[i-1].back();
219 auto tr2pick_scene = last_place_scene->diff();
229 place_cos[i-1].operation = place_cos[i-1].ADD;
230 assert(tr2pick_scene->processCollisionObjectMsg(place_cos[i-1]));
233 planning_scenes_transition[i].push_back(tr2pick_scene);
238 auto pick_scene = tr2pick_scene->diff();
241 pick_cos[i].operation = pick_cos[i].REMOVE;
242 assert(pick_scene->processCollisionObjectMsg(pick_cos[i]));
258 planning_scenes_subprocess[i].push_back(pick_scene);
260 planning_scenes_transition[i].push_back(pick_scene);
262 planning_scenes_subprocess[i].push_back(pick_scene);
267 auto tr2place_scene = pick_scene->diff();
291 planning_scenes_transition[i].push_back(tr2place_scene);
296 auto place_scene = tr2place_scene->diff();
299 last_attached_co.object.operation = last_attached_co.object.REMOVE;
300 assert(place_scene->processAttachedCollisionObjectMsg(last_attached_co));
302 assert(place_scene->processCollisionObjectMsg(last_attached_co.object));
315 planning_scenes_subprocess[i].push_back(place_scene);
317 planning_scenes_transition[i].push_back(place_scene);
319 planning_scenes_subprocess[i].push_back(place_scene);
363 "[Process Planning] constructing planning scenes took " << (build_scenes_end - build_scenes_start).toSec()
368 const std::vector <choreo_msgs::WireFrameCollisionObject> &wf_collision_objs,
369 std::vector <planning_scene::PlanningScenePtr> &planning_scenes_shrinked_approach,
370 std::vector <planning_scene::PlanningScenePtr> &planning_scenes_shrinked_depart,
371 std::vector <planning_scene::PlanningScenePtr> &planning_scenes_full)
375 planning_scenes_shrinked_approach.reserve(wf_collision_objs.size());
376 planning_scenes_shrinked_depart.reserve(wf_collision_objs.size());
377 planning_scenes_full.reserve(wf_collision_objs.size());
382 if (!planning_scene_client.waitForExistence())
384 ROS_ERROR_STREAM(
"[Process Planning] cannot connect with get planning scene server...");
387 moveit_msgs::GetPlanningScene srv;
388 srv.request.components.components =
389 moveit_msgs::PlanningSceneComponents::ROBOT_STATE
390 | moveit_msgs::PlanningSceneComponents::WORLD_OBJECT_GEOMETRY;
392 if (!planning_scene_client.call(srv))
398 root_scene->getCurrentStateNonConst().setToDefaultValues();
399 root_scene->getCurrentStateNonConst().update();
400 root_scene->setPlanningSceneDiffMsg(srv.response.scene);
403 planning_scenes_shrinked_approach.push_back(root_scene);
404 planning_scenes_shrinked_depart.push_back(root_scene);
405 planning_scenes_full.push_back(root_scene);
407 for (std::size_t i = 1; i < wf_collision_objs.size(); ++i)
409 auto last_scene_shrinked = planning_scenes_shrinked_approach.back();
410 auto child_shrinked = last_scene_shrinked->diff();
412 auto c_list = wf_collision_objs[i].recovered_last_neighbor_objs;
413 c_list.push_back(wf_collision_objs[i].last_full_obj);
415 const auto &shrinked_neighbor_objs = wf_collision_objs[i].shrinked_neighbor_objs;
416 c_list.insert(c_list.begin(), shrinked_neighbor_objs.begin(), shrinked_neighbor_objs.end());
418 for (
const auto &c_obj : c_list)
420 if (!child_shrinked->processCollisionObjectMsg(c_obj))
422 ROS_WARN(
"[Process Planning] Failed to process shrinked collision object");
426 auto child_shrinked_depart = child_shrinked->diff();
427 if (!child_shrinked_depart->processCollisionObjectMsg(wf_collision_objs[i].both_side_shrinked_obj))
429 ROS_WARN(
"[Process Planning] Failed to process shrinked collision object");
433 planning_scenes_shrinked_approach.push_back(child_shrinked);
434 planning_scenes_shrinked_depart.push_back(child_shrinked_depart);
439 auto last_scene_full = planning_scenes_full.back();
440 auto child_full = last_scene_full->diff();
443 auto inflated_full_obj = wf_collision_objs[i - 1].full_obj;
446 if (!child_full->processCollisionObjectMsg(inflated_full_obj))
448 ROS_WARN(
"[Process Planning] Failed to process full collision object");
452 planning_scenes_full.push_back(child_full);
457 "[Process Planning] constructing planning scenes took " << (build_scenes_end - build_scenes_start).toSec()
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
void constructPlanningScenes(moveit::core::RobotModelConstPtr moveit_model, const std::string &world_frame, const choreo_msgs::AssemblySequencePickNPlace &as_pnp, std::vector< std::vector< planning_scene::PlanningScenePtr >> &planning_scenes_transition, std::vector< std::vector< planning_scene::PlanningScenePtr >> &planning_scenes_subprocess)
void savedSTLToCollisionObjectMsg(const std::string &file_path, const Eigen::Vector3d &scale_vector, const std::string &frame_id, const geometry_msgs::Pose &p, moveit_msgs::CollisionObject &co, int object_operation=moveit_msgs::CollisionObject::ADD)
static const std::string PICKNPLACE_EEF_NAME
#define ROS_INFO_STREAM(args)
void constructPlanningScene(const planning_scene::PlanningScenePtr base_scene, const std::vector< moveit_msgs::CollisionObject > &add_cos, const std::vector< moveit_msgs::CollisionObject > &remove_cos, const std::vector< moveit_msgs::AttachedCollisionObject > &attach_objs, const std::vector< moveit_msgs::AttachedCollisionObject > &detach_objs, planning_scene::PlanningScenePtr s)
#define ROS_ERROR_STREAM(args)
static const std::string GET_PLANNING_SCENE_SERVICE
static const Eigen::Vector3d MESH_SCALE_VECTOR