forked from JakobHeller/NatureInspiredComputing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SensorData.h
61 lines (49 loc) · 1.17 KB
/
SensorData.h
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
#ifndef __SensorData_H__
#define __SensorData_H__
#include <map>
#include <iostream>
#include "KheperaDefines.h"
enum EDirection
{
Direction_Left = 0,
Direction_FrontLeft = 1,
Direction_Front = 2,
Direction_FrontRight = 3,
Direction_Right = 4,
Direction_Back = 5
};
EDirection AngleToDirection(double angle);
enum EProximity
{
Proximity_Retreat = -1,
Proximity_Clear = 0,
Proximity_Near = 1,
Proximity_Close = 2,
Proximity_Collision = 3
};
struct SValue
{
int sensor;
EProximity proximity;
SValue() { sensor = 0; proximity = ProximityFromValue(0); }
SValue(int s) { sensor = s; proximity = ProximityFromValue(s); }
private:
EProximity ProximityFromValue(double sensorVal);
};
class CSensorData : public std::map<EDirection, SValue>
{
public:
CSensorData(Int8 rawSensors = { {0, 0, 0, 0, 0, 0, 0, 0} });
void Dump(std::ostream &stream = std::cout);
bool Collision();
bool CloseToCollision();
CSensorData GradientFrom(CSensorData previous);
private:
int Front(Int8 raw);
int Back(Int8 raw);
int LeftSide(Int8 raw);
int LeftFront(Int8 raw);
int RightSide(Int8 raw);
int RightFront(Int8 raw);
};
#endif