trajectory_utils.cpp
Go to the documentation of this file.
1 //
2 // Created by yijiangh on 7/9/17.
3 //
4 
5 #include "trajectory_utils.h"
6 
7 static unsigned int calculateRequiredSteps(const std::vector<double>& start,
8  const std::vector<double>& stop, double dtheta)
9 {
10  // calculate max steps required
11  unsigned steps = 0;
12  for (std::size_t i = 0; i < start.size(); ++i)
13  {
14  unsigned this_joint_steps = static_cast<unsigned>(std::ceil(std::abs(start[i] - stop[i]) / dtheta));
15  steps = std::max(steps, this_joint_steps);
16  }
17 
18  return steps;
19 }
20 
21 static std::vector<double> calculateJointSteps(const std::vector<double>& start,
22  const std::vector<double>& stop, unsigned int steps)
23 {
24  // Given max steps, calculate delta for each joint
25  std::vector<double> result;
26  result.reserve(start.size());
27 
28  for (std::size_t i = 0; i < start.size(); ++i)
29  {
30  result.push_back((stop[i] - start[i]) / steps);
31  }
32 
33  return result;
34 }
35 
36 static std::vector<double> interpolateJointSteps(const std::vector<double>& start,
37  const std::vector<double>& step_size,
38  unsigned step)
39 {
40  std::vector<double> result;
41  result.reserve(start.size());
42  for (std::size_t i = 0; i < start.size(); ++i)
43  result.push_back(start[i] + step_size[i] * step);
44  return result;
45 }
46 
48 choreo_process_planning::interpolateCartesian(const Eigen::Affine3d& start,
49  const Eigen::Affine3d& stop, double ds)
50 {
51  // Required position change
52  Eigen::Vector3d delta = (stop.translation() - start.translation());
53  Eigen::Vector3d start_pos = start.translation();
54 
55  // Calculate number of steps
56  unsigned steps = static_cast<unsigned>(delta.norm() / ds) + 1;
57 
58  // Step size
59  Eigen::Vector3d step = delta / steps;
60 
61  // Orientation interpolation
62  Eigen::Quaterniond start_q(start.rotation());
63  Eigen::Quaterniond stop_q(stop.rotation());
64  double slerp_ratio = 1.0 / steps;
65 
67  result.reserve(steps);
68  for (unsigned i = 0; i <= steps; ++i)
69  {
70  Eigen::Vector3d trans = start_pos + step * i;
71  Eigen::Quaterniond q = start_q.slerp(slerp_ratio * i, stop_q);
72  Eigen::Affine3d pose(Eigen::Translation3d(trans) * q);
73  result.push_back(pose);
74  }
75  return result;
76 }
77 
79 choreo_process_planning::interpolateJoint(const std::vector<double>& start,
80  const std::vector<double>& stop, double dtheta)
81 {
83  // joint delta
84  unsigned steps = calculateRequiredSteps(start, stop, dtheta);
85  std::vector<double> delta = calculateJointSteps(start, stop, steps);
86  // Walk interpolation
87  for (std::size_t i = 0; i <= steps; ++i)
88  {
89  std::vector<double> pos = interpolateJointSteps(start, delta, i);
90  result.push_back(pos);
91  }
92  return result;
93 }
q
JointVector interpolateJoint(const std::vector< double > &start, const std::vector< double > &stop, double dtheta)
std::vector< std::vector< double > > JointVector
static std::vector< double > interpolateJointSteps(const std::vector< double > &start, const std::vector< double > &step_size, unsigned step)
static std::vector< double > calculateJointSteps(const std::vector< double > &start, const std::vector< double > &stop, unsigned int steps)
static unsigned int calculateRequiredSteps(const std::vector< double > &start, const std::vector< double > &stop, double dtheta)
unsigned int step
PoseVector interpolateCartesian(const Eigen::Affine3d &start, const Eigen::Affine3d &stop, double ds)
std::vector< Eigen::Affine3d, Eigen::aligned_allocator< Eigen::Affine3d > > PoseVector


choreo_process_planning
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:02