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) {
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
111 RRTNode *ParallelSlot::fposecenter()
113 if (this->slot().bnodes().front()->y() >
114 this->slot().bnodes().back()->y())
115 return this->slot().bnodes().front();
117 return this->slot().bnodes().back();
120 bool ParallelSlot::flast(
124 std::vector<RRTNode *> &cusp
127 BicycleCar *B = new BicycleCar(P->x(), P->y(), P->h());
130 cc = BicycleCar(B->x(), B->y(), B->h()).ccr();
132 cc = BicycleCar(B->x(), B->y(), B->h()).ccl();
135 p = B->move(cc, i * this->DH());
136 while (!this->slot().collide(p->frame())
138 (this->DH() > 0 && p->x() <= 0)
139 || (this->DH() < 0 && p->x() >= 0)
141 if (this->DH() > 0 && p->rfx() <= 0 && p->rrx() <= 0) {
145 if (this->DH() < 0 && p->lfx() >= 0 && p->lrx() >= 0) {
151 p = B->move(cc, i * this->DH());
154 p = B->move(cc, (i - 1) * this->DH());
155 if (this->DH() > 0 && p->rfx() <= 0 && p->rrx() <= 0) {
158 } else if (this->DH() < 0 && p->lfx() >= 0 && p->lrx() >= 0) {
163 return this->flast(p, !right, il + 1, cusp);
168 void ParallelSlot::fpose()
170 bool left = false; // right parking slot
172 BicycleCar *CC = new BicycleCar(
173 this->fposecenter()->x(),
174 this->fposecenter()->y() - 0.01,
177 BicycleCar *B = new BicycleCar(
178 CC->x() - CC->width() / 2,
179 CC->y() - (CC->length() + CC->wheelbase()) / 2,
182 if (this->slot().bnodes()[0]->x() > this->slot().bnodes()[1]->x()) {
187 CC->x() + CC->width() / 2,
188 CC->y() - (CC->length() + CC->wheelbase()) / 2,
192 this->DH(di * 0.01 / CC->out_radi());
195 p = B->move(CC, -i * di * 0.01 / CC->diag_radi());
196 while (!this->slot().collide(p->frame())) {
197 std::vector<RRTNode *> tmpcusp;
198 tmpcusp.push_back(new BicycleCar(p->x(), p->y(), p->h()));
199 if (this->flast(p, left, 0, tmpcusp)) {
200 this->cusp().push_back(tmpcusp);
205 p = B->move(CC, -i * di * 0.01 / CC->diag_radi());