73 const double RS_EPS = 1e-6;
76 inline void tauOmega(
double u,
double v,
double xi,
double eta,
double phi,
double &tau,
double &omega)
78 double delta =
pify(u - v), A =
sin(u) -
sin(delta), B =
cos(u) -
cos(delta) - 1.;
79 double t1 =
atan2(eta * A - xi * B, xi * A + eta * B), t2 = 2. * (
cos(delta) -
cos(v) -
cos(u)) + 3;
80 tau = (t2 < 0) ?
pify(t1 + PI) :
pify(t1);
81 omega =
pify(tau - u + v - phi);
85 inline bool LpSpLp(
double x,
double y,
double phi,
double &t,
double &u,
double &v)
93 assert(fabs(u *
cos(t) +
sin(phi) - x) < RS_EPS);
94 assert(fabs(u *
sin(t) -
cos(phi) + 1 - y) < RS_EPS);
95 assert(fabs(
pify(t + v - phi)) < RS_EPS);
102 inline bool LpSpRp(
double x,
double y,
double phi,
double &t,
double &u,
double &v)
111 theta =
atan2(2., u);
112 t =
pify(t1 + theta);
114 assert(fabs(2 *
sin(t) + u *
cos(t) -
sin(phi) - x) < RS_EPS);
115 assert(fabs(-2 *
cos(t) + u *
sin(t) +
cos(phi) + 1 - y) < RS_EPS);
116 assert(fabs(
pify(t - v - phi)) < RS_EPS);
117 return t >= -RS_ZERO && v >= -RS_ZERO;
121 void CSC(
double x,
double y,
double phi, Reeds_Shepp_State_Space::Reeds_Shepp_Path &
path)
123 double t, u, v, Lmin = path.length(), L;
124 if (LpSpLp(x, y, phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
126 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[14], t, u, v);
129 if (LpSpLp(-x, y, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
131 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[14], -t, -u, -v);
134 if (LpSpLp(x, -y, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
136 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[15], t, u, v);
139 if (LpSpLp(-x, -y, phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
141 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[15], -t, -u, -v);
144 if (LpSpRp(x, y, phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
146 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[12], t, u, v);
149 if (LpSpRp(-x, y, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
151 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[12], -t, -u, -v);
154 if (LpSpRp(x, -y, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
156 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[13], t, u, v);
159 if (LpSpRp(-x, -y, phi, t, u, v) && Lmin > (fabs(t) + fabs(u) + fabs(v)))
160 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[13], -t, -u, -v);
163 inline bool LpRmL(
double x,
double y,
double phi,
double &t,
double &u,
double &v)
165 double xi = x -
sin(phi), eta = y - 1. +
cos(phi), u1, theta;
166 polar(xi, eta, u1, theta);
169 u = -2. *
asin(.25 * u1);
170 t =
pify(theta + .5 * u + PI);
171 v =
pify(phi - t + u);
172 assert(fabs(2 * (
sin(t) -
sin(t - u)) +
sin(phi) - x) < RS_EPS);
173 assert(fabs(2 * (-
cos(t) +
cos(t - u)) -
cos(phi) + 1 - y) < RS_EPS);
174 assert(fabs(
pify(t - u + v - phi)) < RS_EPS);
175 return t >= -RS_ZERO && u <= RS_ZERO;
179 void CCC(
double x,
double y,
double phi, Reeds_Shepp_State_Space::Reeds_Shepp_Path &path)
181 double t, u, v, Lmin = path.length(), L;
182 if (LpRmL(x, y, phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
184 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[0], t, u, v);
187 if (LpRmL(-x, y, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
189 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[0], -t, -u, -v);
192 if (LpRmL(x, -y, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
194 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[1], t, u, v);
197 if (LpRmL(-x, -y, phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
199 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[1], -t, -u, -v);
204 double xb = x *
cos(phi) + y *
sin(phi), yb = x *
sin(phi) - y *
cos(phi);
205 if (LpRmL(xb, yb, phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
207 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[0], v, u, t);
210 if (LpRmL(-xb, yb, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
212 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[0], -v, -u, -t);
215 if (LpRmL(xb, -yb, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
217 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[1], v, u, t);
220 if (LpRmL(-xb, -yb, phi, t, u, v) && Lmin > (fabs(t) + fabs(u) + fabs(v)))
221 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[1], -v, -u, -t);
224 inline bool LpRupLumRm(
double x,
double y,
double phi,
double &t,
double &u,
double &v)
226 double xi = x +
sin(phi), eta = y - 1. -
cos(phi), rho = .25 * (2. +
sqrt(xi * xi + eta * eta));
230 tauOmega(u, -u, xi, eta, phi, t, v);
231 assert(fabs(2 * (
sin(t) -
sin(t - u) +
sin(t - 2 * u)) -
sin(phi) - x) < RS_EPS);
232 assert(fabs(2 * (-
cos(t) +
cos(t - u) -
cos(t - 2 * u)) +
cos(phi) + 1 - y) < RS_EPS);
233 assert(fabs(
pify(t - 2 * u - v - phi)) < RS_EPS);
234 return t >= -RS_ZERO && v <= RS_ZERO;
239 inline bool LpRumLumRp(
double x,
double y,
double phi,
double &t,
double &u,
double &v)
241 double xi = x +
sin(phi), eta = y - 1. -
cos(phi), rho = (20. - xi * xi - eta * eta) / 16.;
242 if (rho >= 0 && rho <= 1)
247 tauOmega(u, u, xi, eta, phi, t, v);
248 assert(fabs(4 *
sin(t) - 2 *
sin(t - u) -
sin(phi) - x) < RS_EPS);
249 assert(fabs(-4 *
cos(t) + 2 *
cos(t - u) +
cos(phi) + 1 - y) < RS_EPS);
250 assert(fabs(
pify(t - v - phi)) < RS_EPS);
251 return t >= -RS_ZERO && v >= -RS_ZERO;
256 void CCCC(
double x,
double y,
double phi, Reeds_Shepp_State_Space::Reeds_Shepp_Path &path)
258 double t, u, v, Lmin = path.length(), L;
259 if (LpRupLumRm(x, y, phi, t, u, v) && Lmin > (L = fabs(t) + 2. * fabs(u) + fabs(v)))
261 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[2], t, u, -u, v);
264 if (LpRupLumRm(-x, y, -phi, t, u, v) && Lmin > (L = fabs(t) + 2. * fabs(u) + fabs(v)))
266 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[2], -t, -u, u, -v);
269 if (LpRupLumRm(x, -y, -phi, t, u, v) && Lmin > (L = fabs(t) + 2. * fabs(u) + fabs(v)))
271 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[3], t, u, -u, v);
274 if (LpRupLumRm(-x, -y, phi, t, u, v) && Lmin > (L = fabs(t) + 2. * fabs(u) + fabs(v)))
276 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[3], -t, -u, u, -v);
280 if (LpRumLumRp(x, y, phi, t, u, v) && Lmin > (L = fabs(t) + 2. * fabs(u) + fabs(v)))
282 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[2], t, u, u, v);
285 if (LpRumLumRp(-x, y, -phi, t, u, v) && Lmin > (L = fabs(t) + 2. * fabs(u) + fabs(v)))
287 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[2], -t, -u, -u, -v);
290 if (LpRumLumRp(x, -y, -phi, t, u, v) && Lmin > (L = fabs(t) + 2. * fabs(u) + fabs(v)))
292 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[3], t, u, u, v);
295 if (LpRumLumRp(-x, -y, phi, t, u, v) && Lmin > (fabs(t) + 2. * fabs(u) + fabs(v)))
296 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[3], -t, -u, -u, -v);
299 inline bool LpRmSmLm(
double x,
double y,
double phi,
double &t,
double &u,
double &v)
301 double xi = x -
sin(phi), eta = y - 1. +
cos(phi), rho, theta;
302 polar(xi, eta, rho, theta);
305 double r =
sqrt(rho * rho - 4.);
308 v =
pify(phi - .5 * PI - t);
309 assert(fabs(2 * (
sin(t) -
cos(t)) - u *
sin(t) +
sin(phi) - x) < RS_EPS);
310 assert(fabs(-2 * (
sin(t) +
cos(t)) + u *
cos(t) -
cos(phi) + 1 - y) < RS_EPS);
311 assert(fabs(
pify(t + PI / 2 + v - phi)) < RS_EPS);
312 return t >= -RS_ZERO && u <= RS_ZERO && v <= RS_ZERO;
317 inline bool LpRmSmRm(
double x,
double y,
double phi,
double &t,
double &u,
double &v)
319 double xi = x +
sin(phi), eta = y - 1. -
cos(phi), rho, theta;
320 polar(-eta, xi, rho, theta);
325 v =
pify(t + .5 * PI - phi);
326 assert(fabs(2 *
sin(t) -
cos(t - v) - u *
sin(t) - x) < RS_EPS);
327 assert(fabs(-2 *
cos(t) -
sin(t - v) + u *
cos(t) + 1 - y) < RS_EPS);
328 assert(fabs(
pify(t + PI / 2 - v - phi)) < RS_EPS);
329 return t >= -RS_ZERO && u <= RS_ZERO && v <= RS_ZERO;
333 void CCSC(
double x,
double y,
double phi, Reeds_Shepp_State_Space::Reeds_Shepp_Path &path)
335 double t, u, v, Lmin = path.length() - .5 *
PI, L;
336 if (LpRmSmLm(x, y, phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
339 Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[4], t, -.5 * PI, u, v);
342 if (LpRmSmLm(-x, y, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
344 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[4], -t, .5 * PI, -u,
348 if (LpRmSmLm(x, -y, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
351 Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[5], t, -.5 * PI, u, v);
354 if (LpRmSmLm(-x, -y, phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
356 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[5], -t, .5 * PI, -u,
361 if (LpRmSmRm(x, y, phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
364 Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[8], t, -.5 * PI, u, v);
367 if (LpRmSmRm(-x, y, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
369 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[8], -t, .5 * PI, -u,
373 if (LpRmSmRm(x, -y, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
376 Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[9], t, -.5 * PI, u, v);
379 if (LpRmSmRm(-x, -y, phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
381 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[9], -t, .5 * PI, -u,
387 double xb = x *
cos(phi) + y *
sin(phi), yb = x *
sin(phi) - y *
cos(phi);
388 if (LpRmSmLm(xb, yb, phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
391 Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[6], v, u, -.5 * PI, t);
394 if (LpRmSmLm(-xb, yb, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
396 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[6], -v, -u, .5 * PI,
400 if (LpRmSmLm(xb, -yb, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
403 Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[7], v, u, -.5 * PI, t);
406 if (LpRmSmLm(-xb, -yb, phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
408 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[7], -v, -u, .5 * PI,
413 if (LpRmSmRm(xb, yb, phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
415 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[10], v, u, -.5 * PI,
419 if (LpRmSmRm(-xb, yb, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
421 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[10], -v, -u,
425 if (LpRmSmRm(xb, -yb, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
427 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[11], v, u, -.5 * PI,
431 if (LpRmSmRm(-xb, -yb, phi, t, u, v) && Lmin > (fabs(t) + fabs(u) + fabs(v)))
432 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[11], -v, -u,
436 inline bool LpRmSLmRp(
double x,
double y,
double phi,
double &t,
double &u,
double &v)
438 double xi = x +
sin(phi), eta = y - 1. -
cos(phi), rho, theta;
439 polar(xi, eta, rho, theta);
442 u = 4. -
sqrt(rho * rho - 4.);
445 t =
pify(
atan2((4 - u) * xi - 2 * eta, -2 * xi + (u - 4) * eta));
447 assert(fabs(4 *
sin(t) - 2 *
cos(t) - u *
sin(t) -
sin(phi) - x) < RS_EPS);
448 assert(fabs(-4 *
cos(t) - 2 *
sin(t) + u *
cos(t) +
cos(phi) + 1 - y) < RS_EPS);
449 assert(fabs(
pify(t - v - phi)) < RS_EPS);
450 return t >= -RS_ZERO && v >= -RS_ZERO;
455 void CCSCC(
double x,
double y,
double phi, Reeds_Shepp_State_Space::Reeds_Shepp_Path &path)
457 double t, u, v, Lmin = path.length() -
PI, L;
458 if (LpRmSLmRp(x, y, phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
460 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[16], t, -.5 * PI, u,
464 if (LpRmSLmRp(-x, y, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
466 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[16], -t, .5 * PI,
470 if (LpRmSLmRp(x, -y, -phi, t, u, v) && Lmin > (L = fabs(t) + fabs(u) + fabs(v)))
472 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[17], t, -.5 * PI, u,
476 if (LpRmSLmRp(-x, -y, phi, t, u, v) && Lmin > (fabs(t) + fabs(u) + fabs(v)))
477 path = Reeds_Shepp_State_Space::Reeds_Shepp_Path(Reeds_Shepp_State_Space::reeds_shepp_path_type[17], -t, .5 * PI,
481 Reeds_Shepp_State_Space::Reeds_Shepp_Path reeds_shepp(
double x,
double y,
double phi)
483 Reeds_Shepp_State_Space::Reeds_Shepp_Path
path;
484 CSC(x, y, phi, path);
485 CCC(x, y, phi, path);
486 CCCC(x, y, phi, path);
487 CCSC(x, y, phi, path);
488 CCSCC(x, y, phi, path);
493 const Reeds_Shepp_State_Space::Reeds_Shepp_Path_Segment_Type Reeds_Shepp_State_Space::reeds_shepp_path_type[18][5] = {
494 { RS_LEFT, RS_RIGHT, RS_LEFT, RS_NOP, RS_NOP },
495 { RS_RIGHT, RS_LEFT, RS_RIGHT, RS_NOP, RS_NOP },
496 { RS_LEFT, RS_RIGHT, RS_LEFT, RS_RIGHT, RS_NOP },
497 { RS_RIGHT, RS_LEFT, RS_RIGHT, RS_LEFT, RS_NOP },
498 { RS_LEFT, RS_RIGHT, RS_STRAIGHT, RS_LEFT, RS_NOP },
499 { RS_RIGHT, RS_LEFT, RS_STRAIGHT, RS_RIGHT, RS_NOP },
500 { RS_LEFT, RS_STRAIGHT, RS_RIGHT, RS_LEFT, RS_NOP },
501 { RS_RIGHT, RS_STRAIGHT, RS_LEFT, RS_RIGHT, RS_NOP },
502 { RS_LEFT, RS_RIGHT, RS_STRAIGHT, RS_RIGHT, RS_NOP },
503 { RS_RIGHT, RS_LEFT, RS_STRAIGHT, RS_LEFT, RS_NOP },
504 { RS_RIGHT, RS_STRAIGHT, RS_RIGHT, RS_LEFT, RS_NOP },
505 { RS_LEFT, RS_STRAIGHT, RS_LEFT, RS_RIGHT, RS_NOP },
506 { RS_LEFT, RS_STRAIGHT, RS_RIGHT, RS_NOP, RS_NOP },
507 { RS_RIGHT, RS_STRAIGHT, RS_LEFT, RS_NOP, RS_NOP },
508 { RS_LEFT, RS_STRAIGHT, RS_LEFT, RS_NOP, RS_NOP },
509 { RS_RIGHT, RS_STRAIGHT, RS_RIGHT, RS_NOP, RS_NOP },
510 { RS_LEFT, RS_RIGHT, RS_STRAIGHT, RS_LEFT, RS_RIGHT },
511 { RS_RIGHT, RS_LEFT, RS_STRAIGHT, RS_RIGHT, RS_LEFT }
515 double u,
double v,
double w,
double x)
523 total_length_ = fabs(t) + fabs(u) + fabs(v) + fabs(w) + fabs(x);
527 const State &state2)
const 529 double dx = state2.
x - state1.
x, dy = state2.
y - state1.
y, dth = state2.
theta - state1.
theta;
531 double x = c * dx +
s * dy, y = -
s * dx + c * dy;
532 return steering::reeds_shepp(x *
kappa_, y * kappa_, dth);
549 vector<Control> controls;
552 for (
unsigned int i = 0; i < 5; ++i)
555 switch (path.
type_[i])
575 controls.push_back(control);
582 vector<Control> controls =
get_controls(state1, state2);
587 const State &state2)
const 596 State state_curr, state_next;
599 for (
const auto &control : controls)
601 double abs_delta_s(fabs(control.delta_s));
604 path.reserve(n_states + 5);
606 state_curr.
x = state.
x;
607 state_curr.
y = state.
y;
610 for (
const auto &control : controls)
612 double delta_s(control.delta_s);
613 double abs_delta_s(fabs(delta_s));
615 double integration_step(0.0);
617 state_curr.
kappa = control.kappa;
618 state_curr.
d =
sgn(delta_s);
619 path.push_back(state_curr);
625 if (s_seg > abs_delta_s)
634 state_next =
integrate_ODE(state_curr, control, integration_step);
635 path.push_back(state_next);
636 state_curr = state_next;
643 const vector<Control> &controls)
const 645 vector<State_With_Covariance> path_with_covariance;
649 for (
const auto &control : controls)
651 double abs_delta_s(fabs(control.delta_s));
654 path_with_covariance.reserve(n_states + 5);
659 for (
int i = 0; i < 16; i++)
666 for (
const auto &control : controls)
668 double delta_s(control.delta_s);
669 double abs_delta_s(fabs(delta_s));
671 double integration_step(0.0);
675 path_with_covariance.push_back(state_curr);
681 if (s_seg > abs_delta_s)
692 ekf_.
predict(state_curr, control, integration_step, state_pred);
697 path_with_covariance.push_back(state_next);
699 for (
int i = 0; i < 16; i++)
707 return path_with_covariance;
712 State state_curr, state_next;
714 state_curr.
x = state.
x;
715 state_curr.
y = state.
y;
720 for (
const auto &control : controls)
722 s_path += fabs(control.delta_s);
729 s_inter = t * s_path;
732 bool interpolated =
false;
733 for (
const auto &control : controls)
738 double delta_s(control.delta_s);
739 double abs_delta_s(fabs(delta_s));
741 double integration_step(0.0);
743 state_curr.
kappa = control.kappa;
744 state_curr.
d =
sgn(delta_s);
749 abs_delta_s = abs_delta_s - (s - s_inter);
757 if (s_seg > abs_delta_s)
766 state_next =
integrate_ODE(state_curr, control, integration_step);
767 state_curr = state_next;
774 double integration_step)
const double get_epsilon()
Return value of epsilon.
std::vector< State > get_path(const State &state1, const State &state2) const
Returns shortest path from state1 to state2 with curvature = kappa_.
std::vector< State > integrate(const State &state, const std::vector< Control > &controls) const
Returns integrated states given a start state and controls with curvature = kappa_.
void set_parameters(const Motion_Noise &motion_noise, const Measurement_Noise &measurement_noise, const Controller &_controller)
Sets the parameters required by the EKF.
double sgn(double x)
Return sign of a number.
const Reeds_Shepp_Path_Segment_Type * type_
State interpolate(const State &state, const std::vector< Control > &controls, double t) const
Returns interpolated state at distance t in [0,1] (percent of total path length with curvature = kapp...
double delta_s
Signed arc length of a segment.
double Lambda[16]
Covariance of the state estimate due to the absence of measurements.
std::vector< State_With_Covariance > get_path_with_covariance(const State_With_Covariance &state1, const State &state2) const
Returns shortest path including covariances from state1 to state2 with curvature = kappa_...
double kappa
Curvature at the beginning of a segment.
void set_filter_parameters(const Motion_Noise &motion_noise, const Measurement_Noise &measurement_noise, const Controller &controller)
Sets the parameters required by the filter.
Complete description of a ReedsShepp path.
double discretization_
Discretization of path.
void end_of_circular_arc(double x_i, double y_i, double theta_i, double kappa, double direction, double length, double *x_f, double *y_f, double *theta_f)
Computation of the end point on a circular arc x_i, y_i, theta_i: initial configuration kappa: curvat...
void polar(double x, double y, double &r, double &theta)
Computation of a point's polar coordinates.
void end_of_straight_line(double x_i, double y_i, double theta, double direction, double length, double *x_f, double *y_f)
Computation of the end point on a straight line x_i, y_i: initial configuration theta: angle of strai...
Parameters of the motion noise model according to the book: Probabilistic Robotics, S. Thrun and others, MIT Press, 2006, p. 127-128 and p.204-206.
Description of a path segment with its corresponding control inputs.
double pify(double alpha)
Conversion of arbitrary angle given in [rad] to [-pi, pi[.
void update(const State_With_Covariance &state_pred, State_With_Covariance &state_corr) const
Predicts the covariances.
State state
Expected state of the robot.
double covariance[16]
Covariance of the state given by Sigma + Lambda: (x_x x_y x_theta x_kappa y_x y_y y_theta y_kappa the...
std::vector< Control > get_controls(const State &state1, const State &state2) const
Returns controls of the shortest path from state1 to state2 with curvature = kappa_.
double x
Position in x of the robot.
Reeds_Shepp_Path_Segment_Type
The Reeds-Shepp path segment types.
INLINE Rall1d< T, V, S > asin(const Rall1d< T, V, S > &x)
Description of a kinematic car's state with covariance.
Parameters of the measurement noise.
Parameters of the feedback controller.
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
EKF ekf_
Extended Kalman Filter for uncertainty propagation.
Description of a kinematic car's state.
State integrate_ODE(const State &state, const Control &control, double integration_step) const
Returns integrated state given a start state, a control, and an integration step. ...
double kappa_inv_
Inverse of curvature.
Reeds_Shepp_Path reeds_shepp(const State &state1, const State &state2) const
Returns type and length of segments of path from state1 to state2 with curvature = 1...
INLINE Rall1d< T, V, S > acos(const Rall1d< T, V, S > &x)
double sigma
Sharpness (derivative of curvature with respect to arc length) of a segment.
std::vector< State_With_Covariance > integrate_with_covariance(const State_With_Covariance &state, const std::vector< Control > &controls) const
Returns integrated states including covariance given a start state and controls with curvature = kapp...
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
double Sigma[16]
Covariance of the state estimation due to motion and measurement noise.
double kappa
Curvature at position (x,y)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
double y
Position in y of the robot.
double get_distance(const State &state1, const State &state2) const
Returns shortest path length from state1 to state2 with curvature = kappa_.
double theta
Orientation of the robot.
void predict(const State_With_Covariance &state, const Control &control, double integration_step, State_With_Covariance &state_pred) const
Predicts the covariances based on the paper: Rapidly-exploring random belief trees for motion plannin...