]> rtime.felk.cvut.cz Git - hubacji1/iamcar2.git/commitdiff
Update test template
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Tue, 8 Oct 2019 06:56:10 +0000 (08:56 +0200)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Tue, 8 Oct 2019 06:56:11 +0000 (08:56 +0200)
src/test-template.cc

index 4c4fe6e288fe48ecf520156c655d0abcadb6322c..5eb890bd6f49b85e419e87391bba56012779e247 100644 (file)
@@ -2,6 +2,8 @@
 #include <iostream>
 #include <jsoncpp/json/json.h>
 
+#include "rrts.h"
+
 std::chrono::high_resolution_clock::time_point TSTART_;
 std::chrono::high_resolution_clock::time_point TEND_;
 inline void TSTART() { TSTART_ = std::chrono::high_resolution_clock::now(); }
@@ -24,7 +26,147 @@ int main()
         Json::Value jvi; // JSON input
         Json::Value jvo; // JSON output
         std::cin >> jvi;
+        if (jvi["init"] == Json::nullValue) {
+                std::cerr << "I need `init` in JSON input scenario";
+                std::cerr << std::endl;
+                return 1;
+        }
+        if (jvi["goal"] == Json::nullValue) {
+                std::cerr << "I need `goal` in JSON input scenario";
+                std::cerr << std::endl;
+                return 1;
+        }
+        if (jvi["goals"] == Json::nullValue) {
+                std::cerr << "I need `goals` in JSON input scenario";
+                std::cerr << std::endl;
+                return 1;
+        }
+        if (jvi["obst"] == Json::nullValue) {
+                std::cerr << "I need `obst` in JSON input scenario";
+                std::cerr << std::endl;
+                return 1;
+        }
+
+        RRTS rrts;
+        rrts.nodes().front().x(jvi["init"][0].asDouble());
+        rrts.nodes().front().y(jvi["init"][1].asDouble());
+        rrts.nodes().front().h(jvi["init"][2].asDouble());
+        {
+                RRTNode tmp_node;
+                tmp_node.x(jvi["goal"][0].asDouble());
+                tmp_node.y(jvi["goal"][1].asDouble());
+                tmp_node.h(jvi["goal"][2].asDouble());
+                rrts.goals().push_back(tmp_node);
+                for (auto g: jvi["goals"]) {
+                        tmp_node.x(g[0].asDouble());
+                        tmp_node.y(g[1].asDouble());
+                        tmp_node.h(g[2].asDouble());
+                        rrts.goals().push_back(tmp_node);
+                }
+        }
+        {
+                Obstacle tmp_obstacle;
+                for (auto o: jvi["obst"]) {
+                        tmp_obstacle.poly().clear();
+                        for (auto c: o) {
+                                double tmp_x = c[0].asDouble();
+                                double tmp_y = c[1].asDouble();
+                                auto tmp_tuple = std::make_tuple(tmp_x, tmp_y);
+                                tmp_obstacle.poly().push_back(tmp_tuple);
+                        }
+                        rrts.obstacles().push_back(tmp_obstacle);
+                }
+        }
+        {
+                double edist_init_goal = sqrt(
+                        pow(
+                                rrts.nodes().front().x()
+                                - rrts.goals().front().x(),
+                                2
+                        )
+                        + pow(
+                                rrts.nodes().front().y()
+                                - rrts.goals().front().y(),
+                                2
+                        )
+                );
+                rrts.set_sample(
+                        rrts.nodes().front().x(), edist_init_goal,
+                        rrts.nodes().front().y(), edist_init_goal,
+                        0, 2 * M_PI
+                );
+        }
+
+        TSTART();
+        TEND();
 
+        {
+                jvo["time"] = TDIFF();
+        }
+        {
+                jvo["init"][0] = rrts.nodes().front().x();
+                jvo["init"][1] = rrts.nodes().front().y();
+                jvo["init"][2] = rrts.nodes().front().h();
+        }
+        {
+                if (rrts.path().size() > 0) {
+                        jvo["cost"] = cc(*rrts.path().back());
+                } else {
+                        jvo["cost"] = -1;
+                }
+        }
+        {
+                if (rrts.path().size() > 0) {
+                        jvo["goal"][0] = rrts.path().back()->x();
+                        jvo["goal"][1] = rrts.path().back()->y();
+                        jvo["goal"][2] = rrts.path().back()->h();
+                }
+                unsigned int cu = 0;
+                unsigned int co = 0;
+                unsigned int pcnt = 0;
+                for (auto n: rrts.path()) {
+                        jvo["path"][pcnt][0] = n->x();
+                        jvo["path"][pcnt][1] = n->y();
+                        jvo["path"][pcnt][2] = n->h();
+                        if (n->t(RRTNodeType::cusp))
+                                cu++;
+                        if (n->t(RRTNodeType::connected))
+                                co++;
+                        pcnt++;
+                }
+                jvo["path#cusp"] = cu;
+                jvo["path#connected"] = co;
+        }
+        {
+                unsigned int gcnt = 0;
+                for (auto g: rrts.goals()) {
+                        jvo["goals"][gcnt][0] = g.x();
+                        jvo["goals"][gcnt][1] = g.y();
+                        jvo["goals"][gcnt][2] = g.h();
+                        gcnt++;
+                }
+        }
+        {
+                unsigned int ocnt = 0;
+                for (auto o: rrts.obstacles()) {
+                        unsigned int ccnt = 0;
+                        for (auto c: o.poly()) {
+                                jvo["obst"][ocnt][ccnt][0] = std::get<0>(c);
+                                jvo["obst"][ocnt][ccnt][1] = std::get<1>(c);
+                                ccnt++;
+                        }
+                        ocnt++;
+                }
+        }
+        //{
+        //        unsigned int ncnt = 0;
+        //        for (auto n: rrts.nodes()) {
+        //                jvo["nodes_x"][ncnt] = n.x();
+        //                jvo["nodes_y"][ncnt] = n.y();
+        //                //jvo["nodes_h"][ncnt] = n.h();
+        //                ncnt++;
+        //        }
+        //}
         std::cout << jvo << std::endl;
         return 0;
 }