amiro-os / devices / DiWheelDrive / amiro_map.hpp @ 4d54a507
History | View | Annotate | Download (3.38 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 | |
| 7 | bdac5bec | galberding | |
| 8 | b8b3a9c9 | galberding | namespace amiro {
|
| 9 | e1f1c4b5 | galberding | |
| 10 | 7520e117 | galberding | struct node {
|
| 11 | uint8_t id; |
||
| 12 | uint8_t flag; |
||
| 13 | uint8_t left; |
||
| 14 | uint8_t right; |
||
| 15 | 3aee55de | galberding | union edge {
|
| 16 | struct edge_id{
|
||
| 17 | uint8_t left; |
||
| 18 | uint8_t right; |
||
| 19 | } edge_id; |
||
| 20 | uint8_t arr[2];
|
||
| 21 | } edge; |
||
| 22 | 7520e117 | galberding | uint8_t visited; |
| 23 | types::position pL; // Left
|
||
| 24 | types::position pR; // Right
|
||
| 25 | types::position pB; // Back
|
||
| 26 | 3aee55de | galberding | union p{
|
| 27 | struct{types::position pL, pR, pB;} points;
|
||
| 28 | types::position arr[3];
|
||
| 29 | } p; |
||
| 30 | 7520e117 | galberding | }; |
| 31 | |||
| 32 | e1f1c4b5 | galberding | |
| 33 | b8b3a9c9 | galberding | class AmiroMap { |
| 34 | public:
|
||
| 35 | 7520e117 | galberding | map_state * get_state() { return &state; }
|
| 36 | a3c54343 | galberding | uint8_t getNodeCount(){ return nodeCount; }
|
| 37 | node * getNodeList(){return nodeList; }
|
||
| 38 | |||
| 39 | b8b3a9c9 | galberding | |
| 40 | 4d54a507 | galberding | AmiroMap(Global *global, LineFollowStrategy lfStrategy) : global(global), lfStrategy(lfStrategy) {}
|
| 41 | b8b3a9c9 | galberding | |
| 42 | /**
|
||
| 43 | * Initialize a new map from configuration.
|
||
| 44 | * @param config map configuration array
|
||
| 45 | *
|
||
| 46 | */
|
||
| 47 | 7520e117 | galberding | uint8_t initialize(); |
| 48 | b8b3a9c9 | galberding | |
| 49 | 4d54a507 | galberding | void reset();
|
| 50 | b8b3a9c9 | galberding | |
| 51 | /**
|
||
| 52 | 7520e117 | galberding | * Update the internal map state according to the detected fixpoint
|
| 53 | * This function should be called for a generic update, each can cycle and in
|
||
| 54 | * case a fixpoint on one side is detected.
|
||
| 55 | * Internal state maschine will go into an error state in case both sensors are black.
|
||
| 56 | *
|
||
| 57 | * @param left fixpoint on left side detected
|
||
| 58 | * @param right fixpoint on right side detected
|
||
| 59 | * @param strategy current line follow strategy
|
||
| 60 | *
|
||
| 61 | *
|
||
| 62 | b8b3a9c9 | galberding | */
|
| 63 | bdac5bec | galberding | uint8_t update(uint16_t WL, uint16_t WR, LineFollowStrategy strategy); |
| 64 | b8b3a9c9 | galberding | |
| 65 | a3c54343 | galberding | |
| 66 | /**
|
||
| 67 | If this is called instead of update new fixpoints can automativally
|
||
| 68 | get detected and will be added to the current nodeList.
|
||
| 69 | Internally the update will be called.
|
||
| 70 | If there are no nodes in the node list they will be created.
|
||
| 71 | */
|
||
| 72 | 3aee55de | galberding | uint8_t trackUpdate(uint16_t WL, uint16_t WR, LineFollowStrategy strategy, ut_states ut_state); |
| 73 | |||
| 74 | |||
| 75 | |||
| 76 | |||
| 77 | a3c54343 | galberding | |
| 78 | b8b3a9c9 | galberding | private:
|
| 79 | Global *global; |
||
| 80 | 7520e117 | galberding | LineFollowStrategy lfStrategy = LineFollowStrategy::EDGE_RIGHT; |
| 81 | // Keeps track of the internal map state
|
||
| 82 | map_state state; |
||
| 83 | // Holds the amount of detected node of the map
|
||
| 84 | b8b3a9c9 | galberding | uint8_t nodeCount = 0;
|
| 85 | 7520e117 | galberding | // Stores all nodes and the corresponding coordinates of last detected fixpoints
|
| 86 | b8b3a9c9 | galberding | node nodeList[MAX_NODES]; |
| 87 | 7520e117 | galberding | // If driving over fixpoint prevent continuous updating
|
| 88 | // True if left sensor is driving over black
|
||
| 89 | 64cba697 | galberding | bool fxpDetected = false; |
| 90 | 7520e117 | galberding | |
| 91 | /**
|
||
| 92 | * Recursively search through all nodes in the node list and
|
||
| 93 | * mark all reached nodes as visited.
|
||
| 94 | *
|
||
| 95 | * @param id node from where to start visiting the other nodes
|
||
| 96 | *
|
||
| 97 | */
|
||
| 98 | a07a7a1c | galberding | void visitNode(uint8_t id);
|
| 99 | bdac5bec | galberding | |
| 100 | /**
|
||
| 101 | * Calculate the distance between two given points
|
||
| 102 | *
|
||
| 103 | * @param p1 point 1
|
||
| 104 | * @param p2 point 2
|
||
| 105 | *
|
||
| 106 | */
|
||
| 107 | uint32_t calculateDist(types::position *p1, types::position *p2); |
||
| 108 | 3aee55de | galberding | |
| 109 | // add node/fxp to the nodeList and return its id
|
||
| 110 | uint8_t addNode(uint8_t l, uint8_t r, uint8_t flags); |
||
| 111 | |||
| 112 | // Calculate dist and elength if possibel
|
||
| 113 | 81b48c66 | galberding | void calTravelState(types::position *p1);
|
| 114 | 3aee55de | galberding | |
| 115 | // Check if all nodes have followers
|
||
| 116 | // Calculate validity check
|
||
| 117 | void checkMap();
|
||
| 118 | |||
| 119 | void switchToNext(types::position *p1);
|
||
| 120 | |||
| 121 | // Copy contents of point from to point to (x, y, f_x)
|
||
| 122 | void copyPoint(types::position *from, types::position *to);
|
||
| 123 | |||
| 124 | // Create the first fxp with flag 1
|
||
| 125 | void createInitNode();
|
||
| 126 | |||
| 127 | uint8_t getNearest(types::position *p1); |
||
| 128 | |||
| 129 | // Either create new fxpoint or assign point to existing one
|
||
| 130 | uint8_t assignFxp(types::position *p1); |
||
| 131 | 4d54a507 | galberding | |
| 132 | 3aee55de | galberding | }; |
| 133 | |||
| 134 | b8b3a9c9 | galberding | }; // namespace amiro
|
| 135 | e1f1c4b5 | galberding | |
| 136 | #endif /* AMIRO_MAP */ |