]> rtime.felk.cvut.cz Git - hubacji1/iamcar.git/blob - incl/bcar.h
Add bicycle car related macros
[hubacji1/iamcar.git] / incl / bcar.h
1 /*
2 This file is part of I am car.
3
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.
8
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.
13
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/>.
16 */
17
18 #ifndef BICYCLECAR_H
19 #define BICYCLECAR_H
20
21 #include <vector>
22 #include "rrtnode.h"
23
24 #define BCAR_HEIGHT 1.450
25 #define BCAR_LENGTH 3.760
26 #define BCAR_SAFETY_DIST 0
27 #define BCAR_TURNING_RADIUS 10.820
28 #define BCAR_WHEEL_BASE 2.450
29 #define BCAR_WIDTH 1.625
30 #define BCAR_DIST_REAR ((BCAR_LENGTH - BCAR_WHEEL_BASE) / 2)
31 #define BCAR_DIST_FRONT (BCAR_LENGTH - BCAR_DIST_REAR)
32 #define BCAR_DIAG_RADI pow(pow(BCAR_DIST_FRONT, 2) + pow(BCAR_WIDTH/2, 2), 0.5)
33 #define BCAR_DIAG_RRADI pow(pow(BCAR_DIST_REAR, 2) + pow(BCAR_WIDTH/2, 2), 0.5)
34 #define BCAR_OUT_RADI pow( \
35         pow(BCAR_TURNING_RADIUS + BCAR_WIDTH/2, 2) + \
36         pow(BCAR_DIST_FRONT, 2), 0.5)
37
38 #define MAXSTEER(wb, tr) ((wb) / (tr))
39
40 class BicycleCar: public RRTNode {
41         private:
42                 // see https://en.wikipedia.org/wiki/Fiat_Punto
43                 const float height_ = BCAR_HEIGHT;
44                 const float length_ = BCAR_LENGTH;
45                 const float safety_dist_ = BCAR_SAFETY_DIST;
46                 const float turning_radius_ = BCAR_TURNING_RADIUS;
47                 const float wheel_base_ = BCAR_WHEEL_BASE;
48                 const float width_ = BCAR_WIDTH;
49
50                 float speed_ = 0;
51                 float steer_ = 0;
52
53                 BicycleCar *bcparent_;
54         public:
55                 using RRTNode::RRTNode;
56
57                 // getter
58                 float length();
59                 float wheelbase();
60                 float width();
61
62                 float dr();
63                 float df();
64
65                 float lfx();
66                 float lrx();
67                 float rrx();
68                 float rfx();
69                 float lfy();
70                 float lry();
71                 float rry();
72                 float rfy();
73
74                 float lwbx();
75                 float lwby();
76                 float rwbx();
77                 float rwby();
78
79                 /** Return circle center on the left side of the car */
80                 RRTNode *ccl();
81                 /** Return circle center on the right side of the car */
82                 RRTNode *ccr();
83
84                 float speed();
85                 float steer();
86
87                 BicycleCar *bcparent() const;
88
89                 // setter
90                 bool speed(float s);
91                 bool steer(float s);
92
93                 void bcparent(BicycleCar *bcp);
94
95                 // other
96                 std::vector<RRTEdge *> frame();
97                 bool next();
98                 bool next(float speed, float steer);
99
100                 /** Return distance from wheelbase center to top corner */
101                 float diag_radi();
102                 /** Return distance from wheelbase center to rear corner */
103                 float diag_rradi();
104                 /** Outer radius of the farthest point */
105                 float out_radi();
106                 /** Angle between wheelbase line and outer radius */
107                 float alfa();
108                 /** Return true if `n` not inside of `ccl`, `ccr` */
109                 bool drivable(RRTNode *n);
110                 /** Return node rotated by `dh` around `c` */
111                 BicycleCar *move(RRTNode *c, float dh);
112 };
113
114 #endif