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

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
 # 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
1
 # 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
2
 # 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
2
 # 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
3
 //Verfassser: Felix Stange, 4056379, MET2016 
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
 # 15 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino" 2
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
 Zumo32U4ProximitySensors proxSensors; //Abstandssensoren
28
 Zumo32U4ProximitySensors proxSensors; //Abstandssensoren
19
 Zumo32U4LineSensors lineSensors; //Liniensensoren
29
 Zumo32U4LineSensors lineSensors; //Liniensensoren
22
 Zumo32U4Encoders encoders; //Motorencoder
32
 Zumo32U4Encoders encoders; //Motorencoder
23
 LSM303 compass; //Beschleunigungssensor x-Achse
33
 LSM303 compass; //Beschleunigungssensor x-Achse
24
 L3G gyro; //Drehbewegungssensor z-Achse
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
 int16_t lineValue[3]; //Liniensensoren
44
 int16_t lineValue[3]; //Liniensensoren
27
 uint16_t lineOffset[3]; //von links (0) nach rechts (2)
45
 uint16_t lineOffset[3]; //von links (0) nach rechts (2)
28
 
46
 
71
   uint32_t total[3] = {0, 0, 0};
89
   uint32_t total[3] = {0, 0, 0};
72
   for(uint8_t i = 0; i < 120; i++)
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
     lineSensors.read(lineOffset);
94
     lineSensors.read(lineOffset);
77
     total[0] += lineOffset[0];
95
     total[0] += lineOffset[0];
78
     total[1] += lineOffset[1];
96
     total[1] += lineOffset[1];
240
 void ProxUpdate()
258
 void ProxUpdate()
241
 {
259
 {
242
   proxSensors.read();
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
 //Update Liniensensoren
267
 //Update Liniensensoren
250
 void LineUpdate()
268
 void LineUpdate()
251
 {
269
 {
252
   uint16_t lineRaw[3];
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
 //Update Drehbewegungssensor
277
 //Update Drehbewegungssensor
304
   while(proxValue[1] == 0 || proxValue[2] == 0)
322
   while(proxValue[1] == 0 || proxValue[2] == 0)
305
   {
323
   {
306
     ProxUpdate();
324
     ProxUpdate();
307
-    motors.setSpeeds(-53, -50);
325
+    motors.setSpeeds(-52, -50);
308
     if(lineValue[0] > 150 || lineValue[2] > 120) break;
326
     if(lineValue[0] > 150 || lineValue[2] > 120) break;
309
   }
327
   }
310
   motors.setSpeeds(0, 0);
328
   motors.setSpeeds(0, 0);
324
   turnAngle = 0;
342
   turnAngle = 0;
325
   rotationAngle = 0;
343
   rotationAngle = 0;
326
   GyroUpdate();
344
   GyroUpdate();
345
+  while(rotationAngle < 20)
346
+  {
347
+    GyroUpdate();
348
+    LineUpdate();
349
+    motors.setSpeeds(26, 100);
350
+  }
351
+  GyroUpdate();
327
   while(rotationAngle < 45)
352
   while(rotationAngle < 45)
328
   {
353
   {
329
     GyroUpdate();
354
     GyroUpdate();
330
     LineUpdate();
355
     LineUpdate();
331
-    motors.setSpeeds(27, 100);
356
+    motors.setSpeeds(26, 100);
332
     if(lineValue[2] > 120 && lineValue[2] < 500) break;
357
     if(lineValue[2] > 120 && lineValue[2] < 500) break;
333
   }
358
   }
334
   //geradeaus über Mittellinie fahren
359
   //geradeaus über Mittellinie fahren
336
   while(lineValue[2] < 120)
361
   while(lineValue[2] < 120)
337
   {
362
   {
338
     LineUpdate();
363
     LineUpdate();
339
-    motors.setSpeeds(106, 100);
364
+    motors.setSpeeds(104, 100);
340
     //if(lineValue[0] > MARKLINE0) break;
365
     //if(lineValue[0] > MARKLINE0) break;
341
   }
366
   }
342
   //rechts drehen
367
   //rechts drehen
345
   {
370
   {
346
     GyroUpdate();
371
     GyroUpdate();
347
     LineUpdate();
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
   //geradeaus fahren
377
   //geradeaus fahren
353
-  motors.setSpeeds(106, 100);
378
+  motors.setSpeeds(104, 100);
354
 
379
 
355
   //Gegenverkehr beachten
380
   //Gegenverkehr beachten
356
   ProxUpdate();
381
   ProxUpdate();
359
     //Schritt 2: Hindernis passieren
384
     //Schritt 2: Hindernis passieren
360
     //Serial1.println("Aufholen"); 
385
     //Serial1.println("Aufholen"); 
361
     lastUpdate = millis();
386
     lastUpdate = millis();
362
-    while(proxValue[3] < 6 && eventTime < 3000)
387
+    while(proxValue[3] < 6)
363
     {
388
     {
364
-      TimeUpdate();
365
       ProxUpdate();
389
       ProxUpdate();
366
       LineUpdate();
390
       LineUpdate();
367
       Spurhalten();
391
       Spurhalten();
392
+      TimeUpdate();
393
+      //Serial1.println(eventTime);
394
+      if(eventTime > 3000) break;
368
     }
395
     }
369
-    //Serial1.println("Überholen"); 
396
+    //Serial1.println("Vorbeifahren"); 
370
     ProxUpdate();
397
     ProxUpdate();
371
     while(proxValue[3] == 6)
398
     while(proxValue[3] == 6)
372
     {
399
     {
379
     TimeUpdate();
406
     TimeUpdate();
380
     while(eventTime < 3000)
407
     while(eventTime < 3000)
381
     {
408
     {
382
-      //Serial1.println(eventTime); 
383
-      TimeUpdate();
384
       LineUpdate();
409
       LineUpdate();
385
       Spurhalten();
410
       Spurhalten();
411
+      TimeUpdate();
412
+      //Serial1.println(eventTime);
386
     }
413
     }
387
   //}
414
   //}
388
 
415
 
391
   turnAngle = 0;
418
   turnAngle = 0;
392
   rotationAngle = 0;
419
   rotationAngle = 0;
393
   GyroUpdate();
420
   GyroUpdate();
421
+  while(rotationAngle > -20)
422
+  {
423
+    GyroUpdate();
424
+    LineUpdate();
425
+    motors.setSpeeds(104, 25);
426
+  }
427
+  GyroUpdate();
394
   while(rotationAngle > -45)
428
   while(rotationAngle > -45)
395
   {
429
   {
396
     GyroUpdate();
430
     GyroUpdate();
397
     LineUpdate();
431
     LineUpdate();
398
-    motors.setSpeeds(106, 25);
432
+    motors.setSpeeds(104, 25);
399
     if(lineValue[0] > 150 && lineValue[0] < 500) break;
433
     if(lineValue[0] > 150 && lineValue[0] < 500) break;
400
   }
434
   }
401
   //geradeaus über Mittellinie fahren
435
   //geradeaus über Mittellinie fahren
403
   while(lineValue[0] < 150)
437
   while(lineValue[0] < 150)
404
   {
438
   {
405
     LineUpdate();
439
     LineUpdate();
406
-    motors.setSpeeds(106, 100);
440
+    motors.setSpeeds(104, 100);
407
     //if(lineValue[0] > MARKLINE0) break;
441
     //if(lineValue[0] > MARKLINE0) break;
408
   }
442
   }
409
   //links drehen
443
   //links drehen
413
     GyroUpdate();
447
     GyroUpdate();
414
     LineUpdate();
448
     LineUpdate();
415
     if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(0, 100);
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
   //geradeaus fahren
453
   //geradeaus fahren
420
   //Serial1.println("Umfahren beendet");
454
   //Serial1.println("Umfahren beendet");
421
   Serial1.print(0);
455
   Serial1.print(0);
422
-  motors.setSpeeds(106, 100);
456
+  motors.setSpeeds(104, 100);
423
 }
457
 }
424
 
458
 
425
 //Funktion Abbiegen
459
 //Funktion Abbiegen
433
   LineUpdate();
467
   LineUpdate();
434
   bool leftCode; //links => 1
468
   bool leftCode; //links => 1
435
   bool rightCode; //rechts => 2
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
   else leftCode = false;
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
   else rightCode = false;
473
   else rightCode = false;
440
 
474
 
441
   //Zufallszahl erzeugen
475
   //Zufallszahl erzeugen
458
   {
492
   {
459
     //Serial1.println("links Abbiegen von der Verbindungsstrecke"); 
493
     //Serial1.println("links Abbiegen von der Verbindungsstrecke"); 
460
     //geradeaus zur Mittellinie fahren
494
     //geradeaus zur Mittellinie fahren
461
-    motors.setSpeeds(106, 100 +10);
495
+    motors.setSpeeds(104, 100 +10);
462
     lastUpdate = millis();
496
     lastUpdate = millis();
463
     TimeUpdate();
497
     TimeUpdate();
464
-    while(eventTime < 300)
498
+    while(eventTime < 1000)
465
     {
499
     {
466
       TimeUpdate();
500
       TimeUpdate();
467
-      motors.setSpeeds(106, 100 +10);
501
+      motors.setSpeeds(104, 100 +10);
468
     }
502
     }
469
     LineUpdate();
503
     LineUpdate();
470
     while(lineValue[0] < 150 && lineValue[2] < 120)
504
     while(lineValue[0] < 150 && lineValue[2] < 120)
471
     {
505
     {
472
       LineUpdate();
506
       LineUpdate();
473
-      motors.setSpeeds(106, 100);
507
+      motors.setSpeeds(104, 100);
474
     }
508
     }
475
     //links drehen
509
     //links drehen
476
     turnAngle = 0;
510
     turnAngle = 0;
481
       GyroUpdate();
515
       GyroUpdate();
482
       LineUpdate();
516
       LineUpdate();
483
       if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(0, 100);
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
     //geradeaus fahren
521
     //geradeaus fahren
488
-    motors.setSpeeds(106, 100);
522
+    motors.setSpeeds(104, 100);
489
   }
523
   }
490
 
524
 
491
   //links Abbiegen (vom Rundkurs)
525
   //links Abbiegen (vom Rundkurs)
501
     {
535
     {
502
       GyroUpdate();
536
       GyroUpdate();
503
       EncoderUpdate();
537
       EncoderUpdate();
504
-      motors.setSpeeds(27, 100);
538
+      motors.setSpeeds(26, 100);
505
       //if(driveRotation[1] > 1) break;
539
       //if(driveRotation[1] > 1) break;
506
     }
540
     }
507
     driveRotation[1] = 0;
541
     driveRotation[1] = 0;
510
     {
544
     {
511
       GyroUpdate();
545
       GyroUpdate();
512
       EncoderUpdate();
546
       EncoderUpdate();
513
-      motors.setSpeeds(27, 100);
547
+      motors.setSpeeds(26, 100);
514
       //if(driveRotation[1] > 1) break;
548
       //if(driveRotation[1] > 1) break;
515
     }
549
     }
516
     //geradeaus fahren
550
     //geradeaus fahren
517
-    motors.setSpeeds(106, 100);
551
+    motors.setSpeeds(104, 100);
518
     lastUpdate = millis();
552
     lastUpdate = millis();
519
     TimeUpdate();
553
     TimeUpdate();
520
     while(eventTime < 1000)
554
     while(eventTime < 1000)
547
       GyroUpdate();
581
       GyroUpdate();
548
       EncoderUpdate();
582
       EncoderUpdate();
549
       LineUpdate();
583
       LineUpdate();
550
-      motors.setSpeeds(106, 25);
584
+      motors.setSpeeds(104, 25);
551
       if(lineValue[0] > 150 && lineValue[0] < 500) break;
585
       if(lineValue[0] > 150 && lineValue[0] < 500) break;
552
     }
586
     }
553
     GyroUpdate();
587
     GyroUpdate();
558
       GyroUpdate();
592
       GyroUpdate();
559
       LineUpdate();
593
       LineUpdate();
560
       if(eventTime > 3000) break;
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
       //else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) motors.setSpeeds(-SLOWSPEEDLEFT, -SLOWSPEEDRIGHT);
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
   else
603
   else
570
   {
604
   {
571
     //Serial1.println("nicht Abbiegen");
605
     //Serial1.println("nicht Abbiegen");
572
-    motors.setSpeeds(106, 100);
606
+    motors.setSpeeds(104, 100);
573
     lastUpdate = millis();
607
     lastUpdate = millis();
574
     TimeUpdate();
608
     TimeUpdate();
575
     while(eventTime < 1000)
609
     while(eventTime < 1000)
586
 //Funktion Spurhalten
620
 //Funktion Spurhalten
587
 void Spurhalten()
621
 void Spurhalten()
588
 {
622
 {
623
+  uint16_t StartTime = millis();
624
+  uint16_t Update = millis();
625
+  uint16_t Time = Update - StartTime;
626
+
589
   //linke Linie erreicht, nach rechts fahren
627
   //linke Linie erreicht, nach rechts fahren
590
   if(lineValue[0] > 150 && lineValue[0] < 500)
628
   if(lineValue[0] > 150 && lineValue[0] < 500)
591
   {
629
   {
592
     ledYellow(1);
630
     ledYellow(1);
593
     //Serial1.println("Spur nach rechts korrigieren");  
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
       LineUpdate();
637
       LineUpdate();
601
       if(lineValue[2] > 120) break;
638
       if(lineValue[2] > 120) break;
602
     }
639
     }
607
   {
644
   {
608
     ledYellow(1);
645
     ledYellow(1);
609
     //Serial1.println("Spur nach links korrigieren");  
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
       LineUpdate();
652
       LineUpdate();
617
       if(lineValue[0] > 150) break;
653
       if(lineValue[0] > 150) break;
618
     }
654
     }
622
   else
658
   else
623
   {
659
   {
624
     ledGreen(1);
660
     ledGreen(1);
625
-    motors.setSpeeds(106/eventSpeed, 100/eventSpeed);
661
+    motors.setSpeeds(104/eventSpeed, 100/eventSpeed);
626
   }
662
   }
627
 }
663
 }
628
 
664
 
637
   {
673
   {
638
     TimeUpdate();
674
     TimeUpdate();
639
     LineUpdate();
675
     LineUpdate();
640
-    motors.setSpeeds(-106, -100);
676
+    motors.setSpeeds(-104, -100);
641
     if(eventTime > 3000) break;
677
     if(eventTime > 3000) break;
642
   }
678
   }
643
   //Serial1.println("Spur gefunden"); 
679
   //Serial1.println("Spur gefunden"); 
695
     eventSpeed = 1.0;
731
     eventSpeed = 1.0;
696
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
732
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
697
     if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
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
     else if(lineValue[1] > 100 && lineValue[1] < 300) Spurfinden();
736
     else if(lineValue[1] > 100 && lineValue[1] < 300) Spurfinden();
701
     else Spurhalten();
737
     else Spurhalten();
702
   }
738
   }

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

2
 #line 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
2
 #line 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
3
 #line 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
3
 #line 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
4
 //Verfassser: Felix Stange, 4056379, MET2016 
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
 #include  <Wire.h>
17
 #include  <Wire.h>
17
 #include  <Zumo32U4.h>
18
 #include  <Zumo32U4.h>
19
+#include  <MedianFilter.h>
18
 
20
 
19
 Zumo32U4ProximitySensors  proxSensors;  //Abstandssensoren
21
 Zumo32U4ProximitySensors  proxSensors;  //Abstandssensoren
20
 Zumo32U4LineSensors       lineSensors;  //Liniensensoren
22
 Zumo32U4LineSensors       lineSensors;  //Liniensensoren
24
 LSM303                    compass;      //Beschleunigungssensor x-Achse
26
 LSM303                    compass;      //Beschleunigungssensor x-Achse
25
 L3G                       gyro;         //Drehbewegungssensor z-Achse
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
 #define   MARKLINE0       150
37
 #define   MARKLINE0       150
28
 #define   MARKLINE1       100
38
 #define   MARKLINE1       100
29
 #define   MARKLINE2       120
39
 #define   MARKLINE2       120
31
 #define   SIGN1           300
41
 #define   SIGN1           300
32
 #define   SIGN2           500
42
 #define   SIGN2           500
33
 #define   MAXSPEED        400
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
 #define   FULLSPEEDRIGHT  100
47
 #define   FULLSPEEDRIGHT  100
38
 #define   HALFSPEEDRIGHT  50
48
 #define   HALFSPEEDRIGHT  50
39
 #define   SLOWSPEEDRIGHT  25
49
 #define   SLOWSPEEDRIGHT  25
68
 /*-----------------------------------------------------------------*/
78
 /*-----------------------------------------------------------------*/
69
 
79
 
70
 //Setup Bluetoothverbindung
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
 void BlueSetup();
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
 void LineSetup();
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
 void ProxSetup();
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
 void GyroSetup();
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
 void CompassSetup();
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
 void setup();
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
 void TimeUpdate();
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
 void LoopTiming();
96
 void LoopTiming();
87
-#line 252 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
88
-void ProxUpdate();
89
 #line 262 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
97
 #line 262 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
90
-void LineUpdate();
98
+void ProxUpdate();
91
 #line 272 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
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
 void GyroUpdate();
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
 void CompassUpdate();
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
 void EncoderUpdate();
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
 void Kontaktvermeiden();
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
 void Hindernisumfahren();
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
 void Abbiegen();
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
 void Spurhalten();
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
 void Spurfinden();
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
 void SerielleAusgabe();
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
 void loop();
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
 void BlueSetup()
122
 void BlueSetup()
113
 {
123
 {
114
   Serial1.begin(9600);                              //Initialisierung mit Datengeschwindigkeit(Baud)
124
   Serial1.begin(9600);                              //Initialisierung mit Datengeschwindigkeit(Baud)
296
 void ProxUpdate()
306
 void ProxUpdate()
297
 {
307
 {
298
   proxSensors.read();
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
 //Update Liniensensoren
315
 //Update Liniensensoren
306
 void LineUpdate()
316
 void LineUpdate()
307
 {
317
 {
308
   uint16_t  lineRaw[3];
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
 //Update Drehbewegungssensor
325
 //Update Drehbewegungssensor
380
   turnAngle = 0;                    
390
   turnAngle = 0;                    
381
   rotationAngle = 0;                                                      
391
   rotationAngle = 0;                                                      
382
   GyroUpdate();                                                 
392
   GyroUpdate();                                                 
393
+  while(rotationAngle < 20)          
394
+  {
395
+    GyroUpdate();  
396
+    LineUpdate();
397
+    motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
398
+  }
399
+  GyroUpdate();                                                 
383
   while(rotationAngle < 45)          
400
   while(rotationAngle < 45)          
384
   {
401
   {
385
     GyroUpdate();  
402
     GyroUpdate();  
415
     //Schritt 2: Hindernis passieren
432
     //Schritt 2: Hindernis passieren
416
     //Serial1.println("Aufholen"); 
433
     //Serial1.println("Aufholen"); 
417
     lastUpdate = millis();
434
     lastUpdate = millis();
418
-    while(proxValue[3] < 6 && eventTime < 3000)
435
+    while(proxValue[3] < 6)
419
     {
436
     {
420
-      TimeUpdate();
421
       ProxUpdate();
437
       ProxUpdate();
422
       LineUpdate();
438
       LineUpdate();
423
       Spurhalten();
439
       Spurhalten();
440
+      TimeUpdate();
441
+      //Serial1.println(eventTime);
442
+      if(eventTime > 3000) break;
424
     }
443
     }
425
-    //Serial1.println("Überholen"); 
444
+    //Serial1.println("Vorbeifahren"); 
426
     ProxUpdate(); 
445
     ProxUpdate(); 
427
     while(proxValue[3] == 6)
446
     while(proxValue[3] == 6)
428
     {
447
     {
435
     TimeUpdate();
454
     TimeUpdate();
436
     while(eventTime < 3000)
455
     while(eventTime < 3000)
437
     {
456
     {
438
-      //Serial1.println(eventTime); 
439
-      TimeUpdate();
440
       LineUpdate();
457
       LineUpdate();
441
       Spurhalten();
458
       Spurhalten();
459
+      TimeUpdate();
460
+      //Serial1.println(eventTime);
442
     }
461
     }
443
   //}
462
   //}
444
   
463
   
447
   turnAngle = 0;                
466
   turnAngle = 0;                
448
   rotationAngle = 0;                                                      
467
   rotationAngle = 0;                                                      
449
   GyroUpdate();                                                 
468
   GyroUpdate();                                                 
469
+  while(rotationAngle > -20)          
470
+  {
471
+    GyroUpdate();  
472
+    LineUpdate();
473
+    motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
474
+  }
475
+  GyroUpdate();                                                 
450
   while(rotationAngle > -45)          
476
   while(rotationAngle > -45)          
451
   {
477
   {
452
     GyroUpdate();  
478
     GyroUpdate();  
489
   LineUpdate(); 
515
   LineUpdate(); 
490
   bool  leftCode;                                                         //links => 1
516
   bool  leftCode;                                                         //links => 1
491
   bool  rightCode;                                                        //rechts => 2
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
   else leftCode = false;
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
   else rightCode = false;
521
   else rightCode = false;
496
 
522
 
497
   //Zufallszahl erzeugen
523
   //Zufallszahl erzeugen
517
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
543
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
518
     lastUpdate = millis();
544
     lastUpdate = millis();
519
     TimeUpdate();
545
     TimeUpdate();
520
-    while(eventTime < 300)
546
+    while(eventTime < 1000)
521
     {
547
     {
522
       TimeUpdate();
548
       TimeUpdate();
523
       motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
549
       motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
642
 //Funktion Spurhalten
668
 //Funktion Spurhalten
643
 void Spurhalten()                                                   
669
 void Spurhalten()                                                   
644
 {
670
 {
671
+  uint16_t StartTime = millis();
672
+  uint16_t Update = millis();
673
+  uint16_t Time = Update - StartTime;
674
+
645
   //linke Linie erreicht, nach rechts fahren
675
   //linke Linie erreicht, nach rechts fahren
646
   if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0)                      
676
   if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0)                      
647
   {
677
   {
648
     ledYellow(1); 
678
     ledYellow(1); 
649
     //Serial1.println("Spur nach rechts korrigieren");  
679
     //Serial1.println("Spur nach rechts korrigieren");  
650
     motors.setSpeeds(FULLSPEEDLEFT/eventSpeed, SLOWSPEEDRIGHT/eventSpeed);
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
       LineUpdate();
685
       LineUpdate();
657
       if(lineValue[2] > MARKLINE2) break;
686
       if(lineValue[2] > MARKLINE2) break;
658
     }   
687
     }   
664
     ledYellow(1); 
693
     ledYellow(1); 
665
     //Serial1.println("Spur nach links korrigieren");  
694
     //Serial1.println("Spur nach links korrigieren");  
666
     motors.setSpeeds(SLOWSPEEDLEFT/eventSpeed, FULLSPEEDRIGHT/eventSpeed);   
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
       LineUpdate();
700
       LineUpdate();
673
       if(lineValue[0] > MARKLINE0) break;
701
       if(lineValue[0] > MARKLINE0) break;
674
     }   
702
     }   
751
     eventSpeed = 1.0;
779
     eventSpeed = 1.0;
752
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
780
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
753
     if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
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
     else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) Spurfinden();
784
     else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) Spurfinden();
757
     else Spurhalten();
785
     else Spurhalten();
758
   }
786
   }

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

31
  C:\Users\Carolin\Documents\Arduino\libraries\Zumo32U4/Zumo32U4LineSensors.h \
31
  C:\Users\Carolin\Documents\Arduino\libraries\Zumo32U4/Zumo32U4LineSensors.h \
32
  C:\Users\Carolin\Documents\Arduino\libraries\Zumo32U4/QTRSensors.h \
32
  C:\Users\Carolin\Documents\Arduino\libraries\Zumo32U4/QTRSensors.h \
33
  C:\Users\Carolin\Documents\Arduino\libraries\Zumo32U4/Zumo32U4Motors.h \
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
 //Verfassser: Felix Stange, 4056379, MET2016 
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
 #include  <Wire.h>
14
 #include  <Wire.h>
14
 #include  <Zumo32U4.h>
15
 #include  <Zumo32U4.h>
16
+#include  <MedianFilter.h>
15
 
17
 
16
 Zumo32U4ProximitySensors  proxSensors;  //Abstandssensoren
18
 Zumo32U4ProximitySensors  proxSensors;  //Abstandssensoren
17
 Zumo32U4LineSensors       lineSensors;  //Liniensensoren
19
 Zumo32U4LineSensors       lineSensors;  //Liniensensoren
21
 LSM303                    compass;      //Beschleunigungssensor x-Achse
23
 LSM303                    compass;      //Beschleunigungssensor x-Achse
22
 L3G                       gyro;         //Drehbewegungssensor z-Achse
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
 #define   MARKLINE0       150
34
 #define   MARKLINE0       150
25
 #define   MARKLINE1       100
35
 #define   MARKLINE1       100
26
 #define   MARKLINE2       120
36
 #define   MARKLINE2       120
28
 #define   SIGN1           300
38
 #define   SIGN1           300
29
 #define   SIGN2           500
39
 #define   SIGN2           500
30
 #define   MAXSPEED        400
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
 #define   FULLSPEEDRIGHT  100
44
 #define   FULLSPEEDRIGHT  100
35
 #define   HALFSPEEDRIGHT  50
45
 #define   HALFSPEEDRIGHT  50
36
 #define   SLOWSPEEDRIGHT  25
46
 #define   SLOWSPEEDRIGHT  25
252
 void ProxUpdate()
262
 void ProxUpdate()
253
 {
263
 {
254
   proxSensors.read();
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
 //Update Liniensensoren
271
 //Update Liniensensoren
262
 void LineUpdate()
272
 void LineUpdate()
263
 {
273
 {
264
   uint16_t  lineRaw[3];
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
 //Update Drehbewegungssensor
281
 //Update Drehbewegungssensor
336
   turnAngle = 0;                    
346
   turnAngle = 0;                    
337
   rotationAngle = 0;                                                      
347
   rotationAngle = 0;                                                      
338
   GyroUpdate();                                                 
348
   GyroUpdate();                                                 
349
+  while(rotationAngle < 20)          
350
+  {
351
+    GyroUpdate();  
352
+    LineUpdate();
353
+    motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
354
+  }
355
+  GyroUpdate();                                                 
339
   while(rotationAngle < 45)          
356
   while(rotationAngle < 45)          
340
   {
357
   {
341
     GyroUpdate();  
358
     GyroUpdate();  
371
     //Schritt 2: Hindernis passieren
388
     //Schritt 2: Hindernis passieren
372
     //Serial1.println("Aufholen"); 
389
     //Serial1.println("Aufholen"); 
373
     lastUpdate = millis();
390
     lastUpdate = millis();
374
-    while(proxValue[3] < 6 && eventTime < 3000)
391
+    while(proxValue[3] < 6)
375
     {
392
     {
376
-      TimeUpdate();
377
       ProxUpdate();
393
       ProxUpdate();
378
       LineUpdate();
394
       LineUpdate();
379
       Spurhalten();
395
       Spurhalten();
396
+      TimeUpdate();
397
+      //Serial1.println(eventTime);
398
+      if(eventTime > 3000) break;
380
     }
399
     }
381
-    //Serial1.println("Überholen"); 
400
+    //Serial1.println("Vorbeifahren"); 
382
     ProxUpdate(); 
401
     ProxUpdate(); 
383
     while(proxValue[3] == 6)
402
     while(proxValue[3] == 6)
384
     {
403
     {
391
     TimeUpdate();
410
     TimeUpdate();
392
     while(eventTime < 3000)
411
     while(eventTime < 3000)
393
     {
412
     {
394
-      //Serial1.println(eventTime); 
395
-      TimeUpdate();
396
       LineUpdate();
413
       LineUpdate();
397
       Spurhalten();
414
       Spurhalten();
415
+      TimeUpdate();
416
+      //Serial1.println(eventTime);
398
     }
417
     }
399
   //}
418
   //}
400
   
419
   
403
   turnAngle = 0;                
422
   turnAngle = 0;                
404
   rotationAngle = 0;                                                      
423
   rotationAngle = 0;                                                      
405
   GyroUpdate();                                                 
424
   GyroUpdate();                                                 
425
+  while(rotationAngle > -20)          
426
+  {
427
+    GyroUpdate();  
428
+    LineUpdate();
429
+    motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
430
+  }
431
+  GyroUpdate();                                                 
406
   while(rotationAngle > -45)          
432
   while(rotationAngle > -45)          
407
   {
433
   {
408
     GyroUpdate();  
434
     GyroUpdate();  
445
   LineUpdate(); 
471
   LineUpdate(); 
446
   bool  leftCode;                                                         //links => 1
472
   bool  leftCode;                                                         //links => 1
447
   bool  rightCode;                                                        //rechts => 2
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
   else leftCode = false;
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
   else rightCode = false;
477
   else rightCode = false;
452
 
478
 
453
   //Zufallszahl erzeugen
479
   //Zufallszahl erzeugen
473
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
499
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
474
     lastUpdate = millis();
500
     lastUpdate = millis();
475
     TimeUpdate();
501
     TimeUpdate();
476
-    while(eventTime < 300)
502
+    while(eventTime < 1000)
477
     {
503
     {
478
       TimeUpdate();
504
       TimeUpdate();
479
       motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
505
       motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
598
 //Funktion Spurhalten
624
 //Funktion Spurhalten
599
 void Spurhalten()                                                   
625
 void Spurhalten()                                                   
600
 {
626
 {
627
+  uint16_t StartTime = millis();
628
+  uint16_t Update = millis();
629
+  uint16_t Time = Update - StartTime;
630
+
601
   //linke Linie erreicht, nach rechts fahren
631
   //linke Linie erreicht, nach rechts fahren
602
   if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0)                      
632
   if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0)                      
603
   {
633
   {
604
     ledYellow(1); 
634
     ledYellow(1); 
605
     //Serial1.println("Spur nach rechts korrigieren");  
635
     //Serial1.println("Spur nach rechts korrigieren");  
606
     motors.setSpeeds(FULLSPEEDLEFT/eventSpeed, SLOWSPEEDRIGHT/eventSpeed);
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
       LineUpdate();
641
       LineUpdate();
613
       if(lineValue[2] > MARKLINE2) break;
642
       if(lineValue[2] > MARKLINE2) break;
614
     }   
643
     }   
620
     ledYellow(1); 
649
     ledYellow(1); 
621
     //Serial1.println("Spur nach links korrigieren");  
650
     //Serial1.println("Spur nach links korrigieren");  
622
     motors.setSpeeds(SLOWSPEEDLEFT/eventSpeed, FULLSPEEDRIGHT/eventSpeed);   
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
       LineUpdate();
656
       LineUpdate();
629
       if(lineValue[0] > MARKLINE0) break;
657
       if(lineValue[0] > MARKLINE0) break;
630
     }   
658
     }   
707
     eventSpeed = 1.0;
735
     eventSpeed = 1.0;
708
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
736
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
709
     if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
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
     else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) Spurfinden();
740
     else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) Spurfinden();
713
     else Spurhalten();
741
     else Spurhalten();
714
   }
742
   }