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>
23 #include "rrtplanner.h"
27 bool run_planner = true;
36 Json::Value jvi; // JSON input
37 Json::Value jvo; // JSON output
41 std::string encoding = jvi.get("encoding", "UTF-8" ).asString();
45 jvi["init"][0].asFloat(),
46 jvi["init"][1].asFloat(),
47 jvi["init"][2].asFloat()),
49 jvi["goal"][0].asFloat(),
50 jvi["goal"][1].asFloat(),
51 jvi["goal"][2].asFloat()));
52 std::vector<CircleObstacle> co;
53 std::vector<SegmentObstacle> so;
54 for (auto o: jvi["obst"]) {
55 if (o["circle"] != Json::nullValue) {
56 co.push_back(CircleObstacle(
57 o["circle"][0].asFloat(),
58 o["circle"][1].asFloat(),
59 o["circle"][2].asFloat()));
61 if (o["segment"] != Json::nullValue) {
62 so.push_back(SegmentObstacle(
64 o["segment"][0][0].asFloat(),
65 o["segment"][0][1].asFloat(),
68 o["segment"][1][0].asFloat(),
69 o["segment"][1][1].asFloat(),
73 p.link_obstacles(&co, &so);
78 std::vector<RRTNode *> tr;
82 signal(SIGTERM, hint);
88 if (!p.goal_found()) {
90 nn = p.nn(p.iy_, p.goal(), p.cost);
92 nn = p.nn(p.nodes(), p.goal(), p.cost);
100 #else // USE_INTERRUPT
101 while(!p.goal_found()) {
104 while (p.elapsed() < TMAX) {
109 nn = p.nn(p.iy_, p.goal(), p.cost);
111 nn = p.nn(p.nodes(), p.goal(), p.cost);
120 #endif // USE_INTERRUPT
122 std::cerr << "Elapsed is " << p.elapsed() << std::endl;
123 std::cerr << "Goal found is " << p.goal_found() << std::endl;
124 std::cerr << "#nodes is " << p.nodes().size() << std::endl;
125 std::cerr << "#samples is " << p.samples().size() << std::endl;
126 std::cerr << "`tlog` size is " << p.tlog().size() << std::endl;
127 std::cerr << "trajectories costs:" << std::endl;
128 for (j = 0; j < p.clog().size(); j++)
129 std::cerr << "- " << p.clog()[j] << std::endl;
130 std::cerr << "RRT #nodes:" << std::endl;
131 for (j = 0; j < p.nlog().size(); j++)
132 std::cerr << "- " << p.nlog()[j] << std::endl;
133 std::cerr << "trajectories seconds:" << std::endl;
134 for (j = 0; j < p.slog().size(); j++)
135 std::cerr << "- " << p.slog()[j] << std::endl;
136 std::cerr << "RRT edges (from root) log size: " << p.rlog().size();
137 std::cerr << std::endl;
138 for (auto edges: p.rlog())
139 std::cerr << "- " << edges.size() << std::endl;
142 jvo["elap"] = p.elapsed();
144 for (j = 0; j < p.clog().size(); j++)
145 jvo["cost"][j] = p.clog()[j];
147 for (j = 0; j < p.nlog().size(); j++)
148 jvo["node"][j] = p.nlog()[j];
150 for (j = 0; j < p.slog().size(); j++)
151 jvo["secs"][j] = p.slog()[j];
155 for (auto traj: p.tlog()) {
158 jvo["traj"][j][i][0] = n->x();
159 jvo["traj"][j][i][1] = n->y();
160 jvo["traj"][j][i][2] = n->h();
169 for (auto edges: p.rlog()) {
171 for (auto e: edges) {
172 jvo["edge"][i][j][0][0] = e->init()->x();
173 jvo["edge"][i][j][0][1] = e->init()->y();
174 jvo["edge"][i][j][1][0] = e->goal()->x();
175 jvo["edge"][i][j][1][1] = e->goal()->y();
181 #if JSONLOGSAMPLES > 0
185 for (auto s: p.samples()) {
186 jvo["samp"][j][0] = s->x();
187 jvo["samp"][j][1] = s->y();
188 jvo["samp"][j][2] = s->h();
193 std::cout << jvo << std::endl;