-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwarmBot.cpp
90 lines (57 loc) · 1.73 KB
/
SwarmBot.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
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
#include "SwarmBot.h"
#include "Arduino.h"
void testCompass2(void);
void SwarmBot::init(void) {
Vibrabot::init();
this->leftMotor.setPwmValue(120);
this->rightMotor.setPwmValue(120);
this->rgbLed.setLEDColor(&ColorOrange);
this->masterSlave.init(this->communicator);
}
void SwarmBot::process(void)
{
ComToken * token;
if (this->mainClock.isTick())
{
this->rgbLed.process();
this->processAnalogData();
this->masterSlave.process();
if (this->communicator.hasTokenToRead())
{
token = this->communicator.readNextToken();
Serial.print("C:");
Serial.print(token->getChannel());
Serial.print(" Sig:");
Serial.println(token->getStrength());
//TODO Only pass token if it is a MasterToken
if (token->getHeader() == MS_TOKEN_HEADER) {
this->masterSlave.passToken(token);
}
}
this->updateLED();
}
}
void SwarmBot::updateLED(void)
{
uint16_t lightLeft;
uint16_t lightRight;
lightLeft = this->adc.getBrightness(0);
lightRight = this->adc.getBrightness(1);
this->rgbLed.setLEDColor(&ColorBlue);
if (this->masterSlave.getMode() == MS_MODE_SINGLE) {
this->rgbLed.setLEDColor(&ColorGreen);
this->leftMotor.off();
this->rightMotor.off();
} else if (this->masterSlave.getMode() & MS_MODE_MASTER && this->masterSlave.getMode() & MS_MODE_SLAVE) {
this->rgbLed.setLEDColor(&ColorBlue);
this->leftMotor.on();
this->rightMotor.on();
} else if (this->masterSlave.getMode() & MS_MODE_SLAVE) {
this->rgbLed.setLEDColor(&ColorRed);
this->leftMotor.off();
this->rightMotor.off();
} else if (this->masterSlave.getMode() & MS_MODE_MASTER) {
this->leftMotor.on();
this->rightMotor.on();
}
}