amiro-os / devices / DiWheelDrive / amiro_map.hpp @ bdac5bec
History | View | Annotate | Download (2.48 KB)
1 | e1f1c4b5 | galberding | #ifndef AMIRO_MAP
|
---|---|---|---|
2 | #define AMIRO_MAP
|
||
3 | |||
4 | #include "global.hpp" |
||
5 | b8b3a9c9 | galberding | #include "linefollow.hpp" |
6 | e1f1c4b5 | galberding | #include <amiroosconf.h> |
7 | b8b3a9c9 | galberding | #include <ch.hpp> |
8 | e1f1c4b5 | galberding | |
9 | bdac5bec | galberding | |
10 | b8b3a9c9 | galberding | namespace amiro {
|
11 | e1f1c4b5 | galberding | |
12 | 7520e117 | galberding | struct node {
|
13 | uint8_t id; |
||
14 | uint8_t flag; |
||
15 | uint8_t left; |
||
16 | uint8_t right; |
||
17 | uint8_t visited; |
||
18 | types::position pL; // Left
|
||
19 | types::position pR; // Right
|
||
20 | types::position pB; // Back
|
||
21 | }; |
||
22 | |||
23 | struct map_state {
|
||
24 | // 0 - left, 1- right
|
||
25 | uint8_t strategy; |
||
26 | // Node ID of last detected fixpoint
|
||
27 | uint8_t current; |
||
28 | // Next node ID
|
||
29 | uint8_t next; |
||
30 | //Traveled Distance between current and next in %
|
||
31 | bdac5bec | galberding | uint32_t dist; |
32 | 7520e117 | galberding | // True if the current loaded map is valid
|
33 | bool valid;
|
||
34 | bdac5bec | galberding | // Length of the currently traveled edge
|
35 | uint32_t eLength; |
||
36 | 7520e117 | galberding | }; |
37 | e1f1c4b5 | galberding | |
38 | b8b3a9c9 | galberding | class AmiroMap { |
39 | public:
|
||
40 | 7520e117 | galberding | map_state * get_state() { return &state; }
|
41 | b8b3a9c9 | galberding | |
42 | AmiroMap(Global *global) : global{global} {} |
||
43 | |||
44 | /**
|
||
45 | * Initialize a new map from configuration.
|
||
46 | * @param config map configuration array
|
||
47 | *
|
||
48 | */
|
||
49 | 7520e117 | galberding | uint8_t initialize(); |
50 | b8b3a9c9 | galberding | |
51 | |||
52 | /**
|
||
53 | 7520e117 | galberding | * Update the internal map state according to the detected fixpoint
|
54 | * This function should be called for a generic update, each can cycle and in
|
||
55 | * case a fixpoint on one side is detected.
|
||
56 | * Internal state maschine will go into an error state in case both sensors are black.
|
||
57 | *
|
||
58 | * @param left fixpoint on left side detected
|
||
59 | * @param right fixpoint on right side detected
|
||
60 | * @param strategy current line follow strategy
|
||
61 | *
|
||
62 | *
|
||
63 | b8b3a9c9 | galberding | */
|
64 | bdac5bec | galberding | uint8_t update(uint16_t WL, uint16_t WR, LineFollowStrategy strategy); |
65 | b8b3a9c9 | galberding | |
66 | private:
|
||
67 | Global *global; |
||
68 | 7520e117 | galberding | LineFollowStrategy lfStrategy = LineFollowStrategy::EDGE_RIGHT; |
69 | // Keeps track of the internal map state
|
||
70 | map_state state; |
||
71 | // Holds the amount of detected node of the map
|
||
72 | b8b3a9c9 | galberding | uint8_t nodeCount = 0;
|
73 | 7520e117 | galberding | // Stores all nodes and the corresponding coordinates of last detected fixpoints
|
74 | b8b3a9c9 | galberding | node nodeList[MAX_NODES]; |
75 | 7520e117 | galberding | // If driving over fixpoint prevent continuous updating
|
76 | // True if left sensor is driving over black
|
||
77 | bool leftDetected = false; |
||
78 | // True if right sensor is driving over black
|
||
79 | bool rightDetected = false; |
||
80 | |||
81 | /**
|
||
82 | * Recursively search through all nodes in the node list and
|
||
83 | * mark all reached nodes as visited.
|
||
84 | *
|
||
85 | * @param id node from where to start visiting the other nodes
|
||
86 | *
|
||
87 | */
|
||
88 | a07a7a1c | galberding | void visitNode(uint8_t id);
|
89 | bdac5bec | galberding | |
90 | /**
|
||
91 | * Calculate the distance between two given points
|
||
92 | *
|
||
93 | * @param p1 point 1
|
||
94 | * @param p2 point 2
|
||
95 | *
|
||
96 | */
|
||
97 | uint32_t calculateDist(types::position *p1, types::position *p2); |
||
98 | a07a7a1c | galberding | }; |
99 | b8b3a9c9 | galberding | }; // namespace amiro
|
100 | e1f1c4b5 | galberding | |
101 | #endif /* AMIRO_MAP */ |