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
 # 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 14.05.2018 
4
+//Datum: erstellt am 19.07.2017, zuletzt geändert am 17.05.2018 
5
 //Projektthema: Untersuchungen und Implementierung eines automatisierten Fahrens mittels Pololu Zumo
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 
6
 /*Kurzbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
7
 
7
 
33
 LSM303 compass; //Beschleunigungssensor x-Achse
33
 LSM303 compass; //Beschleunigungssensor x-Achse
34
 L3G gyro; //Drehbewegungssensor z-Achse
34
 L3G gyro; //Drehbewegungssensor z-Achse
35
 
35
 
36
+//Medianfilter geben mittleren Wert einer Reihe mit ungerader Anzahl aus
36
 MedianFilter LineFilter0(3, 0); //erstellen der Filter für Liniensensoren
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
 MedianFilter ProxFilter0(5, 0); //erstellen der Filter für Abstandssensoren
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
 MedianFilter ProxFilter2(5, 0);
43
 MedianFilter ProxFilter2(5, 0);
42
 MedianFilter ProxFilter3(5, 0);
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
 int16_t lineValue[3]; //Liniensensoren
46
 int16_t lineValue[3]; //Liniensensoren
45
 uint16_t lineOffset[3]; //von links (0) nach rechts (2)
47
 uint16_t lineOffset[3]; //von links (0) nach rechts (2)
46
 
48
 
55
 int16_t gyroOffset;
57
 int16_t gyroOffset;
56
 uint16_t gyroLastUpdate;
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
 int16_t compassOffset;
61
 int16_t compassOffset;
62
-//uint16_t  compassLastUpdate;
62
+int16_t compassLastUpdate;
63
 
63
 
64
 uint16_t lastUpdate = 0; //Systemzeit
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
 float eventSpeed = 1; //vermindert die Geschwindigkeit bei Manövern
68
 float eventSpeed = 1; //vermindert die Geschwindigkeit bei Manövern
68
 int btData = 0; //Gelesene Daten aus Bluetooth
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
   int32_t total = 0;
171
   int32_t total = 0;
170
   for (uint16_t i = 0; i < 1024; i++)
172
   for (uint16_t i = 0; i < 1024; i++)
171
   {
173
   {
172
-    compass.read();
174
+    compass.readAcc();
173
     total += compass.a.x;
175
     total += compass.a.x;
174
   }
176
   }
175
   compassOffset = total / 1024;
177
   compassOffset = total / 1024;
200
   buttonA.waitForButton();
202
   buttonA.waitForButton();
201
   randomSeed(millis());
203
   randomSeed(millis());
202
   delay(500);
204
   delay(500);
205
+  stopUpdate = millis();
203
   //Serial1.println("Start");
206
   //Serial1.println("Start");
204
 }
207
 }
205
 
208
 
206
 /*-----------------------------------------------------------------*/
209
 /*-----------------------------------------------------------------*/
207
 
210
 
208
-//Update Durchlaufzeit
211
+//Update Zeitdifferenz für alle Funktionen
209
 void TimeUpdate()
212
 void TimeUpdate()
210
 {
213
 {
211
   uint16_t m = millis();
214
   uint16_t m = millis();
212
   eventTime = m - lastUpdate;
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
 void LoopTiming()
225
 void LoopTiming()
216
 {
226
 {
217
   const int AL = 100; // Arraylänge, NUR GERADE Zahlen verwenden!
227
   const int AL = 100; // Arraylänge, NUR GERADE Zahlen verwenden!
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
 //Update Abstandssensoren
283
 //Update Abstandssensoren
259
 void ProxUpdate()
284
 void ProxUpdate()
260
 {
285
 {
272
       proxValue[1] = ProxFilter1.in(proxSensors.countsFrontWithLeftLeds());
297
       proxValue[1] = ProxFilter1.in(proxSensors.countsFrontWithLeftLeds());
273
       proxValue[2] = ProxFilter2.in(proxSensors.countsFrontWithRightLeds());
298
       proxValue[2] = ProxFilter2.in(proxSensors.countsFrontWithRightLeds());
274
       proxValue[3] = ProxFilter3.in(proxSensors.countsRightWithRightLeds());
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
       done = true;
300
       done = true;
280
     }
301
     }
281
     else
302
     else
312
 //Update Beschleunigungssensor
333
 //Update Beschleunigungssensor
313
 void CompassUpdate()
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
 //Update Encoder
342
 //Update Encoder
326
 void EncoderUpdate()
343
 void EncoderUpdate()
327
 {
344
 {
328
-  encoderCounts[0] = encoders.getCountsLeft();
345
+  encoderCounts[0] += encoders.getCountsAndResetLeft();
329
   driveRotation[0] = encoderCounts[0] / 910; //12cpr (Motorwelle) * 75,81:1 (Getriebe) = 909,7cpr (Antriebszahnrad)
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
   driveRotation[1] = encoderCounts[1] / 910;
348
   driveRotation[1] = encoderCounts[1] / 910;
332
 }
349
 }
333
 
350
 
344
   while(proxValue[1] == 0 || proxValue[2] == 0)
361
   while(proxValue[1] == 0 || proxValue[2] == 0)
345
   {
362
   {
346
     ProxUpdate();
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
     motors.setSpeeds(-52, -50);
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
   motors.setSpeeds(0, 0);
377
   motors.setSpeeds(0, 0);
378
+  compassLastUpdate = 0;
379
+  compassRate = 0;
380
+  CompassUpdate();
381
+  stop = false;
382
+  stopUpdate = millis();
351
   //Serial1.println("Vermeiden beendet");
383
   //Serial1.println("Vermeiden beendet");
352
   Serial1.print(0);
384
   Serial1.print(0);
353
 }
385
 }
378
     motors.setSpeeds(26, 100);
410
     motors.setSpeeds(26, 100);
379
     if(lineValue[2] > 120 && lineValue[2] < 500) break;
411
     if(lineValue[2] > 120 && lineValue[2] < 500) break;
380
   }
412
   }
413
+
381
   //geradeaus über Mittellinie fahren
414
   //geradeaus über Mittellinie fahren
382
   LineUpdate();
415
   LineUpdate();
383
   while(lineValue[2] < 120)
416
   while(lineValue[2] < 120)
384
   {
417
   {
385
     LineUpdate();
418
     LineUpdate();
386
     motors.setSpeeds(104, 100);
419
     motors.setSpeeds(104, 100);
387
-    //if(lineValue[0] > MARKLINE0) break;
388
   }
420
   }
421
+
389
   //rechts drehen
422
   //rechts drehen
390
   GyroUpdate();
423
   GyroUpdate();
391
   while(rotationAngle > 10)
424
   while(rotationAngle > 10)
396
     else if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(104, 100);
429
     else if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(104, 100);
397
     else motors.setSpeeds(104, 25);
430
     else motors.setSpeeds(104, 25);
398
   }
431
   }
432
+
399
   //geradeaus fahren
433
   //geradeaus fahren
400
   motors.setSpeeds(104, 100);
434
   motors.setSpeeds(104, 100);
401
 
435
 
402
   //Gegenverkehr beachten
436
   //Gegenverkehr beachten
403
   ProxUpdate();
437
   ProxUpdate();
404
-  //if(proxValue[1] < 5 || proxValue[2] < 5)
438
+  //if(proxValue[1] == 6 && proxValue[2] == 6)
405
   //{
439
   //{
406
     //Schritt 2: Hindernis passieren
440
     //Schritt 2: Hindernis passieren
407
     //Serial1.println("Aufholen"); 
441
     //Serial1.println("Aufholen"); 
454
     motors.setSpeeds(104, 25);
488
     motors.setSpeeds(104, 25);
455
     if(lineValue[0] > 150 && lineValue[0] < 500) break;
489
     if(lineValue[0] > 150 && lineValue[0] < 500) break;
456
   }
490
   }
491
+
457
   //geradeaus über Mittellinie fahren
492
   //geradeaus über Mittellinie fahren
458
   LineUpdate();
493
   LineUpdate();
459
   while(lineValue[0] < 150)
494
   while(lineValue[0] < 150)
460
   {
495
   {
461
     LineUpdate();
496
     LineUpdate();
462
     motors.setSpeeds(104, 100);
497
     motors.setSpeeds(104, 100);
463
-    //if(lineValue[0] > MARKLINE0) break;
464
   }
498
   }
499
+
465
   //links drehen
500
   //links drehen
466
   GyroUpdate();
501
   GyroUpdate();
467
   while(rotationAngle < -10)
502
   while(rotationAngle < -10)
472
     else if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(104, 100);
507
     else if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(104, 100);
473
     else motors.setSpeeds(26, 100);
508
     else motors.setSpeeds(26, 100);
474
   }
509
   }
510
+
475
   //geradeaus fahren
511
   //geradeaus fahren
476
   //Serial1.println("Umfahren beendet");
512
   //Serial1.println("Umfahren beendet");
477
-  Serial1.print(0);
478
   motors.setSpeeds(104, 100);
513
   motors.setSpeeds(104, 100);
514
+  stop = false;
515
+  stopUpdate = millis();
516
+  Serial1.print(0);
479
 }
517
 }
480
 
518
 
481
 //Funktion Abbiegen
519
 //Funktion Abbiegen
526
     while(lineValue[0] < 150 && lineValue[2] < 120)
564
     while(lineValue[0] < 150 && lineValue[2] < 120)
527
     {
565
     {
528
       LineUpdate();
566
       LineUpdate();
529
-      motors.setSpeeds(104, 100);
567
+      motors.setSpeeds(104, 100 +10);
530
     }
568
     }
569
+
531
     //links drehen
570
     //links drehen
532
     turnAngle = 0;
571
     turnAngle = 0;
533
     rotationAngle = 0;
572
     rotationAngle = 0;
540
       else if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(52, 100);
579
       else if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(52, 100);
541
       else motors.setSpeeds(26, 100);
580
       else motors.setSpeeds(26, 100);
542
     }
581
     }
582
+
543
     //geradeaus fahren
583
     //geradeaus fahren
544
     motors.setSpeeds(104, 100);
584
     motors.setSpeeds(104, 100);
545
   }
585
   }
549
   {
589
   {
550
     //Serial1.println("links Abbiegen vom Rundkurs"); 
590
     //Serial1.println("links Abbiegen vom Rundkurs"); 
551
     //links drehen
591
     //links drehen
592
+    motors.setSpeeds(26, 100);
552
     turnAngle = 0;
593
     turnAngle = 0;
553
     rotationAngle = 0;
594
     rotationAngle = 0;
554
-    driveRotation[1] = 0;
555
     GyroUpdate();
595
     GyroUpdate();
556
     while(rotationAngle < 40)
596
     while(rotationAngle < 40)
557
     {
597
     {
558
       GyroUpdate();
598
       GyroUpdate();
559
-      EncoderUpdate();
560
       motors.setSpeeds(26, 100);
599
       motors.setSpeeds(26, 100);
561
-      //if(driveRotation[1] > 1) break;
562
     }
600
     }
563
-    driveRotation[1] = 0;
564
     GyroUpdate();
601
     GyroUpdate();
565
     while(rotationAngle < 85)
602
     while(rotationAngle < 85)
566
     {
603
     {
567
       GyroUpdate();
604
       GyroUpdate();
568
-      EncoderUpdate();
569
       motors.setSpeeds(26, 100);
605
       motors.setSpeeds(26, 100);
570
-      //if(driveRotation[1] > 1) break;
571
     }
606
     }
607
+
572
     //geradeaus fahren
608
     //geradeaus fahren
573
     motors.setSpeeds(104, 100);
609
     motors.setSpeeds(104, 100);
574
     lastUpdate = millis();
610
     lastUpdate = millis();
577
     {
613
     {
578
       TimeUpdate();
614
       TimeUpdate();
579
       LineUpdate();
615
       LineUpdate();
616
+      motors.setSpeeds(104, 100);
580
       if(lineValue[2] > 120 && lineValue[2] < 500) break;
617
       if(lineValue[2] > 120 && lineValue[2] < 500) break;
581
     }
618
     }
582
     lastUpdate = millis();
619
     lastUpdate = millis();
594
   {
631
   {
595
     //Serial1.println("rechts Abbiegen"); 
632
     //Serial1.println("rechts Abbiegen"); 
596
     //rechts drehen
633
     //rechts drehen
634
+    motors.setSpeeds(104, 25);
597
     turnAngle = 0;
635
     turnAngle = 0;
598
     rotationAngle = 0;
636
     rotationAngle = 0;
599
-    driveRotation[0] = 0;
600
     GyroUpdate();
637
     GyroUpdate();
601
     while(rotationAngle > -40)
638
     while(rotationAngle > -40)
602
     {
639
     {
603
       GyroUpdate();
640
       GyroUpdate();
604
-      EncoderUpdate();
605
       LineUpdate();
641
       LineUpdate();
606
       motors.setSpeeds(104, 25);
642
       motors.setSpeeds(104, 25);
607
       if(lineValue[0] > 150 && lineValue[0] < 500) break;
643
       if(lineValue[0] > 150 && lineValue[0] < 500) break;
635
       Spurhalten();
671
       Spurhalten();
636
     }
672
     }
637
   }
673
   }
674
+  stop = false;
675
+  stopUpdate = millis();
638
   //Serial1.println("Abbiegen beendet");
676
   //Serial1.println("Abbiegen beendet");
639
   Serial1.print(0);
677
   Serial1.print(0);
640
 }
678
 }
651
   {
689
   {
652
     ledYellow(1);
690
     ledYellow(1);
653
     //Serial1.println("Spur nach rechts korrigieren");  
691
     //Serial1.println("Spur nach rechts korrigieren");  
654
-    motors.setSpeeds(104/eventSpeed, 25/eventSpeed);
692
+    motors.setSpeeds((int)104/eventSpeed, (int)25/eventSpeed);
655
     while(Time < 100)
693
     while(Time < 100)
656
     {
694
     {
657
       Update = millis();
695
       Update = millis();
659
       LineUpdate();
697
       LineUpdate();
660
       if(lineValue[2] > 120) break;
698
       if(lineValue[2] > 120) break;
661
     }
699
     }
700
+    stop = false;
701
+    stopUpdate = millis();
662
   }
702
   }
663
 
703
 
664
   //rechte Linie erreicht, nach links fahren
704
   //rechte Linie erreicht, nach links fahren
666
   {
706
   {
667
     ledYellow(1);
707
     ledYellow(1);
668
     //Serial1.println("Spur nach links korrigieren");  
708
     //Serial1.println("Spur nach links korrigieren");  
669
-    motors.setSpeeds(26/eventSpeed, 100/eventSpeed);
709
+    motors.setSpeeds((int)26/eventSpeed, (int)100/eventSpeed);
670
     while(Time < 100)
710
     while(Time < 100)
671
     {
711
     {
672
       Update = millis();
712
       Update = millis();
674
       LineUpdate();
714
       LineUpdate();
675
       if(lineValue[0] > 150) break;
715
       if(lineValue[0] > 150) break;
676
     }
716
     }
717
+    stop = false;
718
+    stopUpdate = millis();
677
   }
719
   }
678
 
720
 
679
   //normale Fahrt
721
   //normale Fahrt
680
   else
722
   else
681
   {
723
   {
682
     ledGreen(1);
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
     motors.setSpeeds(-104, -100);
741
     motors.setSpeeds(-104, -100);
699
     if(eventTime > 3000) break;
742
     if(eventTime > 3000) break;
700
   }
743
   }
744
+  stop = false;
745
+  stopUpdate = millis();
701
   //Serial1.println("Spur gefunden"); 
746
   //Serial1.println("Spur gefunden"); 
702
   Serial1.print(0);
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
 void loop()
752
 void loop()
732
   CompassUpdate();
763
   CompassUpdate();
733
   LineUpdate();
764
   LineUpdate();
734
   TimeUpdate();
765
   TimeUpdate();
766
+  StopUpdate();
735
 
767
 
736
   //Funktionsauswahl
768
   //Funktionsauswahl
737
-  //btData = Serial1.readString();
738
   if(Serial1.available() > 0) btData = Serial1.read();
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
   //verfügbare Funktionen bei laufenden Manövern
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
     //Serial1.println("Verstanden");
776
     //Serial1.println("Verstanden");
746
     eventSpeed = 1.4;
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
     else Spurhalten();
781
     else Spurhalten();
749
   }
782
   }
783
+
750
   //verfügbare Funktionen im Normalfall
784
   //verfügbare Funktionen im Normalfall
751
   else
785
   else
752
   {
786
   {
753
     eventSpeed = 1.0;
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
     else if((lineValue[0] > 500 && lineValue[0] < 1600) && (lineValue[1] > 300 && lineValue[1] < 800)) Abbiegen();
791
     else if((lineValue[0] > 500 && lineValue[0] < 1600) && (lineValue[1] > 300 && lineValue[1] < 800)) Abbiegen();
757
     else if((lineValue[2] > 500 && lineValue[2] < 1600) && (lineValue[1] > 300 && lineValue[1] < 800)) Abbiegen();
792
     else if((lineValue[2] > 500 && lineValue[2] < 1600) && (lineValue[1] > 300 && lineValue[1] < 800)) Abbiegen();
758
     else if(lineValue[1] > 100 && lineValue[1] < 300) Spurfinden();
793
     else if(lineValue[1] > 100 && lineValue[1] < 300) Spurfinden();

+ 128 - 90
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 14.05.2018 
5
+//Datum: erstellt am 19.07.2017, zuletzt geändert am 17.05.2018 
6
 //Projektthema: Untersuchungen und Implementierung eines automatisierten Fahrens mittels Pololu Zumo
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 
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). 
8
 der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
26
 LSM303                    compass;      //Beschleunigungssensor x-Achse
26
 LSM303                    compass;      //Beschleunigungssensor x-Achse
27
 L3G                       gyro;         //Drehbewegungssensor z-Achse
27
 L3G                       gyro;         //Drehbewegungssensor z-Achse
28
 
28
 
29
+//Medianfilter geben mittleren Wert einer Reihe mit ungerader Anzahl aus
29
 MedianFilter LineFilter0(3, 0);         //erstellen der Filter für Liniensensoren
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
 MedianFilter ProxFilter0(5, 0);         //erstellen der Filter für Abstandssensoren
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
 MedianFilter ProxFilter2(5, 0);
36
 MedianFilter ProxFilter2(5, 0);
35
 MedianFilter ProxFilter3(5, 0);
37
 MedianFilter ProxFilter3(5, 0);
36
 
38
 
40
 #define   SIGN0           500
42
 #define   SIGN0           500
41
 #define   SIGN1           300
43
 #define   SIGN1           300
42
 #define   SIGN2           500
44
 #define   SIGN2           500
45
+
43
 #define   MAXSPEED        400
46
 #define   MAXSPEED        400
44
 #define   FULLSPEEDLEFT   104
47
 #define   FULLSPEEDLEFT   104
45
 #define   HALFSPEEDLEFT   52
48
 #define   HALFSPEEDLEFT   52
61
 int16_t   turnRate;
64
 int16_t   turnRate;
62
 int16_t   gyroOffset;
65
 int16_t   gyroOffset;
63
 uint16_t  gyroLastUpdate;
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
 uint16_t  lastUpdate = 0;               //Systemzeit
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
 float     eventSpeed = 1;               //vermindert die Geschwindigkeit bei Manövern
76
 float     eventSpeed = 1;               //vermindert die Geschwindigkeit bei Manövern
75
 int       btData = 0;                   //Gelesene Daten aus Bluetooth
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
 //Setup Bluetoothverbindung
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
 void BlueSetup();
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
 void LineSetup();
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
 void ProxSetup();
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
 void GyroSetup();
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
 void CompassSetup();
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
 void setup();
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
 void TimeUpdate();
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
 void LoopTiming();
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
 void ProxUpdate();
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
 void LineUpdate();
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
 void GyroUpdate();
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
 void CompassUpdate();
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
 void EncoderUpdate();
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
 void Kontaktvermeiden();
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
 void Hindernisumfahren();
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
 void Abbiegen();
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
 void Spurhalten();
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
 void Spurfinden();
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
 void loop();
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
 void BlueSetup()
127
 void BlueSetup()
123
 {
128
 {
124
   Serial1.begin(9600);                              //Initialisierung mit Datengeschwindigkeit(Baud)
129
   Serial1.begin(9600);                              //Initialisierung mit Datengeschwindigkeit(Baud)
217
   int32_t total = 0;                                              
222
   int32_t total = 0;                                              
218
   for (uint16_t i = 0; i < 1024; i++)
223
   for (uint16_t i = 0; i < 1024; i++)
219
   {
224
   {
220
-    compass.read();
225
+    compass.readAcc();
221
     total += compass.a.x;
226
     total += compass.a.x;
222
   }
227
   }
223
   compassOffset = total / 1024;
228
   compassOffset = total / 1024;
248
   buttonA.waitForButton();
253
   buttonA.waitForButton();
249
   randomSeed(millis());
254
   randomSeed(millis());
250
   delay(500);
255
   delay(500);
256
+  stopUpdate = millis();
251
   //Serial1.println("Start");
257
   //Serial1.println("Start");
252
 }
258
 }
253
 
259
 
254
 /*-----------------------------------------------------------------*/
260
 /*-----------------------------------------------------------------*/
255
 
261
 
256
-//Update Durchlaufzeit
262
+//Update Zeitdifferenz für alle Funktionen
257
 void TimeUpdate()
263
 void TimeUpdate()
258
 {
264
 {
259
   uint16_t m = millis();
265
   uint16_t m = millis();
260
   eventTime = m - lastUpdate;
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
 void LoopTiming()
276
 void LoopTiming()
264
 {
277
 {
265
   const int AL = 100;       // Arraylänge, NUR GERADE Zahlen verwenden!
278
   const int AL = 100;       // Arraylänge, NUR GERADE Zahlen verwenden!
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
 //Update Abstandssensoren
334
 //Update Abstandssensoren
307
 void ProxUpdate()
335
 void ProxUpdate()
308
 {
336
 {
320
       proxValue[1] = ProxFilter1.in(proxSensors.countsFrontWithLeftLeds());
348
       proxValue[1] = ProxFilter1.in(proxSensors.countsFrontWithLeftLeds());
321
       proxValue[2] = ProxFilter2.in(proxSensors.countsFrontWithRightLeds());  
349
       proxValue[2] = ProxFilter2.in(proxSensors.countsFrontWithRightLeds());  
322
       proxValue[3] = ProxFilter3.in(proxSensors.countsRightWithRightLeds()); 
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
       done = true;
351
       done = true;
328
     }
352
     }
329
     else
353
     else
360
 //Update Beschleunigungssensor
384
 //Update Beschleunigungssensor
361
 void CompassUpdate()
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
 //Update Encoder
393
 //Update Encoder
374
 void EncoderUpdate()
394
 void EncoderUpdate()
375
 {
395
 {
376
-  encoderCounts[0] = encoders.getCountsLeft();
396
+  encoderCounts[0] += encoders.getCountsAndResetLeft();
377
   driveRotation[0] = encoderCounts[0] / 910;                        //12cpr (Motorwelle) * 75,81:1 (Getriebe) = 909,7cpr (Antriebszahnrad)
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
   driveRotation[1] = encoderCounts[1] / 910;
399
   driveRotation[1] = encoderCounts[1] / 910;
380
 }
400
 }
381
 
401
 
392
   while(proxValue[1] == 0 || proxValue[2] == 0)
412
   while(proxValue[1] == 0 || proxValue[2] == 0)
393
   {
413
   {
394
     ProxUpdate();
414
     ProxUpdate();
415
+    LineUpdate();
395
     motors.setSpeeds(-HALFSPEEDLEFT, -HALFSPEEDRIGHT);
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
   motors.setSpeeds(0, 0);
428
   motors.setSpeeds(0, 0);
429
+  compassLastUpdate = 0;
430
+  compassRate = 0;
431
+  CompassUpdate();
432
+  stop = false;
433
+  stopUpdate = millis();
399
   //Serial1.println("Vermeiden beendet");
434
   //Serial1.println("Vermeiden beendet");
400
   Serial1.print(0); 
435
   Serial1.print(0); 
401
 }
436
 }
426
     motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
461
     motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
427
     if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
462
     if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
428
   }
463
   }
464
+
429
   //geradeaus über Mittellinie fahren
465
   //geradeaus über Mittellinie fahren
430
   LineUpdate();
466
   LineUpdate();
431
   while(lineValue[2] < MARKLINE2)          
467
   while(lineValue[2] < MARKLINE2)          
432
   {
468
   {
433
     LineUpdate();
469
     LineUpdate();
434
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
470
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
435
-    //if(lineValue[0] > MARKLINE0) break;
436
   } 
471
   } 
472
+
437
   //rechts drehen
473
   //rechts drehen
438
   GyroUpdate();
474
   GyroUpdate();
439
   while(rotationAngle > 10)                                               
475
   while(rotationAngle > 10)                                               
444
     else if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
480
     else if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
445
     else motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
481
     else motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
446
   }
482
   }
483
+
447
   //geradeaus fahren
484
   //geradeaus fahren
448
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
485
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
449
 
486
 
450
   //Gegenverkehr beachten
487
   //Gegenverkehr beachten
451
   ProxUpdate();
488
   ProxUpdate();
452
-  //if(proxValue[1] < 5 || proxValue[2] < 5)
489
+  //if(proxValue[1] == 6 && proxValue[2] == 6)
453
   //{
490
   //{
454
     //Schritt 2: Hindernis passieren
491
     //Schritt 2: Hindernis passieren
455
     //Serial1.println("Aufholen"); 
492
     //Serial1.println("Aufholen"); 
502
     motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
539
     motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
503
     if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) break;
540
     if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) break;
504
   }
541
   }
542
+
505
   //geradeaus über Mittellinie fahren
543
   //geradeaus über Mittellinie fahren
506
   LineUpdate();
544
   LineUpdate();
507
   while(lineValue[0] < MARKLINE0)          
545
   while(lineValue[0] < MARKLINE0)          
508
   {
546
   {
509
     LineUpdate();
547
     LineUpdate();
510
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
548
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
511
-    //if(lineValue[0] > MARKLINE0) break;
512
   } 
549
   } 
550
+
513
   //links drehen
551
   //links drehen
514
   GyroUpdate();
552
   GyroUpdate();
515
   while(rotationAngle < -10)                                               
553
   while(rotationAngle < -10)                                               
520
     else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
558
     else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
521
     else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
559
     else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
522
   }
560
   }
561
+
523
   //geradeaus fahren
562
   //geradeaus fahren
524
   //Serial1.println("Umfahren beendet");
563
   //Serial1.println("Umfahren beendet");
525
-  Serial1.print(0); 
526
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT);
564
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT);
565
+  stop = false;
566
+  stopUpdate = millis();
567
+  Serial1.print(0); 
527
 }
568
 }
528
 
569
 
529
 //Funktion Abbiegen
570
 //Funktion Abbiegen
574
     while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)
615
     while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)
575
     {
616
     {
576
       LineUpdate();
617
       LineUpdate();
577
-      motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
618
+      motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
578
     }
619
     }
620
+
579
     //links drehen
621
     //links drehen
580
     turnAngle = 0;  
622
     turnAngle = 0;  
581
     rotationAngle = 0;
623
     rotationAngle = 0;
588
       else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(HALFSPEEDLEFT, FULLSPEEDRIGHT); 
630
       else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(HALFSPEEDLEFT, FULLSPEEDRIGHT); 
589
       else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
631
       else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
590
     }
632
     }
633
+
591
     //geradeaus fahren
634
     //geradeaus fahren
592
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
635
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
593
   }
636
   }
597
   {
640
   {
598
     //Serial1.println("links Abbiegen vom Rundkurs"); 
641
     //Serial1.println("links Abbiegen vom Rundkurs"); 
599
     //links drehen
642
     //links drehen
643
+    motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
600
     turnAngle = 0;  
644
     turnAngle = 0;  
601
     rotationAngle = 0;
645
     rotationAngle = 0;
602
-    driveRotation[1] = 0;
603
     GyroUpdate();
646
     GyroUpdate();
604
     while(rotationAngle < 40)
647
     while(rotationAngle < 40)
605
     {
648
     {
606
       GyroUpdate();
649
       GyroUpdate();
607
-      EncoderUpdate();
608
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
650
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
609
-      //if(driveRotation[1] > 1) break;
610
     }
651
     }
611
-    driveRotation[1] = 0;
612
     GyroUpdate();
652
     GyroUpdate();
613
     while(rotationAngle < 85)
653
     while(rotationAngle < 85)
614
     {
654
     {
615
       GyroUpdate();
655
       GyroUpdate();
616
-      EncoderUpdate();
617
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
656
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
618
-      //if(driveRotation[1] > 1) break;
619
     }
657
     }
658
+
620
     //geradeaus fahren
659
     //geradeaus fahren
621
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
660
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
622
     lastUpdate = millis();
661
     lastUpdate = millis();
625
     {
664
     {
626
       TimeUpdate();
665
       TimeUpdate();
627
       LineUpdate();
666
       LineUpdate();
667
+      motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
628
       if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
668
       if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
629
     }
669
     }
630
     lastUpdate = millis();
670
     lastUpdate = millis();
642
   {
682
   {
643
     //Serial1.println("rechts Abbiegen"); 
683
     //Serial1.println("rechts Abbiegen"); 
644
     //rechts drehen
684
     //rechts drehen
685
+    motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
645
     turnAngle = 0;  
686
     turnAngle = 0;  
646
     rotationAngle = 0;
687
     rotationAngle = 0;
647
-    driveRotation[0] = 0;
648
     GyroUpdate();
688
     GyroUpdate();
649
     while(rotationAngle > -40)
689
     while(rotationAngle > -40)
650
     {
690
     {
651
       GyroUpdate();
691
       GyroUpdate();
652
-      EncoderUpdate();
653
       LineUpdate();
692
       LineUpdate();
654
       motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
693
       motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
655
       if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) break;
694
       if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) break;
683
       Spurhalten();
722
       Spurhalten();
684
     }
723
     }
685
   }
724
   }
725
+  stop = false;
726
+  stopUpdate = millis();
686
   //Serial1.println("Abbiegen beendet");
727
   //Serial1.println("Abbiegen beendet");
687
   Serial1.print(0); 
728
   Serial1.print(0); 
688
 }
729
 }
699
   {
740
   {
700
     ledYellow(1); 
741
     ledYellow(1); 
701
     //Serial1.println("Spur nach rechts korrigieren");  
742
     //Serial1.println("Spur nach rechts korrigieren");  
702
-    motors.setSpeeds(FULLSPEEDLEFT/eventSpeed, SLOWSPEEDRIGHT/eventSpeed);
743
+    motors.setSpeeds((int)FULLSPEEDLEFT/eventSpeed, (int)SLOWSPEEDRIGHT/eventSpeed);
703
     while(Time < 100)
744
     while(Time < 100)
704
     {
745
     {
705
       Update = millis();
746
       Update = millis();
707
       LineUpdate();
748
       LineUpdate();
708
       if(lineValue[2] > MARKLINE2) break;
749
       if(lineValue[2] > MARKLINE2) break;
709
     }   
750
     }   
751
+    stop = false;
752
+    stopUpdate = millis();
710
   }
753
   }
711
 
754
 
712
   //rechte Linie erreicht, nach links fahren
755
   //rechte Linie erreicht, nach links fahren
714
   {
757
   {
715
     ledYellow(1); 
758
     ledYellow(1); 
716
     //Serial1.println("Spur nach links korrigieren");  
759
     //Serial1.println("Spur nach links korrigieren");  
717
-    motors.setSpeeds(SLOWSPEEDLEFT/eventSpeed, FULLSPEEDRIGHT/eventSpeed);   
760
+    motors.setSpeeds((int)SLOWSPEEDLEFT/eventSpeed, (int)FULLSPEEDRIGHT/eventSpeed);   
718
     while(Time < 100)
761
     while(Time < 100)
719
     {
762
     {
720
       Update = millis();
763
       Update = millis();
722
       LineUpdate();
765
       LineUpdate();
723
       if(lineValue[0] > MARKLINE0) break;
766
       if(lineValue[0] > MARKLINE0) break;
724
     }   
767
     }   
768
+    stop = false;
769
+    stopUpdate = millis();
725
   }
770
   }
726
 
771
 
727
   //normale Fahrt
772
   //normale Fahrt
728
   else                                                                
773
   else                                                                
729
   {
774
   {
730
     ledGreen(1); 
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
     motors.setSpeeds(-FULLSPEEDLEFT, -FULLSPEEDRIGHT);
792
     motors.setSpeeds(-FULLSPEEDLEFT, -FULLSPEEDRIGHT);
747
     if(eventTime > 3000) break;
793
     if(eventTime > 3000) break;
748
   } 
794
   } 
795
+  stop = false;
796
+  stopUpdate = millis();
749
   //Serial1.println("Spur gefunden"); 
797
   //Serial1.println("Spur gefunden"); 
750
   Serial1.print(0);  
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
 void loop() 
803
 void loop() 
780
   CompassUpdate();
814
   CompassUpdate();
781
   LineUpdate();      
815
   LineUpdate();      
782
   TimeUpdate();
816
   TimeUpdate();
817
+  StopUpdate();
783
 
818
 
784
   //Funktionsauswahl
819
   //Funktionsauswahl
785
-  //btData = Serial1.readString();
786
   if(Serial1.available() > 0) btData = Serial1.read();
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
   //verfügbare Funktionen bei laufenden Manövern
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
     //Serial1.println("Verstanden");
827
     //Serial1.println("Verstanden");
794
     eventSpeed = 1.4;
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
     else Spurhalten();
832
     else Spurhalten();
797
   }
833
   }
834
+
798
   //verfügbare Funktionen im Normalfall
835
   //verfügbare Funktionen im Normalfall
799
   else                                                              
836
   else                                                              
800
   {
837
   {
801
     eventSpeed = 1.0;
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
     else if((lineValue[0] > SIGN0 && lineValue[0] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
842
     else if((lineValue[0] > SIGN0 && lineValue[0] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
805
     else if((lineValue[2] > SIGN2 && lineValue[2] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
843
     else if((lineValue[2] > SIGN2 && lineValue[2] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
806
     else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) Spurfinden();
844
     else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) Spurfinden();

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


+ 104 - 68
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 14.05.2018 
2
+//Datum: erstellt am 19.07.2017, zuletzt geändert am 17.05.2018 
3
 //Projektthema: Untersuchungen und Implementierung eines automatisierten Fahrens mittels Pololu Zumo
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 
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). 
5
 der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
23
 LSM303                    compass;      //Beschleunigungssensor x-Achse
23
 LSM303                    compass;      //Beschleunigungssensor x-Achse
24
 L3G                       gyro;         //Drehbewegungssensor z-Achse
24
 L3G                       gyro;         //Drehbewegungssensor z-Achse
25
 
25
 
26
+//Medianfilter geben mittleren Wert einer Reihe mit ungerader Anzahl aus
26
 MedianFilter LineFilter0(3, 0);         //erstellen der Filter für Liniensensoren
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
 MedianFilter ProxFilter0(5, 0);         //erstellen der Filter für Abstandssensoren
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
 MedianFilter ProxFilter2(5, 0);
33
 MedianFilter ProxFilter2(5, 0);
32
 MedianFilter ProxFilter3(5, 0);
34
 MedianFilter ProxFilter3(5, 0);
33
 
35
 
37
 #define   SIGN0           500
39
 #define   SIGN0           500
38
 #define   SIGN1           300
40
 #define   SIGN1           300
39
 #define   SIGN2           500
41
 #define   SIGN2           500
42
+
40
 #define   MAXSPEED        400
43
 #define   MAXSPEED        400
41
 #define   FULLSPEEDLEFT   104
44
 #define   FULLSPEEDLEFT   104
42
 #define   HALFSPEEDLEFT   52
45
 #define   HALFSPEEDLEFT   52
58
 int16_t   turnRate;
61
 int16_t   turnRate;
59
 int16_t   gyroOffset;
62
 int16_t   gyroOffset;
60
 uint16_t  gyroLastUpdate;
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
 uint16_t  lastUpdate = 0;               //Systemzeit
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
 float     eventSpeed = 1;               //vermindert die Geschwindigkeit bei Manövern
73
 float     eventSpeed = 1;               //vermindert die Geschwindigkeit bei Manövern
72
 int       btData = 0;                   //Gelesene Daten aus Bluetooth
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
   int32_t total = 0;                                              
176
   int32_t total = 0;                                              
174
   for (uint16_t i = 0; i < 1024; i++)
177
   for (uint16_t i = 0; i < 1024; i++)
175
   {
178
   {
176
-    compass.read();
179
+    compass.readAcc();
177
     total += compass.a.x;
180
     total += compass.a.x;
178
   }
181
   }
179
   compassOffset = total / 1024;
182
   compassOffset = total / 1024;
204
   buttonA.waitForButton();
207
   buttonA.waitForButton();
205
   randomSeed(millis());
208
   randomSeed(millis());
206
   delay(500);
209
   delay(500);
210
+  stopUpdate = millis();
207
   //Serial1.println("Start");
211
   //Serial1.println("Start");
208
 }
212
 }
209
 
213
 
210
 /*-----------------------------------------------------------------*/
214
 /*-----------------------------------------------------------------*/
211
 
215
 
212
-//Update Durchlaufzeit
216
+//Update Zeitdifferenz für alle Funktionen
213
 void TimeUpdate()
217
 void TimeUpdate()
214
 {
218
 {
215
   uint16_t m = millis();
219
   uint16_t m = millis();
216
   eventTime = m - lastUpdate;
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
 void LoopTiming()
230
 void LoopTiming()
220
 {
231
 {
221
   const int AL = 100;       // Arraylänge, NUR GERADE Zahlen verwenden!
232
   const int AL = 100;       // Arraylänge, NUR GERADE Zahlen verwenden!
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
 //Update Abstandssensoren
288
 //Update Abstandssensoren
263
 void ProxUpdate()
289
 void ProxUpdate()
264
 {
290
 {
276
       proxValue[1] = ProxFilter1.in(proxSensors.countsFrontWithLeftLeds());
302
       proxValue[1] = ProxFilter1.in(proxSensors.countsFrontWithLeftLeds());
277
       proxValue[2] = ProxFilter2.in(proxSensors.countsFrontWithRightLeds());  
303
       proxValue[2] = ProxFilter2.in(proxSensors.countsFrontWithRightLeds());  
278
       proxValue[3] = ProxFilter3.in(proxSensors.countsRightWithRightLeds()); 
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
       done = true;
305
       done = true;
284
     }
306
     }
285
     else
307
     else
316
 //Update Beschleunigungssensor
338
 //Update Beschleunigungssensor
317
 void CompassUpdate()
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
 //Update Encoder
347
 //Update Encoder
330
 void EncoderUpdate()
348
 void EncoderUpdate()
331
 {
349
 {
332
-  encoderCounts[0] = encoders.getCountsLeft();
350
+  encoderCounts[0] += encoders.getCountsAndResetLeft();
333
   driveRotation[0] = encoderCounts[0] / 910;                        //12cpr (Motorwelle) * 75,81:1 (Getriebe) = 909,7cpr (Antriebszahnrad)
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
   driveRotation[1] = encoderCounts[1] / 910;
353
   driveRotation[1] = encoderCounts[1] / 910;
336
 }
354
 }
337
 
355
 
348
   while(proxValue[1] == 0 || proxValue[2] == 0)
366
   while(proxValue[1] == 0 || proxValue[2] == 0)
349
   {
367
   {
350
     ProxUpdate();
368
     ProxUpdate();
369
+    LineUpdate();
351
     motors.setSpeeds(-HALFSPEEDLEFT, -HALFSPEEDRIGHT);
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
   motors.setSpeeds(0, 0);
382
   motors.setSpeeds(0, 0);
383
+  compassLastUpdate = 0;
384
+  compassRate = 0;
385
+  CompassUpdate();
386
+  stop = false;
387
+  stopUpdate = millis();
355
   //Serial1.println("Vermeiden beendet");
388
   //Serial1.println("Vermeiden beendet");
356
   Serial1.print(0); 
389
   Serial1.print(0); 
357
 }
390
 }
382
     motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
415
     motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
383
     if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
416
     if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
384
   }
417
   }
418
+
385
   //geradeaus über Mittellinie fahren
419
   //geradeaus über Mittellinie fahren
386
   LineUpdate();
420
   LineUpdate();
387
   while(lineValue[2] < MARKLINE2)          
421
   while(lineValue[2] < MARKLINE2)          
388
   {
422
   {
389
     LineUpdate();
423
     LineUpdate();
390
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
424
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
391
-    //if(lineValue[0] > MARKLINE0) break;
392
   } 
425
   } 
426
+
393
   //rechts drehen
427
   //rechts drehen
394
   GyroUpdate();
428
   GyroUpdate();
395
   while(rotationAngle > 10)                                               
429
   while(rotationAngle > 10)                                               
400
     else if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
434
     else if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
401
     else motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
435
     else motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
402
   }
436
   }
437
+
403
   //geradeaus fahren
438
   //geradeaus fahren
404
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
439
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
405
 
440
 
406
   //Gegenverkehr beachten
441
   //Gegenverkehr beachten
407
   ProxUpdate();
442
   ProxUpdate();
408
-  //if(proxValue[1] < 5 || proxValue[2] < 5)
443
+  //if(proxValue[1] == 6 && proxValue[2] == 6)
409
   //{
444
   //{
410
     //Schritt 2: Hindernis passieren
445
     //Schritt 2: Hindernis passieren
411
     //Serial1.println("Aufholen"); 
446
     //Serial1.println("Aufholen"); 
458
     motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
493
     motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
459
     if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) break;
494
     if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) break;
460
   }
495
   }
496
+
461
   //geradeaus über Mittellinie fahren
497
   //geradeaus über Mittellinie fahren
462
   LineUpdate();
498
   LineUpdate();
463
   while(lineValue[0] < MARKLINE0)          
499
   while(lineValue[0] < MARKLINE0)          
464
   {
500
   {
465
     LineUpdate();
501
     LineUpdate();
466
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
502
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
467
-    //if(lineValue[0] > MARKLINE0) break;
468
   } 
503
   } 
504
+
469
   //links drehen
505
   //links drehen
470
   GyroUpdate();
506
   GyroUpdate();
471
   while(rotationAngle < -10)                                               
507
   while(rotationAngle < -10)                                               
476
     else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
512
     else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
477
     else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
513
     else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
478
   }
514
   }
515
+
479
   //geradeaus fahren
516
   //geradeaus fahren
480
   //Serial1.println("Umfahren beendet");
517
   //Serial1.println("Umfahren beendet");
481
-  Serial1.print(0); 
482
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT);
518
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT);
519
+  stop = false;
520
+  stopUpdate = millis();
521
+  Serial1.print(0); 
483
 }
522
 }
484
 
523
 
485
 //Funktion Abbiegen
524
 //Funktion Abbiegen
530
     while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)
569
     while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)
531
     {
570
     {
532
       LineUpdate();
571
       LineUpdate();
533
-      motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
572
+      motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
534
     }
573
     }
574
+
535
     //links drehen
575
     //links drehen
536
     turnAngle = 0;  
576
     turnAngle = 0;  
537
     rotationAngle = 0;
577
     rotationAngle = 0;
544
       else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(HALFSPEEDLEFT, FULLSPEEDRIGHT); 
584
       else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(HALFSPEEDLEFT, FULLSPEEDRIGHT); 
545
       else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
585
       else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
546
     }
586
     }
587
+
547
     //geradeaus fahren
588
     //geradeaus fahren
548
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
589
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
549
   }
590
   }
553
   {
594
   {
554
     //Serial1.println("links Abbiegen vom Rundkurs"); 
595
     //Serial1.println("links Abbiegen vom Rundkurs"); 
555
     //links drehen
596
     //links drehen
597
+    motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
556
     turnAngle = 0;  
598
     turnAngle = 0;  
557
     rotationAngle = 0;
599
     rotationAngle = 0;
558
-    driveRotation[1] = 0;
559
     GyroUpdate();
600
     GyroUpdate();
560
     while(rotationAngle < 40)
601
     while(rotationAngle < 40)
561
     {
602
     {
562
       GyroUpdate();
603
       GyroUpdate();
563
-      EncoderUpdate();
564
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
604
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
565
-      //if(driveRotation[1] > 1) break;
566
     }
605
     }
567
-    driveRotation[1] = 0;
568
     GyroUpdate();
606
     GyroUpdate();
569
     while(rotationAngle < 85)
607
     while(rotationAngle < 85)
570
     {
608
     {
571
       GyroUpdate();
609
       GyroUpdate();
572
-      EncoderUpdate();
573
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
610
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
574
-      //if(driveRotation[1] > 1) break;
575
     }
611
     }
612
+
576
     //geradeaus fahren
613
     //geradeaus fahren
577
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
614
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
578
     lastUpdate = millis();
615
     lastUpdate = millis();
581
     {
618
     {
582
       TimeUpdate();
619
       TimeUpdate();
583
       LineUpdate();
620
       LineUpdate();
621
+      motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
584
       if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
622
       if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
585
     }
623
     }
586
     lastUpdate = millis();
624
     lastUpdate = millis();
598
   {
636
   {
599
     //Serial1.println("rechts Abbiegen"); 
637
     //Serial1.println("rechts Abbiegen"); 
600
     //rechts drehen
638
     //rechts drehen
639
+    motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
601
     turnAngle = 0;  
640
     turnAngle = 0;  
602
     rotationAngle = 0;
641
     rotationAngle = 0;
603
-    driveRotation[0] = 0;
604
     GyroUpdate();
642
     GyroUpdate();
605
     while(rotationAngle > -40)
643
     while(rotationAngle > -40)
606
     {
644
     {
607
       GyroUpdate();
645
       GyroUpdate();
608
-      EncoderUpdate();
609
       LineUpdate();
646
       LineUpdate();
610
       motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
647
       motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
611
       if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) break;
648
       if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) break;
639
       Spurhalten();
676
       Spurhalten();
640
     }
677
     }
641
   }
678
   }
679
+  stop = false;
680
+  stopUpdate = millis();
642
   //Serial1.println("Abbiegen beendet");
681
   //Serial1.println("Abbiegen beendet");
643
   Serial1.print(0); 
682
   Serial1.print(0); 
644
 }
683
 }
655
   {
694
   {
656
     ledYellow(1); 
695
     ledYellow(1); 
657
     //Serial1.println("Spur nach rechts korrigieren");  
696
     //Serial1.println("Spur nach rechts korrigieren");  
658
-    motors.setSpeeds(FULLSPEEDLEFT/eventSpeed, SLOWSPEEDRIGHT/eventSpeed);
697
+    motors.setSpeeds((int)FULLSPEEDLEFT/eventSpeed, (int)SLOWSPEEDRIGHT/eventSpeed);
659
     while(Time < 100)
698
     while(Time < 100)
660
     {
699
     {
661
       Update = millis();
700
       Update = millis();
663
       LineUpdate();
702
       LineUpdate();
664
       if(lineValue[2] > MARKLINE2) break;
703
       if(lineValue[2] > MARKLINE2) break;
665
     }   
704
     }   
705
+    stop = false;
706
+    stopUpdate = millis();
666
   }
707
   }
667
 
708
 
668
   //rechte Linie erreicht, nach links fahren
709
   //rechte Linie erreicht, nach links fahren
670
   {
711
   {
671
     ledYellow(1); 
712
     ledYellow(1); 
672
     //Serial1.println("Spur nach links korrigieren");  
713
     //Serial1.println("Spur nach links korrigieren");  
673
-    motors.setSpeeds(SLOWSPEEDLEFT/eventSpeed, FULLSPEEDRIGHT/eventSpeed);   
714
+    motors.setSpeeds((int)SLOWSPEEDLEFT/eventSpeed, (int)FULLSPEEDRIGHT/eventSpeed);   
674
     while(Time < 100)
715
     while(Time < 100)
675
     {
716
     {
676
       Update = millis();
717
       Update = millis();
678
       LineUpdate();
719
       LineUpdate();
679
       if(lineValue[0] > MARKLINE0) break;
720
       if(lineValue[0] > MARKLINE0) break;
680
     }   
721
     }   
722
+    stop = false;
723
+    stopUpdate = millis();
681
   }
724
   }
682
 
725
 
683
   //normale Fahrt
726
   //normale Fahrt
684
   else                                                                
727
   else                                                                
685
   {
728
   {
686
     ledGreen(1); 
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
     motors.setSpeeds(-FULLSPEEDLEFT, -FULLSPEEDRIGHT);
746
     motors.setSpeeds(-FULLSPEEDLEFT, -FULLSPEEDRIGHT);
703
     if(eventTime > 3000) break;
747
     if(eventTime > 3000) break;
704
   } 
748
   } 
749
+  stop = false;
750
+  stopUpdate = millis();
705
   //Serial1.println("Spur gefunden"); 
751
   //Serial1.println("Spur gefunden"); 
706
   Serial1.print(0);  
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
 void loop() 
757
 void loop() 
736
   CompassUpdate();
768
   CompassUpdate();
737
   LineUpdate();      
769
   LineUpdate();      
738
   TimeUpdate();
770
   TimeUpdate();
771
+  StopUpdate();
739
 
772
 
740
   //Funktionsauswahl
773
   //Funktionsauswahl
741
-  //btData = Serial1.readString();
742
   if(Serial1.available() > 0) btData = Serial1.read();
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
   //verfügbare Funktionen bei laufenden Manövern
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
     //Serial1.println("Verstanden");
781
     //Serial1.println("Verstanden");
750
     eventSpeed = 1.4;
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
     else Spurhalten();
786
     else Spurhalten();
753
   }
787
   }
788
+
754
   //verfügbare Funktionen im Normalfall
789
   //verfügbare Funktionen im Normalfall
755
   else                                                              
790
   else                                                              
756
   {
791
   {
757
     eventSpeed = 1.0;
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
     else if((lineValue[0] > SIGN0 && lineValue[0] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
796
     else if((lineValue[0] > SIGN0 && lineValue[0] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
761
     else if((lineValue[2] > SIGN2 && lineValue[2] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
797
     else if((lineValue[2] > SIGN2 && lineValue[2] < 1600) && (lineValue[1] > SIGN1 && lineValue[1] < 800)) Abbiegen();
762
     else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) Spurfinden();
798
     else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) Spurfinden();