-
Notifications
You must be signed in to change notification settings - Fork 0
/
Perseverance_2_receiver.cpp
52 lines (38 loc) · 1019 Bytes
/
Perseverance_2_receiver.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
#include <webots/Robot.hpp>
#include <webots/Receiver.hpp>
#include <webots/LED.hpp>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <stdio.h>
#include<bits/stdc++.h>
using namespace webots;
using namespace std;
Robot *robot = new Robot();
Receiver *receiver = robot -> getReceiver("receiver");
LED *RED = robot -> getLED("led_red");
LED *BLUE = robot -> getLED("led_blue");
int timeStep = (int)robot->getBasicTimeStep();
int main(int argc, char **argv) {
while (robot->step(timeStep) != -1) {
receiver->enable(timeStep);
if (receiver->getQueueLength() > 0) {
string message((const char *)receiver->getData());
receiver->nextPacket();
//cout<<message<<endl;
if (message.compare("R") == 0) {
RED -> set(1);
BLUE -> set(0);
}
if (message.compare("B") == 0) {
BLUE -> set(3);
RED -> set(0);
}
}
};
delete robot;
return 0;
}