cheshirekow  v0.1.0
integrator.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_DUBINS_CURVES_EIGEN_INTEGRATOR_H_
28 #define MPBLOCKS_DUBINS_CURVES_EIGEN_INTEGRATOR_H_
29 
30 namespace mpblocks {
31 namespace dubins {
32 namespace curves_eigen {
33 
35 
38 template <typename Scalar>
39 struct Integrate {
40  typedef Eigen::Matrix<Scalar, 3, 1> Vector3d;
41  typedef Eigen::Matrix<Scalar, 2, 1> Vector2d;
43 
44  static Vector3d L(const Vector3d& q0, const Scalar r, const Scalar arc) {
45  Vector2d c = leftCenter(q0, r);
46  Scalar theta1 = clampRadian(q0[2] + arc);
47  Scalar alpha1 = leftAngleOf(theta1);
48 
49  return Vector3d(c[0] + r * std::cos(alpha1),
50  c[1] + r * std::sin(alpha1),
51  theta1);
52  }
53 
54  static Vector3d R(const Vector3d& q0, const Scalar r, const Scalar arc) {
55  Vector2d c = rightCenter(q0, r);
56  Scalar theta1 = clampRadian(q0[2] - arc);
57  Scalar alpha1 = rightAngleOf(theta1);
58 
59  return Vector3d(c[0] + r * std::cos(alpha1),
60  c[1] + r * std::sin(alpha1),
61  theta1);
62  }
63 
64  static Vector3d S(const Vector3d& q0, const Scalar d1) {
65  return Vector3d(q0[0] + d1 * std::cos(q0[2]),
66  q0[1] + d1 * std::sin(q0[2]),
67  q0[2]);
68  }
69 
70  static Vector3d LRL(const Vector3d& q0, const Vector3d& s, const Scalar r) {
71  Vector3d q1 = L(q0, r, s[0]);
72  Vector3d q2 = R(q1, r, s[1]);
73  return L(q2, r, s[2]);
74  }
75 
76  static Vector3d RLR(const Vector3d& q0, const Vector3d& s, const Scalar r) {
77  Vector3d q1 = R(q0, r, s[0]);
78  Vector3d q2 = L(q1, r, s[1]);
79  return R(q2, r, s[2]);
80  }
81 
82  static Vector3d LSL(const Vector3d& q0, const Vector3d& s, const Scalar r) {
83  Vector3d q1 = L(q0, r, s[0]);
84  Vector3d q2 = S(q1, s[1]);
85  return L(q2, r, s[2]);
86  }
87 
88  static Vector3d RSR(const Vector3d& q0, const Vector3d& s, const Scalar r) {
89  Vector3d q1 = R(q0, r, s[0]);
90  Vector3d q2 = S(q1, s[1]);
91  return R(q2, r, s[2]);
92  }
93 
94  static Vector3d LSR(const Vector3d& q0, const Vector3d& s, const Scalar r) {
95  Vector3d q1 = L(q0, r, s[0]);
96  Vector3d q2 = S(q1, s[1]);
97  return R(q2, r, s[2]);
98  }
99 
100  static Vector3d RSL(const Vector3d& q0, const Vector3d& s, const Scalar r) {
101  Vector3d q1 = R(q0, r, s[0]);
102  Vector3d q2 = S(q1, s[1]);
103  return L(q2, r, s[2]);
104  }
105 
109  static Vector3d solve(const Vector3d q0, const Path_t& path, const Scalar r) {
110  switch (path.id) {
111  case dubins::LRLa:
112  case dubins::LRLb:
113  return LRL(q0, path.s, r);
114 
115  case dubins::RLRa:
116  case dubins::RLRb:
117  return RLR(q0, path.s, r);
118 
119  case dubins::LSL:
120  return LSL(q0, path.s, r);
121 
122  case dubins::RSR:
123  return RSR(q0, path.s, r);
124 
125  case dubins::LSR:
126  return LSR(q0, path.s, r);
127 
128  case dubins::RSL:
129  return RSL(q0, path.s, r);
130 
131  default:
132  return Vector3d::Zero();
133  }
134  }
135 };
136 
138 
141 template <typename Scalar>
143  typedef Eigen::Matrix<Scalar, 3, 1> Vector3d;
144  typedef Eigen::Matrix<Scalar, 2, 1> Vector2d;
146 
147  static Vector3d L(const Vector3d& q0, const Scalar r, Scalar arc,
148  Scalar* budget) {
149  if (*budget < r * arc) {
150  arc = *budget / r;
151  }
152  *budget -= r*arc;
153  Vector2d c = leftCenter(q0, r);
154  Scalar theta1 = clampRadian(q0[2] + arc);
155  Scalar alpha1 = leftAngleOf(theta1);
156 
157  return Vector3d(c[0] + r * std::cos(alpha1), c[1] + r * std::sin(alpha1),
158  theta1);
159  }
160 
161  static Vector3d R(const Vector3d& q0, const Scalar r, Scalar arc,
162  Scalar* budget) {
163  if (*budget < r * arc) {
164  arc = *budget / r;
165  }
166  *budget -= r*arc;
167  Vector2d c = rightCenter(q0, r);
168  Scalar theta1 = clampRadian(q0[2] - arc);
169  Scalar alpha1 = rightAngleOf(theta1);
170 
171  return Vector3d(c[0] + r * std::cos(alpha1), c[1] + r * std::sin(alpha1),
172  theta1);
173  }
174 
175  static Vector3d S(const Vector3d& q0, Scalar d1, double* budget) {
176  if(*budget < d1) {
177  d1 = *budget;
178  }
179  *budget -= d1;
180  return Vector3d(q0[0] + d1 * std::cos(q0[2]),
181  q0[1] + d1 * std::sin(q0[2]),
182  q0[2]);
183  }
184 
185  static Vector3d LRL(const Vector3d& q0, const Vector3d& s, const Scalar r,
186  double* budget) {
187  Vector3d q1 = L(q0, r, s[0], budget);
188  Vector3d q2 = R(q1, r, s[1], budget);
189  return L(q2, r, s[2], budget);
190  }
191 
192  static Vector3d RLR(const Vector3d& q0, const Vector3d& s, const Scalar r,
193  double* budget) {
194  Vector3d q1 = R(q0, r, s[0], budget);
195  Vector3d q2 = L(q1, r, s[1], budget);
196  return R(q2, r, s[2], budget);
197  }
198 
199  static Vector3d LSL(const Vector3d& q0, const Vector3d& s, const Scalar r,
200  double* budget) {
201  Vector3d q1 = L(q0, r, s[0], budget);
202  Vector3d q2 = S(q1, s[1], budget);
203  return L(q2, r, s[2], budget);
204  }
205 
206  static Vector3d RSR(const Vector3d& q0, const Vector3d& s, const Scalar r,
207  double* budget) {
208  Vector3d q1 = R(q0, r, s[0], budget);
209  Vector3d q2 = S(q1, s[1], budget);
210  return R(q2, r, s[2], budget);
211  }
212 
213  static Vector3d LSR(const Vector3d& q0, const Vector3d& s, const Scalar r,
214  double* budget) {
215  Vector3d q1 = L(q0, r, s[0], budget);
216  Vector3d q2 = S(q1, s[1], budget);
217  return R(q2, r, s[2], budget);
218  }
219 
220  static Vector3d RSL(const Vector3d& q0, const Vector3d& s, const Scalar r,
221  double* budget) {
222  Vector3d q1 = R(q0, r, s[0], budget);
223  Vector3d q2 = S(q1, s[1], budget);
224  return L(q2, r, s[2], budget);
225  }
226 
230  static Vector3d solve(const Vector3d q0, const Path_t& path, const Scalar r,
231  double budget) {
232  switch (path.id) {
233  case dubins::LRLa:
234  case dubins::LRLb:
235  return LRL(q0, path.s, r, &budget);
236 
237  case dubins::RLRa:
238  case dubins::RLRb:
239  return RLR(q0, path.s, r, &budget);
240 
241  case dubins::LSL:
242  return LSL(q0, path.s, r, &budget);
243 
244  case dubins::RSR:
245  return RSR(q0, path.s, r, &budget);
246 
247  case dubins::LSR:
248  return LSR(q0, path.s, r, &budget);
249 
250  case dubins::RSL:
251  return RSL(q0, path.s, r, &budget);
252 
253  default:
254  return Vector3d::Zero();
255  }
256  }
257 };
258 
259 } // namespace curves_eigen
260 } // namespace dubins
261 } // namespace mpblocks
262 
263 #endif // MPBLOCKS_DUBINS_CURVES_EIGEN_INTEGRATOR_H_
static Vector3d LSR(const Vector3d &q0, const Vector3d &s, const Scalar r, double *budget)
Definition: integrator.h:213
static Vector3d LRL(const Vector3d &q0, const Vector3d &s, const Scalar r, double *budget)
Definition: integrator.h:185
static Vector3d RLR(const Vector3d &q0, const Vector3d &s, const Scalar r)
Definition: integrator.h:76
static Vector3d LSL(const Vector3d &q0, const Vector3d &s, const Scalar r)
Definition: integrator.h:82
Scalar leftAngleOf(const Scalar q_theta)
return the angle of the vector from the center of the counter clockwise (left) circle coincident to q...
Definition: funcs.hpp:87
static Vector3d R(const Vector3d &q0, const Scalar r, const Scalar arc)
Definition: integrator.h:54
static Vector3d LSL(const Vector3d &q0, const Vector3d &s, const Scalar r, double *budget)
Definition: integrator.h:199
static Vector3d RLR(const Vector3d &q0, const Vector3d &s, const Scalar r, double *budget)
Definition: integrator.h:192
Vector3d s
lengths of each segment, how it's interpreted depends on id
Definition: path.h:47
static Vector3d LRL(const Vector3d &q0, const Vector3d &s, const Scalar r)
Definition: integrator.h:70
static Vector3d RSL(const Vector3d &q0, const Vector3d &s, const Scalar r, double *budget)
Definition: integrator.h:220
static Vector3d L(const Vector3d &q0, const Scalar r, const Scalar arc)
Definition: integrator.h:44
Eigen::Matrix< Scalar, 2, 1 > Vector2d
Definition: integrator.h:41
static Vector3d RSR(const Vector3d &q0, const Vector3d &s, const Scalar r, double *budget)
Definition: integrator.h:206
Eigen::Matrix< Scalar, 3, 1 > Vector3d
Definition: integrator.h:40
static Vector3d solve(const Vector3d q0, const Path_t &path, const Scalar r)
Given an initial dubins state (position, heading), a path primitive composed of three arc segments...
Definition: integrator.h:109
int id
identifies the type of path
Definition: path.h:45
static Vector3d RSR(const Vector3d &q0, const Vector3d &s, const Scalar r)
Definition: integrator.h:88
static Vector3d L(const Vector3d &q0, const Scalar r, Scalar arc, Scalar *budget)
Definition: integrator.h:147
Scalar rightAngleOf(const Scalar q_theta)
return the angle of the vector from the center of the clockwise (right) circle coincident to q...
Definition: funcs.hpp:107
__host__ __device__ Format_t clampRadian(Format_t a)
wraps the input onto [-pi,pi]
Definition: funcs.hpp:37
Eigen::Matrix< Scalar, 2, 1 > rightCenter(const Eigen::Matrix< Scalar, 3, 1 > &q, Scalar r)
return the center of a clockwise (right) circle coincident to q with radius r
Definition: funcs.hpp:76
static Vector3d RSL(const Vector3d &q0, const Vector3d &s, const Scalar r)
Definition: integrator.h:100
static Vector3d S(const Vector3d &q0, const Scalar d1)
Definition: integrator.h:64
static Vector3d LSR(const Vector3d &q0, const Vector3d &s, const Scalar r)
Definition: integrator.h:94
Encodes a dubins path primitive, which is three connected arc segments.
Definition: path.h:42
static Vector3d S(const Vector3d &q0, Scalar d1, double *budget)
Definition: integrator.h:175
Eigen::Matrix< Scalar, 2, 1 > leftCenter(const Eigen::Matrix< Scalar, 3, 1 > &q, Scalar r)
return the center of a counter clockwise (left) circle coincident to q with radius r ...
Definition: funcs.hpp:54
static Vector3d R(const Vector3d &q0, const Scalar r, Scalar arc, Scalar *budget)
Definition: integrator.h:161
static Vector3d solve(const Vector3d q0, const Path_t &path, const Scalar r, double budget)
Given an initial dubins state (position, heading), a path primitive composed of three arc segments...
Definition: integrator.h:230