6 bool PSPlanner::collide()
8 std::vector<std::tuple<double, double>> bc;
9 bc.push_back(std::make_tuple(this->cc().lfx(), this->cc().lfy()));
10 bc.push_back(std::make_tuple(this->cc().lrx(), this->cc().lry()));
11 bc.push_back(std::make_tuple(this->cc().rrx(), this->cc().rry()));
12 bc.push_back(std::make_tuple(this->cc().rfx(), this->cc().rfy()));
13 bc.push_back(std::make_tuple(this->cc().lfx(), this->cc().lfy()));
14 std::vector<std::tuple<double, double>> ps;
15 ps.push_back(std::make_tuple(this->ps().x1(), this->ps().y1()));
16 ps.push_back(std::make_tuple(this->ps().x2(), this->ps().y2()));
17 ps.push_back(std::make_tuple(this->ps().x3(), this->ps().y3()));
18 ps.push_back(std::make_tuple(this->ps().x4(), this->ps().y4()));
19 return std::get<0>(::collide(bc, ps));
22 bool PSPlanner::forward()
24 #if FORWARD_PARKING > 0
31 void PSPlanner::gc_to_4()
33 double angl_slot = atan2(
34 this->ps().y3() - this->ps().y4(),
35 this->ps().x3() - this->ps().x4()
37 double angl_delta = M_PI / 2;
38 if (this->ps().right())
39 angl_delta = -M_PI / 2;
40 double x = this->ps().x4();
41 double y = this->ps().y4();
42 x += (this->gc().dr() + 0.01) * cos(angl_slot);
43 y += (this->gc().dr() + 0.01) * sin(angl_slot);
44 x += (this->gc().w() / 2 + 0.01) * cos(angl_slot + angl_delta);
45 y += (this->gc().w() / 2 + 0.01) * sin(angl_slot + angl_delta);
48 this->gc().h(angl_slot);
51 std::tuple<double, double, double, double> circle_line_intersection(
52 double cx, double cy, double r,
57 double t = (y2 - y1) / (x2 - x1);
58 //double a = 1 + pow(t, 2);
59 //double b = - 2 * cx - 2 * pow(t, 2) * x1 + 2 * t * y1 - 2 * t * cy;
60 //double c = pow(cx, 2) + pow(t, 2) * pow(x1, 2) - 2 * t * y1 * x1
61 // + pow(y1, 2) + 2 * t * cy * x1 - 2 * y1 * cy + pow(cy, 2)
63 double a = 1 + pow(t, 2);
64 double b = - 2 * cx + 2 * t * (-t * x1 + y1) - 2 * cy * t;
65 double c = pow(cx, 2) + pow(cy, 2) - pow(r, 2);
66 c += pow(-t * x1 + y1, 2);
67 c += 2 * cy * t * x1 - 2 * cy * y1;
68 double D = pow(b, 2) - 4 * a * c;
70 return std::make_tuple(cx, cy, cx, cy);
71 double res_x1 = (-b + sqrt(D)) / (2 * a);
72 double res_y1 = t * (res_x1 - x1) + y1;
73 double res_x2 = (-b - sqrt(D)) / (2 * a);
74 double res_y2 = t * (res_x2 - x1) + y1;
75 return std::make_tuple(res_x1, res_y1, res_x2, res_y2);
78 double edist(double x1, double y1, double x2, double y2)
80 return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
83 void PSPlanner::guess_gc()
85 double x = this->ps().x1();
86 double y = this->ps().y1();
87 double h = this->ps().heading();
88 double dts = + M_PI / 2; // direction to slot
89 if (this->ps().right())
91 if (this->ps().parallel()) {
92 x += (this->gc().w() / 2 + 0.01) * cos(h + dts);
93 x += (this->gc().dr() + 0.01) * cos(h);
94 y += (this->gc().w() / 2 + 0.01) * sin(h + dts);
95 y += (this->gc().dr() + 0.01) * sin(h);
97 #if FORWARD_PARKING > 0
99 double entry_width = edist(
100 this->ps().x1(), this->ps().y1(),
101 this->ps().x4(), this->ps().y4()
103 x += entry_width / 2 * cos(h);
104 y += entry_width / 2 * sin(h);
106 this->ps().y2() - this->ps().y1(),
107 this->ps().x2() - this->ps().x1()
109 while (h < 0) h += 2 * M_PI;
110 x += this->gc().dr() * cos(h + M_PI);
111 y += this->gc().dr() * sin(h + M_PI);
114 double entry_width = edist(
115 this->ps().x1(), this->ps().y1(),
116 this->ps().x4(), this->ps().y4()
118 x += entry_width / 2 * cos(h);
119 y += entry_width / 2 * sin(h);
121 this->ps().y1() - this->ps().y2(),
122 this->ps().x1() - this->ps().x2()
124 while (h < 0) h += 2 * M_PI;
125 x += this->gc().df() * cos(h + M_PI);
126 y += this->gc().df() * sin(h + M_PI);
138 std::vector<BicycleCar> PSPlanner::last_maneuver()
140 std::vector<BicycleCar> lm;
141 if (this->ps().parallel()) {
142 // zig-zag out from the slot
143 this->cc() = BicycleCar(this->gc());
145 while (!this->left()) {
146 while (!this->collide() && !this->left()) {
148 lm.push_back(BicycleCar(this->cc()));
150 if (this->left() && !this->collide()) {
154 this->cc().sp(this->cc().sp() * -1);
156 this->cc().st(this->cc().st() * -1);
158 lm.push_back(BicycleCar(this->cc()));
161 if (this->cc().st() < 0) {
163 lm.push_back(BicycleCar(this->cc()));
168 BicycleCar orig_cc(this->cc());
169 for (unsigned int i = 0; i < 10; i++) {
171 lm.push_back(BicycleCar(this->cc()));
173 this->cc() = BicycleCar(orig_cc);
178 bool PSPlanner::left()
180 double lfx = this->cc().lfx();
181 double lfy = this->cc().lfy();
182 double lrx = this->cc().lrx();
183 double lry = this->cc().lry();
184 double rrx = this->cc().rrx();
185 double rry = this->cc().rry();
186 double rfx = this->cc().rfx();
187 double rfy = this->cc().rfy();
189 (lfx - this->ps().x1()) * (this->ps().y4() - this->ps().y1())
190 - (lfy - this->ps().y1()) * (this->ps().x4() - this->ps().x1())
193 (lrx - this->ps().x1()) * (this->ps().y4() - this->ps().y1())
194 - (lry - this->ps().y1()) * (this->ps().x4() - this->ps().x1())
197 (rrx - this->ps().x1()) * (this->ps().y4() - this->ps().y1())
198 - (rry - this->ps().y1()) * (this->ps().x4() - this->ps().x1())
201 (rfx - this->ps().x1()) * (this->ps().y4() - this->ps().y1())
202 - (rfy - this->ps().y1()) * (this->ps().x4() - this->ps().x1())
204 if (this->ps().parallel())
205 return lfs == rfs && (lfs != lrs || lfs != rrs);
206 else if (!this->forward())
207 return lfs == rfs && (lfs != lrs || lfs != rrs);
209 return lrs == rrs && (lrs != lfs || lrs != rfs);
212 bool PSPlanner::parked()
214 std::vector<std::tuple<double, double>> slot;
215 slot.push_back(std::make_tuple(this->ps().x1(), this->ps().y1()));
216 slot.push_back(std::make_tuple(this->ps().x2(), this->ps().y2()));
217 slot.push_back(std::make_tuple(this->ps().x3(), this->ps().y3()));
218 slot.push_back(std::make_tuple(this->ps().x4(), this->ps().y4()));
219 return inside(this->gc().lfx(), this->gc().lfy(), slot)
220 && inside(this->gc().lrx(), this->gc().lry(), slot)
221 && inside(this->gc().rrx(), this->gc().rry(), slot)
222 && inside(this->gc().rfx(), this->gc().rfy(), slot);
225 std::vector<BicycleCar> PSPlanner::possible_goals(
230 std::vector<BicycleCar> pi;
231 if (this->ps().parallel())
235 this->cc().sp(this->cc().sp() * dist);
236 BicycleCar orig_cc(this->cc());
237 for (unsigned int i = 0; i < cnt; i++) {
239 pi.push_back(BicycleCar(this->cc()));
241 this->cc() = BicycleCar(orig_cc);
242 if (this->ps().parallel()) {
244 for (unsigned int i = 0; i < cnt; i++) {
246 pi.push_back(BicycleCar(this->cc()));
248 this->cc() = BicycleCar(orig_cc);
250 if (!this->ps().right()) {
251 this->cc().set_max_steer();
252 for (unsigned int i = 0; i < cnt; i++) {
254 pi.push_back(BicycleCar(this->cc()));
257 this->cc().set_max_steer();
258 this->cc().st(this->cc().st() * -1);
259 for (unsigned int i = 0; i < cnt; i++) {
261 pi.push_back(BicycleCar(this->cc()));
264 this->cc() = BicycleCar(orig_cc);
273 if (this->ps().parallel()) {
274 return this->fe_parallel();
277 this->cc() = BicycleCar(this->gc());
278 //this->cc().set_max_steer();
279 //if (this->ps().right())
280 // this->cc().st(this->cc().st() * -1);
285 double angle_between_closer_point(
286 double sx, double sy, // common start point
287 double cx, double cy, // common middle point
288 double x1, double y1, // first ending point
289 double x2, double y2 // second ending point
291 if (edist(sx, sy, x1, y1) < edist(sx, sy, x2, y2))
292 return ::angle_between_three_points(sx, sy, cx, cy, x1, y1);
294 return ::angle_between_three_points(sx, sy, cx, cy, x2, y2);
297 void PSPlanner::fe_parallel()
299 BicycleCar bco = BicycleCar(this->gc());
300 this->cc() = BicycleCar();
301 this->cc().sp(-0.01);
302 this->cc().set_max_steer();
303 if (!this->ps().right())
304 this->cc().st(this->cc().st() * -1);
305 this->cc().h(this->ps().heading());
306 double angl_in_slot = this->ps().heading() - M_PI / 4;
307 if (!this->ps().right())
308 angl_in_slot += M_PI / 2;
311 + this->cc().w()/2 * cos(
313 + (this->ps().right() ? + M_PI / 2 : - M_PI / 2)
315 + (this->cc().df() + 0.01) * cos(
316 this->ps().heading() + M_PI
321 + this->cc().w()/2 * sin(
323 + (this->ps().right() ? + M_PI / 2 : - M_PI / 2)
325 + (this->cc().df() + 0.01) * sin(
326 this->ps().heading() + M_PI
330 std::queue<BicycleCar, std::list<BicycleCar>> q;
331 while (!this->collide()) {
335 this->ps().y4() - 0.01,
336 ((this->ps().right()) ? 0.001 : -0.001)
339 // BFS - find entry current car `cc` and corresponding goal car `gc`
340 unsigned int iter_cntr = 0;
341 while (!q.empty() && iter_cntr < 30) {
342 this->cc() = BicycleCar(q.front());
344 if (this->ps().right() && this->cc().sp() < 0) {
345 double cclx = this->cc().ccl().x();
346 double ccly = this->cc().ccl().y();
347 double ccl_lr = edist(
349 this->cc().lrx(), this->cc().lry()
351 double ccl_rr = edist(
353 this->cc().rrx(), this->cc().rry()
355 double ccl_p1 = edist(
357 this->ps().x1(), this->ps().y1()
359 if (ccl_rr < ccl_p1) {
362 } else if (ccl_rr >= ccl_p1 && ccl_lr < ccl_p1) {
363 // partially out of parking slot
364 auto cli1 = ::intersect(
366 this->cc().lrx(), this->cc().lry(),
367 this->cc().rrx(), this->cc().rry()
369 double a1 = ::angle_between_closer_point(
370 this->ps().x1(), this->ps().y1(),
372 std::get<1>(cli1), std::get<2>(cli1),
373 std::get<3>(cli1), std::get<4>(cli1)
375 auto cli2 = ::intersect(
377 this->ps().x2(), this->ps().y2(),
378 this->ps().x3(), this->ps().y3()
380 double a2 = angle_between_closer_point(
381 this->cc().rrx(), this->cc().rry(),
383 std::get<1>(cli2), std::get<2>(cli2),
384 std::get<3>(cli2), std::get<4>(cli2)
386 if (std::get<0>(cli1) && (
390 this->cc().rotate(cclx, ccly, -a1);
391 if (::right_side_of_line(
392 this->cc().x(), this->cc().y(),
395 + cos(this->ps().heading()),
397 + sin(this->ps().heading()),
400 + cos(this->cc().h()),
402 + sin(this->cc().h())
406 } else if (std::get<0>(cli2) && (
410 this->cc().rotate(cclx, ccly, -a2);
414 } else if (ccl_lr >= ccl_p1) {
416 auto cli1 = ::intersect(
418 this->ps().x1(), this->ps().y1(),
419 this->ps().x2(), this->ps().y2()
421 double a1 = angle_between_closer_point(
422 this->cc().lrx(), this->cc().lry(),
424 std::get<1>(cli1), std::get<2>(cli1),
425 std::get<3>(cli1), std::get<4>(cli1)
427 auto cli2 = ::intersect(
429 this->ps().x2(), this->ps().y2(),
430 this->ps().x3(), this->ps().y3()
432 double a2 = angle_between_closer_point(
433 this->cc().rrx(), this->cc().rry(),
435 std::get<1>(cli2), std::get<2>(cli2),
436 std::get<3>(cli2), std::get<4>(cli2)
438 if (std::get<0>(cli1) && (
442 this->cc().rotate(cclx, ccly, -a1);
443 if (::right_side_of_line(
444 this->cc().x(), this->cc().y(),
447 + cos(this->ps().heading()),
449 + sin(this->ps().heading()),
452 + cos(this->cc().h()),
454 + sin(this->cc().h())
458 } else if (std::get<0>(cli2) && (
462 this->cc().rotate(cclx, ccly, -a2);
467 } else if (this->ps().right() && this->cc().sp() > 0) {
468 double ccrx = this->cc().ccr().x();
469 double ccry = this->cc().ccr().y();
470 double ccr_lf = edist(
472 this->cc().lfx(), this->cc().lfy()
474 double ccr_rf = edist(
476 this->cc().rfx(), this->cc().rfy()
479 double af = std::abs(
483 auto tmp_cc = BicycleCar(this->cc());
484 this->cc().rotate(ccrx, ccry, -af);
485 this->gc() = BicycleCar(this->cc());
490 this->cc().sp(this->cc().sp() * -1);
491 this->gc() = BicycleCar(this->cc());
494 this->cc() = BicycleCar(tmp_cc);
497 auto cli1 = ::intersect(
499 this->ps().x3(), this->ps().y3(),
500 this->ps().x4(), this->ps().y4()
502 double a1 = angle_between_closer_point(
503 this->cc().rfx(), this->cc().rfy(),
505 std::get<1>(cli1), std::get<2>(cli1),
506 std::get<3>(cli1), std::get<4>(cli1)
508 auto cli2 = ::intersect(
510 this->ps().x2(), this->ps().y2(),
511 this->ps().x3(), this->ps().y3()
513 double a2 = angle_between_closer_point(
514 this->cc().rfx(), this->cc().rfy(),
516 std::get<1>(cli2), std::get<2>(cli2),
517 std::get<3>(cli2), std::get<4>(cli2)
519 auto cli3 = ::intersect(
521 this->ps().x3(), this->ps().y3(),
522 this->ps().x4(), this->ps().y4()
524 double a3 = angle_between_closer_point(
525 this->cc().lfx(), this->cc().lfy(),
527 std::get<1>(cli3), std::get<2>(cli3),
528 std::get<3>(cli3), std::get<4>(cli3)
530 if (std::get<0>(cli1) && (
531 (!std::get<0>(cli2) && !std::get<0>(cli3))
532 || (a1 < a2 && !std::get<0>(cli3))
533 || (a1 < a3 && !std::get<0>(cli2))
534 || (a1 < a2 && a1 < a3)
536 this->cc().rotate(ccrx, ccry, -a1);
537 } else if (std::get<0>(cli2) && (
538 (!std::get<0>(cli1) && !std::get<0>(cli3))
539 || (a2 < a1 && !std::get<0>(cli3))
540 || (a2 < a3 && !std::get<0>(cli1))
541 || (a2 < a1 && a2 < a3)
543 this->cc().rotate(ccrx, ccry, -a2);
544 } else if (std::get<0>(cli3) && (
545 (!std::get<0>(cli1) && !std::get<0>(cli2))
546 || (a3 < a1 && !std::get<0>(cli2))
547 || (a3 < a2 && !std::get<0>(cli1))
548 || (a3 < a1 && a3 < a2)
550 this->cc().rotate(ccrx, ccry, -a3);
554 } else if (!this->ps().right() && this->cc().sp() < 0) {
555 double ccrx = this->cc().ccr().x();
556 double ccry = this->cc().ccr().y();
557 double ccr_rr = edist(
559 this->cc().rrx(), this->cc().rry()
561 double ccr_lr = edist(
563 this->cc().lrx(), this->cc().lry()
565 double ccr_p1 = edist(
567 this->ps().x1(), this->ps().y1()
569 if (ccr_lr < ccr_p1) {
572 } else if (ccr_lr >= ccr_p1 && ccr_rr < ccr_p1) {
573 // partially out of parking slot
574 auto cli1 = ::intersect(
576 this->cc().lrx(), this->cc().lry(),
577 this->cc().rrx(), this->cc().rry()
579 double a1 = ::angle_between_closer_point(
580 this->ps().x1(), this->ps().y1(),
582 std::get<1>(cli1), std::get<2>(cli1),
583 std::get<3>(cli1), std::get<4>(cli1)
585 auto cli2 = ::intersect(
587 this->ps().x2(), this->ps().y2(),
588 this->ps().x3(), this->ps().y3()
590 double a2 = angle_between_closer_point(
591 this->cc().lrx(), this->cc().lry(),
593 std::get<1>(cli2), std::get<2>(cli2),
594 std::get<3>(cli2), std::get<4>(cli2)
596 if (std::get<0>(cli1) && (
600 this->cc().rotate(ccrx, ccry, a1);
601 if (!::right_side_of_line(
602 this->cc().x(), this->cc().y(),
605 + cos(this->ps().heading()),
607 + sin(this->ps().heading()),
610 + cos(this->cc().h()),
612 + sin(this->cc().h())
616 } else if (std::get<0>(cli2) && (
620 this->cc().rotate(ccrx, ccry, a2);
624 } else if (ccr_rr >= ccr_p1) {
626 auto cli1 = ::intersect(
628 this->ps().x1(), this->ps().y1(),
629 this->ps().x2(), this->ps().y2()
631 double a1 = angle_between_closer_point(
632 this->cc().rrx(), this->cc().rry(),
634 std::get<1>(cli1), std::get<2>(cli1),
635 std::get<3>(cli1), std::get<4>(cli1)
637 auto cli2 = ::intersect(
639 this->ps().x2(), this->ps().y2(),
640 this->ps().x3(), this->ps().y3()
642 double a2 = angle_between_closer_point(
643 this->cc().lrx(), this->cc().lry(),
645 std::get<1>(cli2), std::get<2>(cli2),
646 std::get<3>(cli2), std::get<4>(cli2)
648 if (std::get<0>(cli1) && (
652 this->cc().rotate(ccrx, ccry, a1);
653 if (!::right_side_of_line(
654 this->cc().x(), this->cc().y(),
657 + cos(this->ps().heading()),
659 + sin(this->ps().heading()),
662 + cos(this->cc().h()),
664 + sin(this->cc().h())
668 } else if (std::get<0>(cli2) && (
672 this->cc().rotate(ccrx, ccry, a2);
677 } else if (!this->ps().right() && this->cc().sp() > 0) {
678 double cclx = this->cc().ccl().x();
679 double ccly = this->cc().ccl().y();
680 double ccl_rf = edist(
682 this->cc().rfx(), this->cc().rfy()
684 double ccl_lf = edist(
686 this->cc().lfx(), this->cc().lfy()
689 double af = std::abs(
693 auto tmp_cc = BicycleCar(this->cc());
694 this->cc().rotate(cclx, ccly, af);
695 this->gc() = BicycleCar(this->cc());
700 this->cc().sp(this->cc().sp() * -1);
701 this->gc() = BicycleCar(this->cc());
704 this->cc() = BicycleCar(tmp_cc);
707 auto cli1 = ::intersect(
709 this->ps().x3(), this->ps().y3(),
710 this->ps().x4(), this->ps().y4()
712 double a1 = angle_between_closer_point(
713 this->cc().lfx(), this->cc().lfy(),
715 std::get<1>(cli1), std::get<2>(cli1),
716 std::get<3>(cli1), std::get<4>(cli1)
718 auto cli2 = ::intersect(
720 this->ps().x2(), this->ps().y2(),
721 this->ps().x3(), this->ps().y3()
723 double a2 = angle_between_closer_point(
724 this->cc().lfx(), this->cc().lfy(),
726 std::get<1>(cli2), std::get<2>(cli2),
727 std::get<3>(cli2), std::get<4>(cli2)
729 auto cli3 = ::intersect(
731 this->ps().x3(), this->ps().y3(),
732 this->ps().x4(), this->ps().y4()
734 double a3 = angle_between_closer_point(
735 this->cc().rfx(), this->cc().rfy(),
737 std::get<1>(cli3), std::get<2>(cli3),
738 std::get<3>(cli3), std::get<4>(cli3)
740 if (std::get<0>(cli1) && (
741 (!std::get<0>(cli2) && !std::get<0>(cli3))
742 || (a1 < a2 && !std::get<0>(cli3))
743 || (a1 < a3 && !std::get<0>(cli2))
744 || (a1 < a2 && a1 < a3)
746 this->cc().rotate(cclx, ccly, a1);
747 } else if (std::get<0>(cli2) && (
748 (!std::get<0>(cli1) && !std::get<0>(cli3))
749 || (a2 < a1 && !std::get<0>(cli3))
750 || (a2 < a3 && !std::get<0>(cli1))
751 || (a2 < a1 && a2 < a3)
753 this->cc().rotate(cclx, ccly, a2);
754 } else if (std::get<0>(cli3) && (
755 (!std::get<0>(cli1) && !std::get<0>(cli2))
756 || (a3 < a1 && !std::get<0>(cli2))
757 || (a3 < a2 && !std::get<0>(cli1))
758 || (a3 < a1 && a3 < a2)
760 this->cc().rotate(cclx, ccly, a3);
765 // TODO left parking slot (both forward, backward)
767 this->cc().sp(this->cc().sp() * -1);
769 this->gc() = BicycleCar(this->cc());
772 this->cc().st(this->cc().st() * -1);
773 q.push(BicycleCar(this->cc()));
774 if (sgn(this->cc().st()) == sgn(q.front().st()))
778 this->gc() = BicycleCar(bco);
780 return this->fer_parallel();
783 void PSPlanner::fe_perpendicular()
785 // TODO Try multiple angles when going from parking slot.
787 // Do not use just the maximum steer angle. Test angles
788 // until the whole current car `cc` is out of the parking
791 // Another approach could be testing angles from the
792 // beginning of the escape parkig slot maneuver.
794 this->cc().sp(-0.01);
797 while (!this->left())
802 void PSPlanner::fer()
805 if (this->ps().parallel()) {
807 this->cc() = BicycleCar(this->gc());
808 this->cc().set_max_steer();
809 if (!this->ps().right())
810 this->cc().st(this->cc().st() * -1);
812 return this->fer_parallel();
814 return this->fer_perpendicular();
818 void PSPlanner::fer_parallel()
820 this->cusps_.clear();
821 while (!this->left()) {
822 while (!this->collide() && !this->left())
824 if (this->left() && !this->collide()) {
827 this->cc().sp(this->cc().sp() * -1);
829 this->cc().st(this->cc().st() * -1);
831 this->cusps_.push_back(this->cc());
834 if (this->cc().st() < 0) {
836 this->cusps_.push_back(this->cc());
840 void PSPlanner::fer_perpendicular()
842 bool delta_use[] = {true, true, true};
843 double cc_h = this->cc().h();
846 // check inner radius
847 if (this->forward()) {
856 if (this->ps().right()) {
857 x1 = this->cc().ccr().x();
858 y1 = this->cc().ccr().y();
860 x1 = this->cc().ccl().x();
861 y1 = this->cc().ccl().y();
863 double IR = this->cc().iradi();
867 b = (x - x1) * 2 * cos(cc_h) + (y - y1) * 2 * sin(cc_h);
869 b = (x1 - x) * 2 * cos(cc_h) + (y1 - y) * 2 * sin(cc_h);
870 double c = pow(x - x1, 2) + pow(y - y1, 2) - pow(IR, 2);
871 double D = pow(b, 2) - 4 * a * c;
873 delta = -b - sqrt(D);
875 double delta_1 = delta;
877 delta_use[0] = false;
878 // check outer radius
879 if (this->forward()) {
886 IR = this->cc().ofradi();
889 b = (x - x1) * 2 * cos(cc_h) + (y - y1) * 2 * sin(cc_h);
891 b = (x1 - x) * 2 * cos(cc_h) + (y1 - y) * 2 * sin(cc_h);
892 c = pow(x - x1, 2) + pow(y - y1, 2) - pow(IR, 2);
893 D = pow(b, 2) - 4 * a * c;
894 if (this->forward()) {
895 delta = -b + sqrt(D);
898 double delta_2 = delta;
900 delta_use[1] = false;
901 delta = -b - sqrt(D);
903 double delta_3 = delta;
905 delta_use[2] = false;
906 if (delta_use[0] && delta_use[1] && delta_use[2])
907 delta = std::max(delta_1, std::max(delta_2, delta_3));
908 else if (delta_use[0] && delta_use[1])
909 delta = std::max(delta_1, delta_2);
910 else if (delta_use[0] && delta_use[2])
911 delta = std::max(delta_1, delta_3);
912 else if (delta_use[1] && delta_use[2])
913 delta = std::max(delta_2, delta_3);
914 else if (delta_use[0])
916 else if (delta_use[1])
918 else if (delta_use[2])
922 // current car `cc` can get out of slot with max steer
923 this->cc().x(this->cc().x() + delta * cos(cc_h));
924 this->cc().y(this->cc().y() + delta * sin(cc_h));
926 // get current car `cc` out of slot
928 this->cc().sp(-0.01);
931 this->cc().set_max_steer();
932 if (this->ps().right())
933 this->cc().st(this->cc().st() * -1);
934 while (!this->left()) {
935 while (!this->collide() && !this->left())
937 if (this->left() && !this->collide()) {
940 this->cc().sp(this->cc().sp() * -1);
942 this->cc().st(this->cc().st() * -1);
947 PSPlanner::PSPlanner()