2 This file is part of I am car.
4 I am car is nree software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 I am car is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with I am car. If not, see <http://www.gnu.org/licenses/>.
19 #include <jsoncpp/json/json.h>
22 #include "rrtplanner.h"
26 Json::Value jvi; // JSON input
27 Json::Value jvo; // JSON output
31 std::string encoding = jvi.get("encoding", "UTF-8" ).asString();
35 jvi["init"][0].asFloat(),
36 jvi["init"][1].asFloat(),
37 jvi["init"][2].asFloat()),
39 jvi["goal"][0].asFloat(),
40 jvi["goal"][1].asFloat(),
41 jvi["goal"][2].asFloat()));
42 std::vector<CircleObstacle> co;
43 std::vector<SegmentObstacle> so;
44 for (auto o: jvi["obst"]) {
45 if (o["circle"] != Json::nullValue) {
46 co.push_back(CircleObstacle(
47 o["circle"][0].asFloat(),
48 o["circle"][1].asFloat(),
49 o["circle"][2].asFloat()));
51 if (o["segment"] != Json::nullValue) {
52 so.push_back(SegmentObstacle(
54 o["segment"][0][0].asFloat(),
55 o["segment"][0][1].asFloat(),
58 o["segment"][1][0].asFloat(),
59 o["segment"][1][1].asFloat(),
63 p.link_obstacles(&co, &so);
66 while (p.elapsed() < TMAX) {
71 std::cerr << "Elapsed is " << p.elapsed() << std::endl;
72 std::cerr << "Goal found is " << p.goal_found() << std::endl;
73 std::cerr << "#nodes is " << p.nodes().size() << std::endl;
74 std::cerr << "#samples is " << p.samples().size() << std::endl;
75 std::cerr << "`tlog` size is " << p.tlog().size() << std::endl;
76 std::cerr << "trajectories costs:" << std::endl;
77 for (j = 0; j < p.clog().size(); j++)
78 std::cerr << "- " << p.clog()[j] << std::endl;
79 std::cerr << "RRT #nodes:" << std::endl;
80 for (j = 0; j < p.nlog().size(); j++)
81 std::cerr << "- " << p.nlog()[j] << std::endl;
82 std::cerr << "trajectories seconds:" << std::endl;
83 for (j = 0; j < p.slog().size(); j++)
84 std::cerr << "- " << p.slog()[j] << std::endl;
87 jvo["elap"] = p.elapsed();
89 for (j = 0; j < p.clog().size(); j++)
90 jvo["cost"][j] = p.clog()[j];
92 for (j = 0; j < p.nlog().size(); j++)
93 jvo["node"][j] = p.nlog()[j];
95 for (j = 0; j < p.slog().size(); j++)
96 jvo["secs"][j] = p.slog()[j];
100 for (auto traj: p.tlog()) {
103 jvo["traj"][j][i][0] = n->x();
104 jvo["traj"][j][i][1] = n->y();
105 jvo["traj"][j][i][2] = n->h();
114 std::vector<RRTNode *> s; // DFS stack
115 std::vector<RRTNode *> r; // reset visited_
117 s.push_back(p.root());
118 while(s.size() > 0) {
123 for (auto ch: tmp->children()) {
125 jvo["edge"][j][0][0] = tmp->x();
126 jvo["edge"][j][0][1] = tmp->y();
127 jvo["edge"][j][1][0] = ch->x();
128 jvo["edge"][j][1][1] = ch->y();
136 #if JSONLOGSAMPLES > 0
140 for (auto s: p.samples()) {
141 jvo["samp"][j][0] = s->x();
142 jvo["samp"][j][1] = s->y();
143 jvo["samp"][j][2] = s->h();
148 std::cout << jvo << std::endl;