Statistics
| Branch: | Tag: | Revision:

amiro-os / devices / DiWheelDrive / amiro_map.hpp @ bdac5bec

History | View | Annotate | Download (2.48 KB)

1
#ifndef AMIRO_MAP
2
#define AMIRO_MAP
3

    
4
#include "global.hpp"
5
#include "linefollow.hpp"
6
#include <amiroosconf.h>
7
#include <ch.hpp>
8

    
9

    
10
namespace amiro {
11

    
12
  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
    uint32_t dist;
32
    // True if the current loaded map is valid
33
    bool valid;
34
    // Length of the currently traveled edge
35
    uint32_t eLength;
36
  };
37

    
38
class AmiroMap {
39
public:
40
  map_state * get_state() { return &state; }
41

    
42
  AmiroMap(Global *global) : global{global} {}
43

    
44
  /**
45
   * Initialize a new map from configuration.
46
   * @param config map configuration array
47
   *
48
   */
49
  uint8_t initialize();
50

    
51

    
52
  /**
53
   * 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
   */
64
  uint8_t update(uint16_t WL, uint16_t WR, LineFollowStrategy strategy);
65

    
66
private:
67
  Global *global;
68
  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
  uint8_t nodeCount = 0;
73
  // Stores all nodes and the corresponding coordinates of last detected fixpoints
74
  node nodeList[MAX_NODES];
75
  // 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
  void visitNode(uint8_t id);
89

    
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
  };
99
}; // namespace amiro
100

    
101
#endif /* AMIRO_MAP */