Browse Source

Added Filters for Proximity and Line Sensor Values; Solved Problem with Function TimeUpdate

fstange 6 years ago
parent
commit
eba4788a84
47 changed files with 3014 additions and 2761 deletions
  1. BIN
      ArduinoOutput/Hauptprojekt.ino.elf
  2. 1367 1295
      ArduinoOutput/Hauptprojekt.ino.hex
  3. 1367 1295
      ArduinoOutput/Hauptprojekt.ino.with_bootloader.hex
  4. BIN
      ArduinoOutput/core/CDC.cpp.o
  5. BIN
      ArduinoOutput/core/HardwareSerial.cpp.o
  6. BIN
      ArduinoOutput/core/HardwareSerial0.cpp.o
  7. BIN
      ArduinoOutput/core/HardwareSerial1.cpp.o
  8. BIN
      ArduinoOutput/core/HardwareSerial2.cpp.o
  9. BIN
      ArduinoOutput/core/HardwareSerial3.cpp.o
  10. BIN
      ArduinoOutput/core/IPAddress.cpp.o
  11. BIN
      ArduinoOutput/core/PluggableUSB.cpp.o
  12. BIN
      ArduinoOutput/core/Print.cpp.o
  13. BIN
      ArduinoOutput/core/Stream.cpp.o
  14. BIN
      ArduinoOutput/core/Tone.cpp.o
  15. BIN
      ArduinoOutput/core/USBCore.cpp.o
  16. BIN
      ArduinoOutput/core/WInterrupts.c.o
  17. BIN
      ArduinoOutput/core/WMath.cpp.o
  18. BIN
      ArduinoOutput/core/WString.cpp.o
  19. BIN
      ArduinoOutput/core/abi.cpp.o
  20. BIN
      ArduinoOutput/core/core.a
  21. BIN
      ArduinoOutput/core/hooks.c.o
  22. BIN
      ArduinoOutput/core/main.cpp.o
  23. BIN
      ArduinoOutput/core/new.cpp.o
  24. BIN
      ArduinoOutput/core/wiring.c.o
  25. BIN
      ArduinoOutput/core/wiring_analog.c.o
  26. BIN
      ArduinoOutput/core/wiring_digital.c.o
  27. BIN
      ArduinoOutput/core/wiring_pulse.c.o
  28. BIN
      ArduinoOutput/core/wiring_shift.c.o
  29. 16 0
      ArduinoOutput/libraries/MedianFilter/MedianFilter.cpp.d
  30. BIN
      ArduinoOutput/libraries/MedianFilter/MedianFilter.cpp.o
  31. BIN
      ArduinoOutput/libraries/Wire/Wire.cpp.o
  32. BIN
      ArduinoOutput/libraries/Wire/utility/twi.c.o
  33. BIN
      ArduinoOutput/libraries/Zumo32U4/L3G.cpp.o
  34. BIN
      ArduinoOutput/libraries/Zumo32U4/LSM303.cpp.o
  35. BIN
      ArduinoOutput/libraries/Zumo32U4/PololuBuzzer.cpp.o
  36. BIN
      ArduinoOutput/libraries/Zumo32U4/PololuHD44780.cpp.o
  37. BIN
      ArduinoOutput/libraries/Zumo32U4/Pushbutton.cpp.o
  38. BIN
      ArduinoOutput/libraries/Zumo32U4/QTRSensors.cpp.o
  39. BIN
      ArduinoOutput/libraries/Zumo32U4/Zumo32U4Encoders.cpp.o
  40. BIN
      ArduinoOutput/libraries/Zumo32U4/Zumo32U4IRPulses.cpp.o
  41. BIN
      ArduinoOutput/libraries/Zumo32U4/Zumo32U4Motors.cpp.o
  42. BIN
      ArduinoOutput/libraries/Zumo32U4/Zumo32U4ProximitySensors.cpp.o
  43. 107 71
      ArduinoOutput/preproc/ctags_target_for_gcc_minus_e.cpp
  44. 88 60
      ArduinoOutput/sketch/Hauptprojekt.ino.cpp
  45. 2 1
      ArduinoOutput/sketch/Hauptprojekt.ino.cpp.d
  46. BIN
      ArduinoOutput/sketch/Hauptprojekt.ino.cpp.o
  47. 67 39
      Zumo32U4/Hauptprojekt/Hauptprojekt.ino

BIN
ArduinoOutput/Hauptprojekt.ino.elf


File diff suppressed because it is too large
+ 1367 - 1295
ArduinoOutput/Hauptprojekt.ino.hex


File diff suppressed because it is too large
+ 1367 - 1295
ArduinoOutput/Hauptprojekt.ino.with_bootloader.hex


BIN
ArduinoOutput/core/CDC.cpp.o


BIN
ArduinoOutput/core/HardwareSerial.cpp.o


BIN
ArduinoOutput/core/HardwareSerial0.cpp.o


BIN
ArduinoOutput/core/HardwareSerial1.cpp.o


BIN
ArduinoOutput/core/HardwareSerial2.cpp.o


BIN
ArduinoOutput/core/HardwareSerial3.cpp.o


BIN
ArduinoOutput/core/IPAddress.cpp.o


BIN
ArduinoOutput/core/PluggableUSB.cpp.o


BIN
ArduinoOutput/core/Print.cpp.o


BIN
ArduinoOutput/core/Stream.cpp.o


BIN
ArduinoOutput/core/Tone.cpp.o


BIN
ArduinoOutput/core/USBCore.cpp.o


BIN
ArduinoOutput/core/WInterrupts.c.o


BIN
ArduinoOutput/core/WMath.cpp.o


BIN
ArduinoOutput/core/WString.cpp.o


BIN
ArduinoOutput/core/abi.cpp.o


BIN
ArduinoOutput/core/core.a


BIN
ArduinoOutput/core/hooks.c.o


BIN
ArduinoOutput/core/main.cpp.o


BIN
ArduinoOutput/core/new.cpp.o


BIN
ArduinoOutput/core/wiring.c.o


BIN
ArduinoOutput/core/wiring_analog.c.o


BIN
ArduinoOutput/core/wiring_digital.c.o


BIN
ArduinoOutput/core/wiring_pulse.c.o


BIN
ArduinoOutput/core/wiring_shift.c.o


+ 16 - 0
ArduinoOutput/libraries/MedianFilter/MedianFilter.cpp.d

@@ -0,0 +1,16 @@
1
+c:\Users\Carolin\Downloads\VSCode\Zumo32U4\ArduinoOutput\libraries\MedianFilter\MedianFilter.cpp.o: \
2
+ C:\Users\Carolin\Documents\Arduino\libraries\MedianFilter\MedianFilter.cpp \
3
+ C:\Users\Carolin\Documents\Arduino\libraries\MedianFilter\MedianFilter.h \
4
+ C:\Users\Carolin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino/Arduino.h \
5
+ C:\Users\Carolin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino/binary.h \
6
+ C:\Users\Carolin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino/WCharacter.h \
7
+ C:\Users\Carolin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino/WString.h \
8
+ C:\Users\Carolin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino/HardwareSerial.h \
9
+ C:\Users\Carolin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino/Stream.h \
10
+ C:\Users\Carolin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino/Print.h \
11
+ C:\Users\Carolin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino/Printable.h \
12
+ C:\Users\Carolin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino/USBAPI.h \
13
+ C:\Users\Carolin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino/Arduino.h \
14
+ C:\Users\Carolin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino/USBDesc.h \
15
+ C:\Users\Carolin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino/USBCore.h \
16
+ C:\Users\Carolin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\variants\leonardo/pins_arduino.h

BIN
ArduinoOutput/libraries/MedianFilter/MedianFilter.cpp.o


BIN
ArduinoOutput/libraries/Wire/Wire.cpp.o


BIN
ArduinoOutput/libraries/Wire/utility/twi.c.o


BIN
ArduinoOutput/libraries/Zumo32U4/L3G.cpp.o


BIN
ArduinoOutput/libraries/Zumo32U4/LSM303.cpp.o


BIN
ArduinoOutput/libraries/Zumo32U4/PololuBuzzer.cpp.o


BIN
ArduinoOutput/libraries/Zumo32U4/PololuHD44780.cpp.o


BIN
ArduinoOutput/libraries/Zumo32U4/Pushbutton.cpp.o


BIN
ArduinoOutput/libraries/Zumo32U4/QTRSensors.cpp.o


BIN
ArduinoOutput/libraries/Zumo32U4/Zumo32U4Encoders.cpp.o


BIN
ArduinoOutput/libraries/Zumo32U4/Zumo32U4IRPulses.cpp.o


BIN
ArduinoOutput/libraries/Zumo32U4/Zumo32U4Motors.cpp.o


BIN
ArduinoOutput/libraries/Zumo32U4/Zumo32U4ProximitySensors.cpp.o


+ 107 - 71
ArduinoOutput/preproc/ctags_target_for_gcc_minus_e.cpp

@@ -1,19 +1,29 @@
1 1
 # 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
2 2
 # 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
3 3
 //Verfassser: Felix Stange, 4056379, MET2016 
4
-//Datum: erstellt am 19.07.2017, zuletzt geändert am 04.05.2018 
5
-//Projektbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
6
-//der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
7
-//Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
8
-//dennoch zu einer Kollision, wird diese durch den Beschleunigungssensor (LSM303) erkannt. 
9
-//Für den Überholvorgang werden die seitlichen Abstandssensoren und der Drehbewegungssensor (L3G) 
10
-//genutzt. Mithilfe der Quadraturencoder in den Motoren können Wegstrecken vermessen werden. 
11
-//Der Zumo kommuniziert über ein Bluetooth-Modul (HC-05) mit anderen Geräten. Die 
12
-//Kommunikation erfolgt seriell ('SERIAL' für USB, 'SERIAL1' für Bluetooth). 
13
-//Das LCD kann bei Bluetoothnutzung nicht verwendet werden. 
14
-
15
-# 14 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino" 2
4
+//Datum: erstellt am 19.07.2017, zuletzt geändert am 08.05.2018 
5
+//Projektthema: Untersuchungen und Implementierung eines automatisierten Fahrens mittels Pololu Zumo
6
+/*Kurzbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
7
+
8
+der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
9
+
10
+Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
11
+
12
+dennoch zu einer Kollision, wird diese durch den Beschleunigungssensor (LSM303) erkannt. 
13
+
14
+Für den Überholvorgang werden die seitlichen Abstandssensoren und der Drehbewegungssensor (L3G) 
15
+
16
+genutzt. Mithilfe der Quadraturencoder in den Motoren können Wegstrecken vermessen werden. 
17
+
18
+Für die Filterung der Messwerte werden Medianfilter genutzt. Der Zumo kommuniziert über ein 
19
+
20
+Bluetooth-Modul (HC-05) mit anderen Geräten. Die Kommunikation erfolgt seriell ('SERIAL' für USB, 
21
+
22
+'SERIAL1' für Bluetooth). Das LCD kann bei Bluetoothnutzung nicht verwendet werden.*/
23
+# 14 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
16 24
 # 15 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino" 2
25
+# 16 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino" 2
26
+# 17 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino" 2
17 27
 
18 28
 Zumo32U4ProximitySensors proxSensors; //Abstandssensoren
19 29
 Zumo32U4LineSensors lineSensors; //Liniensensoren
@@ -22,7 +32,15 @@ Zumo32U4ButtonA buttonA; //Taste A
22 32
 Zumo32U4Encoders encoders; //Motorencoder
23 33
 LSM303 compass; //Beschleunigungssensor x-Achse
24 34
 L3G gyro; //Drehbewegungssensor z-Achse
25
-# 38 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
35
+
36
+MedianFilter LineFilter0(3, 0); //erstellen der Filter für Liniensensoren
37
+MedianFilter LineFilter1(3, 0); //Medianfilter geben mittleren Wert einer Reihe aus
38
+MedianFilter LineFilter2(3, 0); //Fenstergröße: 3, Basiswerte: 0 0 0
39
+MedianFilter ProxFilter0(3, 0); //erstellen der Filter für Abstandssensoren
40
+MedianFilter ProxFilter1(3, 0);
41
+MedianFilter ProxFilter2(3, 0);
42
+MedianFilter ProxFilter3(3, 0);
43
+# 48 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
26 44
 int16_t lineValue[3]; //Liniensensoren
27 45
 uint16_t lineOffset[3]; //von links (0) nach rechts (2)
28 46
 
@@ -71,8 +89,8 @@ void LineSetup()
71 89
   uint32_t total[3] = {0, 0, 0};
72 90
   for(uint8_t i = 0; i < 120; i++)
73 91
   {
74
-    if (i > 30 && i <= 90) motors.setSpeeds(106, -100);
75
-    else motors.setSpeeds(-106, 100);
92
+    if (i > 30 && i <= 90) motors.setSpeeds(104, -100);
93
+    else motors.setSpeeds(-104, 100);
76 94
     lineSensors.read(lineOffset);
77 95
     total[0] += lineOffset[0];
78 96
     total[1] += lineOffset[1];
@@ -240,20 +258,20 @@ void LoopTiming()
240 258
 void ProxUpdate()
241 259
 {
242 260
   proxSensors.read();
243
-  proxValue[0] = proxSensors.countsLeftWithLeftLeds();
244
-  proxValue[1] = proxSensors.countsFrontWithLeftLeds();
245
-  proxValue[2] = proxSensors.countsFrontWithRightLeds();
246
-  proxValue[3] = proxSensors.countsRightWithRightLeds();
261
+  proxValue[0] = ProxFilter0.in(proxSensors.countsLeftWithLeftLeds());
262
+  proxValue[1] = ProxFilter1.in(proxSensors.countsFrontWithLeftLeds());
263
+  proxValue[2] = ProxFilter2.in(proxSensors.countsFrontWithRightLeds());
264
+  proxValue[3] = ProxFilter3.in(proxSensors.countsRightWithRightLeds());
247 265
 }
248 266
 
249 267
 //Update Liniensensoren
250 268
 void LineUpdate()
251 269
 {
252 270
   uint16_t lineRaw[3];
253
-  lineSensors.read(lineRaw);
254
-  lineValue[0] = lineRaw[0] - lineOffset[0];
255
-  lineValue[1] = lineRaw[1] - lineOffset[1];
256
-  lineValue[2] = lineRaw[2] - lineOffset[2];
271
+  lineSensors.read(lineRaw); //lese Messwerte der Liniensensoren aus
272
+  lineValue[0] = LineFilter0.in(lineRaw[0] - lineOffset[0]); //ziehe Offsetwerte von Messwerten ab und gib diese in Filter ein
273
+  lineValue[1] = LineFilter1.in(lineRaw[1] - lineOffset[1]); //erhält neue mittlere Werte der Filter
274
+  lineValue[2] = LineFilter2.in(lineRaw[2] - lineOffset[2]); //"LineFilter.out" um gefilterte Werte auszugeben ohne neue Werte einzugeben
257 275
 }
258 276
 
259 277
 //Update Drehbewegungssensor
@@ -304,7 +322,7 @@ void Kontaktvermeiden()
304 322
   while(proxValue[1] == 0 || proxValue[2] == 0)
305 323
   {
306 324
     ProxUpdate();
307
-    motors.setSpeeds(-53, -50);
325
+    motors.setSpeeds(-52, -50);
308 326
     if(lineValue[0] > 150 || lineValue[2] > 120) break;
309 327
   }
310 328
   motors.setSpeeds(0, 0);
@@ -324,11 +342,18 @@ void Hindernisumfahren()
324 342
   turnAngle = 0;
325 343
   rotationAngle = 0;
326 344
   GyroUpdate();
345
+  while(rotationAngle < 20)
346
+  {
347
+    GyroUpdate();
348
+    LineUpdate();
349
+    motors.setSpeeds(26, 100);
350
+  }
351
+  GyroUpdate();
327 352
   while(rotationAngle < 45)
328 353
   {
329 354
     GyroUpdate();
330 355
     LineUpdate();
331
-    motors.setSpeeds(27, 100);
356
+    motors.setSpeeds(26, 100);
332 357
     if(lineValue[2] > 120 && lineValue[2] < 500) break;
333 358
   }
334 359
   //geradeaus über Mittellinie fahren
@@ -336,7 +361,7 @@ void Hindernisumfahren()
336 361
   while(lineValue[2] < 120)
337 362
   {
338 363
     LineUpdate();
339
-    motors.setSpeeds(106, 100);
364
+    motors.setSpeeds(104, 100);
340 365
     //if(lineValue[0] > MARKLINE0) break;
341 366
   }
342 367
   //rechts drehen
@@ -345,12 +370,12 @@ void Hindernisumfahren()
345 370
   {
346 371
     GyroUpdate();
347 372
     LineUpdate();
348
-    if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(106, 0);
349
-    else if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(106, 100);
350
-    else motors.setSpeeds(106, 25);
373
+    if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(104, 0);
374
+    else if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(104, 100);
375
+    else motors.setSpeeds(104, 25);
351 376
   }
352 377
   //geradeaus fahren
353
-  motors.setSpeeds(106, 100);
378
+  motors.setSpeeds(104, 100);
354 379
 
355 380
   //Gegenverkehr beachten
356 381
   ProxUpdate();
@@ -359,14 +384,16 @@ void Hindernisumfahren()
359 384
     //Schritt 2: Hindernis passieren
360 385
     //Serial1.println("Aufholen"); 
361 386
     lastUpdate = millis();
362
-    while(proxValue[3] < 6 && eventTime < 3000)
387
+    while(proxValue[3] < 6)
363 388
     {
364
-      TimeUpdate();
365 389
       ProxUpdate();
366 390
       LineUpdate();
367 391
       Spurhalten();
392
+      TimeUpdate();
393
+      //Serial1.println(eventTime);
394
+      if(eventTime > 3000) break;
368 395
     }
369
-    //Serial1.println("Überholen"); 
396
+    //Serial1.println("Vorbeifahren"); 
370 397
     ProxUpdate();
371 398
     while(proxValue[3] == 6)
372 399
     {
@@ -379,10 +406,10 @@ void Hindernisumfahren()
379 406
     TimeUpdate();
380 407
     while(eventTime < 3000)
381 408
     {
382
-      //Serial1.println(eventTime); 
383
-      TimeUpdate();
384 409
       LineUpdate();
385 410
       Spurhalten();
411
+      TimeUpdate();
412
+      //Serial1.println(eventTime);
386 413
     }
387 414
   //}
388 415
 
@@ -391,11 +418,18 @@ void Hindernisumfahren()
391 418
   turnAngle = 0;
392 419
   rotationAngle = 0;
393 420
   GyroUpdate();
421
+  while(rotationAngle > -20)
422
+  {
423
+    GyroUpdate();
424
+    LineUpdate();
425
+    motors.setSpeeds(104, 25);
426
+  }
427
+  GyroUpdate();
394 428
   while(rotationAngle > -45)
395 429
   {
396 430
     GyroUpdate();
397 431
     LineUpdate();
398
-    motors.setSpeeds(106, 25);
432
+    motors.setSpeeds(104, 25);
399 433
     if(lineValue[0] > 150 && lineValue[0] < 500) break;
400 434
   }
401 435
   //geradeaus über Mittellinie fahren
@@ -403,7 +437,7 @@ void Hindernisumfahren()
403 437
   while(lineValue[0] < 150)
404 438
   {
405 439
     LineUpdate();
406
-    motors.setSpeeds(106, 100);
440
+    motors.setSpeeds(104, 100);
407 441
     //if(lineValue[0] > MARKLINE0) break;
408 442
   }
409 443
   //links drehen
@@ -413,13 +447,13 @@ void Hindernisumfahren()
413 447
     GyroUpdate();
414 448
     LineUpdate();
415 449
     if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(0, 100);
416
-    else if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(106, 100);
417
-    else motors.setSpeeds(27, 100);
450
+    else if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(104, 100);
451
+    else motors.setSpeeds(26, 100);
418 452
   }
419 453
   //geradeaus fahren
420 454
   //Serial1.println("Umfahren beendet");
421 455
   Serial1.print(0);
422
-  motors.setSpeeds(106, 100);
456
+  motors.setSpeeds(104, 100);
423 457
 }
424 458
 
425 459
 //Funktion Abbiegen
@@ -433,9 +467,9 @@ void Abbiegen()
433 467
   LineUpdate();
434 468
   bool leftCode; //links => 1
435 469
   bool rightCode; //rechts => 2
436
-  if((lineValue[0] > 500 && lineValue[0] < 1400) && (lineValue[1] > 300 && lineValue[1] < 700)) leftCode = true;
470
+  if((lineValue[0] > 500 && lineValue[0] < 1600) && (lineValue[1] > 300 && lineValue[1] < 800)) leftCode = true;
437 471
   else leftCode = false;
438
-  if((lineValue[2] > 500 && lineValue[2] < 1400) && (lineValue[1] > 300 && lineValue[1] < 700)) rightCode = true;
472
+  if((lineValue[2] > 500 && lineValue[2] < 1600) && (lineValue[1] > 300 && lineValue[1] < 800)) rightCode = true;
439 473
   else rightCode = false;
440 474
 
441 475
   //Zufallszahl erzeugen
@@ -458,19 +492,19 @@ void Abbiegen()
458 492
   {
459 493
     //Serial1.println("links Abbiegen von der Verbindungsstrecke"); 
460 494
     //geradeaus zur Mittellinie fahren
461
-    motors.setSpeeds(106, 100 +10);
495
+    motors.setSpeeds(104, 100 +10);
462 496
     lastUpdate = millis();
463 497
     TimeUpdate();
464
-    while(eventTime < 300)
498
+    while(eventTime < 1000)
465 499
     {
466 500
       TimeUpdate();
467
-      motors.setSpeeds(106, 100 +10);
501
+      motors.setSpeeds(104, 100 +10);
468 502
     }
469 503
     LineUpdate();
470 504
     while(lineValue[0] < 150 && lineValue[2] < 120)
471 505
     {
472 506
       LineUpdate();
473
-      motors.setSpeeds(106, 100);
507
+      motors.setSpeeds(104, 100);
474 508
     }
475 509
     //links drehen
476 510
     turnAngle = 0;
@@ -481,11 +515,11 @@ void Abbiegen()
481 515
       GyroUpdate();
482 516
       LineUpdate();
483 517
       if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(0, 100);
484
-      else if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(53, 100);
485
-      else motors.setSpeeds(27, 100);
518
+      else if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(52, 100);
519
+      else motors.setSpeeds(26, 100);
486 520
     }
487 521
     //geradeaus fahren
488
-    motors.setSpeeds(106, 100);
522
+    motors.setSpeeds(104, 100);
489 523
   }
490 524
 
491 525
   //links Abbiegen (vom Rundkurs)
@@ -501,7 +535,7 @@ void Abbiegen()
501 535
     {
502 536
       GyroUpdate();
503 537
       EncoderUpdate();
504
-      motors.setSpeeds(27, 100);
538
+      motors.setSpeeds(26, 100);
505 539
       //if(driveRotation[1] > 1) break;
506 540
     }
507 541
     driveRotation[1] = 0;
@@ -510,11 +544,11 @@ void Abbiegen()
510 544
     {
511 545
       GyroUpdate();
512 546
       EncoderUpdate();
513
-      motors.setSpeeds(27, 100);
547
+      motors.setSpeeds(26, 100);
514 548
       //if(driveRotation[1] > 1) break;
515 549
     }
516 550
     //geradeaus fahren
517
-    motors.setSpeeds(106, 100);
551
+    motors.setSpeeds(104, 100);
518 552
     lastUpdate = millis();
519 553
     TimeUpdate();
520 554
     while(eventTime < 1000)
@@ -547,7 +581,7 @@ void Abbiegen()
547 581
       GyroUpdate();
548 582
       EncoderUpdate();
549 583
       LineUpdate();
550
-      motors.setSpeeds(106, 25);
584
+      motors.setSpeeds(104, 25);
551 585
       if(lineValue[0] > 150 && lineValue[0] < 500) break;
552 586
     }
553 587
     GyroUpdate();
@@ -558,10 +592,10 @@ void Abbiegen()
558 592
       GyroUpdate();
559 593
       LineUpdate();
560 594
       if(eventTime > 3000) break;
561
-      if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(106, 0);
595
+      if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(104, 0);
562 596
       //else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) motors.setSpeeds(-SLOWSPEEDLEFT, -SLOWSPEEDRIGHT);
563
-      else if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(106, 50);
564
-      else motors.setSpeeds(106, 25);
597
+      else if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(104, 50);
598
+      else motors.setSpeeds(104, 25);
565 599
     }
566 600
   }
567 601
 
@@ -569,7 +603,7 @@ void Abbiegen()
569 603
   else
570 604
   {
571 605
     //Serial1.println("nicht Abbiegen");
572
-    motors.setSpeeds(106, 100);
606
+    motors.setSpeeds(104, 100);
573 607
     lastUpdate = millis();
574 608
     TimeUpdate();
575 609
     while(eventTime < 1000)
@@ -586,17 +620,20 @@ void Abbiegen()
586 620
 //Funktion Spurhalten
587 621
 void Spurhalten()
588 622
 {
623
+  uint16_t StartTime = millis();
624
+  uint16_t Update = millis();
625
+  uint16_t Time = Update - StartTime;
626
+
589 627
   //linke Linie erreicht, nach rechts fahren
590 628
   if(lineValue[0] > 150 && lineValue[0] < 500)
591 629
   {
592 630
     ledYellow(1);
593 631
     //Serial1.println("Spur nach rechts korrigieren");  
594
-    motors.setSpeeds(106/eventSpeed, 25/eventSpeed);
595
-    lastUpdate = millis();
596
-    TimeUpdate();
597
-    while(eventTime < 100)
632
+    motors.setSpeeds(104/eventSpeed, 25/eventSpeed);
633
+    while(Time < 100)
598 634
     {
599
-      TimeUpdate();
635
+      Update = millis();
636
+      Time = Update - StartTime;
600 637
       LineUpdate();
601 638
       if(lineValue[2] > 120) break;
602 639
     }
@@ -607,12 +644,11 @@ void Spurhalten()
607 644
   {
608 645
     ledYellow(1);
609 646
     //Serial1.println("Spur nach links korrigieren");  
610
-    motors.setSpeeds(27/eventSpeed, 100/eventSpeed);
611
-    lastUpdate = millis();
612
-    TimeUpdate();
613
-    while(eventTime < 100)
647
+    motors.setSpeeds(26/eventSpeed, 100/eventSpeed);
648
+    while(Time < 100)
614 649
     {
615
-      TimeUpdate();
650
+      Update = millis();
651
+      Time = Update - StartTime;
616 652
       LineUpdate();
617 653
       if(lineValue[0] > 150) break;
618 654
     }
@@ -622,7 +658,7 @@ void Spurhalten()
622 658
   else
623 659
   {
624 660
     ledGreen(1);
625
-    motors.setSpeeds(106/eventSpeed, 100/eventSpeed);
661
+    motors.setSpeeds(104/eventSpeed, 100/eventSpeed);
626 662
   }
627 663
 }
628 664
 
@@ -637,7 +673,7 @@ void Spurfinden()
637 673
   {
638 674
     TimeUpdate();
639 675
     LineUpdate();
640
-    motors.setSpeeds(-106, -100);
676
+    motors.setSpeeds(-104, -100);
641 677
     if(eventTime > 3000) break;
642 678
   }
643 679
   //Serial1.println("Spur gefunden"); 
@@ -695,8 +731,8 @@ void loop()
695 731
     eventSpeed = 1.0;
696 732
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
697 733
     if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
698
-    else if((lineValue[0] > 500 && lineValue[0] < 1400) && (lineValue[1] > 300 && lineValue[1] < 700)) Abbiegen();
699
-    else if((lineValue[2] > 500 && lineValue[2] < 1400) && (lineValue[1] > 300 && lineValue[1] < 700)) Abbiegen();
734
+    else if((lineValue[0] > 500 && lineValue[0] < 1600) && (lineValue[1] > 300 && lineValue[1] < 800)) Abbiegen();
735
+    else if((lineValue[2] > 500 && lineValue[2] < 1600) && (lineValue[1] > 300 && lineValue[1] < 800)) Abbiegen();
700 736
     else if(lineValue[1] > 100 && lineValue[1] < 300) Spurfinden();
701 737
     else Spurhalten();
702 738
   }

+ 88 - 60
ArduinoOutput/sketch/Hauptprojekt.ino.cpp

@@ -2,19 +2,21 @@
2 2
 #line 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
3 3
 #line 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
4 4
 //Verfassser: Felix Stange, 4056379, MET2016 
5
-//Datum: erstellt am 19.07.2017, zuletzt geändert am 04.05.2018 
6
-//Projektbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
7
-//der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
8
-//Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
9
-//dennoch zu einer Kollision, wird diese durch den Beschleunigungssensor (LSM303) erkannt. 
10
-//Für den Überholvorgang werden die seitlichen Abstandssensoren und der Drehbewegungssensor (L3G) 
11
-//genutzt. Mithilfe der Quadraturencoder in den Motoren können Wegstrecken vermessen werden. 
12
-//Der Zumo kommuniziert über ein Bluetooth-Modul (HC-05) mit anderen Geräten. Die 
13
-//Kommunikation erfolgt seriell ('SERIAL' für USB, 'SERIAL1' für Bluetooth). 
14
-//Das LCD kann bei Bluetoothnutzung nicht verwendet werden. 
5
+//Datum: erstellt am 19.07.2017, zuletzt geändert am 08.05.2018 
6
+//Projektthema: Untersuchungen und Implementierung eines automatisierten Fahrens mittels Pololu Zumo
7
+/*Kurzbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
8
+der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
9
+Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
10
+dennoch zu einer Kollision, wird diese durch den Beschleunigungssensor (LSM303) erkannt. 
11
+Für den Überholvorgang werden die seitlichen Abstandssensoren und der Drehbewegungssensor (L3G) 
12
+genutzt. Mithilfe der Quadraturencoder in den Motoren können Wegstrecken vermessen werden. 
13
+Für die Filterung der Messwerte werden Medianfilter genutzt. Der Zumo kommuniziert über ein 
14
+Bluetooth-Modul (HC-05) mit anderen Geräten. Die Kommunikation erfolgt seriell ('SERIAL' für USB, 
15
+'SERIAL1' für Bluetooth). Das LCD kann bei Bluetoothnutzung nicht verwendet werden.*/
15 16
 
16 17
 #include  <Wire.h>
17 18
 #include  <Zumo32U4.h>
19
+#include  <MedianFilter.h>
18 20
 
19 21
 Zumo32U4ProximitySensors  proxSensors;  //Abstandssensoren
20 22
 Zumo32U4LineSensors       lineSensors;  //Liniensensoren
@@ -24,6 +26,14 @@ Zumo32U4Encoders          encoders;     //Motorencoder
24 26
 LSM303                    compass;      //Beschleunigungssensor x-Achse
25 27
 L3G                       gyro;         //Drehbewegungssensor z-Achse
26 28
 
29
+MedianFilter LineFilter0(3, 0);         //erstellen der Filter für Liniensensoren
30
+MedianFilter LineFilter1(3, 0);         //Medianfilter geben mittleren Wert einer Reihe aus
31
+MedianFilter LineFilter2(3, 0);         //Fenstergröße: 3, Basiswerte: 0 0 0
32
+MedianFilter ProxFilter0(3, 0);         //erstellen der Filter für Abstandssensoren
33
+MedianFilter ProxFilter1(3, 0);
34
+MedianFilter ProxFilter2(3, 0);
35
+MedianFilter ProxFilter3(3, 0);
36
+
27 37
 #define   MARKLINE0       150
28 38
 #define   MARKLINE1       100
29 39
 #define   MARKLINE2       120
@@ -31,9 +41,9 @@ L3G                       gyro;         //Drehbewegungssensor z-Achse
31 41
 #define   SIGN1           300
32 42
 #define   SIGN2           500
33 43
 #define   MAXSPEED        400
34
-#define   FULLSPEEDLEFT   106
35
-#define   HALFSPEEDLEFT   53
36
-#define   SLOWSPEEDLEFT   27
44
+#define   FULLSPEEDLEFT   104
45
+#define   HALFSPEEDLEFT   52
46
+#define   SLOWSPEEDLEFT   26
37 47
 #define   FULLSPEEDRIGHT  100
38 48
 #define   HALFSPEEDRIGHT  50
39 49
 #define   SLOWSPEEDRIGHT  25
@@ -68,47 +78,47 @@ bool      alarm = false;                //zeigt Manöver abhängig von btData
68 78
 /*-----------------------------------------------------------------*/
69 79
 
70 80
 //Setup Bluetoothverbindung
71
-#line 68 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
81
+#line 78 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
72 82
 void BlueSetup();
73
-#line 77 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
83
+#line 87 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
74 84
 void LineSetup();
75
-#line 106 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
85
+#line 116 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
76 86
 void ProxSetup();
77
-#line 112 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
87
+#line 122 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
78 88
 void GyroSetup();
79
-#line 145 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
89
+#line 155 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
80 90
 void CompassSetup();
81
-#line 176 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
91
+#line 186 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
82 92
 void setup();
83
-#line 202 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
93
+#line 212 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
84 94
 void TimeUpdate();
85
-#line 208 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
95
+#line 218 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
86 96
 void LoopTiming();
87
-#line 252 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
88
-void ProxUpdate();
89 97
 #line 262 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
90
-void LineUpdate();
98
+void ProxUpdate();
91 99
 #line 272 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
100
+void LineUpdate();
101
+#line 282 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
92 102
 void GyroUpdate();
93
-#line 285 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
103
+#line 295 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
94 104
 void CompassUpdate();
95
-#line 298 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
105
+#line 308 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
96 106
 void EncoderUpdate();
97
-#line 309 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
107
+#line 319 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
98 108
 void Kontaktvermeiden();
99
-#line 328 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
109
+#line 338 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
100 110
 void Hindernisumfahren();
101
-#line 438 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
111
+#line 464 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
102 112
 void Abbiegen();
103
-#line 599 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
113
+#line 625 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
104 114
 void Spurhalten();
105
-#line 642 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
115
+#line 670 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
106 116
 void Spurfinden();
107
-#line 660 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
117
+#line 688 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
108 118
 void SerielleAusgabe();
109
-#line 675 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
119
+#line 703 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
110 120
 void loop();
111
-#line 68 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
121
+#line 78 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
112 122
 void BlueSetup()
113 123
 {
114 124
   Serial1.begin(9600);                              //Initialisierung mit Datengeschwindigkeit(Baud)
@@ -296,20 +306,20 @@ void LoopTiming()
296 306
 void ProxUpdate()
297 307
 {
298 308
   proxSensors.read();
299
-  proxValue[0] = proxSensors.countsLeftWithLeftLeds();
300
-  proxValue[1] = proxSensors.countsFrontWithLeftLeds();
301
-  proxValue[2] = proxSensors.countsFrontWithRightLeds();  
302
-  proxValue[3] = proxSensors.countsRightWithRightLeds(); 
309
+  proxValue[0] = ProxFilter0.in(proxSensors.countsLeftWithLeftLeds());
310
+  proxValue[1] = ProxFilter1.in(proxSensors.countsFrontWithLeftLeds());
311
+  proxValue[2] = ProxFilter2.in(proxSensors.countsFrontWithRightLeds());  
312
+  proxValue[3] = ProxFilter3.in(proxSensors.countsRightWithRightLeds()); 
303 313
 }
304 314
 
305 315
 //Update Liniensensoren
306 316
 void LineUpdate()
307 317
 {
308 318
   uint16_t  lineRaw[3];
309
-  lineSensors.read(lineRaw);
310
-  lineValue[0] = lineRaw[0] - lineOffset[0];
311
-  lineValue[1] = lineRaw[1] - lineOffset[1];
312
-  lineValue[2] = lineRaw[2] - lineOffset[2];
319
+  lineSensors.read(lineRaw);                                  //lese Messwerte der Liniensensoren aus
320
+  lineValue[0] = LineFilter0.in(lineRaw[0] - lineOffset[0]);  //ziehe Offsetwerte von Messwerten ab und gib diese in Filter ein
321
+  lineValue[1] = LineFilter1.in(lineRaw[1] - lineOffset[1]);  //erhält neue mittlere Werte der Filter
322
+  lineValue[2] = LineFilter2.in(lineRaw[2] - lineOffset[2]);  //"LineFilter.out" um gefilterte Werte auszugeben ohne neue Werte einzugeben
313 323
 }
314 324
 
315 325
 //Update Drehbewegungssensor
@@ -380,6 +390,13 @@ void Hindernisumfahren()
380 390
   turnAngle = 0;                    
381 391
   rotationAngle = 0;                                                      
382 392
   GyroUpdate();                                                 
393
+  while(rotationAngle < 20)          
394
+  {
395
+    GyroUpdate();  
396
+    LineUpdate();
397
+    motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
398
+  }
399
+  GyroUpdate();                                                 
383 400
   while(rotationAngle < 45)          
384 401
   {
385 402
     GyroUpdate();  
@@ -415,14 +432,16 @@ void Hindernisumfahren()
415 432
     //Schritt 2: Hindernis passieren
416 433
     //Serial1.println("Aufholen"); 
417 434
     lastUpdate = millis();
418
-    while(proxValue[3] < 6 && eventTime < 3000)
435
+    while(proxValue[3] < 6)
419 436
     {
420
-      TimeUpdate();
421 437
       ProxUpdate();
422 438
       LineUpdate();
423 439
       Spurhalten();
440
+      TimeUpdate();
441
+      //Serial1.println(eventTime);
442
+      if(eventTime > 3000) break;
424 443
     }
425
-    //Serial1.println("Überholen"); 
444
+    //Serial1.println("Vorbeifahren"); 
426 445
     ProxUpdate(); 
427 446
     while(proxValue[3] == 6)
428 447
     {
@@ -435,10 +454,10 @@ void Hindernisumfahren()
435 454
     TimeUpdate();
436 455
     while(eventTime < 3000)
437 456
     {
438
-      //Serial1.println(eventTime); 
439
-      TimeUpdate();
440 457
       LineUpdate();
441 458
       Spurhalten();
459
+      TimeUpdate();
460
+      //Serial1.println(eventTime);
442 461
     }
443 462
   //}
444 463
   
@@ -447,6 +466,13 @@ void Hindernisumfahren()
447 466
   turnAngle = 0;                
448 467
   rotationAngle = 0;                                                      
449 468
   GyroUpdate();                                                 
469
+  while(rotationAngle > -20)          
470
+  {
471
+    GyroUpdate();  
472
+    LineUpdate();
473
+    motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
474
+  }
475
+  GyroUpdate();                                                 
450 476
   while(rotationAngle > -45)          
451 477
   {
452 478
     GyroUpdate();  
@@ -489,9 +515,9 @@ void Abbiegen()
489 515
   LineUpdate(); 
490 516
   bool  leftCode;                                                         //links => 1
491 517
   bool  rightCode;                                                        //rechts => 2
492
-  if((lineValue[0] > SIGN0 && lineValue[0] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) leftCode = true;
518
+  if((lineValue[0] > SIGN0 && lineValue[0] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) leftCode = true;
493 519
   else leftCode = false;
494
-  if((lineValue[2] > SIGN2 && lineValue[2] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) rightCode = true;
520
+  if((lineValue[2] > SIGN2 && lineValue[2] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) rightCode = true;
495 521
   else rightCode = false;
496 522
 
497 523
   //Zufallszahl erzeugen
@@ -517,7 +543,7 @@ void Abbiegen()
517 543
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
518 544
     lastUpdate = millis();
519 545
     TimeUpdate();
520
-    while(eventTime < 300)
546
+    while(eventTime < 1000)
521 547
     {
522 548
       TimeUpdate();
523 549
       motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
@@ -642,17 +668,20 @@ void Abbiegen()
642 668
 //Funktion Spurhalten
643 669
 void Spurhalten()                                                   
644 670
 {
671
+  uint16_t StartTime = millis();
672
+  uint16_t Update = millis();
673
+  uint16_t Time = Update - StartTime;
674
+
645 675
   //linke Linie erreicht, nach rechts fahren
646 676
   if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0)                      
647 677
   {
648 678
     ledYellow(1); 
649 679
     //Serial1.println("Spur nach rechts korrigieren");  
650 680
     motors.setSpeeds(FULLSPEEDLEFT/eventSpeed, SLOWSPEEDRIGHT/eventSpeed);
651
-    lastUpdate = millis();
652
-    TimeUpdate();
653
-    while(eventTime < 100)
681
+    while(Time < 100)
654 682
     {
655
-      TimeUpdate();
683
+      Update = millis();
684
+      Time = Update - StartTime;
656 685
       LineUpdate();
657 686
       if(lineValue[2] > MARKLINE2) break;
658 687
     }   
@@ -664,11 +693,10 @@ void Spurhalten()
664 693
     ledYellow(1); 
665 694
     //Serial1.println("Spur nach links korrigieren");  
666 695
     motors.setSpeeds(SLOWSPEEDLEFT/eventSpeed, FULLSPEEDRIGHT/eventSpeed);   
667
-    lastUpdate = millis();
668
-    TimeUpdate();
669
-    while(eventTime < 100)
696
+    while(Time < 100)
670 697
     {
671
-      TimeUpdate();
698
+      Update = millis();
699
+      Time = Update - StartTime;
672 700
       LineUpdate();
673 701
       if(lineValue[0] > MARKLINE0) break;
674 702
     }   
@@ -751,8 +779,8 @@ void loop()
751 779
     eventSpeed = 1.0;
752 780
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
753 781
     if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
754
-    else if((lineValue[0] > SIGN0 && lineValue[0] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) Abbiegen();
755
-    else if((lineValue[2] > SIGN2 && lineValue[2] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) Abbiegen();
782
+    else if((lineValue[0] > SIGN0 && lineValue[0] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
783
+    else if((lineValue[2] > SIGN2 && lineValue[2] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
756 784
     else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) Spurfinden();
757 785
     else Spurhalten();
758 786
   }

+ 2 - 1
ArduinoOutput/sketch/Hauptprojekt.ino.cpp.d

@@ -31,4 +31,5 @@ c:\Users\Carolin\Downloads\VSCode\Zumo32U4\ArduinoOutput\sketch\Hauptprojekt.ino
31 31
  C:\Users\Carolin\Documents\Arduino\libraries\Zumo32U4/Zumo32U4LineSensors.h \
32 32
  C:\Users\Carolin\Documents\Arduino\libraries\Zumo32U4/QTRSensors.h \
33 33
  C:\Users\Carolin\Documents\Arduino\libraries\Zumo32U4/Zumo32U4Motors.h \
34
- C:\Users\Carolin\Documents\Arduino\libraries\Zumo32U4/Zumo32U4ProximitySensors.h
34
+ C:\Users\Carolin\Documents\Arduino\libraries\Zumo32U4/Zumo32U4ProximitySensors.h \
35
+ C:\Users\Carolin\Documents\Arduino\libraries\MedianFilter/MedianFilter.h

BIN
ArduinoOutput/sketch/Hauptprojekt.ino.cpp.o


+ 67 - 39
Zumo32U4/Hauptprojekt/Hauptprojekt.ino

@@ -1,17 +1,19 @@
1 1
 //Verfassser: Felix Stange, 4056379, MET2016 
2
-//Datum: erstellt am 19.07.2017, zuletzt geändert am 04.05.2018 
3
-//Projektbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
4
-//der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
5
-//Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
6
-//dennoch zu einer Kollision, wird diese durch den Beschleunigungssensor (LSM303) erkannt. 
7
-//Für den Überholvorgang werden die seitlichen Abstandssensoren und der Drehbewegungssensor (L3G) 
8
-//genutzt. Mithilfe der Quadraturencoder in den Motoren können Wegstrecken vermessen werden. 
9
-//Der Zumo kommuniziert über ein Bluetooth-Modul (HC-05) mit anderen Geräten. Die 
10
-//Kommunikation erfolgt seriell ('SERIAL' für USB, 'SERIAL1' für Bluetooth). 
11
-//Das LCD kann bei Bluetoothnutzung nicht verwendet werden. 
2
+//Datum: erstellt am 19.07.2017, zuletzt geändert am 08.05.2018 
3
+//Projektthema: Untersuchungen und Implementierung eines automatisierten Fahrens mittels Pololu Zumo
4
+/*Kurzbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
5
+der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
6
+Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
7
+dennoch zu einer Kollision, wird diese durch den Beschleunigungssensor (LSM303) erkannt. 
8
+Für den Überholvorgang werden die seitlichen Abstandssensoren und der Drehbewegungssensor (L3G) 
9
+genutzt. Mithilfe der Quadraturencoder in den Motoren können Wegstrecken vermessen werden. 
10
+Für die Filterung der Messwerte werden Medianfilter genutzt. Der Zumo kommuniziert über ein 
11
+Bluetooth-Modul (HC-05) mit anderen Geräten. Die Kommunikation erfolgt seriell ('SERIAL' für USB, 
12
+'SERIAL1' für Bluetooth). Das LCD kann bei Bluetoothnutzung nicht verwendet werden.*/
12 13
 
13 14
 #include  <Wire.h>
14 15
 #include  <Zumo32U4.h>
16
+#include  <MedianFilter.h>
15 17
 
16 18
 Zumo32U4ProximitySensors  proxSensors;  //Abstandssensoren
17 19
 Zumo32U4LineSensors       lineSensors;  //Liniensensoren
@@ -21,6 +23,14 @@ Zumo32U4Encoders          encoders;     //Motorencoder
21 23
 LSM303                    compass;      //Beschleunigungssensor x-Achse
22 24
 L3G                       gyro;         //Drehbewegungssensor z-Achse
23 25
 
26
+MedianFilter LineFilter0(3, 0);         //erstellen der Filter für Liniensensoren
27
+MedianFilter LineFilter1(3, 0);         //Medianfilter geben mittleren Wert einer Reihe aus
28
+MedianFilter LineFilter2(3, 0);         //Fenstergröße: 3, Basiswerte: 0 0 0
29
+MedianFilter ProxFilter0(3, 0);         //erstellen der Filter für Abstandssensoren
30
+MedianFilter ProxFilter1(3, 0);
31
+MedianFilter ProxFilter2(3, 0);
32
+MedianFilter ProxFilter3(3, 0);
33
+
24 34
 #define   MARKLINE0       150
25 35
 #define   MARKLINE1       100
26 36
 #define   MARKLINE2       120
@@ -28,9 +38,9 @@ L3G                       gyro;         //Drehbewegungssensor z-Achse
28 38
 #define   SIGN1           300
29 39
 #define   SIGN2           500
30 40
 #define   MAXSPEED        400
31
-#define   FULLSPEEDLEFT   106
32
-#define   HALFSPEEDLEFT   53
33
-#define   SLOWSPEEDLEFT   27
41
+#define   FULLSPEEDLEFT   104
42
+#define   HALFSPEEDLEFT   52
43
+#define   SLOWSPEEDLEFT   26
34 44
 #define   FULLSPEEDRIGHT  100
35 45
 #define   HALFSPEEDRIGHT  50
36 46
 #define   SLOWSPEEDRIGHT  25
@@ -252,20 +262,20 @@ void LoopTiming()
252 262
 void ProxUpdate()
253 263
 {
254 264
   proxSensors.read();
255
-  proxValue[0] = proxSensors.countsLeftWithLeftLeds();
256
-  proxValue[1] = proxSensors.countsFrontWithLeftLeds();
257
-  proxValue[2] = proxSensors.countsFrontWithRightLeds();  
258
-  proxValue[3] = proxSensors.countsRightWithRightLeds(); 
265
+  proxValue[0] = ProxFilter0.in(proxSensors.countsLeftWithLeftLeds());
266
+  proxValue[1] = ProxFilter1.in(proxSensors.countsFrontWithLeftLeds());
267
+  proxValue[2] = ProxFilter2.in(proxSensors.countsFrontWithRightLeds());  
268
+  proxValue[3] = ProxFilter3.in(proxSensors.countsRightWithRightLeds()); 
259 269
 }
260 270
 
261 271
 //Update Liniensensoren
262 272
 void LineUpdate()
263 273
 {
264 274
   uint16_t  lineRaw[3];
265
-  lineSensors.read(lineRaw);
266
-  lineValue[0] = lineRaw[0] - lineOffset[0];
267
-  lineValue[1] = lineRaw[1] - lineOffset[1];
268
-  lineValue[2] = lineRaw[2] - lineOffset[2];
275
+  lineSensors.read(lineRaw);                                  //lese Messwerte der Liniensensoren aus
276
+  lineValue[0] = LineFilter0.in(lineRaw[0] - lineOffset[0]);  //ziehe Offsetwerte von Messwerten ab und gib diese in Filter ein
277
+  lineValue[1] = LineFilter1.in(lineRaw[1] - lineOffset[1]);  //erhält neue mittlere Werte der Filter
278
+  lineValue[2] = LineFilter2.in(lineRaw[2] - lineOffset[2]);  //"LineFilter.out" um gefilterte Werte auszugeben ohne neue Werte einzugeben
269 279
 }
270 280
 
271 281
 //Update Drehbewegungssensor
@@ -336,6 +346,13 @@ void Hindernisumfahren()
336 346
   turnAngle = 0;                    
337 347
   rotationAngle = 0;                                                      
338 348
   GyroUpdate();                                                 
349
+  while(rotationAngle < 20)          
350
+  {
351
+    GyroUpdate();  
352
+    LineUpdate();
353
+    motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
354
+  }
355
+  GyroUpdate();                                                 
339 356
   while(rotationAngle < 45)          
340 357
   {
341 358
     GyroUpdate();  
@@ -371,14 +388,16 @@ void Hindernisumfahren()
371 388
     //Schritt 2: Hindernis passieren
372 389
     //Serial1.println("Aufholen"); 
373 390
     lastUpdate = millis();
374
-    while(proxValue[3] < 6 && eventTime < 3000)
391
+    while(proxValue[3] < 6)
375 392
     {
376
-      TimeUpdate();
377 393
       ProxUpdate();
378 394
       LineUpdate();
379 395
       Spurhalten();
396
+      TimeUpdate();
397
+      //Serial1.println(eventTime);
398
+      if(eventTime > 3000) break;
380 399
     }
381
-    //Serial1.println("Überholen"); 
400
+    //Serial1.println("Vorbeifahren"); 
382 401
     ProxUpdate(); 
383 402
     while(proxValue[3] == 6)
384 403
     {
@@ -391,10 +410,10 @@ void Hindernisumfahren()
391 410
     TimeUpdate();
392 411
     while(eventTime < 3000)
393 412
     {
394
-      //Serial1.println(eventTime); 
395
-      TimeUpdate();
396 413
       LineUpdate();
397 414
       Spurhalten();
415
+      TimeUpdate();
416
+      //Serial1.println(eventTime);
398 417
     }
399 418
   //}
400 419
   
@@ -403,6 +422,13 @@ void Hindernisumfahren()
403 422
   turnAngle = 0;                
404 423
   rotationAngle = 0;                                                      
405 424
   GyroUpdate();                                                 
425
+  while(rotationAngle > -20)          
426
+  {
427
+    GyroUpdate();  
428
+    LineUpdate();
429
+    motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
430
+  }
431
+  GyroUpdate();                                                 
406 432
   while(rotationAngle > -45)          
407 433
   {
408 434
     GyroUpdate();  
@@ -445,9 +471,9 @@ void Abbiegen()
445 471
   LineUpdate(); 
446 472
   bool  leftCode;                                                         //links => 1
447 473
   bool  rightCode;                                                        //rechts => 2
448
-  if((lineValue[0] > SIGN0 && lineValue[0] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) leftCode = true;
474
+  if((lineValue[0] > SIGN0 && lineValue[0] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) leftCode = true;
449 475
   else leftCode = false;
450
-  if((lineValue[2] > SIGN2 && lineValue[2] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) rightCode = true;
476
+  if((lineValue[2] > SIGN2 && lineValue[2] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) rightCode = true;
451 477
   else rightCode = false;
452 478
 
453 479
   //Zufallszahl erzeugen
@@ -473,7 +499,7 @@ void Abbiegen()
473 499
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
474 500
     lastUpdate = millis();
475 501
     TimeUpdate();
476
-    while(eventTime < 300)
502
+    while(eventTime < 1000)
477 503
     {
478 504
       TimeUpdate();
479 505
       motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
@@ -598,17 +624,20 @@ void Abbiegen()
598 624
 //Funktion Spurhalten
599 625
 void Spurhalten()                                                   
600 626
 {
627
+  uint16_t StartTime = millis();
628
+  uint16_t Update = millis();
629
+  uint16_t Time = Update - StartTime;
630
+
601 631
   //linke Linie erreicht, nach rechts fahren
602 632
   if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0)                      
603 633
   {
604 634
     ledYellow(1); 
605 635
     //Serial1.println("Spur nach rechts korrigieren");  
606 636
     motors.setSpeeds(FULLSPEEDLEFT/eventSpeed, SLOWSPEEDRIGHT/eventSpeed);
607
-    lastUpdate = millis();
608
-    TimeUpdate();
609
-    while(eventTime < 100)
637
+    while(Time < 100)
610 638
     {
611
-      TimeUpdate();
639
+      Update = millis();
640
+      Time = Update - StartTime;
612 641
       LineUpdate();
613 642
       if(lineValue[2] > MARKLINE2) break;
614 643
     }   
@@ -620,11 +649,10 @@ void Spurhalten()
620 649
     ledYellow(1); 
621 650
     //Serial1.println("Spur nach links korrigieren");  
622 651
     motors.setSpeeds(SLOWSPEEDLEFT/eventSpeed, FULLSPEEDRIGHT/eventSpeed);   
623
-    lastUpdate = millis();
624
-    TimeUpdate();
625
-    while(eventTime < 100)
652
+    while(Time < 100)
626 653
     {
627
-      TimeUpdate();
654
+      Update = millis();
655
+      Time = Update - StartTime;
628 656
       LineUpdate();
629 657
       if(lineValue[0] > MARKLINE0) break;
630 658
     }   
@@ -707,8 +735,8 @@ void loop()
707 735
     eventSpeed = 1.0;
708 736
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
709 737
     if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
710
-    else if((lineValue[0] > SIGN0 && lineValue[0] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) Abbiegen();
711
-    else if((lineValue[2] > SIGN2 && lineValue[2] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) Abbiegen();
738
+    else if((lineValue[0] > SIGN0 && lineValue[0] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
739
+    else if((lineValue[2] > SIGN2 && lineValue[2] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
712 740
     else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) Spurfinden();
713 741
     else Spurhalten();
714 742
   }