-
Notifications
You must be signed in to change notification settings - Fork 8
/
kilobotidassignment.h
116 lines (98 loc) · 2.69 KB
/
kilobotidassignment.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
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
110
111
112
113
114
115
116
#ifndef KILOBOTIDASSIGNMENT_H
#define KILOBOTIDASSIGNMENT_H
#include "kilobotexperiment.h"
#include <QElapsedTimer>
#include <QFile>
#include "kilobot.h"
enum assignStage {
START,
SEND,
TEST,
CONFIRM,
RETRY,
COMPLETE,
};
enum assignmethod {
BINARY,
BASETHREE,
};
const int baseFourMultipliers[6] = {1,4,16,64,256,1024};
const int binaryMultipliers[11] = {1,2,4,8,16,32,64,128,256,512,1024};
const int baseThreeMultipliers[8] = {1,3,9,27,81,243,729,2187};
static const double MM_TO_PIXEL = 2000.0/2000.0;
static const double PIXEL_TO_MM = 2000.0/2000.0;
//#define ASSIGNED -INT16_MAX
#define DUPE UINT16_MAX
class KiloLog {
public:
// constructors
KiloLog(){}
KiloLog(kilobot_id id, QPointF pos, double rot, kilobot_colour col,int numofdigits) :
id(id), position(pos), orientation(rot), colour(col){
this->digits.resize(numofdigits);
this->digits.fill(-1);
}
// methods
void updateAllValues(kilobot_id id, QPointF pos, double rot, kilobot_colour col){
this->id = id;
this->position = pos;
this->orientation = rot;
this->colour = col;
}
void setPos(QPointF pos){
this->position = pos;
}
void setOrientation(double rot){
this->orientation = rot;
}
void setCol(kilobot_colour col){
this->colour = col;
}
// variables
kilobot_id id;
QPointF position;
double orientation;
kilobot_colour colour;
QVector <int> digits;
};
class KilobotIDAssignment : public KilobotExperiment
{
Q_OBJECT
public:
KilobotIDAssignment(assignmethod method=BINARY);
virtual ~KilobotIDAssignment() {}
public slots:
void initialise(bool);
void run();
void stopExperiment();
private:
void updateKilobotState(Kilobot kilobotCopy);
void setupInitialKilobotState(Kilobot kilobotCopy);
// internal vars
assignmethod method;
QVector < uint16_t > tempIDs;
QVector < bool > isAssigned;
assignStage stage;
float lastTime = 0.0f;
//int numFound = 0;
bool dupesFound = 0;
int numSegments = 0;
int numofdigits =0;
bool switchSegment = true;
QElapsedTimer t;
int t_since;
int t_move;
// log variables
bool saveImages = false;
int savedImagesCounter = 0;
QFile log_file;
QString log_filename_prefix="log_id_ass";
QTextStream log_stream;
//QVector < kilobot_id > allKiloIDs;
QVector <KiloLog> allKilos;
bool updatedCol = false;
//confirmation stage variables
int increment=0;
bool confirmationrequestsent=false;
};
#endif // KILOBOTIDASSIGNMENT_H