-
Notifications
You must be signed in to change notification settings - Fork 8
/
kilobotexperiment.h
112 lines (92 loc) · 3.37 KB
/
kilobotexperiment.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
#ifndef KILOBOTEXPERIMENT_H
#define KILOBOTEXPERIMENT_H
#include <QObject>
#include <QDebug>
#include <QLayout>
#include <kilobotenvironment.h>
#include <kilobot.h>
#include <QColor>
#include <opencv2/core/core.hpp>
class KilobotExperiment : public QObject
{
Q_OBJECT
public:
KilobotExperiment() {}
virtual ~KilobotExperiment()
{
}
int serviceInterval = 100; // ms
virtual QWidget * createGUI() {return NULL;}
signals:
void updateKilobotStates();
void getInitialKilobotStates();
void experimentComplete();
void saveImage(QString);
void saveVideoFrames(QString,unsigned int);
void signalKilobot(kilobot_message);
void broadcastMessage(kilobot_broadcast);
void setTrackingType(int);
void sendBroadcastingState(bool);
// drawing
void drawCircle(QPointF pos, float r, QColor col, int thickness, std::string text, bool transparent=false);
void drawLine(std::vector<cv::Point> pos, QColor col, int thickness, std::string text, bool transparent);
void clearDrawings();
void drawCircleOnRecordedImage(QPointF pos, float r, QColor col, int thickness, std::string text);
void clearDrawingsOnRecordedImage();
public slots:
virtual void initialise(bool) = 0;
virtual void stopExperiment() {}
virtual void run() {}
void setRuntimeIdentificationLock(bool lock) {this->runtimeIdentificationLock = lock;}
void GetMsgsQueueState(bool state){ ThereIsMsgsToSend=state;}
/*!
* \brief updateStateRequiredCode
* \param kilobot
* \param kilobotCopy
*
* Slot that makes sure that some code is run BEFORE the derived function
*/
void updateStateRequiredCode(Kilobot* kilobot, Kilobot kilobotCopy)
{
//qDebug() << "pre set state 2";
// store pointer for connecting
this->currKilobot = kilobot;
updateKilobotState(kilobotCopy);
}
/*!
* \brief setupInitialStateRequiredCode
* \param kilobot
* \param kilobotCopy
*
* Slot that makes sure that some code is run BEFORE the derived function
*/
void setupInitialStateRequiredCode(Kilobot* kilobot, Kilobot kilobotCopy)
{
//qDebug() << "pre set state";
// store pointer for connecting
this->currKilobot = kilobot;
// switch the signal from setup to standard
kilobot->disconnect(SIGNAL(sendUpdateToExperiment(Kilobot*,Kilobot)));
connect(kilobot,SIGNAL(sendUpdateToExperiment(Kilobot*,Kilobot)), this, SLOT(updateStateRequiredCode(Kilobot*,Kilobot)));
setupInitialKilobotState(kilobotCopy);
}
void signalKilobotExpt(kilobot_message msg)
{
emit signalKilobot(msg);
}
protected:
double time;
bool runtimeIdentificationLock = false;
bool ThereIsMsgsToSend=false;
void setCurrentKilobotEnvironment(KilobotEnvironment * environment) {
if (currKilobot != NULL && environment != NULL) {
QObject::disconnect(currKilobot,SIGNAL(sendUpdateToHardware(Kilobot)), 0, 0);
QObject::connect(currKilobot,SIGNAL(sendUpdateToHardware(Kilobot)), environment, SLOT(updateVirtualSensor(Kilobot)));
}
}
virtual void updateKilobotState(Kilobot) {} // provided in derived class to implement experiment logic for Kilobot state updates
virtual void setupInitialKilobotState(Kilobot) {}
private:
Kilobot * currKilobot = NULL;
};
#endif // KILOBOTEXPERIMENT_H