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"
29 #define ST3TURNINGRADIUS 10.82
33 #define ST4SPEED 0.2 // aka STEP
38 std::vector<RRTNode *> st1(RRTNode *init, RRTNode *goal)
44 std::vector<RRTNode *> nodes;
46 for (i = 1; i < ST1COUNT + 1; i++) {
47 angl = atan2(goal->y() - init->y(), goal->x() - init->x());
48 new_x = init->x() + i * ST1STEP * cos(angl);
49 new_y = init->y() + i * ST1STEP * sin(angl);
51 nodes.push_back(new RRTNode(new_x, new_y, new_h));
56 std::vector<RRTNode *> st2(RRTNode *init, RRTNode *goal)
58 std::vector<RRTNode *> nodes;
59 BicycleCar bc(init->x(), init->y(), init->h());
67 for (i = 0; i < ST2COUNT; i++) {
69 angl = atan2(goal->y() - bc.y(), goal->x() - bc.x());
70 steer = angl - bc.h();
71 co = cos(angl - bc.h());
72 si = sin(angl - bc.h());
85 nodes.push_back(new RRTNode(bc.x(), bc.y(), bc.h()));
90 int cb_st3(double q[4], void *user_data)
92 std::vector<RRTNode *> *nodes = (std::vector<RRTNode *> *) user_data;
93 nodes->push_back(new RRTNode(q[0], q[1], q[2]));
94 nodes->back()->s(q[3]);
98 std::vector<RRTNode *> st3(RRTNode *init, RRTNode *goal)
100 return st3(init, goal, ST3STEP);
103 std::vector<RRTNode *> st3(RRTNode *init, RRTNode *goal, float step)
105 std::vector<RRTNode *> nodes;
106 double q0[] = {init->x(), init->y(), init->h()};
107 double q1[] = {goal->x(), goal->y(), goal->h()};
108 ReedsSheppStateSpace rsss(ST3TURNINGRADIUS);
109 rsss.sample(q0, q1, step, cb_st3, &nodes);
113 std::vector<RRTNode *> st4(RRTNode *init, RRTNode *goal)
115 std::vector<RRTNode *> nodes;
116 BicycleCar bc(init->x(), init->y(), init->h());
118 float angl = atan2(goal->y() - init->y(), goal->x() - init->x());
119 float co = cos(angl - init->h());
120 //float si = sin(angl - init->h());
122 float speed = ST4SPEED; // desired
123 float gx = goal->x();
124 float gy = goal->y();
129 float rx = 0; // recomputed goal x
130 float ry = 0; // recomputed goal y
133 for (i = 0; i < ST4COUNT; i++) {
135 cerr = speed - bc.speed();
136 bc.speed(ST4KP * cerr + ST4KI * lerr);
139 rx = (gx - bc.x()) * cos(-bc.h()) -
140 (gy - bc.y()) * sin(-bc.h());
141 ry = (gx - bc.x()) * sin(-bc.h()) -
142 (gy - bc.y()) * cos(-bc.h());
144 r = pow(rx, 2) + pow(ry, 2) / (2 * ry);
149 nodes.push_back(new RRTNode(bc.x(), bc.y(), bc.h()));