]> rtime.felk.cvut.cz Git - hubacji1/psp.git/commitdiff
Add forward can park computation
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Tue, 7 Jul 2020 11:33:11 +0000 (13:33 +0200)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Tue, 7 Jul 2020 12:19:38 +0000 (14:19 +0200)
src/psp.cc

index 3776cf7879eca848337b5c264426a21c017d3f20..cff29ffcbe75b09c193a835091859e83ae33871a 100644 (file)
@@ -461,7 +461,68 @@ void PSPlanner::fe_parallel()
                                 ccrx, ccry,
                                 this->cc().rfx(), this->cc().rfy()
                         );
-                        // TODO check if I can park
+                        {
+                                auto clif = ::intersect(
+                                        ccrx, ccry, ccr_lf,
+                                        this->ps().x1(), this->ps().y1(),
+                                        this->ps().x4(), this->ps().y4()
+                                );
+                                double af = std::abs(
+                                        this->ps().heading()
+                                        - this->cc().h()
+                                );
+                                double xf = this->ps().x4();
+                                double yf = this->ps().y4();
+                                if (std::get<0>(clif)) {
+                                        xf = std::get<1>(clif);
+                                        yf = std::get<2>(clif);
+                                        if (
+                                                edist(
+                                                        this->ps().x4(),
+                                                        this->ps().y4(),
+                                                        std::get<3>(clif),
+                                                        std::get<4>(clif)
+                                                ) < edist(
+                                                        this->ps().x4(),
+                                                        this->ps().y4(),
+                                                        xf, yf
+                                                )
+                                        ) {
+                                                xf = std::get<3>(clif);
+                                                yf = std::get<4>(clif);
+                                        }
+                                        af = ::angle_between_three_points(
+                                                this->cc().lfx(),
+                                                this->cc().lfy(),
+                                                ccrx, ccry,
+                                                xf, yf
+                                        );
+                                }
+                                auto tmp_cc = BicycleCar(this->cc());
+                                this->cc().rotate(ccrx, ccry, -af);
+                                if (
+                                        !this->collide()
+                                        && (
+                                                edist(
+                                                        this->ps().x1(),
+                                                        this->ps().y1(),
+                                                        xf, yf
+                                                ) < edist(
+                                                        this->ps().x1(),
+                                                        this->ps().y1(),
+                                                        this->ps().x4(),
+                                                        this->ps().y4()
+                                                )
+                                                || !std::get<0>(clif)
+                                        )
+                                ) {
+                                        this->cc().sp(this->cc().sp() * -1);
+                                        this->gc() = BicycleCar(this->cc());
+                                        goto successfinish;
+                                } else {
+                                        this->cc() = BicycleCar(tmp_cc);
+                                }
+                        }
                         // TODO (ccr, rf) x (p3, p4)
                         // TODO (ccr, rf) x (p2, p3)
                         // TODO (ccr, lf) x (p3, p4)