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/>.
23 #include "slotplanner.h"
25 ParallelSlot::ParallelSlot()
29 std::vector<std::vector<RRTNode *>> &ParallelSlot::cusp()
34 float ParallelSlot::DH() const
39 PolygonObstacle &ParallelSlot::slot()
45 void ParallelSlot::DH(float dh)
51 void ParallelSlot::fip()
53 // see https://courses.cs.washington.edu/courses/cse326/03su/homework/hw3/bfs.html
54 // RRTNode.s() works as iteration level
55 std::queue<BicycleCar *, std::list<BicycleCar *>> q;
57 // TODO add init nodes
58 // for now just copy fpose()
59 bool left = false; // right parking slot
61 BicycleCar *CC = new BicycleCar(
62 this->fposecenter()->x(),
63 this->fposecenter()->y() - 0.01,
66 BicycleCar *B = new BicycleCar(
67 CC->x() - CC->width() / 2,
68 CC->y() - (CC->length() + CC->wheelbase()) / 2,
71 if (this->slot().bnodes()[0]->x() > this->slot().bnodes()[1]->x()) {
76 CC->x() + CC->width() / 2,
77 CC->y() - (CC->length() + CC->wheelbase()) / 2,
81 this->DH(di * 0.01 / CC->out_radi());
84 c = B->move(CC, -i * di * 0.01 / CC->diag_radi());
85 while (!this->slot().collide(c->frame())) {
87 c = B->move(CC, -i * di * 0.01 / CC->diag_radi());
90 delete c; // not in q and collide
95 if (this->DH() > 0 && c->rfx() <= 0 && c->rrx() <= 0) {
96 goto createcuspandfinish;
97 } else if (this->DH() < 0 && c->lfx() >= 0 && c->lrx() >= 0) {
98 goto createcuspandfinish;
99 } else if (c->s() < 9) {
100 BicycleCar *cc = this->flnc(c);
105 delete c; // not in q and collide
109 std::vector<RRTNode *> cusp;
111 cusp.push_back(new RRTNode(c->x(), c->y(), c->h()));
114 std::reverse(cusp.begin(), cusp.end());
115 this->cusp().push_back(cusp);
116 std::queue<BicycleCar *, std::list<BicycleCar *>> empty;
120 RRTNode *ParallelSlot::fposecenter()
122 if (this->slot().bnodes().front()->y() >
123 this->slot().bnodes().back()->y())
124 return this->slot().bnodes().front();
126 return this->slot().bnodes().back();
129 bool ParallelSlot::flast(
133 std::vector<RRTNode *> &cusp
136 BicycleCar *B = new BicycleCar(P->x(), P->y(), P->h());
139 cc = BicycleCar(B->x(), B->y(), B->h()).ccr();
141 cc = BicycleCar(B->x(), B->y(), B->h()).ccl();
144 p = B->move(cc, i * this->DH());
145 while (!this->slot().collide(p->frame())
147 (this->DH() > 0 && p->x() <= 0)
148 || (this->DH() < 0 && p->x() >= 0)
150 if (this->DH() > 0 && p->rfx() <= 0 && p->rrx() <= 0) {
154 if (this->DH() < 0 && p->lfx() >= 0 && p->lrx() >= 0) {
160 p = B->move(cc, i * this->DH());
163 p = B->move(cc, (i - 1) * this->DH());
164 if (this->DH() > 0 && p->rfx() <= 0 && p->rrx() <= 0) {
167 } else if (this->DH() < 0 && p->lfx() >= 0 && p->lrx() >= 0) {
172 return this->flast(p, !right, il + 1, cusp);
177 void ParallelSlot::fpose()
179 bool left = false; // right parking slot
181 BicycleCar *CC = new BicycleCar(
182 this->fposecenter()->x(),
183 this->fposecenter()->y() - 0.01,
186 BicycleCar *B = new BicycleCar(
187 CC->x() - CC->width() / 2,
188 CC->y() - (CC->length() + CC->wheelbase()) / 2,
191 if (this->slot().bnodes()[0]->x() > this->slot().bnodes()[1]->x()) {
196 CC->x() + CC->width() / 2,
197 CC->y() - (CC->length() + CC->wheelbase()) / 2,
201 this->DH(di * 0.01 / CC->out_radi());
204 p = B->move(CC, -i * di * 0.01 / CC->diag_radi());
205 while (!this->slot().collide(p->frame())) {
206 std::vector<RRTNode *> tmpcusp;
207 tmpcusp.push_back(new BicycleCar(p->x(), p->y(), p->h()));
208 if (this->flast(p, left, 0, tmpcusp)) {
209 this->cusp().push_back(tmpcusp);
214 p = B->move(CC, -i * di * 0.01 / CC->diag_radi());