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