]> rtime.felk.cvut.cz Git - hubacji1/psp.git/blob - api/psp.h
Make backward default, add goal to last maneuver
[hubacji1/psp.git] / api / psp.h
1 #ifndef PSP_H
2 #define PSP_H
3
4 #include <tuple>
5 #include <vector>
6
7 #include "bcar.h"
8 #include "pslot.h"
9
10 #define FORWARD_PARKING 0
11
12 /*! \brief Parking Slot Planner basic class.
13
14 \param cc Current bicycle car.
15 \param ps Parking slot.
16 \param gc Goal car.
17 */
18 class PSPlanner {
19         private:
20                 BicycleCar cc_;
21                 BicycleCar gc_;
22                 ParkingSlot ps_;
23
24                 unsigned int c_ = 0; // number of cusps
25                 std::vector<BicycleCar> cusps_;
26
27                 // find entry to slot
28                 void fe_parallel();
29                 void fe_perpendicular();
30                 // find entry to slot by reverse approach
31                 void fer_parallel();
32                 void fer_perpendicular();
33                 // set goal car
34                 void gc_to_4();
35         public:
36                 /*! \brief Return `true` if there is collision.
37
38                 If the parking slot `ps` collide with current car `cc`,
39                 return `true`.
40
41                 This method depends on `intersection` function that
42                 returns `true` or `false` if two line segments collide.
43                 Each line segment of current car `cc` (borders) is
44                 checked to each line segment of parking slot `ps`
45                 (parking slot lines).
46                 */
47                 bool collide();
48                 /*! \brief Return parking direction
49
50                 Return `true` if the direction of the parking in the
51                 slot is forward.
52                 */
53                 bool forward();
54                 /*! \brief Guess goal car
55
56                 Set the goal car guessed from the parking slot.
57                 */
58                 void guess_gc();
59                 /*! \brief Return last maneuver to the parking slot.
60
61                 Return path from entry point towards parking slot, such
62                 that ``cc`` is inside the parking slot at the end.
63                 */
64                 std::vector<BicycleCar> last_maneuver();
65                 /*! \brief Has current car `cc` left?
66
67                 Return `true` if the current car `cc` left the parking
68                 slot `ps`;
69                 */
70                 bool left();
71                 /*! \brief Is the goal car `gc` parked?
72
73                 Return `true` if the goal car `gc` is inside the
74                 parking slot `ps`.
75                 */
76                 bool parked();
77                 /*! \brief Return possible starts of parking maneuver
78
79                 When any `BicycleCar` of possible inits is reached, then
80                 parking maneuver is a peace of cake.
81
82                 \param cnt Number of inits.
83                 \param dist Distance between inits.
84                 */
85                 std::vector<BicycleCar> possible_goals(
86                         unsigned int cnt,
87                         double dist
88                 );
89                 std::vector<BicycleCar> possible_goals()
90                 {
91                         return this->possible_goals(10, 0.5);
92                 }
93                 /*! \brief Shrink parking slot to perfect length.
94
95                 Based on goal car dimensions, shrink `p1` and `p2`
96                 towards the `p3` and `p4`. (Because backward parallel
97                 parking).
98
99                 NOTE: This function works for parallel parking only.
100                 */
101                 void shrink_to_perfect_len();
102
103                 // find entry
104                 /*! \brief Find entry to the parking slot.
105                 */
106                 void fe();
107                 /*! \brief Find entry to slot by reverse approach.
108
109                 See `Vorobieva2015` for more information.
110                 */
111                 void fer();
112
113                 // getters, setters
114                 BicycleCar &cc() { return this->cc_; }
115                 BicycleCar &gc() { return this->gc_; }
116                 ParkingSlot &ps() { return this->ps_; }
117
118                 unsigned int c() const { return this->c_; }
119                 std::vector<BicycleCar> &cusps() { return this->cusps_; }
120
121                 PSPlanner();
122 };
123
124 #endif /* PSP_H */