]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blob - incl/pslot.hh
Upgrade version in doxygen config
[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>> _ispaths;
36         std::vector<BicycleCar> _entries;
37         /*! \brief Set parking slot.
38
39         \param p Point with `x`, `y` coordinates of entry side's corner.
40         \param h Direction of the entry side.
41         \param W The width of the slot.
42         \param L The length of the slot.
43         */
44         ParkingSlot(Point p, double h, double W, double L);
45         ParkingSlot(double lrx, double lry, double rrx, double rry, double rfx,
46                 double rfy, double lfx, double lfy);
47
48         /*! Get slot's length. */
49         double len() const;
50
51         /*! Get slot's width. */
52         double w() const;
53
54         /*! Get slot's left front x coordinate. */
55         double lfx() const;
56
57         /*! Get slot's left front y coordinate. */
58         double lfy() const;
59
60         /*! Get slot's left rear x coordinate. */
61         double lrx() const;
62
63         /*! Get slot's left rear y coordinate. */
64         double lry() const;
65
66         /*! Get slot's right rear x coordinate. */
67         double rrx() const;
68
69         /*! Get slot's right rear y coordinate. */
70         double rry() const;
71
72         /*! Get slot's right front x coordinate. */
73         double rfx() const;
74
75         /*! Get slot's right front y coordinate. */
76         double rfy() const;
77
78         /*! Return parking slot's orientation. */
79         double h() const;
80
81         /*! Get parking slot's left front point. */
82         Point lf() const;
83
84         /*! Get parking slot's left rear point. */
85         Point lr() const;
86
87         /*! Get parking slot's right rear point. */
88         Point rr() const;
89
90         /*! Get parking slot's right front point. */
91         Point rf() const;
92
93         /*! Get parking slot's entry side. */
94         Line entry() const;
95
96         /*! Get parking slot's rear side. */
97         Line rear() const;
98
99         /*! Get parking slot's curb side. */
100         Line curb() const;
101
102         /*! Get parking slot's front side. */
103         Line front() const;
104
105         /*! Car's next iteration distance. (Negative for backward.) */
106         void set_parking_speed(double s);
107
108         /*! Maximum allowed number of cusp inside the parking slot. */
109         unsigned int get_max_cusp() const;
110         void set_max_cusp(unsigned int m);
111
112         /*! Angle's increment when creating start positions. */
113         void set_delta_angle_to_slot(double d);
114
115         /*! Return `true` for the parallel parking slot. */
116         bool parallel() const;
117
118         /*! Return `true` for the parking slot on the right side. */
119         bool right() const;
120
121         /*! Change side of the parking slot. */
122         void swap_side();
123
124         /*! Return `true` if car `c` is parking in slot `this`. */
125         bool parked(BicycleCar const& c) const;
126
127         /*! Return `true` if `c`'s car frame collide with `this` border. */
128         bool collide(BicycleCar const& c) const;
129
130         /*! \brief Set car `c` to the start position.
131          *
132          * \param c Bicycle car.
133          */
134         void set_to_start(BicycleCar& c);
135
136         /*! \brief Drive car `c` into the parking slot `this`.
137          *
138          * \param c Starting bicycle car.
139          */
140         std::vector<BicycleCar> drive_in_slot(BicycleCar c);
141
142         /*! \brief Drive car `c` from slot.
143          *
144          * \param c Starting bicycle car.
145          */
146         std::vector<BicycleCar> drive_of_slot(BicycleCar c);
147
148         /*! \brief Steer car `c` into the parking slot `this`.
149          *
150          * `steer_in_slot` returns the complete path as the list of `Pose`s, not
151          * just cusp `BicycleCar`s as `drive_to_slot`.
152          *
153          * \param c Starting bicycle car.
154          */
155         std::vector<Pose> steer_in_slot(BicycleCar c);
156
157         /*! \brief Find entry.
158          *
159          * \param c For which `BicycleCar` should entry be found?
160          */
161         PoseRange fe(BicycleCar c);
162
163         /*! \brief Compute entries from `this->_ispaths`.
164          *
165          * The problem with in-slot paths is that car can't leave the parking
166          * slot with full rate to the right (for right sided parking slot.)
167          *
168          * The idea is to move the first cars of in-slot paths (the one that is
169          * computed as entry to the parking slot) with the full rate to the left
170          * until they can leave the parking slot with full rate to the right.
171          *
172          * The computed cars are stored in `this->_entries`.
173          */
174         void compute_entries();
175
176         /*! \brief Recompute zero slot's `PoseRange` entry for `this`.
177          *
178          * The _zero slot_ is the `ParkingSlot(Point(0.0, 0.0), 0.0, W, L);`.
179          *
180          * \param p Computed `PoseRange` entry.
181          */
182         PoseRange recompute_entry(PoseRange p);
183
184         /*! Generate output for plotting with gnuplot. */
185         void gen_gnuplot_to(std::ostream& out);
186
187         friend std::ostream& operator<<(std::ostream& o, ParkingSlot const& s);
188 };
189
190 } // namespace bcar
191 #endif /* BCAR_PSLOT_H */