amiro-os / devices / DiWheelDrive / amiro_map.cpp @ a07a7a1c
History | View | Annotate | Download (1.395 KB)
1 |
#include "amiro_map.hpp" |
---|---|
2 |
#include <cstdint> |
3 |
|
4 |
|
5 |
void AmiroMap::initialize(uint8_t (&config)[MAX_NODES][NODE_ATTRIBUTES]){
|
6 |
|
7 |
// Clear old values in case the map is initialized again
|
8 |
uint8_t visitTable[MAX_NODES]; |
9 |
this->current = 0; |
10 |
this->next = 0; |
11 |
this->valid = false; |
12 |
|
13 |
// convert proto map to internal representation
|
14 |
for (int i=0; i<MAX_NODES; i++){ |
15 |
if(config[i][2] == 0xff && i != 0){ |
16 |
break;
|
17 |
} else if (config[i][2] == 0xff && i == 0) { |
18 |
this->valid = false; |
19 |
return;
|
20 |
} |
21 |
|
22 |
//look for start node (default is Node 0)
|
23 |
if (config[i][2] == 1 ) { |
24 |
this->current= i;
|
25 |
} |
26 |
|
27 |
this->nodeList[i].id = i;
|
28 |
this->nodeList[i].left = config[i][0]; |
29 |
this->nodeList[i].right = config[i][1]; |
30 |
this->nodeList[i].flag = config[i][2]; |
31 |
this->nodeCount++;
|
32 |
} |
33 |
|
34 |
// TODO make validity check
|
35 |
bool all_visited = true; |
36 |
for (int j=0; j<nodeCount; j++) { |
37 |
visitNode(j); |
38 |
for (int k = 0; k < nodeCount; k++) { |
39 |
if (nodeList[k].visited == 1) { |
40 |
nodeList[k].visited = 0;
|
41 |
} else {
|
42 |
this->valid = false; |
43 |
return;
|
44 |
} |
45 |
} |
46 |
} |
47 |
|
48 |
this->valid = true; |
49 |
} |
50 |
|
51 |
void AmiroMap::visitNode(uint8_t id){
|
52 |
if (this->nodeList[id].visited > 0){ |
53 |
return;
|
54 |
}else{
|
55 |
nodeList[id].visited++; |
56 |
visitNode(this->nodeList[id].left);
|
57 |
visitNode(this->nodeList[id].right);
|
58 |
} |
59 |
} |
60 |
|
61 |
|
62 |
void AmiroMap::update(bool left, bool right, LineFollowStrategy strategy) { |
63 |
|
64 |
} |