Frankx  0.2.0
A High-Level Motion API for Franka
segment.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 
5 #include <Eigen/Core>
6 
7 
8 namespace movex {
9 
10 using Vector7d = Eigen::Matrix<double, 7, 1>;
11 
12 struct Segment {
13  double length;
14 
15  virtual double get_length() const = 0;
16  virtual Vector7d q(double s) const = 0;
17  virtual Vector7d pdq(double s) const = 0;
18  virtual Vector7d pddq(double s) const = 0;
19  virtual Vector7d pdddq(double s) const = 0;
20 
21  Vector7d dq(double s, double ds) const {
22  return pdq(s) * ds;
23  }
24 
25  Vector7d ddq(double s, double ds, double dds) const {
26  return pddq(s) * std::pow(ds, 2) + pdq(s) * dds;
27  }
28 
29  Vector7d dddq(double s, double ds, double dds, double ddds) const {
30  return 3 * ds * pddq(s) * dds + std::pow(ds, 3) * pdddq(s) + pdq(s) * ddds;
31  }
32 
33  virtual Vector7d max_pddq() const = 0;
34  virtual Vector7d max_pdddq() const = 0;
35 };
36 
37 
38 class LineSegment: public Segment {
39 public:
41 
42  explicit LineSegment(const Vector7d& start, const Vector7d&end): start(start), end(end) {
43  Vector7d diff = end - start;
44 
45  length = diff.norm();
46  }
47 
48  double get_length() const {
49  return length;
50  }
51 
52  Vector7d q(double s) const {
53  return start + s / length * (end - start);
54  }
55 
56  Vector7d pdq(double s) const {
57  return (end - start) / length;
58  }
59 
60  Vector7d pddq(double s) const {
61  return Vector7d::Zero();
62  }
63 
64  Vector7d pdddq(double s) const {
65  return Vector7d::Zero();
66  }
67 
68  Vector7d max_pddq() const {
69  return Vector7d::Zero();
70  }
71 
72  Vector7d max_pdddq() const {
73  return Vector7d::Zero();
74  }
75 };
76 
77 
78 class CircleSegment: public Segment {
79 
80 };
81 
82 
83 class QuinticSegment: public Segment {
84 
85 };
86 
87 
89  void integrate_path_length() {
90  length = 0.0;
91 
92  Vector7d f_s = q(0.0), f_s_new;
93  const size_t steps {5000};
94  const double step_length = s_length / steps;
95  const double step_length_squared = std::pow(step_length, 2);
96  for (int i = 1; i < steps; i += 1) {
97  f_s_new = q(i * step_length);
98  length += std::sqrt((f_s_new - f_s).squaredNorm() + step_length_squared);
99  std::swap(f_s_new, f_s);
100  }
101  }
102 
103 public:
104  double s_length;
105  Vector7d b, c, e, f;
107 
108  explicit QuarticBlendSegment(const Vector7d& lb, const Vector7d& lm, const Vector7d& rb, const Vector7d& rm, double s_mid, double max_diff, double s_abs_max): lb(lb), lm(lm), rb(rb), rm(rm) {
109  Vector7d sAbs_ = ((-16*max_diff)/(3.*(lm - rm).array())).abs();
110  double s_abs_min = std::min<double>({sAbs_.minCoeff(), s_abs_max});
111  s_length = 2 * s_abs_min;
112 
113  b = (lm - rm).array() / (16.*std::pow(s_abs_min, 3));
114  c = (-lm + rm).array() / (4.*std::pow(s_abs_min, 2));
115  e = lm;
116  f = lb.array() + lm.array()*(-s_abs_min + s_mid);
117  }
118 
119  double get_length() const {
120  return s_length;
121  }
122 
123  Vector7d q(double s) const {
124  return f + s * (e + s * (s * (c + s * b)));
125  }
126 
127  Vector7d pdq(double s) const {
128  return e + s * (s * (3 * c + s * 4 * b));
129  }
130 
131  Vector7d pddq(double s) const {
132  return s * (6 * c + s * 12 * b);
133  }
134 
135  Vector7d pdddq(double s) const {
136  return 6 * c + s * 24 * b;
137  }
138 
139  Vector7d max_pddq() const {
140  double s_abs = s_length / 2;
141  return (-3*(lm - rm))/(4.*s_abs);
142  }
143 
144  Vector7d max_pdddq() const {
145  double s_abs = s_length / 2;
146  return (3*(lm - rm))/(2.*std::pow(s_abs,2));
147  }
148 };
149 
150 } // namespace movex
movex::Segment::length
double length
Definition: segment.hpp:13
movex::QuarticBlendSegment::pddq
Vector7d pddq(double s) const
Definition: segment.hpp:131
movex::LineSegment::get_length
double get_length() const
Definition: segment.hpp:48
movex::Segment::dq
Vector7d dq(double s, double ds) const
Definition: segment.hpp:21
movex::QuarticBlendSegment::c
Vector7d c
Definition: segment.hpp:105
movex::QuarticBlendSegment
Definition: segment.hpp:88
movex::Segment::pdddq
virtual Vector7d pdddq(double s) const =0
movex::LineSegment::LineSegment
LineSegment(const Vector7d &start, const Vector7d &end)
Definition: segment.hpp:42
movex::LineSegment::start
Vector7d start
Definition: segment.hpp:40
movex::QuarticBlendSegment::e
Vector7d e
Definition: segment.hpp:105
movex::QuarticBlendSegment::rm
Vector7d rm
Definition: segment.hpp:106
movex::QuarticBlendSegment::q
Vector7d q(double s) const
Definition: segment.hpp:123
movex::LineSegment::pdddq
Vector7d pdddq(double s) const
Definition: segment.hpp:64
movex::QuarticBlendSegment::pdddq
Vector7d pdddq(double s) const
Definition: segment.hpp:135
movex::QuarticBlendSegment::get_length
double get_length() const
Definition: segment.hpp:119
movex::LineSegment::pddq
Vector7d pddq(double s) const
Definition: segment.hpp:60
movex::QuarticBlendSegment::rb
Vector7d rb
Definition: segment.hpp:106
movex::QuarticBlendSegment::b
Vector7d b
Definition: segment.hpp:105
movex::QuarticBlendSegment::QuarticBlendSegment
QuarticBlendSegment(const Vector7d &lb, const Vector7d &lm, const Vector7d &rb, const Vector7d &rm, double s_mid, double max_diff, double s_abs_max)
Definition: segment.hpp:108
movex::QuarticBlendSegment::f
Vector7d f
Definition: segment.hpp:105
movex::QuarticBlendSegment::max_pdddq
Vector7d max_pdddq() const
Definition: segment.hpp:144
movex::Segment::ddq
Vector7d ddq(double s, double ds, double dds) const
Definition: segment.hpp:25
movex::QuarticBlendSegment::pdq
Vector7d pdq(double s) const
Definition: segment.hpp:127
movex::LineSegment::max_pdddq
Vector7d max_pdddq() const
Definition: segment.hpp:72
movex::Segment::max_pddq
virtual Vector7d max_pddq() const =0
movex::QuinticSegment
Definition: segment.hpp:83
movex::Segment::pddq
virtual Vector7d pddq(double s) const =0
movex::Segment::get_length
virtual double get_length() const =0
movex::LineSegment
Definition: segment.hpp:38
movex::Segment::dddq
Vector7d dddq(double s, double ds, double dds, double ddds) const
Definition: segment.hpp:29
movex::Vector7d
Eigen::Matrix< double, 7, 1 > Vector7d
Definition: segment.hpp:10
movex::QuarticBlendSegment::lm
Vector7d lm
Definition: segment.hpp:106
movex::Segment
Definition: segment.hpp:12
movex::LineSegment::q
Vector7d q(double s) const
Definition: segment.hpp:52
movex::LineSegment::max_pddq
Vector7d max_pddq() const
Definition: segment.hpp:68
movex::Segment::q
virtual Vector7d q(double s) const =0
movex::LineSegment::end
Vector7d end
Definition: segment.hpp:40
movex::CircleSegment
Definition: segment.hpp:78
movex::QuarticBlendSegment::lb
Vector7d lb
Definition: segment.hpp:106
movex
Definition: motion_impedance.hpp:13
movex::Segment::pdq
virtual Vector7d pdq(double s) const =0
movex::Segment::max_pdddq
virtual Vector7d max_pdddq() const =0
movex::LineSegment::pdq
Vector7d pdq(double s) const
Definition: segment.hpp:56
movex::QuarticBlendSegment::s_length
double s_length
Definition: segment.hpp:104
movex::QuarticBlendSegment::max_pddq
Vector7d max_pddq() const
Definition: segment.hpp:139