capsulated_ladder_tree.h
Go to the documentation of this file.
1 //
2 // Created by yijiangh on 11/28/17.
3 //
4 
5 #ifndef CHOREO_DESCARTES_CAPSULATED_LADDER_TREE_H
6 #define CHOREO_DESCARTES_CAPSULATED_LADDER_TREE_H
7 
8 // for Constrained Segment
10 
12 
13 const static double ORIENTATION_PREFERENCE_WEIGHT = 0.0;
14 const static double EXTERNAL_AXIS_PENALIZE_COST = 100.0;
15 
17 {
18 
19 class CapVert
20 {
21  public:
22  explicit CapVert(const double dof) : dof_(dof), z_axis_angle_(-1)
23  {
24  }
25 
27  {}
28 
29  inline double distance(CapVert* v) const
30  {
31  // sanity check
32  if(NULL == v)
33  {
34  return 0.0;
35  }
36 
37  assert(v->dof_ == this->dof_);
38 
39  // directed distance prev.end -> this.start
40  const auto dof = this->dof_;
41  double cost = std::numeric_limits<double>::max();
42  const auto n_prev_end = v->end_joint_data_.size() / dof;
43  const auto n_this_start = this->start_joint_data_.size() / dof;
44 
45  for(size_t i=0; i < n_prev_end; i++)
46  {
47  const auto prev_end_index = i * dof;
48 
49  for (size_t j=0; j < n_this_start; j++)
50  {
51  const auto this_start_index = j * dof;
52 
53  std::vector<double> delta_buffer;
54 
55  if(dof <= 6)
56  {
57  for (size_t k = 0; k < dof; k++)
58  {
59  delta_buffer.push_back(std::abs(v->end_joint_data_[prev_end_index + k]
60  - this->start_joint_data_[this_start_index + k]));
61  }
62  }
63  else
64  {
65  // penalize linear track movement
66  for (size_t k = 0; k < dof; k++)
67  {
68  double axis_weight = 1.0;
69 
70  if(k < dof - 6)
71  {
72  axis_weight = EXTERNAL_AXIS_PENALIZE_COST;
73  }
74 
75  delta_buffer.push_back(axis_weight *
76  std::abs(v->end_joint_data_[prev_end_index + k]
77  - this->start_joint_data_[this_start_index + k]));
78  }
79  }
80 
81  double tmp_cost = std::accumulate(delta_buffer.begin(), delta_buffer.end(), 0.0);
82 
83  if(tmp_cost < cost)
84  {
85  cost = tmp_cost;
86  }
87  }
88  }
89 
90  return cost;
91  }
92 
93  inline double getToParentCost() { return this->to_parent_cost_; }
94 
95  inline CapVert* getParentVertPtr() const { return this->ptr_prev_cap_vert_; }
96 
97  inline void setParentVertPtr(CapVert* ptr_v)
98  {
99  this->ptr_prev_cap_vert_ = ptr_v;
100  this->to_parent_cost_ = this->distance(ptr_v);
101 // + ORIENTATION_PREFERENCE_WEIGHT * delta_o_to_ideal_angle_;
102  }
103 
104  // accumulated cost (the function g)
105  inline double getCost() const
106  {
107  // trace back tree to compute cost
108  CapVert* ptr_prev_v = this->ptr_prev_cap_vert_;
109  double cost = this->to_parent_cost_;
110 
111  while(NULL != ptr_prev_v)
112  {
113  if(NULL != ptr_prev_v->ptr_prev_cap_vert_)
114  {
115  cost += ptr_prev_v->getToParentCost();
116  }
117  ptr_prev_v = ptr_prev_v->ptr_prev_cap_vert_;
118  }
119 
120  return cost;
121  }
122 
123  public:
124  int dof_;
125 
126  // joint values stored in one contiguous array
127  // first joint pose in first partition
128  std::vector<double> start_joint_data_;
129  // last joint pose in last partition
130  std::vector<double> end_joint_data_;
131 
132  size_t rung_id_;
133 
134  // rotation angle around z axis, TODO: only used in spatial extrusion
135  // TODO: temporarily used to distinguish two processes
137 
138  // base orientation, the chosen orientation for each kinematics segment
139  std::vector<Eigen::Matrix3d> orientation_;
140 
141 // double delta_o_to_ideal_angle_;
142 
145 };
146 
147 struct CapRung
148 {
149  std::vector<CapVert*> ptr_cap_verts_;
150 
151  std::vector<std::vector<Eigen::Vector3d>> path_pts_;
152 
153  // stores all the candidate orientations for each kinematics segment (family)
154  std::vector<std::vector<Eigen::Matrix3d>> orientations_;
155 
156  // partition of path points inside (needs to be divided later)
157  std::vector<int> sub_segment_ids_;
158 
159  // associated planning for each partition
160  std::vector<planning_scene::PlanningScenePtr> planning_scene_;
161 
162  // TODO: this is temporal patch to add element that is being printed
163  std::vector<planning_scene::PlanningScenePtr> planning_scene_completed_;
164 
165  // ONLY USED in spatial extrusion
166  // discretization degree for rotation around central z axis
167  double z_axis_disc_;
168 
169  // used in line movement discretization
170  double linear_vel_;
171 };
172 
173 }
174 
175 #endif //DESCARTES_CAPSULATED_LADDER_TREE_H
std::vector< planning_scene::PlanningScenePtr > planning_scene_
static const double EXTERNAL_AXIS_PENALIZE_COST
#define NULL
std::vector< CapVert * > ptr_cap_verts_
std::vector< double > end_joint_data_
std::vector< std::vector< Eigen::Matrix3d > > orientations_
std::vector< std::vector< Eigen::Vector3d > > path_pts_
std::vector< double > start_joint_data_
std::vector< planning_scene::PlanningScenePtr > planning_scene_completed_
void setParentVertPtr(CapVert *ptr_v)
std::vector< Eigen::Matrix3d > orientation_
static const double ORIENTATION_PREFERENCE_WEIGHT
double distance(CapVert *v) const


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