Revision b8b3a9c9 devices/DiWheelDrive/amiro_map.hpp

View differences:

devices/DiWheelDrive/amiro_map.hpp
1 1
#ifndef AMIRO_MAP
2 2
#define AMIRO_MAP
3 3

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

  
10
#define MAX_NODES 10
11
#define NODE_ATTRIBUTES 3
8 12

  
9
#define MAX_NODES 20
10
#define NODE_ATTRIBUTES 4
13
namespace amiro {
11 14

  
15
struct node {
16
  uint8_t id;
17
  uint8_t flag;
18
  uint8_t left;
19
  uint8_t right;
20
  types::position pL; // Left
21
  types::position pR; // Right
22
  types::position pB; // Back
23
};
12 24

  
13
namespace amiro {
25
class AmiroMap {
26
public:
27
  uint8_t get_next()  { return next; }
14 28

  
29
  void set_next( uint8_t next) { this->next = next; }
15 30

  
16
  struct node{
17
    uint8_t id;
18
    uint8_t flag;
19
    types::position pL; //Left
20
    types::position pR; //Right
21
    types::position pB; //Back
22
  };
23

  
24
  class AmiroMap{
25
  public:
26
    AmiroMap(Global *global):global{global}{}
27
    void initialize(int8_t (&config)[MAX_NODES][NODE_ATTRIBUTES]);
28
    void update();
29
  private:
30
    Global *global;
31
    bool valid = false;
32
    node *nodeList = NULL;
33
    node *current = NULL;
34
    node *next = NULL;
35
    void uninitialize();
36
  };
37
};
31
  uint8_t get_current()  { return current; }
32

  
33
  void set_current( uint8_t current) { this->current = current; }
34

  
35
  node* get_nodeList()  { return nodeList; }
36

  
37
  uint8_t get_nodeCount()  { return nodeCount; }
38

  
39
  void set_nodeCount( uint8_t nodeCount) { this->nodeCount = nodeCount; }
38 40

  
41
  bool get_valid()  { return valid; }
42

  
43
  void set_valid( bool valid) { this->valid = valid; }
44

  
45
  AmiroMap(Global *global) : global{global} {}
46

  
47
  /**
48
   * Initialize a new map from configuration.
49
   * @param config map configuration array
50
   *
51
   */
52
  void initialize(uint8_t (&config)[MAX_NODES][NODE_ATTRIBUTES]);
53

  
54

  
55
  /**
56
     Update the internal map state according to the detected fixpoint
57
     This function should be called for a generic update, each can cycle and in
58
     case a fixpoint on one side is detected.
59
     Internal state maschine will go into an error state in case both sensors are black.
60

  
61
     @param left fixpoint on left side detected
62
     @param right fixpoint on right side detected
63
     @param strategy current line follow strategy
64

  
65

  
66
   */
67
  void update(bool left, bool right, LineFollowStrategy strategy);
68

  
69
private:
70
  Global *global;
71
  bool valid = false;
72
  uint8_t nodeCount = 0;
73
  node nodeList[MAX_NODES];
74
  uint8_t current = 0;
75
  uint8_t next = 0;
76
};
77
}; // namespace amiro
39 78

  
40 79
#endif /* AMIRO_MAP */

Also available in: Unified diff