-
Notifications
You must be signed in to change notification settings - Fork 2
/
KheperaUtility.h
78 lines (62 loc) · 1.58 KB
/
KheperaUtility.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef __KheperaUtility_H__
#define __KheperaUtility_H__
#include <random>
#include <mutex>
#include "KheperaInterface.h"
// custom types
struct SSpeed
{
double left;
double right;
SSpeed(double l = 0, double r = 0) { left = l; right = r; }
};
struct SIOSet
{
Int8 sensors;
SSpeed speed;
SIOSet(Int8 sens = Int8(), SSpeed spd = SSpeed()) { sensors = sens; speed = spd; }
SIOSet(const SIOSet &other)
{
for (int i = 0; i < 8; i++)
{
this->sensors.data[i] = other.sensors.data[i];
}
this->speed.left = other.speed.left;
this->speed.right = other.speed.right;
}
};
typedef std::lock_guard<std::mutex> ScopedMutexLocker;
// value defines
#define CLOSE_SENSOR_VAL 1024
#define FAR_SENSOR_VAL 0
#define SENSOR_VAL_RANGE abs(FAR_SENSOR_VAL - CLOSE_SENSOR_VAL)
#define MAX_SPEED 20
class CKheperaUtility
{
public:
CKheperaUtility();
~CKheperaUtility();
// for khepera interaction
Int8 GetSensorData();
void SetSpeed(Int2 newSpeed);
// for controller output
void SetNetworkResult(SIOSet results);
SIOSet GetLastNetworkResult();
// for value system output
void SetCorrectedResult(SIOSet results);
SIOSet GetLastCorrectedResult();
// randomness
double GetUniformRandom(double min = 0, double max = 1);
// info dumping
void SetVerbosity(bool bVerbose);
private:
KheperaInterface* m_pKhep;
std::default_random_engine m_rGenerator;
SIOSet m_LastResult;
SIOSet m_LastCorrectedResult;
std::mutex m_KheperaMutex;
std::mutex m_ResultMutex;
std::mutex m_CorrectedResultMutex;
bool m_bVerbose;
};
#endif