]> rtime.felk.cvut.cz Git - hubacji1/iamcar.git/blob - incl/bcar.h
Merge branch 'release/0.7.0'
[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 #define BCAR_OUT_RRADI pow( \
38         pow(BCAR_TURNING_RADIUS + BCAR_WIDTH/2, 2) + \
39         pow(BCAR_DIST_REAR, 2), 0.5)
40 #define BCAR_IN_RADI (BCAR_TURNING_RADIUS - BCAR_WIDTH/2)
41
42 #define MAXSTEER(wb, tr) ((wb) / (tr))
43
44 class BicycleCar: public RRTNode {
45         private:
46                 // see https://en.wikipedia.org/wiki/Fiat_Punto
47                 const float height_ = BCAR_HEIGHT;
48                 const float length_ = BCAR_LENGTH;
49                 const float safety_dist_ = BCAR_SAFETY_DIST;
50                 const float turning_radius_ = BCAR_TURNING_RADIUS;
51                 const float wheel_base_ = BCAR_WHEEL_BASE;
52                 const float width_ = BCAR_WIDTH;
53
54                 float speed_ = 0;
55                 float steer_ = 0;
56
57                 BicycleCar *bcparent_;
58         public:
59                 using RRTNode::RRTNode;
60
61                 // getter
62                 float length();
63                 float wheelbase();
64                 float width();
65
66                 float dr();
67                 float df();
68
69                 float lfx();
70                 float lrx();
71                 float rrx();
72                 float rfx();
73                 float lfy();
74                 float lry();
75                 float rry();
76                 float rfy();
77
78                 float lwbx();
79                 float lwby();
80                 float rwbx();
81                 float rwby();
82
83                 /** Return circle center on the left side of the car */
84                 RRTNode *ccl();
85                 /** Return circle center on the right side of the car */
86                 RRTNode *ccr();
87
88                 float speed();
89                 float steer();
90
91                 BicycleCar *bcparent() const;
92
93                 // setter
94                 bool speed(float s);
95                 bool steer(float s);
96
97                 void bcparent(BicycleCar *bcp);
98
99                 // other
100                 std::vector<RRTEdge *> frame();
101                 bool next();
102                 bool next(float speed, float steer);
103
104                 /** Return distance from wheelbase center to top corner */
105                 float diag_radi();
106                 /** Return distance from wheelbase center to rear corner */
107                 float diag_rradi();
108                 /** Outer radius of the farthest point */
109                 float out_radi();
110                 /** Angle between wheelbase line and outer radius */
111                 float alfa();
112                 /** Return true if `n` not inside of `ccl`, `ccr` */
113                 bool drivable(RRTNode *n);
114                 /** Return ``RRTNode`` where ``BicycleCar`` may steer to.
115
116                 When the node ``n`` is not drivable, use guess.
117
118                 @param n The node to drive to.
119
120                 */
121                 RRTNode *drivableNode(RRTNode *n);
122                 /** Return node rotated by `dh` around `c` */
123                 BicycleCar *move(RRTNode *c, float dh);
124 };
125
126 #endif