pose_verification_helpers.cpp
Go to the documentation of this file.
1 //
2 // Created by yijiangh on 4/9/18.
3 //
4 
5 #include "../include/choreo_descartes_planner/pose_verification_helpers.h"
6 
7 namespace descartes_planner
8 {
9 
11  descartes_core::RobotModel& model,
12  const std::vector<Eigen::Affine3d>& poses,
15 {
16  // sanity check
17  assert(cap_rung.path_pts_.size() > 0);
18  assert(poses.size() == cap_rung.path_pts_[0].size());
19 
20  std::vector<double> st_jt;
21  std::vector<double> end_jt;
22 
23  std::vector<std::vector<double>> joint_poses;
24 
25  assert(cap_rung.planning_scene_.size() > 0);
26 
27  // check ik feasibility for each of the path points
28  for(size_t c_id = 0; c_id < poses.size(); c_id++)
29  {
30  joint_poses.clear();
31 
32  if(c_id < poses.size() - 1)
33  {
34  model.setPlanningScene(cap_rung.planning_scene_[0]);
35  }
36  else
37  {
38  // TODO: this is temporal workaround
39  // the last pose, prevent eef collide with element being printed
40  model.setPlanningScene(cap_rung.planning_scene_completed_.size()>0 ? cap_rung.planning_scene_completed_[0] : cap_rung.planning_scene_[0]);
41  }
42 
43  model.getAllIK(poses[c_id], joint_poses);
44 
45  if(joint_poses.empty())
46  {
47  // current capsule is invalid if there exists one path point without feasible kinematics solution.
48  return false;
49  }
50  else
51  {
52  // only store kinematics family for only start and end path point
53  if(0 == c_id)
54  {
55  // turn packed joint solution in a contiguous array
56  for (const auto& sol : joint_poses)
57  {
58  st_jt.insert(st_jt.end(), sol.cbegin(), sol.cend());
59  }
60  cap_vert.start_joint_data_ = st_jt;
61  }
62  if(poses.size()-1 == c_id)
63  {
64  // turn packed joint solution in a contiguous array
65  for (const auto& sol : joint_poses)
66  {
67  end_jt.insert(end_jt.end(), sol.cbegin(), sol.cend());
68  }
69  cap_vert.end_joint_data_ = end_jt;
70  }
71  }
72  }// end loop over poses
73 
74  // all poses are valid (have feasible ik solutions)!
75  return true;
76 }
77 
79  descartes_core::RobotModel& model,
80  const std::vector<std::vector<Eigen::Affine3d>>& poses,
83 {
84  // sanity check
85  assert(cap_rung.path_pts_.size() > 0);
86  const int kin_family_size = cap_rung.path_pts_.size();
87 
88  assert(poses.size() == kin_family_size);
89  assert(cap_rung.planning_scene_.size() == kin_family_size);
90 
91  std::vector<double> st_jt;
92  std::vector<double> end_jt;
93 
94  for(int k=0; k<kin_family_size; k++)
95  {
96  std::vector<std::vector<double>> joint_poses;
97 
98  // check ik feasibility for each of the path points
99  for (size_t c_id = 0; c_id < poses[k].size(); c_id++)
100  {
101  joint_poses.clear();
102 
103  model.setPlanningScene(cap_rung.planning_scene_[k]);
104 
105  if (!model.getAllIK(poses[k][c_id], joint_poses))
106  {
107  // current capsule is invalid if there exists one path point without feasible kinematics solution.
108  return false;
109  }
110  else
111  {
112  // only store all kinematics solutions for only start (at first kin family)
113  // and last (at last kin family)
114  if (0 == c_id && 0 == k)
115  {
116  // turn packed joint solution in a contiguous array
117  for (const auto &sol : joint_poses)
118  {
119  st_jt.insert(st_jt.end(), sol.cbegin(), sol.cend());
120  }
121  cap_vert.start_joint_data_ = st_jt;
122  }
123 
124  if (poses[k].size() - 1 == c_id && kin_family_size - 1 == k)
125  {
126  // turn packed joint solution in a contiguous array
127  for (const auto &sol : joint_poses)
128  {
129  end_jt.insert(end_jt.end(), sol.cbegin(), sol.cend());
130  }
131  cap_vert.end_joint_data_ = end_jt;
132  }
133  }
134  }// end loop over poses
135  }
136 
137  // all poses are valid (have feasible ik solutions)!
138  return true;
139 }
140 
142  descartes_core::RobotModel& model,
143  descartes_planner::CapRung& cap_rung,
144  descartes_planner::CapVert& cap_vert)
145 {
146  assert(cap_rung.path_pts_.size() > 0);
147  assert(cap_rung.orientations_.size() > 0);
148 
149  // direct enumeration of domain
150  const std::vector<Eigen::Vector3d> pts = cap_rung.path_pts_[0];
151  std::vector<Eigen::Affine3d> poses;
152  poses.reserve(cap_rung.path_pts_.size());
153 
154  const auto n_angle_disc = std::lround( 2 * M_PI / cap_rung.z_axis_disc_);
155  const auto angle_step = 2 * M_PI / n_angle_disc;
156 
157  for (const auto& orientation : cap_rung.orientations_[0])
158  {
159  for (long i = 0; i < n_angle_disc; ++i)
160  {
161  const auto angle = angle_step * i;
162  poses.clear();
163 
164  for(const auto& pt : pts)
165  {
166  poses.push_back(makePose(pt, orientation, angle));
167  }
168 
169  if(checkFeasibility(model, poses, cap_rung, cap_vert))
170  {
171  cap_vert.orientation_.push_back(orientation);
172  cap_vert.z_axis_angle_ = angle;
173  return true;
174  }
175  }
176  }
177 
178  return false;
179 }
180 
181 }
std::vector< planning_scene::PlanningScenePtr > planning_scene_
std::vector< double > end_joint_data_
#define M_PI
std::vector< std::vector< Eigen::Matrix3d > > orientations_
bool checkFeasibility(descartes_core::RobotModel &model, const std::vector< Eigen::Affine3d > &poses, descartes_planner::CapRung &cap_rung, descartes_planner::CapVert &cap_vert)
std::vector< std::vector< Eigen::Vector3d > > path_pts_
bool checkFeasibilityPickNPlace(descartes_core::RobotModel &model, const std::vector< std::vector< Eigen::Affine3d >> &poses, descartes_planner::CapRung &cap_rung, descartes_planner::CapVert &cap_vert)
std::vector< double > start_joint_data_
std::vector< planning_scene::PlanningScenePtr > planning_scene_completed_
std::vector< Eigen::Matrix3d > orientation_
bool domainDiscreteEnumerationCheck(descartes_core::RobotModel &model, descartes_planner::CapRung &cap_rung, descartes_planner::CapVert &cap_vert)
Eigen::Affine3d makePose(const Eigen::Vector3d &position, const Eigen::Matrix3d &orientation, const double z_axis_angle)


choreo_descartes_planner
Author(s): Yijiang Huang , Jonathan Meyer
autogenerated on Thu Jul 18 2019 03:58:35