-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
55 lines (41 loc) · 1.5 KB
/
main.cpp
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
#include <QCoreApplication>
#include <QDebug>
#include <thread>
#include <timer/timer.h>
#include "vision/vision.h"
#include "referee/referee.h"
#include "actuator/actuator.h"
#include "replacer/replacer.h"
#include "worldmap/worldmap.h"
#include "coach/coach.h"
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
// Setting our color as YELLOW
VSSRef::Color ourColor = VSSRef::Color::YELLOW;
// Desired frequency in hz
float freq = 60.0;
// Starting timer
Timer timer;
VisionClient *visionClient = new VisionClient("224.0.0.1", 10002);
ActuatorClient *actuatorClient = new ActuatorClient("127.0.0.1", 20011);
WorldMap *wm = new WorldMap(visionClient);
Coach *coach = new Coach(wm, actuatorClient, ourColor);
// Setting actuator and replacer teamColor
actuatorClient->setTeamColor(ourColor);
while(1) {
visionClient->run();
wm->updateFrame();
if (wm->updateFrame() == true) {
coach->runCoach();
}
// Stop timer
timer.stop();
// Since we want the loop to run at a 60Hz frequency, we use T = 10E3 / f to get the remaining time in miliSeconds and subtract the elapsed time
long remainingTime = (1000 / freq) - timer.getMiliSeconds();
std::this_thread::sleep_for(std::chrono::milliseconds(remainingTime)); // Pauses current thread until remaining time
}
// Closing clients
visionClient->close();
actuatorClient->close();
return a.exec();
}