-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathArduinoToOdroid.cpp
More file actions
315 lines (255 loc) · 8.34 KB
/
Copy pathArduinoToOdroid.cpp
File metadata and controls
315 lines (255 loc) · 8.34 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#include <ArduinoToOdroid.h>
/*
* Software License Agreement
*
* Copyright (c) 2021, Applied Robotics, Inc.
* All rights reserved.
*
*/
Odroid::Odroid(){
mainString = " ";
WheelDiffVelocity[0] = 0;
WheelDiffVelocity[1] = 0;
TargetPoint[0] = 0.0;
TargetPoint[1] = 0.0;
TargetPoint[2] = 0.0;
TargetVelocity[0] = 0;
TargetVelocity[1] = 0;
TargetVelocity[2] = 0;
Serial.begin(57600);
// Serial.setTimeout(1);
}
Odroid::~Odroid(){
Serial.end();
}
void Odroid::IKsolv(){
if (isOmni){
WheelAngularVelocity[0] = (1/R*(TargetVelocity[0]
-TargetVelocity[1]+(L1+L2)*(TargetVelocity[2]/2))*1);
WheelAngularVelocity[1] = (1/R*(TargetVelocity[0]
+TargetVelocity[1]-(L1+L2)*(TargetVelocity[2]/2))*(-1));
WheelAngularVelocity[2] = (1/R*(-TargetVelocity[0]
-CurrentVelocity[1]-(L1+L2)*(TargetVelocity[2]/2))*(-1));
WheelAngularVelocity[3] = (1/R*(-TargetVelocity[0]
+TargetVelocity[1]+(L1+L2)*(TargetVelocity[2]/2))*1);
}
else{
WheelDiffVelocity[0] = (2*TargetVelocity[0] - L1*TargetVelocity[2])/(2*R);
WheelDiffVelocity[1] = (2*TargetVelocity[0] + L1*TargetVelocity[2])/(2*R);
}
}
void Odroid::FKsolv(){
if (isOmni){
RealVelocity[0] = (CurrentVelocity[0]+CurrentVelocity[1]+CurrentVelocity[2]+CurrentVelocity[3])*(R/4);
RealVelocity[1] = (-CurrentVelocity[0]-CurrentVelocity[1]+CurrentVelocity[2]+CurrentVelocity[3])*(R/4);
RealVelocity[2] = (-CurrentVelocity[0]+CurrentVelocity[1]-CurrentVelocity[2]+CurrentVelocity[3])*(R/(2*(L1+L2)));
}
else{
RealVelocity[0] = (R*(CurrentVelocity[0]+CurrentVelocity[1]))/2;
RealVelocity[1] = 0.0;
RealVelocity[2] = (R*(CurrentVelocity[0]-CurrentVelocity[1]))/L1;
}
}
void Odroid::testParsing(){
byte dividerIndex = mainString.indexOf(';');
String buf1 = mainString.substring(0, dividerIndex);
parsingLocal(buf1);
mainString = mainString.substring(dividerIndex + 1);
if (mainString != NULL) testParsing();
}
void Odroid::parsingLocal(String tempString){
byte dividerIndex = tempString.indexOf(':');
String buf1 = tempString.substring(0, dividerIndex);
String buf2 = tempString.substring(dividerIndex + 1);
if (buf1.equals("tv")){
if(isOmni){
dividerIndex = buf2.indexOf(',');
buf1 = buf2.substring(0, dividerIndex);
TargetVelocity[0] = buf1.toFloat();
String buf3 = buf2.substring(dividerIndex + 1);
dividerIndex = buf3.indexOf(',');
buf1 = buf3.substring(0, dividerIndex);
buf2 = buf3.substring(dividerIndex + 1);
TargetVelocity[1] = buf1.toFloat();
TargetVelocity[2] = buf2.toFloat();
}
else{
// dividerIndex = buf2.indexOf(',');
// buf1 = buf2.substring(0, dividerIndex);
// String buf3 = buf2.substring(dividerIndex + 1);
// TargetVelocity[0] = buf1.toFloat();
// TargetVelocity[1] = 0;
// TargetVelocity[2] = buf3.toFloat();
dividerIndex = buf2.indexOf(',');
buf1 = buf2.substring(0, dividerIndex);
TargetVelocity[0] = buf1.toFloat();
String buf3 = buf2.substring(dividerIndex + 1);
dividerIndex = buf3.indexOf(',');
buf1 = buf3.substring(0, dividerIndex);
buf2 = buf3.substring(dividerIndex + 1);
TargetVelocity[1] = 0;
TargetVelocity[2] = buf2.toFloat();
}
}
if (buf1.equals("rp")){
dividerIndex = buf2.indexOf(',');
buf1 = buf2.substring(0, dividerIndex);
CurrentPoint[0] = buf1.toFloat();
String buf3 = buf2.substring(dividerIndex + 1);
dividerIndex = buf3.indexOf(',');
buf1 = buf3.substring(0, dividerIndex);
buf2 = buf3.substring(dividerIndex + 1);
CurrentPoint[1] = buf1.toFloat();
CurrentPoint[2] = buf2.toFloat();
}
if(buf1.equals("s")){
state = buf2;
}
}
void Odroid::parsingGlobal(){
String bufString = Serial.readString();
byte dividerIndex = bufString.indexOf(';');
String buf1 = bufString.substring(0, dividerIndex);
String buf2 = bufString.substring(dividerIndex + 1);
parsingLocal(buf1);
parsingLocal(buf2);
}
bool Odroid::onReceivingListener(){
if (Serial.available() > 10){
//parsingGlobal();
mainString = Serial.readString();
testParsing();
return true;
}else return false;
}
bool Odroid::pushCurrentPoint(){
// Итоговая строка с данными, отправляемая в одроид.
Serial.print("tp,");
for(int i = 0; i<3; i++){
Serial.print(TargetPoint[i]);
if(i < 2)
Serial.print(",");
}
Serial.print(";");
return true; // Проверка на дошло/не дошло (доработать?).
}
bool Odroid::pushCurrentVelocity(){
String inputString = "cv,"; // Итоговая строка с данными, отправляемая в одроид.
Serial.print("cv,");
for(int i = 0; i<3; i++){
Serial.print(RealVelocity[i]);
if(i < 2)
Serial.print(",");
}
Serial.print(";");
return true; // Проверка на дошло/не дошло (доработать?).
}
bool Odroid::pushString(){
pushCurrentPoint();
FKsolv();
pushCurrentVelocity();
Serial.println();
return true;
}
float* Odroid::getTargetVelocity(){
return TargetVelocity;
}
float* Odroid::getCurrentPoint(){
return CurrentPoint;
}
float* Odroid::getWheelAngularVelocity(){
return WheelAngularVelocity;
}
float* Odroid::getWheelDiffVelocity(){
IKsolv();
return WheelDiffVelocity;
}
bool Odroid::init(String type){
if (type.equals("omni")){
isOmni = true;
R = 0.05; L1 = 0.25; L2 = 0.25;
return true;
}
else if(type.equals("diff")){
isOmni = false;
R = 0.05; L1 = 0.25; L2 = 0;
return true;
}
else{
return false; // Какая-то ошибка.
}
}
bool Odroid::init(String type, float R){
if (type.equals("omni")){
isOmni = true;
this->R = R; L1 = 0.25; L2 = 0.25;
return true;
}
else if(type.equals("diff")){
isOmni = false;
this->R = R; L1 = 0.25; L2 = 0;
return true;
}
else{
return false; // Какая-то ошибка.
}
}
bool Odroid::init(String type, float R, float L1){
if (type.equals("omni")){
isOmni = true;
this->R = R; this->L1 = L1; L2 = 0.25;
return true;
}
else if(type.equals("diff")){
isOmni = false;
this->R = R; this->L1 = L1; L2 = 0;
return true;
}
else{
return false; // Какая-то ошибка.
}
}
bool Odroid::init(String type, float R, float L1, float L2){
if (type.equals("omni")){
isOmni = true;
this->R = R; this->L1 = L1; this->L2 = L2;
return true;
}
else if(type.equals("diff")){
isOmni = false;
this->R = R; this->L1 = L1; L2 = 0;
return true;
}
else{
return false; // Какая-то ошибка.
}
}
//--------------------------------- Пока не реализуем ---------------------------------//
// bool Odroid::moveTo(float x, float y, float alpha){
// String inputString = "moveto,"; // Итоговая строка с данными, отправляемая в плату и парсящаяся там.
// inputString += x; inputString += ",";
// inputString += y; inputString += ",";
// inputString += alpha;
// Serial.println(inputString);
// return true; // Возврат успеха/провала на Ардуино (доработать).
// }
// // Реализация функции включения навигации.
// bool Odroid::startSLAM(){
// String inputString = "startSLAM"; // Итоговая строка с данными, отправляемая в плату и парсящаяся там.
// Serial.println(inputString);
// return true; // Возврат успеха/провала на Ардуино (доработать).
// }
// // Реализация функции выключения навигации.
// bool Odroid::stopSLAM(){
// String inputString = "stopSLAM"; // Итоговая строка с данными, отправляемая в плату и парсящаяся там.
// Serial.println(inputString);
// return true; // Возврат успеха/провала на Ардуино (доработать).
// }
// // Реализация функции включения навигации.#include <ArduinoToOdroid.h>
/*
* Software License Agreement
*
* Copyright (c) 2021, Applied Robotics, Inc.
* All rights reserved.
*
*/