-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapping.h
More file actions
109 lines (85 loc) · 2.32 KB
/
mapping.h
File metadata and controls
109 lines (85 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef _Mapping_h
#define _Mapping_h
#include <EEPROM.h>
const byte MAP_RESOLUTION = 25;
const byte MAP_DEFAULT_FEATURE = '#';
const int MAP_X=1800;
const int MAP_Y=1800;
class Mapper
{
public:
void resetMap();
void printMap();
void updateMapFeature(byte feature, int y, int x);
void updateMapFeature(byte feature, float y, float x);
int indexToPose(int i, int map_size, int resolution);
int poseToIndex(int x, int map_size, int resolution);
private:
int X_size;
int Y_size;
};
void Mapper::resetMap()
{
for (int i=0;i<MAP_RESOLUTION;i++)
{
for (int j=0;j<MAP_RESOLUTION;j++)
{
int eeprom_address = (i*MAP_RESOLUTION)+j;
if (eeprom_address > 1023)
{
Serial.println(F("Error: EEPROM Address greater than 1023"));
}
else
{
EEPROM.update(eeprom_address, MAP_DEFAULT_FEATURE );
}
}
}
}
void Mapper::printMap()
{
Serial.println("Map");
for (int i=0;i<MAP_RESOLUTION;i++)
{
for(int j=0;j<MAP_RESOLUTION;j++)
{
int eeprom_address = (i*MAP_RESOLUTION)+j;
byte value;
value = EEPROM.read(eeprom_address);//, value);
Serial.print( (char)value );
Serial.print(" ");
}
Serial.println("");
}
}
int Mapper::poseToIndex(int x, int map_size, int resolution)
{
return x / (map_size / resolution);
}
int Mapper::indexToPose(int i, int map_size, int resolution)
{
return i* (map_size / resolution);
}
void Mapper::updateMapFeature(byte feature, float y, float x) {
updateMapFeature( feature, (int)y, (int)x );
}
void Mapper::updateMapFeature(byte feature, int y, int x)
{
if (x > MAP_X || x < 0 || y > MAP_Y || y < 0)
{
Serial.println(F("Error:Invalid co-ordinate"));
return;
}
int x_index = poseToIndex(x, MAP_X, MAP_RESOLUTION);
int y_index = poseToIndex(y, MAP_Y, MAP_RESOLUTION);
int eeprom_address = (x_index * MAP_RESOLUTION) + y_index;
if (eeprom_address > 1023)
{
Serial.println(F("Error: EEPROM Address greater than 1023"));
}
else
{
EEPROM.update(eeprom_address, feature);
}
}
#endif