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/>.
21 float BicycleCar::speed()
26 float BicycleCar::steer()
31 bool BicycleCar::speed(float s)
37 bool BicycleCar::steer(float s)
43 std::vector<RRTEdge *> BicycleCar::frame()
45 std::vector<RRTEdge *> frame;
46 float dr = (this->length_ - this->wheel_base_) / 2;
47 float df = this->length_ - dr;
49 float lfx = this->x();
50 lfx += (this->width_ / 2) * cos(this->h() + M_PI / 2);
51 lfx += df * cos(this->h());
52 lfx += this->safety_dist_ * cos(this->h());
54 float lrx = this->x();
55 lrx += (this->width_ / 2) * cos(this->h() + M_PI / 2);
56 lrx += -dr * cos(this->h());
57 lrx += -this->safety_dist_ * cos(this->h());
59 float rrx = this->x();
60 rrx += (this->width_ / 2) * cos(this->h() - M_PI / 2);
61 rrx += -dr * cos(this->h());
62 rrx += -this->safety_dist_ * cos(this->h());
64 float rfx = this->x();
65 rfx += (this->width_ / 2) * cos(this->h() - M_PI / 2);
66 rfx += df * cos(this->h());
67 rfx += this->safety_dist_ * cos(this->h());
69 float lfy = this->y();
70 lfy += (this->width_ / 2) * sin(this->h() + M_PI / 2);
71 lfy += df * sin(this->h());
72 lfy += this->safety_dist_ * sin(this->h());
74 float lry = this->y();
75 lry += (this->width_ / 2) * sin(this->h() + M_PI / 2);
76 lry += -dr * sin(this->h());
77 lry += -this->safety_dist_ * sin(this->h());
79 float rry = this->y();
80 rry += (this->width_ / 2) * sin(this->h() - M_PI / 2);
81 rry += -dr * sin(this->h());
82 rry += -this->safety_dist_ * sin(this->h());
84 float rfy = this->y();
85 rfy += (this->width_ / 2) * sin(this->h() - M_PI / 2);
86 rfy += df * sin(this->h());
87 rfy += this->safety_dist_ * sin(this->h());
89 frame.push_back(new RRTEdge(
90 new RRTNode(lfx, lfy),
91 new RRTNode(lrx, lry)));
92 frame.push_back(new RRTEdge(
93 new RRTNode(lrx, lry),
94 new RRTNode(rrx, rry)));
95 frame.push_back(new RRTEdge(
96 new RRTNode(rrx, rry),
97 new RRTNode(rfx, rfy)));
98 frame.push_back(new RRTEdge(
99 new RRTNode(rfx, rfy),
100 new RRTNode(lfx, rfy)));
104 bool BicycleCar::next()
106 if (this->steer_ > MAXSTEER(this->wheel_base_, this->turning_radius_))
107 this->steer_ = MAXSTEER(
109 this->turning_radius_);
110 if (this->steer_ < -MAXSTEER(this->wheel_base_, this->turning_radius_))
111 this->steer_ = -MAXSTEER(
113 this->turning_radius_);
114 this->h_ += (this->speed_ / this->wheel_base_) * tan(this->steer_);
115 this->x_ += this->speed_ * cos(this->h_);
116 this->y_ += this->speed_ * sin(this->h_);
120 bool BicycleCar::next(float speed, float steer)
122 this->speed_ = speed;
123 this->steer_ = steer;