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/>.
22 #include "slotplanner.h"
24 ParallelSlot::ParallelSlot()
28 std::vector<std::vector<RRTNode *>> &ParallelSlot::cusp()
33 float ParallelSlot::DH() const
38 PolygonObstacle &ParallelSlot::slot()
44 void ParallelSlot::DH(float dh)
50 void ParallelSlot::fip()
52 // see https://courses.cs.washington.edu/courses/cse326/03su/homework/hw3/bfs.html
53 // RRTNode.s() works as iteration level
54 std::queue<BicycleCar *, std::list<BicycleCar *>> q;
56 // TODO add init nodes
57 // for now just copy fpose()
58 bool left = false; // right parking slot
60 BicycleCar *CC = new BicycleCar(
61 this->fposecenter()->x(),
62 this->fposecenter()->y() - 0.01,
65 BicycleCar *B = new BicycleCar(
66 CC->x() - CC->width() / 2,
67 CC->y() - (CC->length() + CC->wheelbase()) / 2,
70 if (this->slot().bnodes()[0]->x() > this->slot().bnodes()[1]->x()) {
75 CC->x() + CC->width() / 2,
76 CC->y() - (CC->length() + CC->wheelbase()) / 2,
80 this->DH(di * 0.01 / CC->out_radi());
83 c = B->move(CC, -i * di * 0.01 / CC->diag_radi());
84 while (!this->slot().collide(c->frame())) {
86 c = B->move(CC, -i * di * 0.01 / CC->diag_radi());
89 delete c; // not in q and collide
94 if (this->DH() > 0 && c->rfx() <= 0 && c->rrx() <= 0) {
95 goto createcuspandfinish;
96 } else if (this->DH() < 0 && c->lfx() >= 0 && c->lrx() >= 0) {
97 goto createcuspandfinish;
98 } else if (c->s() < 9) {
99 BicycleCar *cc = this->flnc(c);
104 delete c; // not in q and collide
108 std::vector<RRTNode *> cusp;
110 cusp.push_back(new RRTNode(c->x(), c->y(), c->h()));
113 std::reverse(cusp.begin(), cusp.end());
114 this->cusp().push_back(cusp);
115 std::queue<BicycleCar *, std::list<BicycleCar *>> empty;
119 BicycleCar *ParallelSlot::flnc(BicycleCar *B)
121 // TODO find last not colliding
122 // for now just copy flast()
124 if (int(B->s()) % 2 == 0)
125 cc = BicycleCar(B->x(), B->y(), B->h()).ccr();
127 cc = BicycleCar(B->x(), B->y(), B->h()).ccl();
130 p = B->move(cc, i * this->DH());
131 while (!this->slot().collide(p->frame())
133 (this->DH() > 0 && p->x() <= 0)
134 || (this->DH() < 0 && p->x() >= 0)
136 if (this->DH() > 0 && p->rfx() <= 0 && p->rrx() <= 0) {
140 if (this->DH() < 0 && p->lfx() >= 0 && p->lrx() >= 0) {
146 p = B->move(cc, i * this->DH());
149 return B->move(cc, (i - 1) * this->DH());
152 RRTNode *ParallelSlot::fposecenter()
154 if (this->slot().bnodes().front()->y() >
155 this->slot().bnodes().back()->y())
156 return this->slot().bnodes().front();
158 return this->slot().bnodes().back();
161 bool ParallelSlot::flast(
165 std::vector<RRTNode *> &cusp
168 BicycleCar *B = new BicycleCar(P->x(), P->y(), P->h());
171 cc = BicycleCar(B->x(), B->y(), B->h()).ccr();
173 cc = BicycleCar(B->x(), B->y(), B->h()).ccl();
176 p = B->move(cc, i * this->DH());
177 while (!this->slot().collide(p->frame())
179 (this->DH() > 0 && p->x() <= 0)
180 || (this->DH() < 0 && p->x() >= 0)
182 if (this->DH() > 0 && p->rfx() <= 0 && p->rrx() <= 0) {
186 if (this->DH() < 0 && p->lfx() >= 0 && p->lrx() >= 0) {
192 p = B->move(cc, i * this->DH());
195 p = B->move(cc, (i - 1) * this->DH());
196 if (this->DH() > 0 && p->rfx() <= 0 && p->rrx() <= 0) {
199 } else if (this->DH() < 0 && p->lfx() >= 0 && p->lrx() >= 0) {
204 return this->flast(p, !right, il + 1, cusp);
209 void ParallelSlot::fpose()
211 bool left = false; // right parking slot
213 BicycleCar *CC = new BicycleCar(
214 this->fposecenter()->x(),
215 this->fposecenter()->y() - 0.01,
218 BicycleCar *B = new BicycleCar(
219 CC->x() - CC->width() / 2,
220 CC->y() - (CC->length() + CC->wheelbase()) / 2,
223 if (this->slot().bnodes()[0]->x() > this->slot().bnodes()[1]->x()) {
228 CC->x() + CC->width() / 2,
229 CC->y() - (CC->length() + CC->wheelbase()) / 2,
233 this->DH(di * 0.01 / CC->out_radi());
236 p = B->move(CC, -i * di * 0.01 / CC->diag_radi());
237 while (!this->slot().collide(p->frame())) {
238 std::vector<RRTNode *> tmpcusp;
239 tmpcusp.push_back(new BicycleCar(p->x(), p->y(), p->h()));
240 if (this->flast(p, left, 0, tmpcusp)) {
241 this->cusp().push_back(tmpcusp);
246 p = B->move(CC, -i * di * 0.01 / CC->diag_radi());