]> rtime.felk.cvut.cz Git - hubacji1/iamcar2.git/blobdiff - src/template-with-reset.cc
Add more car dimensions, remove unused comments
[hubacji1/iamcar2.git] / src / template-with-reset.cc
index c9f3ea044f909638b241f80226ed91c66e5204cd..0d17b0603357028118236a2fb08fc304d18fba43 100644 (file)
@@ -28,6 +28,8 @@ int main()
                jvi["slot"][2][0].asDouble(), jvi["slot"][2][1].asDouble(),
                jvi["slot"][3][0].asDouble(), jvi["slot"][3][1].asDouble());
        bcar::BicycleCar c;
+       c.become("porsche cayenne");
+
        bool swapped = false;
        if (s.parallel() && !s.right()) {
                s.swap_side();
@@ -38,7 +40,7 @@ int main()
                s.swap_side();
                pr.reflect(s.entry());
        }
-       std::cerr << ip_time.scnt() << std::endl;
+       //std::cerr << ip_time.scnt() << std::endl;
        // The following uses precomputed entries and needs `"fiat_punto.h"` to
        // be included.
        //auto pr = get_fiat_punto_entry(s.len(), s.w());
@@ -48,7 +50,7 @@ int main()
        c.h(pr.h());
        c.sp(-0.1);
        c.st(0.0);
-       std::vector<bcar::Pose> ispath;
+       std::vector<bcar::BicycleCar> ispath;
        if (s.right()) {
                while (!c.rf().on_right_side_of(s.entry())) {
                        c.next();
@@ -62,12 +64,8 @@ int main()
        }
        if (s.parallel()) {
                c.set_max_steer();
-               if (!s.right()) {
-                       c.st(c.st() * -1.0);
-               }
-               for (auto p: s.steer_in_slot(c)) {
-                       c.next();
-                       ispath.push_back(c);
+               for (auto &n : s.drive_in_slot(c)) {
+                       ispath.push_back(n);
                }
        }
        jvi["goal"][0] = pr.x();
@@ -77,6 +75,9 @@ int main()
        jvi["goal_inside"][0] = ispath.back().x();
        jvi["goal_inside"][1] = ispath.back().y();
        jvi["goal_inside"][2] = ispath.back().h();
+
+       p.set_bc_to_become("porsche cayenne");
+
        p.json(jvi);
        unsigned int icnt = 0;
        unsigned int rcnt = 0;
@@ -85,6 +86,7 @@ int main()
        Json::Value best_path;
        Json::Value pj;
        double cost = 0.0;
+       p.reset();
        while (icnt < 1000) {
                p.icnt(icnt);
                while (p.next()) {}
@@ -112,13 +114,6 @@ int main()
        }
        double elapsed = p.scnt();
        auto jvo = p.json();
-       unsigned int i = 0;
-       for (auto p: ispath) {
-               jvo["ispath"][i][0] = p.x();
-               jvo["ispath"][i][1] = p.y();
-               jvo["ispath"][i][2] = p.h();
-               i += 1;
-       }
        jvo["init"] = jvi["init"];
        jvo["slot"] = jvi["slot"];
        jvo["obst"] = jvi["obst"];
@@ -129,8 +124,54 @@ int main()
        jvo["time"] = elapsed;
        jvo["icnt"] = p.icnt();
        jvo["rcnt"] = rcnt;
+       jvo["ncnt"] = ncnt;
        jvo["bcnt"] = bcnt;
        jvo["path"] = best_path;
+       unsigned int best_path_size = best_path.size();
+       double best_path_gx = best_path[best_path_size - 1][0].asDouble();
+       double best_path_gy = best_path[best_path_size - 1][1].asDouble();
+       double best_path_gh = best_path[best_path_size - 1][2].asDouble();
+       // FIXME for perpendicular parking.
+       //assert(std::abs(best_path_gx - ispath[0].x()) < 1e-3
+       //      && std::abs(best_path_gy - ispath[0].y()) < 1e-3
+       //      && std::abs(best_path_gh - ispath[0].h()) < 1e-3);
+       unsigned int i = 0;
+       for (auto p: ispath) {
+               jvo["ispath"][i][0] = p.x();
+               jvo["ispath"][i][1] = p.y();
+               jvo["ispath"][i][2] = p.h();
+               if (i == 0) {
+                       // The first pose of in-slot path is entry
+                       // configuration, i.e. the last pose of the path.
+                       // We just need to check if the last pose of the path
+                       // (goal) is cusp.
+                       int best_path_goal_sgn = bcar::sgn(
+                               jvo["path"][best_path_size - 1][3].asDouble());
+                       int ispath_goal_sgn = bcar::sgn(ispath[0].sp());
+                       if (best_path_goal_sgn != ispath_goal_sgn) {
+                               jvo["path"][best_path_size - 1][5] = true;
+                       }
+                       i++;
+                       continue;
+               }
+               jvo["path"][best_path_size + i - 1][0] = p.x();
+               jvo["path"][best_path_size + i - 1][1] = p.y();
+               jvo["path"][best_path_size + i - 1][2] = p.h();
+               jvo["path"][best_path_size + i - 1][3] = p.sp();
+               int segment_type = 0;
+               if (p.st() > 0) {
+                       segment_type = 1;
+               } else if (p.st() < 0) {
+                       segment_type = -1;
+               }
+               jvo["path"][best_path_size + i - 1][4] = segment_type;
+               bool is_cusp = false;
+               if (bcar::sgn(p.sp()) != bcar::sgn(ispath[i - 1].sp())) {
+                       is_cusp = true;
+               }
+               jvo["path"][best_path_size + i - 1][5] = is_cusp;
+               i++;
+       }
        jvo["goal_cc"] = cost;
        std::cout << jvo << std::endl;
        return 0;