]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blob - api/bcar.h
Overload << for bicycle car
[hubacji1/bcar.git] / api / bcar.h
1 #ifndef BCAR_H
2 #define BCAR_H
3
4 #include <ostream>
5
6 /*! \brief Bicycle car basic class.
7
8 This class contains some geometrical computations of bicycle car.
9
10 \param x Horizontal coordinate of rear axle center.
11 \param y Vertical coordinate of rear axle center.
12 \param h Heading of the car.
13 \param mtr Minimum turning radius.
14 \param wb Wheelbase.
15 \param w The width of the car.
16 \param l The length of the car.
17 \param he The height of the car.
18 \param sd The safety distance.
19 \param df Distance from rear axle center to the front of the car.
20 \param dr Distance from rear axle center to the back of the car.
21 \param sp Speed of the car.
22 \param st Steering of the car.
23 */
24 class BicycleCar {
25         private:
26                 // coordinates
27                 double x_ = 0;
28                 double y_ = 0;
29                 double h_ = 0;
30                 // kinematic constraints
31                 double mtr_ = 10.820;
32                 double wb_ = 2.450;
33                 // dimensions
34                 double w_ = 1.625;
35                 double l_ = 3.760;
36                 double he_ = 1.450;
37                 double sd_ = 0;
38                 double df_ = 3.105;
39                 double dr_ = 0.655;
40                 // moving
41                 double sp_ = 0;
42                 double st_ = 0;
43         public:
44                 // kinematic constraints
45                 /*! \brief Return `false` if `bc` is not achievable.
46
47                 When `true` is returned the `bc` may still be not
48                 achievable because in the current implementation,
49                 heading is not considered.
50
51                 \param[in] bc The bicycle car to achieve.
52                 */
53                 bool drivable(const BicycleCar &bc) const;
54                 /*! \brief Return inner radius.
55
56                 The inner radius is the distance from minimum turning
57                 radius circle center to the nearest point on the car. In
58                 this case, the nearest points on the car are rear axle
59                 endpoints.
60                 */
61                 double iradi() const;
62                 /*! \brief Return outer front radius.
63
64                 The outer front radius is the distance from minimum
65                 turning radius circle center to the farthest point on
66                 the front (from the rear axle view) part of the car.
67                 */
68                 double ofradi() const;
69                 /*! \brief Return outer rear radius.
70
71                 The outer rear radius is the distance from minimum
72                 turning radius circle center to the farthest point on
73                 the rear (from the rear axle view) part of the car.
74                 */
75                 double orradi() const;
76
77                 // car frame
78                 double lfx() const; double lfy() const;
79                 double lrx() const; double lry() const;
80                 double rrx() const; double rry() const;
81                 double rfx() const; double rfy() const;
82
83                 double ralx() const; double raly() const;
84                 double rarx() const; double rary() const;
85
86                 /*! \brief Min. turning radius circle center on left.
87
88                 Important are coordinates `x` and `y`. The heading `h`
89                 is set as the heading of `this->h()`.
90                 */
91                 BicycleCar ccl() const;
92                 /*! \brief Min. turning radius circle center on rigth.
93
94                 Important are coordinates `x` and `y`. The heading `h`
95                 is set as the heading of `this->h()`.
96                 */
97                 BicycleCar ccr() const;
98
99                 // moving
100                 /*! \brief Next car position based on `sp` and `st`.
101
102                 Where `sp` is speed and `st` is steering of the car.
103                 */
104                 void next();
105
106                 // getters, setters
107                 double x() const { return this->x_; }
108                 void x(double x) { this->x_ = x; }
109
110                 double y() const { return this->y_; }
111                 void y(double y) { this->y_ = y; }
112
113                 double h() const { return this->h_; }
114                 void h(double h) { this->h_ = h; }
115
116                 double mtr() const { return this->mtr_; }
117                 void mtr(double mtr) { this->mtr_ = mtr; }
118
119                 double wb() const { return this->wb_; }
120                 void wb(double wb) { this->wb_ = wb; }
121
122                 double w() const { return this->w_; }
123                 void w(double w) { this->w_ = w; }
124
125                 double l() const { return this->l_; }
126                 void l(double l) { this->l_ = l; }
127
128                 double he() const { return this->he_; }
129                 void he(double he) { this->he_ = he; }
130
131                 double sd() const { return this->sd_; }
132                 void sd(double sd) { this->sd_ = sd; }
133
134                 double df() const { return this->df_; }
135                 void df(double df) { this->df_ = df; }
136
137                 double dr() const { return this->dr_; }
138                 void dr(double dr) { this->dr_ = dr; }
139
140                 double sp() const { return this->sp_; }
141                 void sp(double sp) { this->sp_ = sp; }
142
143                 double st() const { return this->st_; }
144                 void st(double st) { this->st_ = st; }
145
146                 BicycleCar();
147                 friend std::ostream &operator<<(
148                         std::ostream &out,
149                         const BicycleCar &bc
150                 )
151                 {
152                         out << "[" << bc.x();
153                         out << "," << bc.y();
154                         out << "," << bc.h();
155                         out << "]";
156                         return out;
157                 }
158 };
159
160 #endif /* BCAR_H */