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