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()
43 SlotType ParallelSlot::slotType()
45 if (this->slotType_ == NONE) {
47 this->slot().bnodes()[0],
48 this->slot().bnodes()[1]
51 this->slot().bnodes()[1],
52 this->slot().bnodes()[2]
55 this->slotType_ = PERPENDICULAR;
57 this->slotType_ = PARALLEL;
59 return this->slotType_;
63 void ParallelSlot::DH(float dh)
69 void ParallelSlot::fip()
71 // see https://courses.cs.washington.edu/courses/cse326/03su/homework/hw3/bfs.html
72 // RRTNode.s() works as iteration level
73 std::queue<BicycleCar *, std::list<BicycleCar *>> q;
75 // TODO add init nodes
76 // for now just copy fpose()
77 bool left = false; // right parking slot
79 BicycleCar *CC = new BicycleCar(
80 this->fposecenter()->x(),
81 this->fposecenter()->y() - 0.01,
84 BicycleCar *B = new BicycleCar(
85 CC->x() - CC->width() / 2,
86 CC->y() - (CC->length() + CC->wheelbase()) / 2,
89 if (this->slot().bnodes()[0]->x() > this->slot().bnodes()[1]->x()) {
94 CC->x() + CC->width() / 2,
95 CC->y() - (CC->length() + CC->wheelbase()) / 2,
99 this->DH(di * 0.01 / CC->out_radi());
102 c = B->move(CC, -i * di * 0.01 / CC->diag_radi());
103 while (!this->slot().collide(c->frame())) {
105 c = B->move(CC, -i * di * 0.01 / CC->diag_radi());
108 delete c; // not in q and collide
113 if (this->DH() > 0 && c->rfx() <= 0 && c->rrx() <= 0) {
114 goto createcuspandfinish;
115 } else if (this->DH() < 0 && c->lfx() >= 0 && c->lrx() >= 0) {
116 goto createcuspandfinish;
117 } else if (c->s() < 9) {
118 BicycleCar *cc = this->flnc(c);
123 delete c; // not in q and collide
127 std::vector<RRTNode *> cusp;
129 cusp.push_back(new RRTNode(c->x(), c->y(), c->h()));
132 std::reverse(cusp.begin(), cusp.end());
133 this->cusp().push_back(cusp);
134 std::queue<BicycleCar *, std::list<BicycleCar *>> empty;
138 BicycleCar *ParallelSlot::flnc(BicycleCar *B)
140 // TODO find last not colliding
141 // for now just copy flast()
143 if (int(B->s()) % 2 == 0)
144 cc = BicycleCar(B->x(), B->y(), B->h()).ccr();
146 cc = BicycleCar(B->x(), B->y(), B->h()).ccl();
149 p = B->move(cc, i * this->DH());
150 while (!this->slot().collide(p->frame())
152 (this->DH() > 0 && p->x() <= 0)
153 || (this->DH() < 0 && p->x() >= 0)
155 if (this->DH() > 0 && p->rfx() <= 0 && p->rrx() <= 0) {
159 if (this->DH() < 0 && p->lfx() >= 0 && p->lrx() >= 0) {
165 p = B->move(cc, i * this->DH());
168 return B->move(cc, (i - 1) * this->DH());
171 RRTNode *ParallelSlot::fposecenter()
173 return this->slot().bnodes().front();
176 bool ParallelSlot::flast(
180 std::vector<RRTNode *> &cusp
183 BicycleCar *B = new BicycleCar(P->x(), P->y(), P->h());
186 cc = BicycleCar(B->x(), B->y(), B->h()).ccr();
188 cc = BicycleCar(B->x(), B->y(), B->h()).ccl();
191 p = B->move(cc, i * this->DH());
192 while (!this->slot().collide(p->frame())
194 (this->DH() > 0 && p->x() <= 0)
195 || (this->DH() < 0 && p->x() >= 0)
197 if (this->DH() > 0 && p->rfx() <= 0 && p->rrx() <= 0) {
201 if (this->DH() < 0 && p->lfx() >= 0 && p->lrx() >= 0) {
207 p = B->move(cc, i * this->DH());
210 p = B->move(cc, (i - 1) * this->DH());
211 if (this->DH() > 0 && p->rfx() <= 0 && p->rrx() <= 0) {
214 } else if (this->DH() < 0 && p->lfx() >= 0 && p->lrx() >= 0) {
219 return this->flast(p, !right, il + 1, cusp);
224 void ParallelSlot::fpose()
226 bool left = false; // right parking slot
228 BicycleCar *CC = new BicycleCar(
229 this->fposecenter()->x(),
230 this->fposecenter()->y() - 0.01,
233 BicycleCar *B = new BicycleCar(
234 CC->x() - CC->width() / 2,
235 CC->y() - (CC->length() + CC->wheelbase()) / 2,
238 if (this->slot().bnodes()[0]->x() > this->slot().bnodes()[1]->x()) {
243 CC->x() + CC->width() / 2,
244 CC->y() - (CC->length() + CC->wheelbase()) / 2,
248 this->DH(di * 0.01 / CC->out_radi());
251 p = B->move(CC, -i * di * 0.01 / CC->diag_radi());
252 while (!this->slot().collide(p->frame())) {
253 std::vector<RRTNode *> tmpcusp;
254 tmpcusp.push_back(new BicycleCar(p->x(), p->y(), p->h()));
255 if (this->flast(p, left, 0, tmpcusp)) {
256 this->cusp().push_back(tmpcusp);
261 p = B->move(CC, -i * di * 0.01 / CC->diag_radi());
265 struct SamplingInfo ParallelSlot::getSamplingInfo()
267 struct SamplingInfo si;
268 si.x = this->slot().bnodes()[0]->x();
269 si.y = this->slot().bnodes()[0]->y();
271 si.h = 3 * M_PI / 2 - acos(EDIST( // TODO generalize
272 this->slot().bnodes()[0],
273 this->slot().bnodes()[1]