choreo_visual_tools.cpp
Go to the documentation of this file.
2 
5 
6 // msg
7 #include <visualization_msgs/MarkerArray.h>
8 
9 #include <boost/filesystem.hpp>
10 
14 
18 
20 
22 
26 
28 
31 
32 const static std::string FILE_URL_PREFIX = "file://";
33 
34 const static Eigen::Affine3d ZERO_POSE = Eigen::Affine3d::Identity();
35 
36 const static double VISUAL_DIAMETER_SCALE = 10;
37 
38 // TODO: mesh scale should read from input model param
39 // default millimeter
40 const static double PNP_MESH_SCALE = 0.001;
41 
42 // TODO: should make ee group name as input or ros param!
43 const static std::string EE_GROUP_NAME = "manipulator_ee";
44 
46  std::string marker_topic,
47  robot_model::RobotModelConstPtr robot_model)
48 {
49  visual_tools_.reset(
50  new moveit_visual_tools::MoveItVisualTools(frame_name, marker_topic, robot_model));
51 
52 // visual_tools_->setLifetime(120.0);
53  visual_tools_->loadMarkerPub();
54 
55  // Clear messages
56  visual_tools_->deleteAllMarkers();
57  visual_tools_->enableBatchPublishing();
58 }
59 
61  const PathArray& path_array, VisualPathArray& visual_path_array)
62 {
63  visual_path_array.clear();
64 
65  for(int i=0; i < path_array_.size(); i++)
66  {
67  VisualUnitProcessPath v_unit_path;
68 
69  // fill in element info
70  tf::pointMsgToEigen(path_array[i].start_pt, v_unit_path.start_pt);
71  tf::pointMsgToEigen(path_array[i].end_pt, v_unit_path.end_pt);
72  v_unit_path.type =
73  static_cast<choreo_visual_tools::UNIT_PATH_TYPE>(path_array[i].type);
74  v_unit_path.diameter = path_array[i].element_diameter * VISUAL_DIAMETER_SCALE;
75 
76  // fill in feasible orientations
77  v_unit_path.oriented_st_pts.clear();
78  Eigen::Vector3d avr_vec = Eigen::Vector3d(0,0,0);
79  int m = path_array[i].feasible_orients.size();
80  for(int j=0; j < m; j++)
81  {
82  Eigen::Vector3d e;
83  tf::vectorMsgToEigen(path_array[i].feasible_orients[j], e);
84 
85  e = e * 0.001 * 15 * VISUAL_DIAMETER_SCALE;
86  avr_vec = avr_vec + e;
87  e = e + v_unit_path.start_pt;
88 
89  v_unit_path.oriented_st_pts.push_back(e);
90  }
91  avr_vec = avr_vec / avr_vec.norm() * 0.001 * 15;
92  avr_vec = avr_vec + v_unit_path.start_pt;
93 
94  v_unit_path.avr_orient_vec = avr_vec;
95 
96  visual_path_array.push_back(v_unit_path);
97  }
98 }
99 
101  const PathArray& path_array, VisualPathArray& visual_path_array)
102 {
103  visual_path_array.clear();
104 
105  for(int i=0; i < path_array_.size(); i++)
106  {
107  VisualUnitProcessPath v_unit_path;
108 
109  // fill in element info
110  tf::pointMsgToEigen(path_array[i].start_pt, v_unit_path.start_pt);
111  tf::pointMsgToEigen(path_array[i].end_pt, v_unit_path.end_pt);
112  v_unit_path.layer_id = path_array[i].layer_id;
113  v_unit_path.diameter = path_array[i].element_diameter;
114 
115  visual_path_array.push_back(v_unit_path);
116  }
117 }
118 
120 {
121  visual_tools_->deleteAllMarkers();
122 
123 // ROS_INFO_STREAM("publishing all paths...");
124 
125  for(std::size_t i = 0; i < visual_path_array_.size(); i++)
126  {
127  rviz_visual_tools::colors type_color;
128 
130  {
131  type_color = rviz_visual_tools::BLUE;
132  }
133 
135  {
136  type_color = rviz_visual_tools::YELLOW;
137  }
138 
140  {
141  type_color = rviz_visual_tools::RED;
142  }
143 
144  visual_tools_->publishArrow(
145  visual_tools_->getVectorBetweenPoints(visual_path_array_[i].start_pt,
146  visual_path_array_[i].end_pt),
147  type_color, WIREFRAME_SIZE,
148  (visual_path_array_[i].start_pt - visual_path_array_[i].end_pt).norm());
149  }
150 
151  visual_tools_->trigger();
152 }
153 
155 {
156  visual_tools_->deleteAllMarkers();
157 
158  assert(as_pnp_.sequenced_elements.size() > 0);
159 
161 
162  for(std::size_t i = 0; i < as_pnp_.sequenced_elements.size(); i++)
163  {
164  const auto& current_as = as_pnp_.sequenced_elements[i];
165 
166  assert(boost::filesystem::exists(current_as.file_path + current_as.pick_element_geometry_file_name));
167  assert(boost::filesystem::exists(current_as.file_path + current_as.place_element_geometry_file_name));
168 
169  visual_tools_->publishMesh(
170  ZERO_POSE,
171  FILE_URL_PREFIX + current_as.file_path + current_as.pick_element_geometry_file_name,
172  PICK_COLOR,
174 
175  visual_tools_->publishMesh(
176  ZERO_POSE,
177  FILE_URL_PREFIX + current_as.file_path + current_as.place_element_geometry_file_name,
178  PLACE_COLOR,
180  }
181 
182  visual_tools_->trigger();
183 }
184 
186 {
187  visual_tools_->deleteAllMarkers();
188 
189  assert(0 <= i && i < visual_path_array_.size());
190 
191  if(0 != i)
192  {
193  for(std::size_t j = 0; j < i; j++)
194  {
195  visual_tools_->publishArrow(
196  visual_tools_->getVectorBetweenPoints(visual_path_array_[j].start_pt,
197  visual_path_array_[j].end_pt),
199  (visual_path_array_[j].start_pt - visual_path_array_[j].end_pt).norm());
200  }
201  }
202 
203  visual_tools_->publishArrow(
204  visual_tools_->getVectorBetweenPoints(visual_path_array_[i].start_pt,
205  visual_path_array_[i].end_pt),
207  (visual_path_array_[i].start_pt - visual_path_array_[i].end_pt).norm());
208 
209  visual_tools_->trigger();
210 }
211 
213 {
214  visual_tools_->deleteAllMarkers();
215 
216  assert(as_pnp_.sequenced_elements.size() > 0 && i < as_pnp_.sequenced_elements.size() && i >= 0);
217 
218  const auto& current_as = as_pnp_.sequenced_elements[i];
219 
220  assert(boost::filesystem::exists(current_as.file_path + current_as.pick_element_geometry_file_name));
221  assert(boost::filesystem::exists(current_as.file_path + current_as.place_element_geometry_file_name));
222 
223  visual_tools_->publishMesh(
224  ZERO_POSE,
225  FILE_URL_PREFIX + current_as.file_path + current_as.pick_element_geometry_file_name,
226  PICK_COLOR,
228 
229  visual_tools_->publishMesh(
230  ZERO_POSE,
231  FILE_URL_PREFIX + current_as.file_path + current_as.place_element_geometry_file_name,
232  PLACE_COLOR,
234 
235  // TODO color switching not working!
236  visualizeSupportSurfaces(current_as.pick_support_surface_file_names, current_as.place_support_surface_file_names);
237 
238  // visualize everything that are placed already
239  for(std::size_t j = 0; j < i; j++)
240  {
241  const auto& as = as_pnp_.sequenced_elements[j];
243 
244  assert(boost::filesystem::exists(as.file_path + as.place_element_geometry_file_name));
245 
246  if (std::find(current_as.place_contact_ngh_ids.begin(),current_as.place_contact_ngh_ids.end(),j)
247  != current_as.place_contact_ngh_ids.end())
248  {
249  p_c = PLACE_NGH_COLOR;
250  }
251  else
252  {
253  p_c = EXIST_ELEMENT_COLOR;
254  }
255 
256  visual_tools_->publishMesh(
257  ZERO_POSE,
258  FILE_URL_PREFIX + as.file_path + as.place_element_geometry_file_name,
259  p_c,
261  }
262 
263  // everything still in the picking pile
264  for(std::size_t j = i+1; j < as_pnp_.sequenced_elements.size(); j++)
265  {
266  const auto& as = as_pnp_.sequenced_elements[j];
268 
269  assert(boost::filesystem::exists(as.file_path + as.pick_element_geometry_file_name));
270 
271  if (std::find(current_as.pick_contact_ngh_ids.begin(),current_as.pick_contact_ngh_ids.end(),j)
272  != current_as.pick_contact_ngh_ids.end())
273  {
274  p_c = PICK_NGH_COLOR;
275  }
276  else
277  {
278  p_c = EXIST_ELEMENT_COLOR;
279  }
280 
281  visual_tools_->publishMesh(
282  ZERO_POSE,
283  FILE_URL_PREFIX + as.file_path + as.pick_element_geometry_file_name,
284  p_c,
286  }
287 
288  visual_tools_->trigger();
289 }
290 
292 {
293  assert(0 <= i && i < visual_path_array_.size());
294 
295  for(int j = 0; j < visual_path_array_[i].oriented_st_pts.size(); j++)
296  {
297  rviz_visual_tools::colors type_color;
298  if(!solid)
299  {
300  type_color = rviz_visual_tools::TRANSLUCENT;
301  }
302  else
303  {
304  type_color = rviz_visual_tools::GREEN;
305  }
306 
307  visual_tools_->publishCylinder(
308  visual_path_array_[i].start_pt,
309  visual_path_array_[i].oriented_st_pts[j],
310  type_color,
311  0.0003 * VISUAL_DIAMETER_SCALE,
312  "orientation_cylinder");
313  }
314 
315  rviz_visual_tools::colors type_color_avr;
316  if(!solid)
317  {
318  type_color_avr = rviz_visual_tools::TRANSLUCENT;
319  }
320  else
321  {
322  type_color_avr = rviz_visual_tools::PURPLE;
323  }
324 
325  visual_tools_->publishCylinder(
326  visual_path_array_[i].start_pt,
327  visual_path_array_[i].avr_orient_vec,
328  type_color_avr,
329  0.0003 * VISUAL_DIAMETER_SCALE,
330  "orientation_cylinder");
331 
332  visual_tools_->trigger();
333 }
334 
335 void choreo_visual_tools::ChoreoVisualTools::visualizeGraspPickNPlace(int index, int grasp_id, bool visualize_ee)
336 {
337  assert(0 <= index && index < as_pnp_.sequenced_elements.size());
338  assert(0 <= grasp_id && grasp_id < as_pnp_.sequenced_elements[index].grasps.size());
339 
340  const auto& g = as_pnp_.sequenced_elements[index].grasps[grasp_id];
341 
342  visual_tools_->publishAxis(g.pick_grasp_pose, GRASP_POSE_ARROW_SIZE);
343  visual_tools_->publishAxis(g.pick_grasp_approach_pose, GRASP_POSE_ARROW_SIZE);
344  visual_tools_->publishAxis(g.pick_grasp_retreat_pose, GRASP_POSE_ARROW_SIZE);
345 
346  visual_tools_->publishAxis(g.place_grasp_pose, GRASP_POSE_ARROW_SIZE);
347  visual_tools_->publishAxis(g.place_grasp_approach_pose, GRASP_POSE_ARROW_SIZE);
348  visual_tools_->publishAxis(g.place_grasp_retreat_pose, GRASP_POSE_ARROW_SIZE);
349 
350  if (visualize_ee)
351  {
352  // TODO: hardcoded end effector group now!
353  const robot_model::JointModelGroup
354  *pick_ee_jmg = visual_tools_->getRobotModel()->getJointModelGroup(EE_GROUP_NAME);
355  assert(visual_tools_->loadEEMarker(pick_ee_jmg));
356 
357 // visual_tools_->loadSharedRobotState();
358 // auto& sbot = visual_tools_->getSharedRobotState();
359 // sbot->setToDefaultValues();
360 // sbot->update();
361 //
362 // const std::vector<std::string>& ee_link_names = pick_ee_jmg->getLinkModelNames();
363 // for(auto s : ee_link_names)
364 // {
365 // ROS_INFO_STREAM("ee group link name : " << s);
366 // }
367 //
368 // visualization_msgs::MarkerArray vm;
369 // std_msgs::ColorRGBA marker_color = visual_tools_->getColor(rviz_visual_tools::GREY);
370 // sbot->getRobotMarkers(vm, ee_link_names, marker_color, pick_ee_jmg->getName(),
371 // ros::Duration());
372 // ROS_INFO_STREAM("Number of rviz markers in end effector: " << vm.markers.size());
373 
374  assert(visual_tools_->publishEEMarkers(g.pick_grasp_pose, pick_ee_jmg, END_EFFECTOR_COLOR));
375 
376  const robot_model::JointModelGroup
377  *place_ee_jmg = visual_tools_->getRobotModel()->getJointModelGroup(EE_GROUP_NAME);
378  assert(visual_tools_->loadEEMarker(place_ee_jmg));
379 
380  assert(visual_tools_->publishEEMarkers(g.place_grasp_pose, place_ee_jmg, END_EFFECTOR_COLOR));
381  }
382 
383  visual_tools_->trigger();
384 }
385 
387 {
388  visual_tools_->deleteAllMarkers();
389 
390  for(std::size_t i = 0; i < visual_path_array_.size(); i++)
391  {
392  rviz_visual_tools::colors type_color =
393  static_cast<rviz_visual_tools::colors>((visual_path_array_[i].layer_id) % 14 + 1);
394 
395  visual_tools_->publishCylinder(visual_path_array_[i].start_pt,
396  visual_path_array_[i].end_pt,
397  type_color,
398  visual_path_array_[i].diameter * VISUAL_DIAMETER_SCALE * 10);
399  }
400 
401  visual_tools_->trigger();
402 }
403 
405 {
406  std::vector<std::string> empty_v;
407  empty_v.clear();
408 
409  visualizeSupportSurfaces(empty_v, empty_v);
410 }
411 
413  const std::vector<std::string>& pick_contact_surf_names,
414  const std::vector<std::string>& place_contact_surf_names)
415 {
416  for(const std::string& pick_surf : as_pnp_.pick_support_surface_file_names)
417  {
418  assert(boost::filesystem::exists(as_pnp_.file_path + pick_surf));
419 
421 
422  // TODO color switching not working!
423  if (std::find(pick_contact_surf_names.begin(),pick_contact_surf_names.end(),pick_surf)
424  != pick_contact_surf_names.end())
425  {
427  }
428  else
429  {
430  p_c = SUPPORT_SURFACE_COLOR;
431  }
432 
433  visual_tools_->publishMesh(
434  ZERO_POSE,
435  FILE_URL_PREFIX + as_pnp_.file_path + pick_surf,
436  p_c,
438  }
439 
440  for(const std::string& place_surf : as_pnp_.place_support_surface_file_names)
441  {
442  assert(boost::filesystem::exists(as_pnp_.file_path + place_surf));
443 
445 
446  if (std::find(place_contact_surf_names.begin(),place_contact_surf_names.end(), place_surf)
447  != place_contact_surf_names.end())
448  {
450  }
451  else
452  {
453  p_c = SUPPORT_SURFACE_COLOR;
454  }
455 
456  visual_tools_->publishMesh(
457  ZERO_POSE,
458  FILE_URL_PREFIX + as_pnp_.file_path + place_surf,
459  p_c,
461  }
462 
463  visual_tools_->trigger();
464 }
465 
467 {
468  visual_tools_->deleteAllMarkers();
469  visual_tools_->trigger();
470 }
static const rviz_visual_tools::colors PICK_CONTACT_SURF_COLOR
static const double PNP_MESH_SCALE
static const rviz_visual_tools::colors GRASP_POSE_COLOR
static const rviz_visual_tools::colors PLACE_COLOR
static const rviz_visual_tools::colors END_EFFECTOR_COLOR
std::vector< Eigen::Vector3d > oriented_st_pts
static const rviz_visual_tools::colors PLACE_CONTACT_SURF_COLOR
std::vector< choreo_msgs::ElementCandidatePoses > PathArray
static const rviz_visual_tools::colors PRE_GRASP_POSE_COLOR
static const rviz_visual_tools::scales GRASP_POSE_ARROW_SIZE
static const rviz_visual_tools::scales WIREFRAME_SIZE
std::vector< choreo_visual_tools::VisualUnitProcessPath > VisualPathArray
static const rviz_visual_tools::colors PLACE_NGH_COLOR
void init(std::string frame_name, std::string marker_topic, robot_model::RobotModelConstPtr robot_model=robot_model::RobotModelConstPtr())
void vectorMsgToEigen(const geometry_msgs::Vector3 &m, Eigen::Vector3d &e)
static const rviz_visual_tools::colors PICK_COLOR
void convertPathVisual(const PathArray &path_array, VisualPathArray &visual_path_array)
void pointMsgToEigen(const geometry_msgs::Point &m, Eigen::Vector3d &e)
static const std::string FILE_URL_PREFIX
static const rviz_visual_tools::colors POST_GRASP_POSE_COLOR
void visualizeGraspPickNPlace(int index, int grasp_id, bool visualize_ee)
void visualizeFeasibleOrientations(int index, bool solid)
static const std::string EE_GROUP_NAME
static const Eigen::Affine3d ZERO_POSE
static const rviz_visual_tools::colors SUPPORT_SURFACE_COLOR
moveit_visual_tools::MoveItVisualToolsPtr visual_tools_
choreo_msgs::AssemblySequencePickNPlace as_pnp_
static const rviz_visual_tools::colors PICK_NGH_COLOR
static const double VISUAL_DIAMETER_SCALE
void convertWireFrameVisual(const PathArray &path_array, VisualPathArray &visual_path_array)
static const rviz_visual_tools::colors EXIST_ELEMENT_COLOR


choreo_visual_tools
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:34