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