unit_process.cpp
Go to the documentation of this file.
1 //
2 // Created by yijiangh on 6/26/17.
3 //
4 #include <ros/ros.h>
5 #include <ros/console.h>
6 
10 
11 double dist(const Eigen::Vector3d& from, const Eigen::Vector3d& to)
12 {
13  return (from - to).norm();
14 }
15 
17  const Eigen::Vector3d& st_pt, const Eigen::Vector3d& end_pt) const
18 {
19  geometry_msgs::Pose cylinder_pose;
20 
21  // rotation
22  Eigen::Vector3d axis = end_pt - st_pt;
23  axis.normalize();
24  Eigen::Vector3d z_vec(0.0, 0.0, 1.0);
25  const Eigen::Vector3d& x_vec = axis.cross(z_vec);
26 
27  tf::Quaternion tf_q;
28  if(0 == x_vec.norm())
29  {
30  // axis = z_vec
31  tf_q = tf::Quaternion(0, 0, 0, 1);
32  }
33  else
34  {
35  double theta = axis.dot(z_vec);
36  double angle = -1.0 * acos(theta);
37 
38  // convert eigen vertor to tf::Vector3
39  tf::Vector3 x_vec_tf;
40  tf::vectorEigenToTF(x_vec, x_vec_tf);
41 
42  // Create quaternion
43  tf_q = tf::Quaternion(x_vec_tf, angle);
44  tf_q.normalize();
45  }
46 
47  //back to ros coords
48  tf::quaternionTFToMsg(tf_q, cylinder_pose.orientation);
49  tf::pointEigenToMsg((end_pt + st_pt) * 0.5, cylinder_pose.position);
50 
51  return cylinder_pose;
52 }
53 
55  const int& id, const Eigen::Vector3d& st_pt, const Eigen::Vector3d& end_pt,
56  const double& element_diameter, std::string&& shrink_type_suffix) const
57 {
58  moveit_msgs::CollisionObject collision_cylinder;
59  std::string cylinder_id = "element_" + std::to_string(id) + "_" + shrink_type_suffix;
60 
61  collision_cylinder.id = cylinder_id;
62  collision_cylinder.header.frame_id = world_frame_;
63  collision_cylinder.operation = moveit_msgs::CollisionObject::ADD;
64 
65  shape_msgs::SolidPrimitive cylinder_solid;
66  cylinder_solid.type = shape_msgs::SolidPrimitive::CYLINDER;
67  cylinder_solid.dimensions.resize(2);
68  cylinder_solid.dimensions[0] = dist(st_pt, end_pt);
69  cylinder_solid.dimensions[1] = element_diameter;
70  collision_cylinder.primitives.push_back(cylinder_solid);
71  collision_cylinder.primitive_poses.push_back(computeCylinderPose(st_pt, end_pt));
72 
73  return collision_cylinder;
74 }
75 
76 void choreo_task_sequence_processing_utils::UnitProcess::createShrinkedEndPoint(Eigen::Vector3d& st_pt, Eigen::Vector3d& end_pt,
77  double shrink_length)
78 {
79  Eigen::Vector3d translation_vec = end_pt - st_pt;
80  translation_vec.normalize();
81 
82  if(2 * shrink_length > (st_pt - end_pt).norm())
83  {
84  ROS_WARN_STREAM("[ts processing] shrink length longer than element length!");
85  shrink_length = 0.2 * (st_pt - end_pt).norm();
86  }
87 
88  st_pt = st_pt + shrink_length * translation_vec;
89  end_pt = end_pt - shrink_length * translation_vec;
90 }
91 
93 {
94  choreo_msgs::ElementCandidatePoses msg;
95 
96  // element index
97  msg.element_id = id_;
98  msg.wireframe_id = wireframe_id_;
99 
100  // process element's type
101  if("support" == type_)
102  {
103  msg.type = choreo_msgs::ElementCandidatePoses::SUPPORT;
104  }
105  if("create" == type_)
106  {
107  msg.type = choreo_msgs::ElementCandidatePoses::CREATE;
108  }
109  if("connect" == type_)
110  {
111  msg.type = choreo_msgs::ElementCandidatePoses::CONNECT;
112  }
113 
114  // add start end point data
115  tf::pointEigenToMsg(st_pt_, msg.start_pt);
116  tf::pointEigenToMsg(end_pt_, msg.end_pt);
117 
118  msg.element_diameter = element_diameter_;
119 
120  Eigen::Vector3d shrinked_st_pt = st_pt_;
121  Eigen::Vector3d shrinked_end_pt = end_pt_;
122 
123  createShrinkedEndPoint(shrinked_st_pt, shrinked_end_pt, shrink_length_);
124 
125  tf::pointEigenToMsg(shrinked_st_pt, msg.shrinked_start_pt);
126  tf::pointEigenToMsg(shrinked_end_pt, msg.shrinked_end_pt);
127 
128  msg.both_side_shrinked_collision_object = createCollisionObject(id_, shrinked_st_pt, shrinked_end_pt,
129  element_diameter_, "shrink_both_ends");
130 
131  msg.st_shrinked_collision_object = createCollisionObject(id_, shrinked_st_pt, end_pt_,
132  element_diameter_, "shrink_start");
133 
134  msg.end_shrinked_collision_object = createCollisionObject(id_, st_pt_, shrinked_end_pt,
135  element_diameter_, "shrink_end");
136 
137 
138 // // for safety, we inflate the full collision geometry
139 // Eigen::Vector3d extended_st_pt = st_pt_;
140 // Eigen::Vector3d extended_end_pt = end_pt_;
141 // createShrinkedEndPoint(extended_st_pt, extended_st_pt, - shrink_length_);
142 
143  msg.full_collision_object = createCollisionObject(id_, st_pt_, end_pt_,
144  element_diameter_, "full");
145 
146 
147  // add feasible EEF orientations
148  for(int i=0; i < feasible_orients_.size(); i++)
149  {
150  geometry_msgs::Vector3 vec_msg;
152 
153  msg.feasible_orients.push_back(vec_msg);
154  }
155 
156  return msg;
157 }
Quaternion & normalize()
void vectorEigenToTF(const Eigen::Vector3d &e, tf::Vector3 &t)
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
void vectorEigenToMsg(const Eigen::Vector3d &e, geometry_msgs::Vector3 &m)
static void quaternionTFToMsg(const Quaternion &bt, geometry_msgs::Quaternion &msg)
#define ROS_WARN_STREAM(args)
void pointEigenToMsg(const Eigen::Vector3d &e, geometry_msgs::Point &m)
void createShrinkedEndPoint(Eigen::Vector3d &st_pt, Eigen::Vector3d &end_st, double shrink_length)
INLINE Rall1d< T, V, S > acos(const Rall1d< T, V, S > &x)
std::vector< Eigen::Vector3d > feasible_orients_
Definition: unit_process.h:62
choreo_msgs::ElementCandidatePoses asElementCandidatePoses()
double dist(const Eigen::Vector3d &from, const Eigen::Vector3d &to)
geometry_msgs::Pose computeCylinderPose(const Eigen::Vector3d &st_pt, const Eigen::Vector3d &end_pt) const
moveit_msgs::CollisionObject createCollisionObject(const int &id, const Eigen::Vector3d &st_pt, const Eigen::Vector3d &end_pt, const double &element_diameter, std::string &&shrink_type_suffix="") const


choreo_task_sequence_processor
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:29