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>
21 #include "rrtplanner.h"
27 Json::Value jvi; // JSON input
29 std::string encoding = jvi.get("encoding", "UTF-8" ).asString();
34 jvi["init"][0].asFloat(),
35 jvi["init"][1].asFloat(),
36 jvi["init"][2].asFloat()),
38 jvi["goal"][0].asFloat(),
39 jvi["goal"][1].asFloat(),
40 jvi["goal"][2].asFloat()));
41 std::vector<CircleObstacle> co;
42 std::vector<SegmentObstacle> so;
43 for (auto o: jvi["obst"]) {
44 if (o["circle"] != Json::nullValue) {
45 co.push_back(CircleObstacle(
46 o["circle"][0].asFloat(),
47 o["circle"][1].asFloat(),
48 o["circle"][2].asFloat()));
50 if (o["segment"] != Json::nullValue) {
51 so.push_back(SegmentObstacle(
53 o["segment"][0][0].asFloat(),
54 o["segment"][0][1].asFloat(),
57 o["segment"][1][0].asFloat(),
58 o["segment"][1][1].asFloat(),
62 p.link_obstacles(&co, &so);
65 while (!p.goal_found() && p.elapsed() < 10) {
70 std::cerr << "Elapsed is " << p.elapsed() << std::endl;
71 std::cerr << "Goal found is " << p.goal_found() << std::endl;
72 std::cerr << "`tlog` size is " << p.tlog().size() << std::endl;
74 Json::Value jvo; // JSON output
80 for (auto traj: p.tlog()) {
83 jvo["traj"][j][i][0] = n->x();
84 jvo["traj"][j][i][1] = n->y();
85 jvo["traj"][j][i][2] = n->h();
93 std::vector<RRTNode *> s; // DFS stack
94 std::vector<RRTNode *> r; // reset visited_
96 s.push_back(p.root());
102 for (auto ch: tmp->children()) {
104 jvo["edge"][j][0][0] = tmp->x();
105 jvo["edge"][j][0][1] = tmp->y();
106 jvo["edge"][j][1][0] = ch->x();
107 jvo["edge"][j][1][1] = ch->y();
117 for (auto s: p.samples()) {
118 jvo["samp"][j][0] = s->x();
119 jvo["samp"][j][1] = s->y();
120 jvo["samp"][j][2] = s->h();
124 std::cout << jvo << std::endl;
131 for (auto n: p.nodes())
133 for (auto s: p.samples())