-
Notifications
You must be signed in to change notification settings - Fork 0
/
serialCommands.ino
executable file
·185 lines (158 loc) · 5.19 KB
/
serialCommands.ino
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
void processSerialInputs() { //called in the loop
/**
Serial 0
List of commands
$bb* PC asking for current location
$pt,[double x],[double y]* PC sending point to store
$alive* PC replies its alive
$trajStart* PC ask to start trajectory system
$trajStop* PC ask to stop trajectory system
$clearPoints* PC ask to clear the buffer and reset stored coordinates
TODO
Set position
Set zero/ reset
**/
if (stringComplete) {
if (inputString == "bb") {// message from PC asking position & heading
sendPositionPC();
} else if (inputString == "alive") {
// Serial.println("YEESSSSSSSSSSSSSSSS");
isPCAlive = true;
} else if (inputString.length() > 4 && inputString.substring(0, 2) == "pt") {
int commaIndex = inputString.indexOf(',');
double xIn, yIn;
if (commaIndex != -1) {
xIn = strtod(inputString.substring(commaIndex + 1).c_str(), NULL);
}
commaIndex = inputString.indexOf(',', commaIndex + 1);
if (commaIndex != -1) {
yIn = strtod(inputString.substring(commaIndex + 1).c_str(), NULL);
addPoint(xIn, yIn);
}
} else if (inputString == "trajStart") {
Serial1.println("trajstart");
startTraj();
} else if (inputString == "stopMotion") {
Serial1.println("trajstart");
stopTraj();
} else if (inputString == "trajStop") {
Serial1.println("trajstart");
stopTraj();
} else if (inputString == "clearPoints") {
for (short i = 0; i < TRAJ_INDEX_MAX; i++) {
disablePoint(i);
}
ringBufIndex = 0;
lastUpdatedIndex = -1;
addedPoints = 0;
Serial1.println("removed Points");
}
inputString = "";
stringComplete = false;
}
/**
Serial 1 - WIFI and Debug
List of commands
$bb* PC asking for current location
$pt,[double x],[double y]* PC sending point to store
$alive* PC replies its alive
$trajStart* PC ask to start trajectory system
$trajStop* PC ask to stop trajectory system
$clearPoints* PC ask to clear the buffer and reset stored coordinates
TODO
Set position
Set zero/ reset
**/
if (stringCompleteDebug) {
if (inputStringDebug == "bb") {// message from PC asking position & heading
sendPositionPC();
} else if (inputStringDebug == "alive") {
// Serial.println("YEESSSSSSSSSSSSSSSS");
isPCAlive = true;
} else if (inputStringDebug.length() > 4 && inputStringDebug.substring(0, 2) == "pt") {
int commaIndex = inputStringDebug.indexOf(',');
double xIn, yIn;
if (commaIndex != -1) {
xIn = strtod(inputStringDebug.substring(commaIndex + 1).c_str(), NULL);
}
commaIndex = inputStringDebug.indexOf(',', commaIndex + 1);
if (commaIndex != -1) {
yIn = strtod(inputStringDebug.substring(commaIndex + 1).c_str(), NULL);
addPoint(xIn, yIn);
}
} else if (inputStringDebug == "trajStart") {
Serial1.println("trajstart");
startLogging();
ticks = 0;
if (isLoggingEnabled()) {
beginCSVData();
delay(20);
}
startTraj();
} else if (inputStringDebug == "trajStop") {
Serial1.println("trajstart");
void stopLogging();
stopTraj();
} else if (inputStringDebug == "zero") {
xMM = 0;
yMM = 0;
Serial1.println("zero");
} else if (inputStringDebug == "clearPoints") {
for (short i = 0; i < TRAJ_INDEX_MAX; i++) {
disablePoint(i);
}
ringBufIndex = 0;
lastUpdatedIndex = -1;
addedPoints = 0;
Serial1.println("removed Points");
}
else if (inputStringDebug == "calib") {
calibrateCompass();
}
inputStringDebug = "";
stringCompleteDebug = false;
}
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
if (inChar == '$') { //beginning of message;
//ideally two buffers should be used to make sure nothing is missed.
inputString = "";
} else if (inChar == '*') {
stringComplete = true;
} else {
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
}
}
}
/*
For Serial 1 - WIFI
*/
void serialEvent1() {
while (Serial1.available()) {
// get the new byte:
char inChar = (char)Serial1.read();
// add it to the inputString:
if (inChar == '$') { //beginning of message;
//ideally two buffers should be used to make sure nothing is missed.
inputStringDebug = "";
} else if (inChar == '*') {
stringCompleteDebug = true;
} else {
inputStringDebug += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
}
}
}