]> rtime.felk.cvut.cz Git - hubacji1/psp.git/blobdiff - src/psp.cc
Fix rotation of init for bfs paralell parking
[hubacji1/psp.git] / src / psp.cc
index 3063ff769b5145b338b9c51f8c575171a810d942..9bcd7bb754771389bb558f198fca2c246c6d6183 100644 (file)
@@ -96,7 +96,6 @@ void PSPlanner::guess_gc()
         if (this->ps().right())
                 dts = - M_PI / 2;
         if (this->ps().parallel()) {
-                dts *= 0.99; // precision workaround
                 x += (this->gc().w() / 2 + 0.01) * cos(h + dts);
                 x += (this->gc().dr() + 0.01) * cos(h);
                 y += (this->gc().w() / 2 + 0.01) * sin(h + dts);
@@ -256,6 +255,10 @@ std::vector<BicycleCar> PSPlanner::possible_goals(
 )
 {
         std::vector<BicycleCar> pi;
+        if (this->cc().sp() > 0)
+                this->cc().sp(1);
+        else
+                this->cc().sp(-1);
         this->cc().sp(this->cc().sp() * dist);
         this->cc().st(this->cc().st() * 1);
         BicycleCar orig_cc(this->cc());
@@ -270,74 +273,61 @@ std::vector<BicycleCar> PSPlanner::possible_goals(
 // find entry
 void PSPlanner::fe()
 {
-        if (this->ps().parallel())
+        this->c_ = 0;
+        if (this->ps().parallel()) {
                 return this->fe_parallel();
-        else
-                return this->fe_perpendicular();
+        } else {
+                this->guess_gc();
+                this->cc() = BicycleCar(this->gc());
+                return this->fer_perpendicular();
+        }
 }
 
 void PSPlanner::fe_parallel()
 {
-        // angle for distance from "entry" corner
-        double dist_angl = this->ps().heading() + M_PI;
-        dist_angl += (this->ps().right()) ? - M_PI / 4 : + M_PI / 4;
-        // set bicycle car `bci` basic dimensions and heading
-        BicycleCar bci = BicycleCar(this->gc());
         BicycleCar bco = BicycleCar(this->gc());
-        bci.h(this->ps().heading());
-        // move 0.01 from the "entry" corner
-        bci.x(this->ps().x4() + 0.01 * cos(dist_angl));
-        bci.y(this->ps().y4() + 0.01 * sin(dist_angl));
-        // align with parking "top" of slot (move backward)
-        dist_angl = bci.h() + M_PI;
-        bci.x(bci.x() + bci.df() * cos(dist_angl));
-        bci.y(bci.y() + bci.df() * sin(dist_angl));
-        // align with "entry" to pakring slot (move outside)
-        dist_angl = this->ps().heading();
-        dist_angl += (this->ps().right()) ? + M_PI / 2 : - M_PI / 2;
-        bci.x(bci.x() + bci.w() / 2 * cos(dist_angl));
-        bci.y(bci.y() + bci.w() / 2 * sin(dist_angl));
-        // set default speed, steer
-        bci.st(bci.wb() / bci.mtr());
+        this->cc() = BicycleCar();
+        this->cc().sp(-0.01);
+        this->cc().set_max_steer();
         if (!this->ps().right())
-                bci.st(bci.st() * -1);
-        bci.sp(-0.01);
-        // BFS - init all starts
-        // see https://courses.cs.washington.edu/courses/cse326/03su/homework/hw3/bfs.html
-        double dist_diag = sqrt(pow(bci.w() / 2, 2) + pow(bci.df(), 2));
-        if (this->ps().right())
-                dist_angl = atan2(bci.y() - bci.rfy(), bci.x() - bci.rfx());
-        else
-                dist_angl = atan2(bci.y() - bci.lfy(), bci.x() - bci.lfx());
-        double DIST_ANGL = dist_angl;
-        std::queue<BicycleCar, std::list<BicycleCar>> q;
-        while (
-                (
-                        this->ps().right()
-                        && dist_angl < DIST_ANGL + 3 * M_PI / 4
+                this->cc().st(this->cc().st() * -1);
+        this->cc().h(this->ps().heading());
+        double angl_in_slot = this->ps().heading() - M_PI / 4;
+        if (!this->ps().right())
+                angl_in_slot += M_PI / 2;
+        this->cc().x(
+                this->ps().x4()
+                + this->cc().w()/2 * cos(
+                        this->ps().heading()
+                        + (this->ps().right() ? + M_PI / 2 : - M_PI / 2)
                 )
-                || (
-                        !this->ps().right()
-                        && dist_angl > DIST_ANGL - 3 * M_PI / 4
+                + (this->cc().df() + 0.01) * cos(
+                        this->ps().heading() + M_PI
                 )
-        ) {
-                this->cc() = BicycleCar(bci);
-                if (this->ps().right()) {
-                        this->cc().x(bci.rfx() + dist_diag * cos(dist_angl));
-                        this->cc().y(bci.rfy() + dist_diag * sin(dist_angl));
-                } else {
-                        this->cc().x(bci.lfx() + dist_diag * cos(dist_angl));
-                        this->cc().y(bci.lfy() + dist_diag * sin(dist_angl));
-                }
-                this->cc().h(this->ps().heading() + dist_angl - DIST_ANGL);
-                if (!this->collide()) {
-                        q.push(BicycleCar(this->cc()));
-                }
-                dist_angl += (this->ps().right()) ? + 0.01 : - 0.01;
+        );
+        this->cc().y(
+                this->ps().y4()
+                + this->cc().w()/2 * sin(
+                        this->ps().heading()
+                        + (this->ps().right() ? + M_PI / 2 : - M_PI / 2)
+                )
+                + (this->cc().df() + 0.01) * sin(
+                        this->ps().heading() + M_PI
+                )
+        );
+
+        std::queue<BicycleCar, std::list<BicycleCar>> q;
+        while (!this->collide()) {
+                q.push(this->cc());
+                this->cc().rotate(
+                        this->ps().x4(),
+                        this->ps().y4() - 0.01,
+                        ((this->ps().right()) ? 0.01 : -0.01)
+                );
         }
         // BFS - find entry current car `cc` and corresponding goal car `gc`
         unsigned int iter_cntr = 0;
-        while (!q.empty() && iter_cntr < 9) {
+        while (!q.empty() && iter_cntr < 30) {
                 this->cc() = BicycleCar(q.front());
                 q.pop();
                 while (
@@ -387,18 +377,22 @@ void PSPlanner::fe_perpendicular()
 
 void PSPlanner::fer()
 {
-        if (this->ps().parallel())
+        this->c_ = 0;
+        if (this->ps().parallel()) {
+                this->guess_gc();
+                this->cc() = BicycleCar(this->gc());
+                this->cc().set_max_steer();
+                if (!this->ps().right())
+                        this->cc().st(this->cc().st() * -1);
+                this->cc().sp(0.01);
                 return this->fer_parallel();
-        else
+        } else {
                 return this->fer_perpendicular();
+        }
 }
 
 void PSPlanner::fer_parallel()
 {
-        this->cc().st(this->cc().wb() / this->cc().mtr());
-        if (!this->ps().right())
-                this->cc().st(this->cc().st() * -1);
-        this->cc().sp(0.01);
         this->cusps_.clear();
         while (!this->left()) {
                 while (!this->collide() && !this->left())
@@ -413,6 +407,10 @@ void PSPlanner::fer_parallel()
                         this->cusps_.push_back(this->cc());
                 }
         }
+        if (this->cc().st() < 0) {
+                this->c_++;
+                this->cusps_.push_back(this->cc());
+        }
 }
 
 void PSPlanner::fer_perpendicular()
@@ -506,7 +504,7 @@ void PSPlanner::fer_perpendicular()
                 this->cc().sp(-0.01);
         else
                 this->cc().sp(0.01);
-        this->cc().st(this->cc().wb() / this->cc().mtr());
+        this->cc().set_max_steer();
         if (this->ps().right())
                 this->cc().st(this->cc().st() * -1);
         while (!this->left()) {