]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blob - incl/pslot.hh
fbadd41495cffa3d8ae023c799817a915a1168f3
[hubacji1/bcar.git] / incl / pslot.hh
1 /*
2  * SPDX-FileCopyrightText: 2021 Jiri Vlasak <jiri.vlasak.2@cvut.cz>
3  *
4  * SPDX-License-Identifier: GPL-3.0-only
5  */
6
7 /*! \file */
8 #ifndef BCAR_PSLOT_H
9 #define BCAR_PSLOT_H
10
11 #include <ostream>
12 #include <vector>
13 #include "bcar.hh"
14
15 namespace bcar {
16
17 /*! \brief Parking slot basic class.
18  *
19  * This class contains some geometrical computations of parking slot. Parking
20  * slot consists of 4 cartesian coordinates `border` representing the border of
21  * the parking slot.
22  */
23 class ParkingSlot {
24 private:
25         double _offset = 0.001; // to avoid collision during init
26         double _parking_speed = -0.1;
27         unsigned int _max_cusp = 10;
28         double _delta_angle_to_slot = 0.001;
29         Point _border[4];
30         Line _entry;
31         Line _rear;
32         Line _curb;
33         Line _front;
34 public:
35         std::vector<std::vector<BicycleCar>> _entries;
36         /*! \brief Set parking slot.
37
38         \param p Point with `x`, `y` coordinates of entry side's corner.
39         \param h Direction of the entry side.
40         \param W The width of the slot.
41         \param L The length of the slot.
42         */
43         ParkingSlot(Point p, double h, double W, double L);
44         ParkingSlot(double lrx, double lry, double rrx, double rry, double rfx,
45                 double rfy, double lfx, double lfy);
46
47         /*! Get slot's length. */
48         double len() const;
49
50         /*! Get slot's width. */
51         double w() const;
52
53         /*! Get slot's left front x coordinate. */
54         double lfx() const;
55
56         /*! Get slot's left front y coordinate. */
57         double lfy() const;
58
59         /*! Get slot's left rear x coordinate. */
60         double lrx() const;
61
62         /*! Get slot's left rear y coordinate. */
63         double lry() const;
64
65         /*! Get slot's right rear x coordinate. */
66         double rrx() const;
67
68         /*! Get slot's right rear y coordinate. */
69         double rry() const;
70
71         /*! Get slot's right front x coordinate. */
72         double rfx() const;
73
74         /*! Get slot's right front y coordinate. */
75         double rfy() const;
76
77         /*! Return parking slot's orientation. */
78         double h() const;
79
80         /*! Get parking slot's left front point. */
81         Point lf() const;
82
83         /*! Get parking slot's left rear point. */
84         Point lr() const;
85
86         /*! Get parking slot's right rear point. */
87         Point rr() const;
88
89         /*! Get parking slot's right front point. */
90         Point rf() const;
91
92         /*! Get parking slot's entry side. */
93         Line entry() const;
94
95         /*! Get parking slot's rear side. */
96         Line rear() const;
97
98         /*! Get parking slot's curb side. */
99         Line curb() const;
100
101         /*! Get parking slot's front side. */
102         Line front() const;
103
104         /*! Car's next iteration distance. (Negative for backward.) */
105         void set_parking_speed(double s);
106
107         /*! Maximum allowed number of cusp inside the parking slot. */
108         unsigned int get_max_cusp() const;
109         void set_max_cusp(unsigned int m);
110
111         /*! Angle's increment when creating start positions. */
112         void set_delta_angle_to_slot(double d);
113
114         /*! Return `true` for the parallel parking slot. */
115         bool parallel() const;
116
117         /*! Return `true` for the parking slot on the right side. */
118         bool right() const;
119
120         /*! Change side of the parking slot. */
121         void swap_side();
122
123         /*! Return `true` if car `c` is parking in slot `this`. */
124         bool parked(BicycleCar const& c) const;
125
126         /*! Return `true` if `c`'s car frame collide with `this` border. */
127         bool collide(BicycleCar const& c) const;
128
129         /*! \brief Drive car `c` into the parking slot `this`.
130          *
131          * \param c Starting bicycle car.
132          */
133         std::vector<BicycleCar> drive_in_slot(BicycleCar c);
134
135         /*! \brief Drive car `c` from slot.
136          *
137          * \param c Starting bicycle car.
138          */
139         std::vector<BicycleCar> drive_of_slot(BicycleCar c);
140
141         /*! \brief Steer car `c` into the parking slot `this`.
142          *
143          * `steer_in_slot` returns the complete path as the list of `Pose`s, not
144          * just cusp `BicycleCar`s as `drive_to_slot`.
145          *
146          * \param c Starting bicycle car.
147          */
148         std::vector<Pose> steer_in_slot(BicycleCar c);
149
150         /*! \brief Find entry.
151          *
152          * \param c For which `BicycleCar` should entry be found?
153          */
154         PoseRange fe(BicycleCar c);
155
156         /*! \brief Recompute zero slot's `PoseRange` entry for `this`.
157          *
158          * The _zero slot_ is the `ParkingSlot(Point(0.0, 0.0), 0.0, W, L);`.
159          *
160          * \param p Computed `PoseRange` entry.
161          */
162         PoseRange recompute_entry(PoseRange p);
163
164         /*! Generate output for plotting with gnuplot. */
165         void gen_gnuplot_to(std::ostream& out);
166
167         friend std::ostream& operator<<(std::ostream& o, ParkingSlot const& s);
168 };
169
170 } // namespace bcar
171 #endif /* BCAR_PSLOT_H */