Browse Source

"Kontaktvermeiden" now working

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

BIN
ArduinoOutput/Hauptprojekt.ino.elf


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


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


File diff suppressed because it is too large
+ 1 - 1
ArduinoOutput/build.options.json


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.S.o


BIN
ArduinoOutput/core/wiring_pulse.c.o


BIN
ArduinoOutput/core/wiring_shift.c.o


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


+ 102 - 67
ArduinoOutput/preproc/ctags_target_for_gcc_minus_e.cpp

@@ -1,7 +1,7 @@
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 14.05.2018 
4
+//Datum: erstellt am 19.07.2017, zuletzt geändert am 17.05.2018 
5 5
 //Projektthema: Untersuchungen und Implementierung eines automatisierten Fahrens mittels Pololu Zumo
6 6
 /*Kurzbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
7 7
 
@@ -33,14 +33,16 @@ Zumo32U4Encoders encoders; //Motorencoder
33 33
 LSM303 compass; //Beschleunigungssensor x-Achse
34 34
 L3G gyro; //Drehbewegungssensor z-Achse
35 35
 
36
+//Medianfilter geben mittleren Wert einer Reihe mit ungerader Anzahl aus
36 37
 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
38
+MedianFilter LineFilter1(3, 0); //Fenstergröße: 3, Basiswerte: 0 0 0
39
+MedianFilter LineFilter2(3, 0);
40
+
39 41
 MedianFilter ProxFilter0(5, 0); //erstellen der Filter für Abstandssensoren
40
-MedianFilter ProxFilter1(5, 0);
42
+MedianFilter ProxFilter1(5, 0); //Fenstergröße: 5, Basiswerte: 0 0 0 0 0
41 43
 MedianFilter ProxFilter2(5, 0);
42 44
 MedianFilter ProxFilter3(5, 0);
43
-# 48 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
45
+# 51 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
44 46
 int16_t lineValue[3]; //Liniensensoren
45 47
 uint16_t lineOffset[3]; //von links (0) nach rechts (2)
46 48
 
@@ -55,18 +57,18 @@ int16_t turnRate;
55 57
 int16_t gyroOffset;
56 58
 uint16_t gyroLastUpdate;
57 59
 
58
-//int32_t   moveDisplay = 0;              //Beschleunigung
59
-//int32_t   moveDistance = 0;   
60
-int16_t moveRate;
60
+int16_t compassRate; //Beschleunigung
61 61
 int16_t compassOffset;
62
-//uint16_t  compassLastUpdate;
62
+int16_t compassLastUpdate;
63 63
 
64 64
 uint16_t lastUpdate = 0; //Systemzeit
65
-uint16_t eventTime = 0; //Zeit seit letzter Geschwindigkeitsänderung
66
-char report[200]; //Ausgabe
65
+uint16_t eventTime = 0; //Zeitdifferenz
66
+uint16_t stopUpdate = 0; //Systemzeit
67
+uint16_t stopTime = 0; //Zeit seit letztem Manöver
67 68
 float eventSpeed = 1; //vermindert die Geschwindigkeit bei Manövern
68 69
 int btData = 0; //Gelesene Daten aus Bluetooth
69
-bool alarm = false; //zeigt Manöver abhängig von btData
70
+bool btBuffer = false; //puffert Daten von btData
71
+bool stop = false; //Sperrt Funktion Kontaktvermeiden
70 72
 
71 73
 /*-----------------------------------------------------------------*/
72 74
 
@@ -169,7 +171,7 @@ void CompassSetup()
169 171
   int32_t total = 0;
170 172
   for (uint16_t i = 0; i < 1024; i++)
171 173
   {
172
-    compass.read();
174
+    compass.readAcc();
173 175
     total += compass.a.x;
174 176
   }
175 177
   compassOffset = total / 1024;
@@ -200,18 +202,26 @@ void setup()
200 202
   buttonA.waitForButton();
201 203
   randomSeed(millis());
202 204
   delay(500);
205
+  stopUpdate = millis();
203 206
   //Serial1.println("Start");
204 207
 }
205 208
 
206 209
 /*-----------------------------------------------------------------*/
207 210
 
208
-//Update Durchlaufzeit
211
+//Update Zeitdifferenz für alle Funktionen
209 212
 void TimeUpdate()
210 213
 {
211 214
   uint16_t m = millis();
212 215
   eventTime = m - lastUpdate;
213 216
 }
214 217
 
218
+//Update Zeit für Kontaktvermeiden
219
+void StopUpdate()
220
+{
221
+  uint16_t m = millis();
222
+  stopTime = m - stopUpdate;
223
+}
224
+
215 225
 void LoopTiming()
216 226
 {
217 227
   const int AL = 100; // Arraylänge, NUR GERADE Zahlen verwenden!
@@ -255,6 +265,21 @@ void LoopTiming()
255 265
     }
256 266
 }
257 267
 
268
+//Funktion Serielle Ausgabe
269
+void SerielleAusgabe()
270
+{
271
+  char report[200];
272
+  snprintf_P(report, sizeof(report),
273
+    (__extension__({static const char __c[] __attribute__((__progmem__)) = ("Abstand: %d %d %d %d   Linie: %d %d %d"); &__c[0];})),
274
+    proxValue[0], proxValue[1], proxValue[2], proxValue[3],
275
+    lineValue[0], lineValue[1], lineValue[2]);
276
+  Serial1.println(report);
277
+  snprintf_P(report, sizeof(report),
278
+    (__extension__({static const char __c[] __attribute__((__progmem__)) = ("Weg: %d %d   Winkel: %d   Beschleunigung: %d"); &__c[0];})),
279
+    driveRotation[0], driveRotation[1], rotationAngle, compassRate);
280
+  Serial1.println(report);
281
+}
282
+
258 283
 //Update Abstandssensoren
259 284
 void ProxUpdate()
260 285
 {
@@ -272,10 +297,6 @@ void ProxUpdate()
272 297
       proxValue[1] = ProxFilter1.in(proxSensors.countsFrontWithLeftLeds());
273 298
       proxValue[2] = ProxFilter2.in(proxSensors.countsFrontWithRightLeds());
274 299
       proxValue[3] = ProxFilter3.in(proxSensors.countsRightWithRightLeds());
275
-      // Serial.println(proxValue[0]);
276
-      // Serial.println(proxValue[1]);
277
-      // Serial.println(proxValue[2]);
278
-      // Serial.println(proxValue[3]);
279 300
       done = true;
280 301
     }
281 302
     else
@@ -312,22 +333,18 @@ void GyroUpdate()
312 333
 //Update Beschleunigungssensor
313 334
 void CompassUpdate()
314 335
 {
315
-  compass.read(); //Rohwert 16384 entspricht 1g (9,81m/s²) bzw.
316
-  moveRate = compass.a.x - compassOffset; //bei +/-2g Messbereich 0,61mg/LSB
317
-  // uint16_t m = micros();
318
-  // uint16_t dt = m - compassLastUpdate;
319
-  // compassLastUpdate = m;
320
-  // int32_t d = (int32_t)moveRate * dt;
321
-  // moveDistance += (int64_t)d * dt >> 14;
322
-  // moveDisplay = moveDistance * 9,81 / 1000;
336
+  compass.read(); //Rohwert 16384 entspricht 1g (9,81m/s²) bzw. bei +/-2g Messbereich 0,61mg/LSB
337
+  int16_t x = compass.a.x - compassOffset;
338
+  compassRate = x - compassLastUpdate;
339
+  compassLastUpdate = x;
323 340
 }
324 341
 
325 342
 //Update Encoder
326 343
 void EncoderUpdate()
327 344
 {
328
-  encoderCounts[0] = encoders.getCountsLeft();
345
+  encoderCounts[0] += encoders.getCountsAndResetLeft();
329 346
   driveRotation[0] = encoderCounts[0] / 910; //12cpr (Motorwelle) * 75,81:1 (Getriebe) = 909,7cpr (Antriebszahnrad)
330
-  encoderCounts[1] = encoders.getCountsRight();
347
+  encoderCounts[1] += encoders.getCountsAndResetRight();
331 348
   driveRotation[1] = encoderCounts[1] / 910;
332 349
 }
333 350
 
@@ -344,10 +361,25 @@ void Kontaktvermeiden()
344 361
   while(proxValue[1] == 0 || proxValue[2] == 0)
345 362
   {
346 363
     ProxUpdate();
364
+    LineUpdate();
365
+    motors.setSpeeds(-52, -50);
366
+    if(lineValue[0] > 150 || lineValue[1] > 100 || lineValue[2] > 120) break;
367
+  }
368
+  lastUpdate = millis();
369
+  TimeUpdate();
370
+  while(eventTime < 1000)
371
+  {
372
+    TimeUpdate();
373
+    LineUpdate();
347 374
     motors.setSpeeds(-52, -50);
348
-    if(lineValue[0] > 150 || lineValue[2] > 120) break;
375
+    if(lineValue[0] > 150 || lineValue[1] > 100 || lineValue[2] > 120) break;
349 376
   }
350 377
   motors.setSpeeds(0, 0);
378
+  compassLastUpdate = 0;
379
+  compassRate = 0;
380
+  CompassUpdate();
381
+  stop = false;
382
+  stopUpdate = millis();
351 383
   //Serial1.println("Vermeiden beendet");
352 384
   Serial1.print(0);
353 385
 }
@@ -378,14 +410,15 @@ void Hindernisumfahren()
378 410
     motors.setSpeeds(26, 100);
379 411
     if(lineValue[2] > 120 && lineValue[2] < 500) break;
380 412
   }
413
+
381 414
   //geradeaus über Mittellinie fahren
382 415
   LineUpdate();
383 416
   while(lineValue[2] < 120)
384 417
   {
385 418
     LineUpdate();
386 419
     motors.setSpeeds(104, 100);
387
-    //if(lineValue[0] > MARKLINE0) break;
388 420
   }
421
+
389 422
   //rechts drehen
390 423
   GyroUpdate();
391 424
   while(rotationAngle > 10)
@@ -396,12 +429,13 @@ void Hindernisumfahren()
396 429
     else if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(104, 100);
397 430
     else motors.setSpeeds(104, 25);
398 431
   }
432
+
399 433
   //geradeaus fahren
400 434
   motors.setSpeeds(104, 100);
401 435
 
402 436
   //Gegenverkehr beachten
403 437
   ProxUpdate();
404
-  //if(proxValue[1] < 5 || proxValue[2] < 5)
438
+  //if(proxValue[1] == 6 && proxValue[2] == 6)
405 439
   //{
406 440
     //Schritt 2: Hindernis passieren
407 441
     //Serial1.println("Aufholen"); 
@@ -454,14 +488,15 @@ void Hindernisumfahren()
454 488
     motors.setSpeeds(104, 25);
455 489
     if(lineValue[0] > 150 && lineValue[0] < 500) break;
456 490
   }
491
+
457 492
   //geradeaus über Mittellinie fahren
458 493
   LineUpdate();
459 494
   while(lineValue[0] < 150)
460 495
   {
461 496
     LineUpdate();
462 497
     motors.setSpeeds(104, 100);
463
-    //if(lineValue[0] > MARKLINE0) break;
464 498
   }
499
+
465 500
   //links drehen
466 501
   GyroUpdate();
467 502
   while(rotationAngle < -10)
@@ -472,10 +507,13 @@ void Hindernisumfahren()
472 507
     else if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(104, 100);
473 508
     else motors.setSpeeds(26, 100);
474 509
   }
510
+
475 511
   //geradeaus fahren
476 512
   //Serial1.println("Umfahren beendet");
477
-  Serial1.print(0);
478 513
   motors.setSpeeds(104, 100);
514
+  stop = false;
515
+  stopUpdate = millis();
516
+  Serial1.print(0);
479 517
 }
480 518
 
481 519
 //Funktion Abbiegen
@@ -526,8 +564,9 @@ void Abbiegen()
526 564
     while(lineValue[0] < 150 && lineValue[2] < 120)
527 565
     {
528 566
       LineUpdate();
529
-      motors.setSpeeds(104, 100);
567
+      motors.setSpeeds(104, 100 +10);
530 568
     }
569
+
531 570
     //links drehen
532 571
     turnAngle = 0;
533 572
     rotationAngle = 0;
@@ -540,6 +579,7 @@ void Abbiegen()
540 579
       else if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(52, 100);
541 580
       else motors.setSpeeds(26, 100);
542 581
     }
582
+
543 583
     //geradeaus fahren
544 584
     motors.setSpeeds(104, 100);
545 585
   }
@@ -549,26 +589,22 @@ void Abbiegen()
549 589
   {
550 590
     //Serial1.println("links Abbiegen vom Rundkurs"); 
551 591
     //links drehen
592
+    motors.setSpeeds(26, 100);
552 593
     turnAngle = 0;
553 594
     rotationAngle = 0;
554
-    driveRotation[1] = 0;
555 595
     GyroUpdate();
556 596
     while(rotationAngle < 40)
557 597
     {
558 598
       GyroUpdate();
559
-      EncoderUpdate();
560 599
       motors.setSpeeds(26, 100);
561
-      //if(driveRotation[1] > 1) break;
562 600
     }
563
-    driveRotation[1] = 0;
564 601
     GyroUpdate();
565 602
     while(rotationAngle < 85)
566 603
     {
567 604
       GyroUpdate();
568
-      EncoderUpdate();
569 605
       motors.setSpeeds(26, 100);
570
-      //if(driveRotation[1] > 1) break;
571 606
     }
607
+
572 608
     //geradeaus fahren
573 609
     motors.setSpeeds(104, 100);
574 610
     lastUpdate = millis();
@@ -577,6 +613,7 @@ void Abbiegen()
577 613
     {
578 614
       TimeUpdate();
579 615
       LineUpdate();
616
+      motors.setSpeeds(104, 100);
580 617
       if(lineValue[2] > 120 && lineValue[2] < 500) break;
581 618
     }
582 619
     lastUpdate = millis();
@@ -594,14 +631,13 @@ void Abbiegen()
594 631
   {
595 632
     //Serial1.println("rechts Abbiegen"); 
596 633
     //rechts drehen
634
+    motors.setSpeeds(104, 25);
597 635
     turnAngle = 0;
598 636
     rotationAngle = 0;
599
-    driveRotation[0] = 0;
600 637
     GyroUpdate();
601 638
     while(rotationAngle > -40)
602 639
     {
603 640
       GyroUpdate();
604
-      EncoderUpdate();
605 641
       LineUpdate();
606 642
       motors.setSpeeds(104, 25);
607 643
       if(lineValue[0] > 150 && lineValue[0] < 500) break;
@@ -635,6 +671,8 @@ void Abbiegen()
635 671
       Spurhalten();
636 672
     }
637 673
   }
674
+  stop = false;
675
+  stopUpdate = millis();
638 676
   //Serial1.println("Abbiegen beendet");
639 677
   Serial1.print(0);
640 678
 }
@@ -651,7 +689,7 @@ void Spurhalten()
651 689
   {
652 690
     ledYellow(1);
653 691
     //Serial1.println("Spur nach rechts korrigieren");  
654
-    motors.setSpeeds(104/eventSpeed, 25/eventSpeed);
692
+    motors.setSpeeds((int)104/eventSpeed, (int)25/eventSpeed);
655 693
     while(Time < 100)
656 694
     {
657 695
       Update = millis();
@@ -659,6 +697,8 @@ void Spurhalten()
659 697
       LineUpdate();
660 698
       if(lineValue[2] > 120) break;
661 699
     }
700
+    stop = false;
701
+    stopUpdate = millis();
662 702
   }
663 703
 
664 704
   //rechte Linie erreicht, nach links fahren
@@ -666,7 +706,7 @@ void Spurhalten()
666 706
   {
667 707
     ledYellow(1);
668 708
     //Serial1.println("Spur nach links korrigieren");  
669
-    motors.setSpeeds(26/eventSpeed, 100/eventSpeed);
709
+    motors.setSpeeds((int)26/eventSpeed, (int)100/eventSpeed);
670 710
     while(Time < 100)
671 711
     {
672 712
       Update = millis();
@@ -674,13 +714,16 @@ void Spurhalten()
674 714
       LineUpdate();
675 715
       if(lineValue[0] > 150) break;
676 716
     }
717
+    stop = false;
718
+    stopUpdate = millis();
677 719
   }
678 720
 
679 721
   //normale Fahrt
680 722
   else
681 723
   {
682 724
     ledGreen(1);
683
-    motors.setSpeeds(104/eventSpeed, 100/eventSpeed);
725
+    motors.setSpeeds((int)104/eventSpeed, (int)100/eventSpeed);
726
+    stop = true;
684 727
   }
685 728
 }
686 729
 
@@ -698,24 +741,12 @@ void Spurfinden()
698 741
     motors.setSpeeds(-104, -100);
699 742
     if(eventTime > 3000) break;
700 743
   }
744
+  stop = false;
745
+  stopUpdate = millis();
701 746
   //Serial1.println("Spur gefunden"); 
702 747
   Serial1.print(0);
703 748
 }
704 749
 
705
-//Funktion Serielle Ausgabe
706
-void SerielleAusgabe()
707
-{
708
-  snprintf_P(report, sizeof(report),
709
-    (__extension__({static const char __c[] __attribute__((__progmem__)) = ("Abstand: %d %d %d %d   Linie: %d %d %d"); &__c[0];})),
710
-    proxValue[0], proxValue[1], proxValue[2], proxValue[3],
711
-    lineValue[0], lineValue[1], lineValue[2]);
712
-  Serial1.println(report);
713
-  snprintf_P(report, sizeof(report),
714
-    (__extension__({static const char __c[] __attribute__((__progmem__)) = ("Weg: %d %d   Winkel: %d   Beschleunigung: %d"); &__c[0];})),
715
-    driveRotation[0], driveRotation[1], rotationAngle, moveRate);
716
-  Serial1.println(report);
717
-}
718
-
719 750
 /*-----------------------------------------------------------------*/
720 751
 
721 752
 void loop()
@@ -732,27 +763,31 @@ void loop()
732 763
   CompassUpdate();
733 764
   LineUpdate();
734 765
   TimeUpdate();
766
+  StopUpdate();
735 767
 
736 768
   //Funktionsauswahl
737
-  //btData = Serial1.readString();
738 769
   if(Serial1.available() > 0) btData = Serial1.read();
739
-  if(btData == '1') alarm = true;
740
-  else if(btData == '0') alarm = false;
770
+  if(btData == '1') btBuffer = true;
771
+  else if(btData == '0') btBuffer = false;
772
+
741 773
   //verfügbare Funktionen bei laufenden Manövern
742
-  //if(btData == "Abbiegen" || btData == "Hindernisumfahren" || btData == "Kontaktvermeiden"|| btData == "Spurfinden")   
743
-  if(alarm == true)
774
+  if(btBuffer == true)
744 775
   {
745 776
     //Serial1.println("Verstanden");
746 777
     eventSpeed = 1.4;
747
-    if(moveRate > 1500 || (proxValue[1] == 6 && proxValue[2] == 6) || lineValue[0] > 500 || lineValue[2] > 500 || lineValue[1] > 100) motors.setSpeeds(0, 0);
778
+    if(proxValue[0] == 6 || (proxValue[1] == 6 && proxValue[2] == 6)) motors.setSpeeds(0, 0);
779
+    else if(stop == true && stopTime > 2000 && ((compassRate)>0?(compassRate):-(compassRate)) > 3500) motors.setSpeeds(0, 0);
780
+    else if(lineValue[0] > 500 || lineValue[2] > 500 || lineValue[1] > 100) motors.setSpeeds(0, 0);
748 781
     else Spurhalten();
749 782
   }
783
+
750 784
   //verfügbare Funktionen im Normalfall
751 785
   else
752 786
   {
753 787
     eventSpeed = 1.0;
754
-    //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
755
-    if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
788
+    if(stop == true && stopTime > 2000 && ((compassRate)>0?(compassRate):-(compassRate)) > 3500) Kontaktvermeiden();
789
+    else if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
790
+    else if(lineValue[0] > 1600 && lineValue[2] > 1600) motors.setSpeeds(0, 0);
756 791
     else if((lineValue[0] > 500 && lineValue[0] < 1600) && (lineValue[1] > 300 && lineValue[1] < 800)) Abbiegen();
757 792
     else if((lineValue[2] > 500 && lineValue[2] < 1600) && (lineValue[1] > 300 && lineValue[1] < 800)) Abbiegen();
758 793
     else if(lineValue[1] > 100 && lineValue[1] < 300) Spurfinden();

+ 128 - 90
ArduinoOutput/sketch/Hauptprojekt.ino.cpp

@@ -2,7 +2,7 @@
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 14.05.2018 
5
+//Datum: erstellt am 19.07.2017, zuletzt geändert am 17.05.2018 
6 6
 //Projektthema: Untersuchungen und Implementierung eines automatisierten Fahrens mittels Pololu Zumo
7 7
 /*Kurzbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
8 8
 der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
@@ -26,11 +26,13 @@ Zumo32U4Encoders          encoders;     //Motorencoder
26 26
 LSM303                    compass;      //Beschleunigungssensor x-Achse
27 27
 L3G                       gyro;         //Drehbewegungssensor z-Achse
28 28
 
29
+//Medianfilter geben mittleren Wert einer Reihe mit ungerader Anzahl aus
29 30
 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
31
+MedianFilter LineFilter1(3, 0);         //Fenstergröße: 3, Basiswerte: 0 0 0
32
+MedianFilter LineFilter2(3, 0);         
33
+
32 34
 MedianFilter ProxFilter0(5, 0);         //erstellen der Filter für Abstandssensoren
33
-MedianFilter ProxFilter1(5, 0);
35
+MedianFilter ProxFilter1(5, 0);         //Fenstergröße: 5, Basiswerte: 0 0 0 0 0
34 36
 MedianFilter ProxFilter2(5, 0);
35 37
 MedianFilter ProxFilter3(5, 0);
36 38
 
@@ -40,6 +42,7 @@ MedianFilter ProxFilter3(5, 0);
40 42
 #define   SIGN0           500
41 43
 #define   SIGN1           300
42 44
 #define   SIGN2           500
45
+
43 46
 #define   MAXSPEED        400
44 47
 #define   FULLSPEEDLEFT   104
45 48
 #define   HALFSPEEDLEFT   52
@@ -61,64 +64,66 @@ int32_t   turnAngle = 0;
61 64
 int16_t   turnRate;
62 65
 int16_t   gyroOffset;
63 66
 uint16_t  gyroLastUpdate;
64
-
65
-//int32_t   moveDisplay = 0;              //Beschleunigung
66
-//int32_t   moveDistance = 0;   
67
-int16_t   moveRate;
68
-int16_t   compassOffset;                
69
-//uint16_t  compassLastUpdate;
67
+            
68
+int16_t   compassRate;                  //Beschleunigung
69
+int16_t   compassOffset;          
70
+int16_t   compassLastUpdate;      
70 71
 
71 72
 uint16_t  lastUpdate = 0;               //Systemzeit
72
-uint16_t  eventTime = 0;                //Zeit seit letzter Geschwindigkeitsänderung
73
-char      report[200];                  //Ausgabe
73
+uint16_t  eventTime = 0;                //Zeitdifferenz
74
+uint16_t  stopUpdate = 0;               //Systemzeit
75
+uint16_t  stopTime = 0;                 //Zeit seit letztem Manöver
74 76
 float     eventSpeed = 1;               //vermindert die Geschwindigkeit bei Manövern
75 77
 int       btData = 0;                   //Gelesene Daten aus Bluetooth
76
-bool      alarm = false;                //zeigt Manöver abhängig von btData
78
+bool      btBuffer = false;             //puffert Daten von btData
79
+bool      stop = false;                 //Sperrt Funktion Kontaktvermeiden
77 80
 
78 81
 /*-----------------------------------------------------------------*/
79 82
 
80 83
 //Setup Bluetoothverbindung
81
-#line 78 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
84
+#line 81 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
82 85
 void BlueSetup();
83
-#line 88 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
86
+#line 91 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
84 87
 void LineSetup();
85
-#line 117 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
88
+#line 120 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
86 89
 void ProxSetup();
87
-#line 123 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
90
+#line 126 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
88 91
 void GyroSetup();
89
-#line 156 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
92
+#line 159 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
90 93
 void CompassSetup();
91
-#line 187 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
94
+#line 190 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
92 95
 void setup();
93
-#line 213 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
96
+#line 217 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
94 97
 void TimeUpdate();
95
-#line 219 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
98
+#line 224 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
99
+void StopUpdate();
100
+#line 230 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
96 101
 void LoopTiming();
97
-#line 263 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
102
+#line 274 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
103
+void SerielleAusgabe();
104
+#line 289 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
98 105
 void ProxUpdate();
99
-#line 294 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
106
+#line 316 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
100 107
 void LineUpdate();
101
-#line 304 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
108
+#line 326 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
102 109
 void GyroUpdate();
103
-#line 317 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
110
+#line 339 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
104 111
 void CompassUpdate();
105
-#line 330 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
112
+#line 348 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
106 113
 void EncoderUpdate();
107
-#line 341 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
114
+#line 359 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
108 115
 void Kontaktvermeiden();
109
-#line 360 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
116
+#line 393 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
110 117
 void Hindernisumfahren();
111
-#line 486 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
118
+#line 525 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
112 119
 void Abbiegen();
113
-#line 647 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
120
+#line 686 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
114 121
 void Spurhalten();
115
-#line 692 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
122
+#line 736 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
116 123
 void Spurfinden();
117
-#line 710 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
118
-void SerielleAusgabe();
119
-#line 725 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
124
+#line 757 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
120 125
 void loop();
121
-#line 78 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
126
+#line 81 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
122 127
 void BlueSetup()
123 128
 {
124 129
   Serial1.begin(9600);                              //Initialisierung mit Datengeschwindigkeit(Baud)
@@ -217,7 +222,7 @@ void CompassSetup()
217 222
   int32_t total = 0;                                              
218 223
   for (uint16_t i = 0; i < 1024; i++)
219 224
   {
220
-    compass.read();
225
+    compass.readAcc();
221 226
     total += compass.a.x;
222 227
   }
223 228
   compassOffset = total / 1024;
@@ -248,18 +253,26 @@ void setup()
248 253
   buttonA.waitForButton();
249 254
   randomSeed(millis());
250 255
   delay(500);
256
+  stopUpdate = millis();
251 257
   //Serial1.println("Start");
252 258
 }
253 259
 
254 260
 /*-----------------------------------------------------------------*/
255 261
 
256
-//Update Durchlaufzeit
262
+//Update Zeitdifferenz für alle Funktionen
257 263
 void TimeUpdate()
258 264
 {
259 265
   uint16_t m = millis();
260 266
   eventTime = m - lastUpdate;
261 267
 }
262 268
 
269
+//Update Zeit für Kontaktvermeiden
270
+void StopUpdate()
271
+{
272
+  uint16_t m = millis();
273
+  stopTime = m - stopUpdate;
274
+}
275
+
263 276
 void LoopTiming()
264 277
 {
265 278
   const int AL = 100;       // Arraylänge, NUR GERADE Zahlen verwenden!
@@ -303,6 +316,21 @@ void LoopTiming()
303 316
     }
304 317
 }
305 318
 
319
+//Funktion Serielle Ausgabe
320
+void SerielleAusgabe()                                                     
321
+{
322
+  char report[200]; 
323
+  snprintf_P(report, sizeof(report),
324
+    PSTR("Abstand: %d %d %d %d   Linie: %d %d %d"),
325
+    proxValue[0], proxValue[1], proxValue[2], proxValue[3], 
326
+    lineValue[0], lineValue[1], lineValue[2]);
327
+  Serial1.println(report);
328
+  snprintf_P(report, sizeof(report),
329
+    PSTR("Weg: %d %d   Winkel: %d   Beschleunigung: %d"),
330
+    driveRotation[0], driveRotation[1], rotationAngle, compassRate);
331
+  Serial1.println(report);
332
+}
333
+
306 334
 //Update Abstandssensoren
307 335
 void ProxUpdate()
308 336
 {
@@ -320,10 +348,6 @@ void ProxUpdate()
320 348
       proxValue[1] = ProxFilter1.in(proxSensors.countsFrontWithLeftLeds());
321 349
       proxValue[2] = ProxFilter2.in(proxSensors.countsFrontWithRightLeds());  
322 350
       proxValue[3] = ProxFilter3.in(proxSensors.countsRightWithRightLeds()); 
323
-      // Serial.println(proxValue[0]);
324
-      // Serial.println(proxValue[1]);
325
-      // Serial.println(proxValue[2]);
326
-      // Serial.println(proxValue[3]);
327 351
       done = true;
328 352
     }
329 353
     else
@@ -360,22 +384,18 @@ void GyroUpdate()
360 384
 //Update Beschleunigungssensor
361 385
 void CompassUpdate()
362 386
 {
363
-  compass.read();                           //Rohwert 16384 entspricht 1g (9,81m/s²) bzw.
364
-  moveRate = compass.a.x - compassOffset;   //bei +/-2g Messbereich 0,61mg/LSB
365
-  // uint16_t m = micros();
366
-  // uint16_t dt = m - compassLastUpdate;
367
-  // compassLastUpdate = m;
368
-  // int32_t d = (int32_t)moveRate * dt;
369
-  // moveDistance += (int64_t)d * dt >> 14;
370
-  // moveDisplay = moveDistance * 9,81 / 1000;
387
+  compass.read();                           //Rohwert 16384 entspricht 1g (9,81m/s²) bzw. bei +/-2g Messbereich 0,61mg/LSB
388
+  int16_t x = compass.a.x - compassOffset;
389
+  compassRate = x - compassLastUpdate;
390
+  compassLastUpdate = x;
371 391
 }
372 392
 
373 393
 //Update Encoder
374 394
 void EncoderUpdate()
375 395
 {
376
-  encoderCounts[0] = encoders.getCountsLeft();
396
+  encoderCounts[0] += encoders.getCountsAndResetLeft();
377 397
   driveRotation[0] = encoderCounts[0] / 910;                        //12cpr (Motorwelle) * 75,81:1 (Getriebe) = 909,7cpr (Antriebszahnrad)
378
-  encoderCounts[1] = encoders.getCountsRight();
398
+  encoderCounts[1] += encoders.getCountsAndResetRight();
379 399
   driveRotation[1] = encoderCounts[1] / 910;
380 400
 }
381 401
 
@@ -392,10 +412,25 @@ void Kontaktvermeiden()
392 412
   while(proxValue[1] == 0 || proxValue[2] == 0)
393 413
   {
394 414
     ProxUpdate();
415
+    LineUpdate();
395 416
     motors.setSpeeds(-HALFSPEEDLEFT, -HALFSPEEDRIGHT);
396
-    if(lineValue[0] > MARKLINE0 || lineValue[2] > MARKLINE2) break;
417
+    if(lineValue[0] > MARKLINE0 || lineValue[1] > MARKLINE1 || lineValue[2] > MARKLINE2) break;
418
+  }
419
+  lastUpdate = millis();
420
+  TimeUpdate();
421
+  while(eventTime < 1000)
422
+  {
423
+    TimeUpdate();
424
+    LineUpdate();
425
+    motors.setSpeeds(-HALFSPEEDLEFT, -HALFSPEEDRIGHT);
426
+    if(lineValue[0] > MARKLINE0 || lineValue[1] > MARKLINE1 || lineValue[2] > MARKLINE2) break;
397 427
   }
398 428
   motors.setSpeeds(0, 0);
429
+  compassLastUpdate = 0;
430
+  compassRate = 0;
431
+  CompassUpdate();
432
+  stop = false;
433
+  stopUpdate = millis();
399 434
   //Serial1.println("Vermeiden beendet");
400 435
   Serial1.print(0); 
401 436
 }
@@ -426,14 +461,15 @@ void Hindernisumfahren()
426 461
     motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
427 462
     if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
428 463
   }
464
+
429 465
   //geradeaus über Mittellinie fahren
430 466
   LineUpdate();
431 467
   while(lineValue[2] < MARKLINE2)          
432 468
   {
433 469
     LineUpdate();
434 470
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
435
-    //if(lineValue[0] > MARKLINE0) break;
436 471
   } 
472
+
437 473
   //rechts drehen
438 474
   GyroUpdate();
439 475
   while(rotationAngle > 10)                                               
@@ -444,12 +480,13 @@ void Hindernisumfahren()
444 480
     else if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
445 481
     else motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
446 482
   }
483
+
447 484
   //geradeaus fahren
448 485
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
449 486
 
450 487
   //Gegenverkehr beachten
451 488
   ProxUpdate();
452
-  //if(proxValue[1] < 5 || proxValue[2] < 5)
489
+  //if(proxValue[1] == 6 && proxValue[2] == 6)
453 490
   //{
454 491
     //Schritt 2: Hindernis passieren
455 492
     //Serial1.println("Aufholen"); 
@@ -502,14 +539,15 @@ void Hindernisumfahren()
502 539
     motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
503 540
     if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) break;
504 541
   }
542
+
505 543
   //geradeaus über Mittellinie fahren
506 544
   LineUpdate();
507 545
   while(lineValue[0] < MARKLINE0)          
508 546
   {
509 547
     LineUpdate();
510 548
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
511
-    //if(lineValue[0] > MARKLINE0) break;
512 549
   } 
550
+
513 551
   //links drehen
514 552
   GyroUpdate();
515 553
   while(rotationAngle < -10)                                               
@@ -520,10 +558,13 @@ void Hindernisumfahren()
520 558
     else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
521 559
     else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
522 560
   }
561
+
523 562
   //geradeaus fahren
524 563
   //Serial1.println("Umfahren beendet");
525
-  Serial1.print(0); 
526 564
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT);
565
+  stop = false;
566
+  stopUpdate = millis();
567
+  Serial1.print(0); 
527 568
 }
528 569
 
529 570
 //Funktion Abbiegen
@@ -574,8 +615,9 @@ void Abbiegen()
574 615
     while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)
575 616
     {
576 617
       LineUpdate();
577
-      motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
618
+      motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
578 619
     }
620
+
579 621
     //links drehen
580 622
     turnAngle = 0;  
581 623
     rotationAngle = 0;
@@ -588,6 +630,7 @@ void Abbiegen()
588 630
       else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(HALFSPEEDLEFT, FULLSPEEDRIGHT); 
589 631
       else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
590 632
     }
633
+
591 634
     //geradeaus fahren
592 635
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
593 636
   }
@@ -597,26 +640,22 @@ void Abbiegen()
597 640
   {
598 641
     //Serial1.println("links Abbiegen vom Rundkurs"); 
599 642
     //links drehen
643
+    motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
600 644
     turnAngle = 0;  
601 645
     rotationAngle = 0;
602
-    driveRotation[1] = 0;
603 646
     GyroUpdate();
604 647
     while(rotationAngle < 40)
605 648
     {
606 649
       GyroUpdate();
607
-      EncoderUpdate();
608 650
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
609
-      //if(driveRotation[1] > 1) break;
610 651
     }
611
-    driveRotation[1] = 0;
612 652
     GyroUpdate();
613 653
     while(rotationAngle < 85)
614 654
     {
615 655
       GyroUpdate();
616
-      EncoderUpdate();
617 656
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
618
-      //if(driveRotation[1] > 1) break;
619 657
     }
658
+
620 659
     //geradeaus fahren
621 660
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
622 661
     lastUpdate = millis();
@@ -625,6 +664,7 @@ void Abbiegen()
625 664
     {
626 665
       TimeUpdate();
627 666
       LineUpdate();
667
+      motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
628 668
       if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
629 669
     }
630 670
     lastUpdate = millis();
@@ -642,14 +682,13 @@ void Abbiegen()
642 682
   {
643 683
     //Serial1.println("rechts Abbiegen"); 
644 684
     //rechts drehen
685
+    motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
645 686
     turnAngle = 0;  
646 687
     rotationAngle = 0;
647
-    driveRotation[0] = 0;
648 688
     GyroUpdate();
649 689
     while(rotationAngle > -40)
650 690
     {
651 691
       GyroUpdate();
652
-      EncoderUpdate();
653 692
       LineUpdate();
654 693
       motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
655 694
       if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) break;
@@ -683,6 +722,8 @@ void Abbiegen()
683 722
       Spurhalten();
684 723
     }
685 724
   }
725
+  stop = false;
726
+  stopUpdate = millis();
686 727
   //Serial1.println("Abbiegen beendet");
687 728
   Serial1.print(0); 
688 729
 }
@@ -699,7 +740,7 @@ void Spurhalten()
699 740
   {
700 741
     ledYellow(1); 
701 742
     //Serial1.println("Spur nach rechts korrigieren");  
702
-    motors.setSpeeds(FULLSPEEDLEFT/eventSpeed, SLOWSPEEDRIGHT/eventSpeed);
743
+    motors.setSpeeds((int)FULLSPEEDLEFT/eventSpeed, (int)SLOWSPEEDRIGHT/eventSpeed);
703 744
     while(Time < 100)
704 745
     {
705 746
       Update = millis();
@@ -707,6 +748,8 @@ void Spurhalten()
707 748
       LineUpdate();
708 749
       if(lineValue[2] > MARKLINE2) break;
709 750
     }   
751
+    stop = false;
752
+    stopUpdate = millis();
710 753
   }
711 754
 
712 755
   //rechte Linie erreicht, nach links fahren
@@ -714,7 +757,7 @@ void Spurhalten()
714 757
   {
715 758
     ledYellow(1); 
716 759
     //Serial1.println("Spur nach links korrigieren");  
717
-    motors.setSpeeds(SLOWSPEEDLEFT/eventSpeed, FULLSPEEDRIGHT/eventSpeed);   
760
+    motors.setSpeeds((int)SLOWSPEEDLEFT/eventSpeed, (int)FULLSPEEDRIGHT/eventSpeed);   
718 761
     while(Time < 100)
719 762
     {
720 763
       Update = millis();
@@ -722,13 +765,16 @@ void Spurhalten()
722 765
       LineUpdate();
723 766
       if(lineValue[0] > MARKLINE0) break;
724 767
     }   
768
+    stop = false;
769
+    stopUpdate = millis();
725 770
   }
726 771
 
727 772
   //normale Fahrt
728 773
   else                                                                
729 774
   {
730 775
     ledGreen(1); 
731
-    motors.setSpeeds(FULLSPEEDLEFT/eventSpeed, FULLSPEEDRIGHT/eventSpeed);
776
+    motors.setSpeeds((int)FULLSPEEDLEFT/eventSpeed, (int)FULLSPEEDRIGHT/eventSpeed);
777
+    stop = true;
732 778
   }
733 779
 }
734 780
 
@@ -746,24 +792,12 @@ void Spurfinden()
746 792
     motors.setSpeeds(-FULLSPEEDLEFT, -FULLSPEEDRIGHT);
747 793
     if(eventTime > 3000) break;
748 794
   } 
795
+  stop = false;
796
+  stopUpdate = millis();
749 797
   //Serial1.println("Spur gefunden"); 
750 798
   Serial1.print(0);  
751 799
 }  
752 800
 
753
-//Funktion Serielle Ausgabe
754
-void SerielleAusgabe()                                                     
755
-{
756
-  snprintf_P(report, sizeof(report),
757
-    PSTR("Abstand: %d %d %d %d   Linie: %d %d %d"),
758
-    proxValue[0], proxValue[1], proxValue[2], proxValue[3], 
759
-    lineValue[0], lineValue[1], lineValue[2]);
760
-  Serial1.println(report);
761
-  snprintf_P(report, sizeof(report),
762
-    PSTR("Weg: %d %d   Winkel: %d   Beschleunigung: %d"),
763
-    driveRotation[0], driveRotation[1], rotationAngle, moveRate);
764
-  Serial1.println(report);
765
-}
766
-
767 801
 /*-----------------------------------------------------------------*/
768 802
 
769 803
 void loop() 
@@ -780,27 +814,31 @@ void loop()
780 814
   CompassUpdate();
781 815
   LineUpdate();      
782 816
   TimeUpdate();
817
+  StopUpdate();
783 818
 
784 819
   //Funktionsauswahl
785
-  //btData = Serial1.readString();
786 820
   if(Serial1.available() > 0) btData = Serial1.read();
787
-  if(btData == '1') alarm = true;
788
-  else if(btData == '0') alarm = false;
821
+  if(btData == '1') btBuffer = true;
822
+  else if(btData == '0') btBuffer = false;
823
+
789 824
   //verfügbare Funktionen bei laufenden Manövern
790
-  //if(btData == "Abbiegen" || btData == "Hindernisumfahren" || btData == "Kontaktvermeiden"|| btData == "Spurfinden")   
791
-  if(alarm == true)                                    
825
+  if(btBuffer == true)                                    
792 826
   {
793 827
     //Serial1.println("Verstanden");
794 828
     eventSpeed = 1.4;
795
-    if(moveRate > 1500 || (proxValue[1] == 6 && proxValue[2] == 6) || lineValue[0] > SIGN0 || lineValue[2] > SIGN2 || lineValue[1] > MARKLINE1) motors.setSpeeds(0, 0);  
829
+    if(proxValue[0] == 6 || (proxValue[1] == 6 && proxValue[2] == 6)) motors.setSpeeds(0, 0); 
830
+    else if(stop == true && stopTime > 2000 && abs(compassRate) > 3500) motors.setSpeeds(0, 0); 
831
+    else if(lineValue[0] > SIGN0 || lineValue[2] > SIGN2 || lineValue[1] > MARKLINE1) motors.setSpeeds(0, 0);  
796 832
     else Spurhalten();
797 833
   }
834
+
798 835
   //verfügbare Funktionen im Normalfall
799 836
   else                                                              
800 837
   {
801 838
     eventSpeed = 1.0;
802
-    //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
803
-    if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
839
+    if(stop == true && stopTime > 2000 && abs(compassRate) > 3500) Kontaktvermeiden();           
840
+    else if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
841
+    else if(lineValue[0] > 1600 && lineValue[2] > 1600) motors.setSpeeds(0, 0);
804 842
     else if((lineValue[0] > SIGN0 && lineValue[0] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
805 843
     else if((lineValue[2] > SIGN2 && lineValue[2] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
806 844
     else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) Spurfinden();

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


+ 104 - 68
Zumo32U4/Hauptprojekt/Hauptprojekt.ino

@@ -1,5 +1,5 @@
1 1
 //Verfassser: Felix Stange, 4056379, MET2016 
2
-//Datum: erstellt am 19.07.2017, zuletzt geändert am 14.05.2018 
2
+//Datum: erstellt am 19.07.2017, zuletzt geändert am 17.05.2018 
3 3
 //Projektthema: Untersuchungen und Implementierung eines automatisierten Fahrens mittels Pololu Zumo
4 4
 /*Kurzbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
5 5
 der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
@@ -23,11 +23,13 @@ Zumo32U4Encoders          encoders;     //Motorencoder
23 23
 LSM303                    compass;      //Beschleunigungssensor x-Achse
24 24
 L3G                       gyro;         //Drehbewegungssensor z-Achse
25 25
 
26
+//Medianfilter geben mittleren Wert einer Reihe mit ungerader Anzahl aus
26 27
 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
28
+MedianFilter LineFilter1(3, 0);         //Fenstergröße: 3, Basiswerte: 0 0 0
29
+MedianFilter LineFilter2(3, 0);         
30
+
29 31
 MedianFilter ProxFilter0(5, 0);         //erstellen der Filter für Abstandssensoren
30
-MedianFilter ProxFilter1(5, 0);
32
+MedianFilter ProxFilter1(5, 0);         //Fenstergröße: 5, Basiswerte: 0 0 0 0 0
31 33
 MedianFilter ProxFilter2(5, 0);
32 34
 MedianFilter ProxFilter3(5, 0);
33 35
 
@@ -37,6 +39,7 @@ MedianFilter ProxFilter3(5, 0);
37 39
 #define   SIGN0           500
38 40
 #define   SIGN1           300
39 41
 #define   SIGN2           500
42
+
40 43
 #define   MAXSPEED        400
41 44
 #define   FULLSPEEDLEFT   104
42 45
 #define   HALFSPEEDLEFT   52
@@ -58,19 +61,19 @@ int32_t   turnAngle = 0;
58 61
 int16_t   turnRate;
59 62
 int16_t   gyroOffset;
60 63
 uint16_t  gyroLastUpdate;
61
-
62
-//int32_t   moveDisplay = 0;              //Beschleunigung
63
-//int32_t   moveDistance = 0;   
64
-int16_t   moveRate;
65
-int16_t   compassOffset;                
66
-//uint16_t  compassLastUpdate;
64
+            
65
+int16_t   compassRate;                  //Beschleunigung
66
+int16_t   compassOffset;          
67
+int16_t   compassLastUpdate;      
67 68
 
68 69
 uint16_t  lastUpdate = 0;               //Systemzeit
69
-uint16_t  eventTime = 0;                //Zeit seit letzter Geschwindigkeitsänderung
70
-char      report[200];                  //Ausgabe
70
+uint16_t  eventTime = 0;                //Zeitdifferenz
71
+uint16_t  stopUpdate = 0;               //Systemzeit
72
+uint16_t  stopTime = 0;                 //Zeit seit letztem Manöver
71 73
 float     eventSpeed = 1;               //vermindert die Geschwindigkeit bei Manövern
72 74
 int       btData = 0;                   //Gelesene Daten aus Bluetooth
73
-bool      alarm = false;                //zeigt Manöver abhängig von btData
75
+bool      btBuffer = false;             //puffert Daten von btData
76
+bool      stop = false;                 //Sperrt Funktion Kontaktvermeiden
74 77
 
75 78
 /*-----------------------------------------------------------------*/
76 79
 
@@ -173,7 +176,7 @@ void CompassSetup()
173 176
   int32_t total = 0;                                              
174 177
   for (uint16_t i = 0; i < 1024; i++)
175 178
   {
176
-    compass.read();
179
+    compass.readAcc();
177 180
     total += compass.a.x;
178 181
   }
179 182
   compassOffset = total / 1024;
@@ -204,18 +207,26 @@ void setup()
204 207
   buttonA.waitForButton();
205 208
   randomSeed(millis());
206 209
   delay(500);
210
+  stopUpdate = millis();
207 211
   //Serial1.println("Start");
208 212
 }
209 213
 
210 214
 /*-----------------------------------------------------------------*/
211 215
 
212
-//Update Durchlaufzeit
216
+//Update Zeitdifferenz für alle Funktionen
213 217
 void TimeUpdate()
214 218
 {
215 219
   uint16_t m = millis();
216 220
   eventTime = m - lastUpdate;
217 221
 }
218 222
 
223
+//Update Zeit für Kontaktvermeiden
224
+void StopUpdate()
225
+{
226
+  uint16_t m = millis();
227
+  stopTime = m - stopUpdate;
228
+}
229
+
219 230
 void LoopTiming()
220 231
 {
221 232
   const int AL = 100;       // Arraylänge, NUR GERADE Zahlen verwenden!
@@ -259,6 +270,21 @@ void LoopTiming()
259 270
     }
260 271
 }
261 272
 
273
+//Funktion Serielle Ausgabe
274
+void SerielleAusgabe()                                                     
275
+{
276
+  char report[200]; 
277
+  snprintf_P(report, sizeof(report),
278
+    PSTR("Abstand: %d %d %d %d   Linie: %d %d %d"),
279
+    proxValue[0], proxValue[1], proxValue[2], proxValue[3], 
280
+    lineValue[0], lineValue[1], lineValue[2]);
281
+  Serial1.println(report);
282
+  snprintf_P(report, sizeof(report),
283
+    PSTR("Weg: %d %d   Winkel: %d   Beschleunigung: %d"),
284
+    driveRotation[0], driveRotation[1], rotationAngle, compassRate);
285
+  Serial1.println(report);
286
+}
287
+
262 288
 //Update Abstandssensoren
263 289
 void ProxUpdate()
264 290
 {
@@ -276,10 +302,6 @@ void ProxUpdate()
276 302
       proxValue[1] = ProxFilter1.in(proxSensors.countsFrontWithLeftLeds());
277 303
       proxValue[2] = ProxFilter2.in(proxSensors.countsFrontWithRightLeds());  
278 304
       proxValue[3] = ProxFilter3.in(proxSensors.countsRightWithRightLeds()); 
279
-      // Serial.println(proxValue[0]);
280
-      // Serial.println(proxValue[1]);
281
-      // Serial.println(proxValue[2]);
282
-      // Serial.println(proxValue[3]);
283 305
       done = true;
284 306
     }
285 307
     else
@@ -316,22 +338,18 @@ void GyroUpdate()
316 338
 //Update Beschleunigungssensor
317 339
 void CompassUpdate()
318 340
 {
319
-  compass.read();                           //Rohwert 16384 entspricht 1g (9,81m/s²) bzw.
320
-  moveRate = compass.a.x - compassOffset;   //bei +/-2g Messbereich 0,61mg/LSB
321
-  // uint16_t m = micros();
322
-  // uint16_t dt = m - compassLastUpdate;
323
-  // compassLastUpdate = m;
324
-  // int32_t d = (int32_t)moveRate * dt;
325
-  // moveDistance += (int64_t)d * dt >> 14;
326
-  // moveDisplay = moveDistance * 9,81 / 1000;
341
+  compass.read();                           //Rohwert 16384 entspricht 1g (9,81m/s²) bzw. bei +/-2g Messbereich 0,61mg/LSB
342
+  int16_t x = compass.a.x - compassOffset;
343
+  compassRate = x - compassLastUpdate;
344
+  compassLastUpdate = x;
327 345
 }
328 346
 
329 347
 //Update Encoder
330 348
 void EncoderUpdate()
331 349
 {
332
-  encoderCounts[0] = encoders.getCountsLeft();
350
+  encoderCounts[0] += encoders.getCountsAndResetLeft();
333 351
   driveRotation[0] = encoderCounts[0] / 910;                        //12cpr (Motorwelle) * 75,81:1 (Getriebe) = 909,7cpr (Antriebszahnrad)
334
-  encoderCounts[1] = encoders.getCountsRight();
352
+  encoderCounts[1] += encoders.getCountsAndResetRight();
335 353
   driveRotation[1] = encoderCounts[1] / 910;
336 354
 }
337 355
 
@@ -348,10 +366,25 @@ void Kontaktvermeiden()
348 366
   while(proxValue[1] == 0 || proxValue[2] == 0)
349 367
   {
350 368
     ProxUpdate();
369
+    LineUpdate();
351 370
     motors.setSpeeds(-HALFSPEEDLEFT, -HALFSPEEDRIGHT);
352
-    if(lineValue[0] > MARKLINE0 || lineValue[2] > MARKLINE2) break;
371
+    if(lineValue[0] > MARKLINE0 || lineValue[1] > MARKLINE1 || lineValue[2] > MARKLINE2) break;
372
+  }
373
+  lastUpdate = millis();
374
+  TimeUpdate();
375
+  while(eventTime < 1000)
376
+  {
377
+    TimeUpdate();
378
+    LineUpdate();
379
+    motors.setSpeeds(-HALFSPEEDLEFT, -HALFSPEEDRIGHT);
380
+    if(lineValue[0] > MARKLINE0 || lineValue[1] > MARKLINE1 || lineValue[2] > MARKLINE2) break;
353 381
   }
354 382
   motors.setSpeeds(0, 0);
383
+  compassLastUpdate = 0;
384
+  compassRate = 0;
385
+  CompassUpdate();
386
+  stop = false;
387
+  stopUpdate = millis();
355 388
   //Serial1.println("Vermeiden beendet");
356 389
   Serial1.print(0); 
357 390
 }
@@ -382,14 +415,15 @@ void Hindernisumfahren()
382 415
     motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
383 416
     if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
384 417
   }
418
+
385 419
   //geradeaus über Mittellinie fahren
386 420
   LineUpdate();
387 421
   while(lineValue[2] < MARKLINE2)          
388 422
   {
389 423
     LineUpdate();
390 424
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
391
-    //if(lineValue[0] > MARKLINE0) break;
392 425
   } 
426
+
393 427
   //rechts drehen
394 428
   GyroUpdate();
395 429
   while(rotationAngle > 10)                                               
@@ -400,12 +434,13 @@ void Hindernisumfahren()
400 434
     else if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
401 435
     else motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
402 436
   }
437
+
403 438
   //geradeaus fahren
404 439
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
405 440
 
406 441
   //Gegenverkehr beachten
407 442
   ProxUpdate();
408
-  //if(proxValue[1] < 5 || proxValue[2] < 5)
443
+  //if(proxValue[1] == 6 && proxValue[2] == 6)
409 444
   //{
410 445
     //Schritt 2: Hindernis passieren
411 446
     //Serial1.println("Aufholen"); 
@@ -458,14 +493,15 @@ void Hindernisumfahren()
458 493
     motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
459 494
     if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) break;
460 495
   }
496
+
461 497
   //geradeaus über Mittellinie fahren
462 498
   LineUpdate();
463 499
   while(lineValue[0] < MARKLINE0)          
464 500
   {
465 501
     LineUpdate();
466 502
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
467
-    //if(lineValue[0] > MARKLINE0) break;
468 503
   } 
504
+
469 505
   //links drehen
470 506
   GyroUpdate();
471 507
   while(rotationAngle < -10)                                               
@@ -476,10 +512,13 @@ void Hindernisumfahren()
476 512
     else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
477 513
     else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
478 514
   }
515
+
479 516
   //geradeaus fahren
480 517
   //Serial1.println("Umfahren beendet");
481
-  Serial1.print(0); 
482 518
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT);
519
+  stop = false;
520
+  stopUpdate = millis();
521
+  Serial1.print(0); 
483 522
 }
484 523
 
485 524
 //Funktion Abbiegen
@@ -530,8 +569,9 @@ void Abbiegen()
530 569
     while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)
531 570
     {
532 571
       LineUpdate();
533
-      motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
572
+      motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
534 573
     }
574
+
535 575
     //links drehen
536 576
     turnAngle = 0;  
537 577
     rotationAngle = 0;
@@ -544,6 +584,7 @@ void Abbiegen()
544 584
       else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(HALFSPEEDLEFT, FULLSPEEDRIGHT); 
545 585
       else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
546 586
     }
587
+
547 588
     //geradeaus fahren
548 589
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
549 590
   }
@@ -553,26 +594,22 @@ void Abbiegen()
553 594
   {
554 595
     //Serial1.println("links Abbiegen vom Rundkurs"); 
555 596
     //links drehen
597
+    motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
556 598
     turnAngle = 0;  
557 599
     rotationAngle = 0;
558
-    driveRotation[1] = 0;
559 600
     GyroUpdate();
560 601
     while(rotationAngle < 40)
561 602
     {
562 603
       GyroUpdate();
563
-      EncoderUpdate();
564 604
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
565
-      //if(driveRotation[1] > 1) break;
566 605
     }
567
-    driveRotation[1] = 0;
568 606
     GyroUpdate();
569 607
     while(rotationAngle < 85)
570 608
     {
571 609
       GyroUpdate();
572
-      EncoderUpdate();
573 610
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
574
-      //if(driveRotation[1] > 1) break;
575 611
     }
612
+
576 613
     //geradeaus fahren
577 614
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
578 615
     lastUpdate = millis();
@@ -581,6 +618,7 @@ void Abbiegen()
581 618
     {
582 619
       TimeUpdate();
583 620
       LineUpdate();
621
+      motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
584 622
       if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
585 623
     }
586 624
     lastUpdate = millis();
@@ -598,14 +636,13 @@ void Abbiegen()
598 636
   {
599 637
     //Serial1.println("rechts Abbiegen"); 
600 638
     //rechts drehen
639
+    motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
601 640
     turnAngle = 0;  
602 641
     rotationAngle = 0;
603
-    driveRotation[0] = 0;
604 642
     GyroUpdate();
605 643
     while(rotationAngle > -40)
606 644
     {
607 645
       GyroUpdate();
608
-      EncoderUpdate();
609 646
       LineUpdate();
610 647
       motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
611 648
       if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) break;
@@ -639,6 +676,8 @@ void Abbiegen()
639 676
       Spurhalten();
640 677
     }
641 678
   }
679
+  stop = false;
680
+  stopUpdate = millis();
642 681
   //Serial1.println("Abbiegen beendet");
643 682
   Serial1.print(0); 
644 683
 }
@@ -655,7 +694,7 @@ void Spurhalten()
655 694
   {
656 695
     ledYellow(1); 
657 696
     //Serial1.println("Spur nach rechts korrigieren");  
658
-    motors.setSpeeds(FULLSPEEDLEFT/eventSpeed, SLOWSPEEDRIGHT/eventSpeed);
697
+    motors.setSpeeds((int)FULLSPEEDLEFT/eventSpeed, (int)SLOWSPEEDRIGHT/eventSpeed);
659 698
     while(Time < 100)
660 699
     {
661 700
       Update = millis();
@@ -663,6 +702,8 @@ void Spurhalten()
663 702
       LineUpdate();
664 703
       if(lineValue[2] > MARKLINE2) break;
665 704
     }   
705
+    stop = false;
706
+    stopUpdate = millis();
666 707
   }
667 708
 
668 709
   //rechte Linie erreicht, nach links fahren
@@ -670,7 +711,7 @@ void Spurhalten()
670 711
   {
671 712
     ledYellow(1); 
672 713
     //Serial1.println("Spur nach links korrigieren");  
673
-    motors.setSpeeds(SLOWSPEEDLEFT/eventSpeed, FULLSPEEDRIGHT/eventSpeed);   
714
+    motors.setSpeeds((int)SLOWSPEEDLEFT/eventSpeed, (int)FULLSPEEDRIGHT/eventSpeed);   
674 715
     while(Time < 100)
675 716
     {
676 717
       Update = millis();
@@ -678,13 +719,16 @@ void Spurhalten()
678 719
       LineUpdate();
679 720
       if(lineValue[0] > MARKLINE0) break;
680 721
     }   
722
+    stop = false;
723
+    stopUpdate = millis();
681 724
   }
682 725
 
683 726
   //normale Fahrt
684 727
   else                                                                
685 728
   {
686 729
     ledGreen(1); 
687
-    motors.setSpeeds(FULLSPEEDLEFT/eventSpeed, FULLSPEEDRIGHT/eventSpeed);
730
+    motors.setSpeeds((int)FULLSPEEDLEFT/eventSpeed, (int)FULLSPEEDRIGHT/eventSpeed);
731
+    stop = true;
688 732
   }
689 733
 }
690 734
 
@@ -702,24 +746,12 @@ void Spurfinden()
702 746
     motors.setSpeeds(-FULLSPEEDLEFT, -FULLSPEEDRIGHT);
703 747
     if(eventTime > 3000) break;
704 748
   } 
749
+  stop = false;
750
+  stopUpdate = millis();
705 751
   //Serial1.println("Spur gefunden"); 
706 752
   Serial1.print(0);  
707 753
 }  
708 754
 
709
-//Funktion Serielle Ausgabe
710
-void SerielleAusgabe()                                                     
711
-{
712
-  snprintf_P(report, sizeof(report),
713
-    PSTR("Abstand: %d %d %d %d   Linie: %d %d %d"),
714
-    proxValue[0], proxValue[1], proxValue[2], proxValue[3], 
715
-    lineValue[0], lineValue[1], lineValue[2]);
716
-  Serial1.println(report);
717
-  snprintf_P(report, sizeof(report),
718
-    PSTR("Weg: %d %d   Winkel: %d   Beschleunigung: %d"),
719
-    driveRotation[0], driveRotation[1], rotationAngle, moveRate);
720
-  Serial1.println(report);
721
-}
722
-
723 755
 /*-----------------------------------------------------------------*/
724 756
 
725 757
 void loop() 
@@ -736,27 +768,31 @@ void loop()
736 768
   CompassUpdate();
737 769
   LineUpdate();      
738 770
   TimeUpdate();
771
+  StopUpdate();
739 772
 
740 773
   //Funktionsauswahl
741
-  //btData = Serial1.readString();
742 774
   if(Serial1.available() > 0) btData = Serial1.read();
743
-  if(btData == '1') alarm = true;
744
-  else if(btData == '0') alarm = false;
775
+  if(btData == '1') btBuffer = true;
776
+  else if(btData == '0') btBuffer = false;
777
+
745 778
   //verfügbare Funktionen bei laufenden Manövern
746
-  //if(btData == "Abbiegen" || btData == "Hindernisumfahren" || btData == "Kontaktvermeiden"|| btData == "Spurfinden")   
747
-  if(alarm == true)                                    
779
+  if(btBuffer == true)                                    
748 780
   {
749 781
     //Serial1.println("Verstanden");
750 782
     eventSpeed = 1.4;
751
-    if(moveRate > 1500 || (proxValue[1] == 6 && proxValue[2] == 6) || lineValue[0] > SIGN0 || lineValue[2] > SIGN2 || lineValue[1] > MARKLINE1) motors.setSpeeds(0, 0);  
783
+    if(proxValue[0] == 6 || (proxValue[1] == 6 && proxValue[2] == 6)) motors.setSpeeds(0, 0); 
784
+    else if(stop == true && stopTime > 2000 && abs(compassRate) > 3500) motors.setSpeeds(0, 0); 
785
+    else if(lineValue[0] > SIGN0 || lineValue[2] > SIGN2 || lineValue[1] > MARKLINE1) motors.setSpeeds(0, 0);  
752 786
     else Spurhalten();
753 787
   }
788
+
754 789
   //verfügbare Funktionen im Normalfall
755 790
   else                                                              
756 791
   {
757 792
     eventSpeed = 1.0;
758
-    //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
759
-    if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
793
+    if(stop == true && stopTime > 2000 && abs(compassRate) > 3500) Kontaktvermeiden();           
794
+    else if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
795
+    else if(lineValue[0] > 1600 && lineValue[2] > 1600) motors.setSpeeds(0, 0);
760 796
     else if((lineValue[0] > SIGN0 && lineValue[0] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
761 797
     else if((lineValue[2] > SIGN2 && lineValue[2] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
762 798
     else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) Spurfinden();