]> rtime.felk.cvut.cz Git - hubacji1/psp.git/blobdiff - src/psp.cc
Remove inefficient code
[hubacji1/psp.git] / src / psp.cc
index 583bad203cdd0b67541542f10dd5e9ce6ef58a44..31d4a741dd17b23f877ca52a33874e164d1dbc86 100644 (file)
@@ -115,8 +115,6 @@ void PSPlanner::guess_gc()
                         this->ps().x2() - this->ps().x1()
                 );
                 while (h < 0) h += 2 * M_PI;
-                x += 2 * cos(h);
-                y += 2 * sin(h);
 
                 //// This is for backward parking only.
                 //double entry_width = edist(
@@ -154,6 +152,46 @@ void PSPlanner::guess_gc()
         this->gc().h(h);
 }
 
+std::vector<BicycleCar> PSPlanner::last_maneuver()
+{
+        std::vector<BicycleCar> lm;
+        if (this->ps().parallel()) {
+                // zig-zag out from the slot
+                this->cc() = BicycleCar(this->gc());
+                this->cc().sp(0.1);
+                while (!this->left()) {
+                        while (!this->collide() && !this->left()) {
+                                this->cc().next();
+                                lm.push_back(BicycleCar(this->cc()));
+                        }
+                        if (this->left() && !this->collide()) {
+                                break;
+                        } else {
+                                lm.pop_back();
+                                this->cc().sp(this->cc().sp() * -1);
+                                this->cc().next();
+                                this->cc().st(this->cc().st() * -1);
+                                this->c_++;
+                                lm.push_back(BicycleCar(this->cc()));
+                        }
+                }
+                if (this->cc().st() < 0) {
+                        this->c_++;
+                        lm.push_back(BicycleCar(this->cc()));
+                }
+        } else {
+                // go 1 m forward
+                this->cc().sp(0.1);
+                BicycleCar orig_cc(this->cc());
+                for (unsigned int i = 0; i < 10; i++) {
+                        this->cc().next();
+                        lm.push_back(BicycleCar(this->cc()));
+                }
+                this->cc() = BicycleCar(orig_cc);
+        }
+        return lm;
+}
+
 bool PSPlanner::left()
 {
        double lfx = this->cc().lfx();
@@ -212,14 +250,36 @@ std::vector<BicycleCar> PSPlanner::possible_goals(
         else
                 this->cc().sp(-1);
         this->cc().sp(this->cc().sp() * dist);
-        if (this->ps().right())
-                this->cc().st(this->cc().st() * -1);
         BicycleCar orig_cc(this->cc());
         for (unsigned int i = 0; i < cnt; i++) {
                 this->cc().next();
                 pi.push_back(BicycleCar(this->cc()));
         }
         this->cc() = BicycleCar(orig_cc);
+        if (this->ps().parallel()) {
+                this->cc().st(0);
+                for (unsigned int i = 0; i < cnt; i++) {
+                        this->cc().next();
+                        pi.push_back(BicycleCar(this->cc()));
+                }
+                this->cc() = BicycleCar(orig_cc);
+        } else {
+                if (!this->ps().right()) {
+                        this->cc().set_max_steer();
+                        for (unsigned int i = 0; i < cnt; i++) {
+                                this->cc().next();
+                                pi.push_back(BicycleCar(this->cc()));
+                        }
+                } else {
+                        this->cc().set_max_steer();
+                        this->cc().st(this->cc().st() * -1);
+                        for (unsigned int i = 0; i < cnt; i++) {
+                                this->cc().next();
+                                pi.push_back(BicycleCar(this->cc()));
+                        }
+                }
+                this->cc() = BicycleCar(orig_cc);
+        }
         return pi;
 }
 
@@ -286,16 +346,6 @@ void PSPlanner::fe_parallel()
         while (!q.empty() && iter_cntr < 30) {
                 this->cc() = BicycleCar(q.front());
                 q.pop();
-                while (
-                        !this->collide()
-                        && (std::abs(
-                                this->cc().h() - this->ps().heading()
-                        ) > M_PI / 32)
-                        && (std::abs(
-                                this->cc().h() - this->ps().heading()
-                        ) < M_PI / 2)
-                )
-                        this->cc().next();
                 this->cc().sp(this->cc().sp() * -1);
                 this->cc().next();
                 this->gc() = BicycleCar(this->cc());