2 This file is part of I am car.
4 I am car is free 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/>.
20 #include "reeds_shepp.h"
23 #define ST2WHEELBASE 2.450
24 #define ST2TURNINGRADI 10.82
25 #define ST2MAXSTEERING atan(ST2WHEELBASE / ST2TURNINGRADI)
31 std::vector<RRTNode *> st1(RRTNode *init, RRTNode *goal)
37 std::vector<RRTNode *> nodes;
39 for (i = 1; i < 2; i++) { // TODO
40 angl = atan2(goal->y() - init->y(), goal->x() - init->x());
41 new_x = init->x() + i * 1 * cos(angl); // TODO
42 new_y = init->y() + i * 1 * sin(angl); // TODO
44 nodes.push_back(new RRTNode(new_x, new_y, new_h));
49 std::vector<RRTNode *> st2(RRTNode *init, RRTNode *goal)
52 float angl = atan2(goal->y() - init->y(), goal->x() - init->x());
53 float sa = angl - init->h(); // steering angle
54 float co = cos(angl - init->h());
55 float si = sin(angl - init->h());
64 if (sa > ST2MAXSTEERING)
66 if (sa < -ST2MAXSTEERING)
68 float new_h = init->h() + (speed / ST2WHEELBASE) * tan(sa);
69 float new_x = init->x() + speed * cos(new_h);
70 float new_y = init->y() + speed * sin(new_h);
71 std::vector<RRTNode *> nodes;
72 nodes.push_back(new RRTNode(new_x, new_y, new_h));
76 int cb_st3(double q[3], void *user_data)
78 std::vector<RRTNode *> *nodes = (std::vector<RRTNode *> *) user_data;
79 nodes->push_back(new RRTNode(q[0], q[1], q[2]));
83 std::vector<RRTNode *> st3(RRTNode *init, RRTNode *goal)
85 std::vector<RRTNode *> nodes;
86 double q0[] = {init->x(), init->y(), init->h()};
87 double q1[] = {goal->x(), goal->y(), goal->h()};
88 ReedsSheppStateSpace rsss(10.82); // TODO const param
89 rsss.sample(q0, q1, 1, cb_st3, &nodes); // TODO const
93 std::vector<RRTNode *> st4(RRTNode *init, RRTNode *goal)
95 std::vector<RRTNode *> nodes;
96 BicycleCar bc(init->x(), init->y(), init->h());
98 float angl = atan2(goal->y() - init->y(), goal->x() - init->x());
99 float co = cos(angl - init->h());
100 //float si = sin(angl - init->h());
102 float speed = 1; // desired
103 float gx = goal->x();
104 float gy = goal->y();
109 float rx = 0; // recomputed goal x
110 float ry = 0; // recomputed goal y
113 for (i = 0; i < ST3COUNT; i++) {
115 cerr = speed - bc.speed();
116 bc.speed(ST3KP * cerr + ST3KI * lerr);
119 rx = (gx - bc.x()) * cos(-bc.h()) -
120 (gy - bc.y()) * sin(-bc.h());
121 ry = (gx - bc.x()) * sin(-bc.h()) -
122 (gy - bc.y()) * cos(-bc.h());
124 r = pow(rx, 2) + pow(ry, 2) / (2 * ry);
129 nodes.push_back(new RRTNode(bc.x(), bc.y(), bc.h()));