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

BIN
ArduinoOutput/Hauptprojekt.ino.elf


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


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


BIN
ArduinoOutput/core/CDC.cpp.o


BIN
ArduinoOutput/core/HardwareSerial.cpp.o


BIN
ArduinoOutput/core/HardwareSerial0.cpp.o


BIN
ArduinoOutput/core/HardwareSerial1.cpp.o


BIN
ArduinoOutput/core/HardwareSerial2.cpp.o


BIN
ArduinoOutput/core/HardwareSerial3.cpp.o


BIN
ArduinoOutput/core/IPAddress.cpp.o


BIN
ArduinoOutput/core/PluggableUSB.cpp.o


BIN
ArduinoOutput/core/Print.cpp.o


BIN
ArduinoOutput/core/Stream.cpp.o


BIN
ArduinoOutput/core/Tone.cpp.o


BIN
ArduinoOutput/core/USBCore.cpp.o


BIN
ArduinoOutput/core/WInterrupts.c.o


BIN
ArduinoOutput/core/WMath.cpp.o


BIN
ArduinoOutput/core/WString.cpp.o


BIN
ArduinoOutput/core/abi.cpp.o


BIN
ArduinoOutput/core/core.a


BIN
ArduinoOutput/core/hooks.c.o


BIN
ArduinoOutput/core/main.cpp.o


BIN
ArduinoOutput/core/new.cpp.o


BIN
ArduinoOutput/core/wiring.c.o


BIN
ArduinoOutput/core/wiring_analog.c.o


BIN
ArduinoOutput/core/wiring_digital.c.o


BIN
ArduinoOutput/core/wiring_pulse.S.o


BIN
ArduinoOutput/core/wiring_pulse.c.o


BIN
ArduinoOutput/core/wiring_shift.c.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


+ 132 - 112
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 13.04.2018 
4
+//Datum: erstellt am 19.07.2017, zuletzt geändert am 04.05.2018 
5
 //Projektbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
5
 //Projektbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
6
 //der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
6
 //der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
7
 //Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
7
 //Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
58
   Serial1.begin(9600); //Initialisierung mit Datengeschwindigkeit(Baud)
58
   Serial1.begin(9600); //Initialisierung mit Datengeschwindigkeit(Baud)
59
   Serial1.setTimeout(10); //verkürzt Serial(1).read auf 10 ms statt 1000 ms
59
   Serial1.setTimeout(10); //verkürzt Serial(1).read auf 10 ms statt 1000 ms
60
   if(Serial1.available()) Serial.println("Bluetoothverbindung hergestellt");
60
   if(Serial1.available()) Serial.println("Bluetoothverbindung hergestellt");
61
+  if(Serial1.available() > 0) Serial1.read(); //Verwerfen der alten Informationen aus dem Puffer
61
 }
62
 }
62
 
63
 
63
 //Setup Liniensensoren
64
 //Setup Liniensensoren
66
   ledYellow(1);
67
   ledYellow(1);
67
   lineSensors.initThreeSensors(); //Initialisierung von 3 Sensoren (max 5)
68
   lineSensors.initThreeSensors(); //Initialisierung von 3 Sensoren (max 5)
68
 
69
 
69
-  // //Kalibrierung
70
-  // uint32_t total[3] = {0, 0, 0};  
71
-  // for(uint8_t i = 0; i < 120; i++)                                
72
-  // {
73
-  //   if (i > 30 && i <= 90) motors.setSpeeds(FULLSPEEDLEFT, -FULLSPEEDRIGHT);
74
-  //   else motors.setSpeeds(-FULLSPEEDLEFT, FULLSPEEDRIGHT);
75
-  //   lineSensors.read(lineOffset);  
76
-  //   total[0] += lineOffset[0];
77
-  //   total[1] += lineOffset[1];
78
-  //   total[2] += lineOffset[2];
79
-    lineSensors.calibrate();
80
-  // }
81
-  // motors.setSpeeds(0, 0);
82
-  // lineOffset[0] = total[0] / 120;
83
-  // lineOffset[1] = total[1] / 120;
84
-  // lineOffset[2] = total[2] / 120;
70
+  //Kalibrierung
71
+  uint32_t total[3] = {0, 0, 0};
72
+  for(uint8_t i = 0; i < 120; i++)
73
+  {
74
+    if (i > 30 && i <= 90) motors.setSpeeds(106, -100);
75
+    else motors.setSpeeds(-106, 100);
76
+    lineSensors.read(lineOffset);
77
+    total[0] += lineOffset[0];
78
+    total[1] += lineOffset[1];
79
+    total[2] += lineOffset[2];
80
+   lineSensors.calibrate();
81
+  }
82
+  motors.setSpeeds(0, 0);
83
+  lineOffset[0] = total[0] / 120;
84
+  lineOffset[1] = total[1] / 120;
85
+  lineOffset[2] = total[2] / 120;
85
   ledYellow(0);
86
   ledYellow(0);
86
 
87
 
87
-  lineOffset[0] = 240;
88
-  lineOffset[1] = 120;
89
-  lineOffset[2] = 220;
88
+  // lineOffset[0] = 240;
89
+  // lineOffset[1] = 120;
90
+  // lineOffset[2] = 220;
90
 }
91
 }
91
 
92
 
92
 //Setup Abstandssensoren
93
 //Setup Abstandssensoren
106
     ledRed(1);
107
     ledRed(1);
107
     while(1)
108
     while(1)
108
     {
109
     {
109
-      //Serial1.println("Fehler Drehbewegungssensors");
110
-      delay(1000);
110
+      Serial.println("Fehler Drehbewegungssensors");
111
+      delay(5000);
111
     }
112
     }
112
   }
113
   }
113
   gyro.writeReg(L3G::CTRL1, 0b11111111); //Ausgaberate 800Hz, Tiefpassfilter 100Hz
114
   gyro.writeReg(L3G::CTRL1, 0b11111111); //Ausgaberate 800Hz, Tiefpassfilter 100Hz
139
     ledRed(1);
140
     ledRed(1);
140
     while(1)
141
     while(1)
141
     {
142
     {
142
-      //Serial1.println("Fehler Beschleunigungssensors");
143
-      delay(1000);
143
+      Serial.println("Fehler Beschleunigungssensors");
144
+      delay(5000);
144
     }
145
     }
145
   }
146
   }
146
   compass.enableDefault();
147
   compass.enableDefault();
296
 void Kontaktvermeiden()
297
 void Kontaktvermeiden()
297
 {
298
 {
298
   //Serial1.println("Kontaktvermeiden");
299
   //Serial1.println("Kontaktvermeiden");
299
-  Serial1.println(1);
300
+  Serial1.print(1);
300
   ledRed(1);
301
   ledRed(1);
301
-
302
   motors.setSpeeds(0, 0);
302
   motors.setSpeeds(0, 0);
303
-  delay(500);
303
+  delay(1000);
304
   while(proxValue[1] == 0 || proxValue[2] == 0)
304
   while(proxValue[1] == 0 || proxValue[2] == 0)
305
   {
305
   {
306
     ProxUpdate();
306
     ProxUpdate();
307
-    motors.setSpeeds(-54, -50);
308
-    if(lineValue[0] > 150 || lineValue[2] > 170) break;
307
+    motors.setSpeeds(-53, -50);
308
+    if(lineValue[0] > 150 || lineValue[2] > 120) break;
309
   }
309
   }
310
-  delay(500);
310
+  motors.setSpeeds(0, 0);
311
   //Serial1.println("Vermeiden beendet");
311
   //Serial1.println("Vermeiden beendet");
312
-  Serial1.println(0);
312
+  Serial1.print(0);
313
 }
313
 }
314
 
314
 
315
 //Funktion Hindernisumfahrung
315
 //Funktion Hindernisumfahrung
316
 void Hindernisumfahren()
316
 void Hindernisumfahren()
317
 {
317
 {
318
   //Serial1.println("Hindernisumfahren"); 
318
   //Serial1.println("Hindernisumfahren"); 
319
-  Serial1.println(1);
319
+  Serial1.print(1);
320
   ledYellow(1);
320
   ledYellow(1);
321
 
321
 
322
   //Schritt 1: Spurwechsel links   
322
   //Schritt 1: Spurwechsel links   
329
     GyroUpdate();
329
     GyroUpdate();
330
     LineUpdate();
330
     LineUpdate();
331
     motors.setSpeeds(27, 100);
331
     motors.setSpeeds(27, 100);
332
-    if(lineValue[2] > 170 && lineValue[2] < 450) break;
332
+    if(lineValue[2] > 120 && lineValue[2] < 500) break;
333
   }
333
   }
334
   //geradeaus über Mittellinie fahren
334
   //geradeaus über Mittellinie fahren
335
   LineUpdate();
335
   LineUpdate();
336
-  while(lineValue[2] < 170)
336
+  while(lineValue[2] < 120)
337
   {
337
   {
338
     LineUpdate();
338
     LineUpdate();
339
-    motors.setSpeeds(107, 100);
339
+    motors.setSpeeds(106, 100);
340
     //if(lineValue[0] > MARKLINE0) break;
340
     //if(lineValue[0] > MARKLINE0) break;
341
   }
341
   }
342
   //rechts drehen
342
   //rechts drehen
345
   {
345
   {
346
     GyroUpdate();
346
     GyroUpdate();
347
     LineUpdate();
347
     LineUpdate();
348
-    if(lineValue[0] > 150 && lineValue[0] < 400) motors.setSpeeds(107, 0);
349
-    else if(lineValue[2] > 170 && lineValue[2] < 450) motors.setSpeeds(107, 100);
350
-    else motors.setSpeeds(107, 25);
348
+    if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(106, 0);
349
+    else if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(106, 100);
350
+    else motors.setSpeeds(106, 25);
351
   }
351
   }
352
   //geradeaus fahren
352
   //geradeaus fahren
353
-  motors.setSpeeds(107, 100);
353
+  motors.setSpeeds(106, 100);
354
 
354
 
355
   //Gegenverkehr beachten
355
   //Gegenverkehr beachten
356
   ProxUpdate();
356
   ProxUpdate();
395
   {
395
   {
396
     GyroUpdate();
396
     GyroUpdate();
397
     LineUpdate();
397
     LineUpdate();
398
-    motors.setSpeeds(107, 25);
399
-    if(lineValue[0] > 150 && lineValue[0] < 400) break;
398
+    motors.setSpeeds(106, 25);
399
+    if(lineValue[0] > 150 && lineValue[0] < 500) break;
400
   }
400
   }
401
   //geradeaus über Mittellinie fahren
401
   //geradeaus über Mittellinie fahren
402
   LineUpdate();
402
   LineUpdate();
403
   while(lineValue[0] < 150)
403
   while(lineValue[0] < 150)
404
   {
404
   {
405
     LineUpdate();
405
     LineUpdate();
406
-    motors.setSpeeds(107, 100);
406
+    motors.setSpeeds(106, 100);
407
     //if(lineValue[0] > MARKLINE0) break;
407
     //if(lineValue[0] > MARKLINE0) break;
408
   }
408
   }
409
   //links drehen
409
   //links drehen
412
   {
412
   {
413
     GyroUpdate();
413
     GyroUpdate();
414
     LineUpdate();
414
     LineUpdate();
415
-    if(lineValue[2] > 170 && lineValue[2] < 450) motors.setSpeeds(0, 100);
416
-    else if(lineValue[0] > 150 && lineValue[0] < 400) motors.setSpeeds(107, 100);
415
+    if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(0, 100);
416
+    else if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(106, 100);
417
     else motors.setSpeeds(27, 100);
417
     else motors.setSpeeds(27, 100);
418
   }
418
   }
419
   //geradeaus fahren
419
   //geradeaus fahren
420
   //Serial1.println("Umfahren beendet");
420
   //Serial1.println("Umfahren beendet");
421
-  Serial1.println(0);
422
-  motors.setSpeeds(107, 100);
421
+  Serial1.print(0);
422
+  motors.setSpeeds(106, 100);
423
 }
423
 }
424
 
424
 
425
 //Funktion Abbiegen
425
 //Funktion Abbiegen
427
 {
427
 {
428
   ledYellow(1);
428
   ledYellow(1);
429
   //Serial1.println("Abbiegen");  
429
   //Serial1.println("Abbiegen");  
430
-  Serial1.println(1);
430
+  Serial1.print(1);
431
 
431
 
432
   //Markierung analysieren
432
   //Markierung analysieren
433
   LineUpdate();
433
   LineUpdate();
434
   bool leftCode; //links => 1
434
   bool leftCode; //links => 1
435
   bool rightCode; //rechts => 2
435
   bool rightCode; //rechts => 2
436
-  if(lineValue[0] > 400) leftCode = true;
436
+  if((lineValue[0] > 500 && lineValue[0] < 1400) && (lineValue[1] > 300 && lineValue[1] < 700)) leftCode = true;
437
   else leftCode = false;
437
   else leftCode = false;
438
-  if(lineValue[2] > 450) rightCode = true;
438
+  if((lineValue[2] > 500 && lineValue[2] < 1400) && (lineValue[1] > 300 && lineValue[1] < 700)) rightCode = true;
439
   else rightCode = false;
439
   else rightCode = false;
440
 
440
 
441
   //Zufallszahl erzeugen
441
   //Zufallszahl erzeugen
442
   uint8_t randy; //geradeaus => 0
442
   uint8_t randy; //geradeaus => 0
443
   if(leftCode == true && rightCode == true) randy = random(1, 3); //1, 2
443
   if(leftCode == true && rightCode == true) randy = random(1, 3); //1, 2
444
-  else if(leftCode == true && rightCode == false) randy = 1;
445
-  // else if(leftCode == true && rightCode == false) 
446
-  // {
447
-  //   randy = random(0, 2);                                                 //0, 1
448
-  //   if(randy == 0) randy = random(0, 2);                                  //erhöht Wahrscheinlickeit abzubiegen
449
-  // }
450
-  else if(leftCode == false && rightCode == true) randy = 2;
451
-  // else if(leftCode == false && rightCode == true)
452
-  // {
453
-  //   randy = random(3);                                                    //0, (1), 2
454
-  //   if(randy == 0) randy = random(3);                                     //erhöht Wahrscheinlickeit abzubiegen
455
-  //   while(randy == 1) randy = random(3);                                  //!1 => 0, 2
456
-  // }
444
+  else if(leftCode == true && rightCode == false) //randy = 1;
445
+  {
446
+    randy = random(0, 2); //0, 1
447
+    //if(randy == 0) randy = random(0, 2);                                  //erhöht Wahrscheinlickeit abzubiegen
448
+  }
449
+  else if(leftCode == false && rightCode == true) //randy = 2;
450
+  {
451
+    randy = random(0, 2); //0, 1
452
+    //if(randy == 0) randy = random(0, 2);                                  //erhöht Wahrscheinlickeit abzubiegen
453
+    if(randy == 1) randy = 2; //!1 => 2
454
+  }
457
 
455
 
458
   //links Abbiegen (von der Verbindungsstrecke)
456
   //links Abbiegen (von der Verbindungsstrecke)
459
   if(randy == 1 && rightCode == true)
457
   if(randy == 1 && rightCode == true)
460
   {
458
   {
461
     //Serial1.println("links Abbiegen von der Verbindungsstrecke"); 
459
     //Serial1.println("links Abbiegen von der Verbindungsstrecke"); 
462
     //geradeaus zur Mittellinie fahren
460
     //geradeaus zur Mittellinie fahren
463
-    motors.setSpeeds(107, 100 +10);
461
+    motors.setSpeeds(106, 100 +10);
464
     lastUpdate = millis();
462
     lastUpdate = millis();
465
     TimeUpdate();
463
     TimeUpdate();
466
     while(eventTime < 300)
464
     while(eventTime < 300)
467
     {
465
     {
468
       TimeUpdate();
466
       TimeUpdate();
469
-      //Serial1.println(eventTime); 
470
-      motors.setSpeeds(107, 100 +10);
467
+      motors.setSpeeds(106, 100 +10);
471
     }
468
     }
472
     LineUpdate();
469
     LineUpdate();
473
-    //Serial1.println("Linie suchen"); 
474
-    while(lineValue[0] < 150 && lineValue[2] < 170)
470
+    while(lineValue[0] < 150 && lineValue[2] < 120)
475
     {
471
     {
476
       LineUpdate();
472
       LineUpdate();
477
-      motors.setSpeeds(107, 100);
473
+      motors.setSpeeds(106, 100);
478
     }
474
     }
479
     //links drehen
475
     //links drehen
480
     turnAngle = 0;
476
     turnAngle = 0;
481
     rotationAngle = 0;
477
     rotationAngle = 0;
482
     GyroUpdate();
478
     GyroUpdate();
483
-    //Serial1.println("Drehen"); 
484
     while(rotationAngle < 90)
479
     while(rotationAngle < 90)
485
     {
480
     {
486
       GyroUpdate();
481
       GyroUpdate();
487
       LineUpdate();
482
       LineUpdate();
488
-      if(lineValue[2] > 170 && lineValue[2] < 450) motors.setSpeeds(0, 100);
489
-      else if(lineValue[0] > 150 && lineValue[0] < 400) motors.setSpeeds(107, 100);
483
+      if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(0, 100);
484
+      else if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(53, 100);
490
       else motors.setSpeeds(27, 100);
485
       else motors.setSpeeds(27, 100);
491
     }
486
     }
492
     //geradeaus fahren
487
     //geradeaus fahren
493
-    motors.setSpeeds(107, 100);
488
+    motors.setSpeeds(106, 100);
494
   }
489
   }
495
 
490
 
496
   //links Abbiegen (vom Rundkurs)
491
   //links Abbiegen (vom Rundkurs)
507
       GyroUpdate();
502
       GyroUpdate();
508
       EncoderUpdate();
503
       EncoderUpdate();
509
       motors.setSpeeds(27, 100);
504
       motors.setSpeeds(27, 100);
510
-      if(driveRotation[1] > 1) break;
505
+      //if(driveRotation[1] > 1) break;
511
     }
506
     }
512
     driveRotation[1] = 0;
507
     driveRotation[1] = 0;
513
     GyroUpdate();
508
     GyroUpdate();
516
       GyroUpdate();
511
       GyroUpdate();
517
       EncoderUpdate();
512
       EncoderUpdate();
518
       motors.setSpeeds(27, 100);
513
       motors.setSpeeds(27, 100);
519
-      if(driveRotation[1] > 1) break;
514
+      //if(driveRotation[1] > 1) break;
520
     }
515
     }
521
     //geradeaus fahren
516
     //geradeaus fahren
522
-    motors.setSpeeds(107, 100);
517
+    motors.setSpeeds(106, 100);
523
     lastUpdate = millis();
518
     lastUpdate = millis();
524
     TimeUpdate();
519
     TimeUpdate();
525
     while(eventTime < 1000)
520
     while(eventTime < 1000)
526
     {
521
     {
527
       TimeUpdate();
522
       TimeUpdate();
528
       LineUpdate();
523
       LineUpdate();
529
-      if(lineValue[2] > 170 && lineValue[2] < 450) break;
524
+      if(lineValue[2] > 120 && lineValue[2] < 500) break;
525
+    }
526
+    lastUpdate = millis();
527
+    TimeUpdate();
528
+    while(eventTime < 1000)
529
+    {
530
+      TimeUpdate();
531
+      LineUpdate();
532
+      Spurhalten();
530
     }
533
     }
531
   }
534
   }
532
 
535
 
533
   //rechts Abbiegen
536
   //rechts Abbiegen
534
   else if(randy == 2 && rightCode == true)
537
   else if(randy == 2 && rightCode == true)
535
   {
538
   {
539
+    //Serial1.println("rechts Abbiegen"); 
536
     //rechts drehen
540
     //rechts drehen
537
     turnAngle = 0;
541
     turnAngle = 0;
538
     rotationAngle = 0;
542
     rotationAngle = 0;
543
       GyroUpdate();
547
       GyroUpdate();
544
       EncoderUpdate();
548
       EncoderUpdate();
545
       LineUpdate();
549
       LineUpdate();
546
-      motors.setSpeeds(107, 25);
547
-      if(driveRotation[0] > 1 || (lineValue[0] > 150 && lineValue[0] < 400)) break;
550
+      motors.setSpeeds(106, 25);
551
+      if(lineValue[0] > 150 && lineValue[0] < 500) break;
548
     }
552
     }
549
     GyroUpdate();
553
     GyroUpdate();
550
     lastUpdate = millis();
554
     lastUpdate = millis();
554
       GyroUpdate();
558
       GyroUpdate();
555
       LineUpdate();
559
       LineUpdate();
556
       if(eventTime > 3000) break;
560
       if(eventTime > 3000) break;
557
-      if(lineValue[0] > 150 && lineValue[0] < 400) motors.setSpeeds(107, 0);
561
+      if(lineValue[0] > 150 && lineValue[0] < 500) motors.setSpeeds(106, 0);
558
       //else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) motors.setSpeeds(-SLOWSPEEDLEFT, -SLOWSPEEDRIGHT);
562
       //else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) motors.setSpeeds(-SLOWSPEEDLEFT, -SLOWSPEEDRIGHT);
559
-      else if(lineValue[2] > 170 && lineValue[2] < 450) motors.setSpeeds(107, 50);
560
-      else motors.setSpeeds(107, 25);
563
+      else if(lineValue[2] > 120 && lineValue[2] < 500) motors.setSpeeds(106, 50);
564
+      else motors.setSpeeds(106, 25);
561
     }
565
     }
562
   }
566
   }
563
 
567
 
564
   //nicht Abbiegen, geradeaus fahren
568
   //nicht Abbiegen, geradeaus fahren
565
   else
569
   else
566
   {
570
   {
567
-    motors.setSpeeds(107, 100);
571
+    //Serial1.println("nicht Abbiegen");
572
+    motors.setSpeeds(106, 100);
568
     lastUpdate = millis();
573
     lastUpdate = millis();
569
     TimeUpdate();
574
     TimeUpdate();
570
     while(eventTime < 1000)
575
     while(eventTime < 1000)
575
     }
580
     }
576
   }
581
   }
577
   //Serial1.println("Abbiegen beendet");
582
   //Serial1.println("Abbiegen beendet");
578
-  Serial1.println(0);
583
+  Serial1.print(0);
579
 }
584
 }
580
 
585
 
581
 //Funktion Spurhalten
586
 //Funktion Spurhalten
582
 void Spurhalten()
587
 void Spurhalten()
583
 {
588
 {
584
   //linke Linie erreicht, nach rechts fahren
589
   //linke Linie erreicht, nach rechts fahren
585
-  if(lineValue[0] > 150 && lineValue[0] < 400)
590
+  if(lineValue[0] > 150 && lineValue[0] < 500)
586
   {
591
   {
587
     ledYellow(1);
592
     ledYellow(1);
588
     //Serial1.println("Spur nach rechts korrigieren");  
593
     //Serial1.println("Spur nach rechts korrigieren");  
589
-    motors.setSpeeds(107/eventSpeed, 25/eventSpeed);
590
-    delay(100);
594
+    motors.setSpeeds(106/eventSpeed, 25/eventSpeed);
595
+    lastUpdate = millis();
596
+    TimeUpdate();
597
+    while(eventTime < 100)
598
+    {
599
+      TimeUpdate();
600
+      LineUpdate();
601
+      if(lineValue[2] > 120) break;
602
+    }
591
   }
603
   }
592
 
604
 
593
   //rechte Linie erreicht, nach links fahren
605
   //rechte Linie erreicht, nach links fahren
594
-  else if(lineValue[2] > 170 && lineValue[2] < 450)
606
+  else if(lineValue[2] > 120 && lineValue[2] < 500)
595
   {
607
   {
596
     ledYellow(1);
608
     ledYellow(1);
597
     //Serial1.println("Spur nach links korrigieren");  
609
     //Serial1.println("Spur nach links korrigieren");  
598
     motors.setSpeeds(27/eventSpeed, 100/eventSpeed);
610
     motors.setSpeeds(27/eventSpeed, 100/eventSpeed);
599
-    delay(100);
600
-  }
601
-
602
-  //Linie überfahren, zurücksetzen
603
-  else if(lineValue[1] > 100 && lineValue[1] < 350)
604
-  {
605
-    ledRed(1);
606
-    //Serial1.println("Spurfinden"); 
607
-    Serial1.println(1);
608
     lastUpdate = millis();
611
     lastUpdate = millis();
609
-    while(lineValue[0] < 150 && lineValue[2] < 170) //Zumo fährt solange rückwärst bis er wieder auf der Spur steht
612
+    TimeUpdate();
613
+    while(eventTime < 100)
610
     {
614
     {
611
       TimeUpdate();
615
       TimeUpdate();
612
       LineUpdate();
616
       LineUpdate();
613
-      motors.setSpeeds(-107/eventSpeed, -100/eventSpeed);
614
-      if(eventTime > 3000) break;
617
+      if(lineValue[0] > 150) break;
615
     }
618
     }
616
-    delay(100);
617
-    //Serial1.println("Spur gefunden"); 
618
-    Serial1.println(0);
619
   }
619
   }
620
 
620
 
621
   //normale Fahrt
621
   //normale Fahrt
622
   else
622
   else
623
   {
623
   {
624
     ledGreen(1);
624
     ledGreen(1);
625
-    motors.setSpeeds(107/eventSpeed, 100/eventSpeed);
625
+    motors.setSpeeds(106/eventSpeed, 100/eventSpeed);
626
   }
626
   }
627
 }
627
 }
628
 
628
 
629
+//Funktion Spurfinden
630
+void Spurfinden()
631
+{
632
+  ledRed(1);
633
+  //Serial1.println("Spurfinden"); 
634
+  Serial1.print(1);
635
+  lastUpdate = millis();
636
+  while(lineValue[0] < 150 && lineValue[2] < 120) //Zumo fährt solange rückwärst bis er wieder auf der Spur steht
637
+  {
638
+    TimeUpdate();
639
+    LineUpdate();
640
+    motors.setSpeeds(-106, -100);
641
+    if(eventTime > 3000) break;
642
+  }
643
+  //Serial1.println("Spur gefunden"); 
644
+  Serial1.print(0);
645
+}
646
+
629
 //Funktion Serielle Ausgabe
647
 //Funktion Serielle Ausgabe
630
 void SerielleAusgabe()
648
 void SerielleAusgabe()
631
 {
649
 {
644
 
662
 
645
 void loop()
663
 void loop()
646
 {
664
 {
647
-  //LoopTiming();                             //Zykluszeit beträgt max. 30ms im Idle
665
+  //LoopTiming();                             //Zykluszeit beträgt max. 20ms im Idle
648
   ledGreen(0);
666
   ledGreen(0);
649
   ledYellow(0);
667
   ledYellow(0);
650
   ledRed(0);
668
   ledRed(0);
651
 
669
 
652
-  //Abfragen der Sensordaten
653
-  LineUpdate();
670
+  //Abfragen der Sensordaten                                 
654
   ProxUpdate();
671
   ProxUpdate();
655
   EncoderUpdate();
672
   EncoderUpdate();
656
   GyroUpdate();
673
   GyroUpdate();
657
   CompassUpdate();
674
   CompassUpdate();
675
+  LineUpdate();
658
   TimeUpdate();
676
   TimeUpdate();
659
 
677
 
660
   //Funktionsauswahl
678
   //Funktionsauswahl
667
   if(alarm == true)
685
   if(alarm == true)
668
   {
686
   {
669
     //Serial1.println("Verstanden");
687
     //Serial1.println("Verstanden");
670
-    eventSpeed = 2;
671
-    if(moveRate > 1000 || proxValue[1] == 6 || proxValue[2] == 6 || lineValue[0] > 400 || lineValue[2] > 450) motors.setSpeeds(0, 0);
688
+    eventSpeed = 1.4;
689
+    if(moveRate > 1500 || (proxValue[1] == 6 && proxValue[2] == 6) || lineValue[0] > 500 || lineValue[2] > 500 || lineValue[1] > 100) motors.setSpeeds(0, 0);
672
     else Spurhalten();
690
     else Spurhalten();
673
   }
691
   }
674
   //verfügbare Funktionen im Normalfall
692
   //verfügbare Funktionen im Normalfall
675
   else
693
   else
676
   {
694
   {
677
-    eventSpeed = 1;
695
+    eventSpeed = 1.0;
678
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
696
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
679
-    if(proxValue[2] == 6) Hindernisumfahren();
680
-    else if(lineValue[0] > 400 && lineValue[0] < 1000 || lineValue[2] > 450 && lineValue[2] < 1000) Abbiegen();
697
+    if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
698
+    else if((lineValue[0] > 500 && lineValue[0] < 1400) && (lineValue[1] > 300 && lineValue[1] < 700)) Abbiegen();
699
+    else if((lineValue[2] > 500 && lineValue[2] < 1400) && (lineValue[1] > 300 && lineValue[1] < 700)) Abbiegen();
700
+    else if(lineValue[1] > 100 && lineValue[1] < 300) Spurfinden();
681
     else Spurhalten();
701
     else Spurhalten();
682
   }
702
   }
683
-  //LoopTiming();                                                       
703
+  //LoopTiming();                                                     
684
 }
704
 }

+ 129 - 108
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 13.04.2018 
5
+//Datum: erstellt am 19.07.2017, zuletzt geändert am 04.05.2018 
6
 //Projektbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
6
 //Projektbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
7
 //der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
7
 //der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
8
 //Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
8
 //Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
26
 
26
 
27
 #define   MARKLINE0       150
27
 #define   MARKLINE0       150
28
 #define   MARKLINE1       100
28
 #define   MARKLINE1       100
29
-#define   MARKLINE2       170
30
-#define   SIGN0           400
31
-#define   SIGN1           350
32
-#define   SIGN2           450
29
+#define   MARKLINE2       120
30
+#define   SIGN0           500
31
+#define   SIGN1           300
32
+#define   SIGN2           500
33
 #define   MAXSPEED        400
33
 #define   MAXSPEED        400
34
-#define   FULLSPEEDLEFT   107
35
-#define   HALFSPEEDLEFT   54
34
+#define   FULLSPEEDLEFT   106
35
+#define   HALFSPEEDLEFT   53
36
 #define   SLOWSPEEDLEFT   27
36
 #define   SLOWSPEEDLEFT   27
37
 #define   FULLSPEEDRIGHT  100
37
 #define   FULLSPEEDRIGHT  100
38
 #define   HALFSPEEDRIGHT  50
38
 #define   HALFSPEEDRIGHT  50
70
 //Setup Bluetoothverbindung
70
 //Setup Bluetoothverbindung
71
 #line 68 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
71
 #line 68 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
72
 void BlueSetup();
72
 void BlueSetup();
73
-#line 76 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
73
+#line 77 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
74
 void LineSetup();
74
 void LineSetup();
75
-#line 105 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
75
+#line 106 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
76
 void ProxSetup();
76
 void ProxSetup();
77
-#line 111 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
77
+#line 112 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
78
 void GyroSetup();
78
 void GyroSetup();
79
-#line 144 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
79
+#line 145 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
80
 void CompassSetup();
80
 void CompassSetup();
81
-#line 175 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
81
+#line 176 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
82
 void setup();
82
 void setup();
83
-#line 201 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
83
+#line 202 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
84
 void TimeUpdate();
84
 void TimeUpdate();
85
-#line 207 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
85
+#line 208 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
86
 void LoopTiming();
86
 void LoopTiming();
87
-#line 251 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
87
+#line 252 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
88
 void ProxUpdate();
88
 void ProxUpdate();
89
-#line 261 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
89
+#line 262 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
90
 void LineUpdate();
90
 void LineUpdate();
91
-#line 271 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
91
+#line 272 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
92
 void GyroUpdate();
92
 void GyroUpdate();
93
-#line 284 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
93
+#line 285 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
94
 void CompassUpdate();
94
 void CompassUpdate();
95
-#line 297 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
95
+#line 298 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
96
 void EncoderUpdate();
96
 void EncoderUpdate();
97
-#line 308 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
97
+#line 309 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
98
 void Kontaktvermeiden();
98
 void Kontaktvermeiden();
99
 #line 328 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
99
 #line 328 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
100
 void Hindernisumfahren();
100
 void Hindernisumfahren();
101
 #line 438 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
101
 #line 438 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
102
 void Abbiegen();
102
 void Abbiegen();
103
-#line 594 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
103
+#line 599 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
104
 void Spurhalten();
104
 void Spurhalten();
105
 #line 642 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
105
 #line 642 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
106
+void Spurfinden();
107
+#line 660 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
106
 void SerielleAusgabe();
108
 void SerielleAusgabe();
107
-#line 657 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
109
+#line 675 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
108
 void loop();
110
 void loop();
109
 #line 68 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
111
 #line 68 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
110
 void BlueSetup()
112
 void BlueSetup()
111
 {
113
 {
112
-  Serial1.begin(9600);                      //Initialisierung mit Datengeschwindigkeit(Baud)
113
-  Serial1.setTimeout(10);                   //verkürzt Serial(1).read auf 10 ms statt 1000 ms
114
-  if(Serial1.available()) Serial.println("Bluetoothverbindung hergestellt");      
114
+  Serial1.begin(9600);                              //Initialisierung mit Datengeschwindigkeit(Baud)
115
+  Serial1.setTimeout(10);                           //verkürzt Serial(1).read auf 10 ms statt 1000 ms
116
+  if(Serial1.available()) Serial.println("Bluetoothverbindung hergestellt");   
117
+  if(Serial1.available() > 0) Serial1.read();       //Verwerfen der alten Informationen aus dem Puffer
115
 }           
118
 }           
116
 
119
 
117
 //Setup Liniensensoren
120
 //Setup Liniensensoren
120
   ledYellow(1);
123
   ledYellow(1);
121
   lineSensors.initThreeSensors();           //Initialisierung von 3 Sensoren (max 5)
124
   lineSensors.initThreeSensors();           //Initialisierung von 3 Sensoren (max 5)
122
   
125
   
123
-  // //Kalibrierung
124
-  // uint32_t total[3] = {0, 0, 0};  
125
-  // for(uint8_t i = 0; i < 120; i++)                                
126
-  // {
127
-  //   if (i > 30 && i <= 90) motors.setSpeeds(FULLSPEEDLEFT, -FULLSPEEDRIGHT);
128
-  //   else motors.setSpeeds(-FULLSPEEDLEFT, FULLSPEEDRIGHT);
129
-  //   lineSensors.read(lineOffset);  
130
-  //   total[0] += lineOffset[0];
131
-  //   total[1] += lineOffset[1];
132
-  //   total[2] += lineOffset[2];
133
-    lineSensors.calibrate();                                      
134
-  // }
135
-  // motors.setSpeeds(0, 0);
136
-  // lineOffset[0] = total[0] / 120;
137
-  // lineOffset[1] = total[1] / 120;
138
-  // lineOffset[2] = total[2] / 120;
126
+  //Kalibrierung
127
+  uint32_t total[3] = {0, 0, 0};  
128
+  for(uint8_t i = 0; i < 120; i++)                                
129
+  {
130
+    if (i > 30 && i <= 90) motors.setSpeeds(FULLSPEEDLEFT, -FULLSPEEDRIGHT);
131
+    else motors.setSpeeds(-FULLSPEEDLEFT, FULLSPEEDRIGHT);
132
+    lineSensors.read(lineOffset);  
133
+    total[0] += lineOffset[0];
134
+    total[1] += lineOffset[1];
135
+    total[2] += lineOffset[2];
136
+   lineSensors.calibrate();                                      
137
+  }
138
+  motors.setSpeeds(0, 0);
139
+  lineOffset[0] = total[0] / 120;
140
+  lineOffset[1] = total[1] / 120;
141
+  lineOffset[2] = total[2] / 120;
139
   ledYellow(0);
142
   ledYellow(0);
140
 
143
 
141
-  lineOffset[0] = 240;
142
-  lineOffset[1] = 120;
143
-  lineOffset[2] = 220;
144
+  // lineOffset[0] = 240;
145
+  // lineOffset[1] = 120;
146
+  // lineOffset[2] = 220;
144
 }
147
 }
145
 
148
 
146
 //Setup Abstandssensoren
149
 //Setup Abstandssensoren
160
     ledRed(1);
163
     ledRed(1);
161
     while(1)
164
     while(1)
162
     {
165
     {
163
-      //Serial1.println("Fehler Drehbewegungssensors");
164
-      delay(1000);
166
+      Serial.println("Fehler Drehbewegungssensors");
167
+      delay(5000);
165
     }
168
     }
166
   }
169
   }
167
   gyro.writeReg(L3G::CTRL1, 0b11111111);                          //Ausgaberate 800Hz, Tiefpassfilter 100Hz
170
   gyro.writeReg(L3G::CTRL1, 0b11111111);                          //Ausgaberate 800Hz, Tiefpassfilter 100Hz
193
     ledRed(1);
196
     ledRed(1);
194
     while(1)
197
     while(1)
195
     {
198
     {
196
-      //Serial1.println("Fehler Beschleunigungssensors");
197
-      delay(1000);
199
+      Serial.println("Fehler Beschleunigungssensors");
200
+      delay(5000);
198
     }
201
     }
199
   }
202
   }
200
   compass.enableDefault();  
203
   compass.enableDefault();  
350
 void Kontaktvermeiden()                                            
353
 void Kontaktvermeiden()                                            
351
 {
354
 {
352
   //Serial1.println("Kontaktvermeiden");
355
   //Serial1.println("Kontaktvermeiden");
353
-  Serial1.println(1); 
356
+  Serial1.print(1); 
354
   ledRed(1);
357
   ledRed(1);
355
-
356
   motors.setSpeeds(0, 0);
358
   motors.setSpeeds(0, 0);
357
-  delay(500);
359
+  delay(1000);
358
   while(proxValue[1] == 0 || proxValue[2] == 0)
360
   while(proxValue[1] == 0 || proxValue[2] == 0)
359
   {
361
   {
360
     ProxUpdate();
362
     ProxUpdate();
361
     motors.setSpeeds(-HALFSPEEDLEFT, -HALFSPEEDRIGHT);
363
     motors.setSpeeds(-HALFSPEEDLEFT, -HALFSPEEDRIGHT);
362
     if(lineValue[0] > MARKLINE0 || lineValue[2] > MARKLINE2) break;
364
     if(lineValue[0] > MARKLINE0 || lineValue[2] > MARKLINE2) break;
363
   }
365
   }
364
-  delay(500); 
366
+  motors.setSpeeds(0, 0);
365
   //Serial1.println("Vermeiden beendet");
367
   //Serial1.println("Vermeiden beendet");
366
-  Serial1.println(0); 
368
+  Serial1.print(0); 
367
 }
369
 }
368
 
370
 
369
 //Funktion Hindernisumfahrung
371
 //Funktion Hindernisumfahrung
370
 void Hindernisumfahren()                                              
372
 void Hindernisumfahren()                                              
371
 {
373
 {
372
   //Serial1.println("Hindernisumfahren"); 
374
   //Serial1.println("Hindernisumfahren"); 
373
-  Serial1.println(1); 
375
+  Serial1.print(1); 
374
   ledYellow(1);
376
   ledYellow(1);
375
 
377
 
376
   //Schritt 1: Spurwechsel links   
378
   //Schritt 1: Spurwechsel links   
472
   }
474
   }
473
   //geradeaus fahren
475
   //geradeaus fahren
474
   //Serial1.println("Umfahren beendet");
476
   //Serial1.println("Umfahren beendet");
475
-  Serial1.println(0); 
477
+  Serial1.print(0); 
476
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT);
478
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT);
477
 }
479
 }
478
 
480
 
481
 {
483
 {
482
   ledYellow(1); 
484
   ledYellow(1); 
483
   //Serial1.println("Abbiegen");  
485
   //Serial1.println("Abbiegen");  
484
-  Serial1.println(1); 
486
+  Serial1.print(1); 
485
 
487
 
486
   //Markierung analysieren
488
   //Markierung analysieren
487
   LineUpdate(); 
489
   LineUpdate(); 
488
   bool  leftCode;                                                         //links => 1
490
   bool  leftCode;                                                         //links => 1
489
   bool  rightCode;                                                        //rechts => 2
491
   bool  rightCode;                                                        //rechts => 2
490
-  if(lineValue[0] > SIGN0) leftCode = true;
492
+  if((lineValue[0] > SIGN0 && lineValue[0] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) leftCode = true;
491
   else leftCode = false;
493
   else leftCode = false;
492
-  if(lineValue[2] > SIGN2) rightCode = true;
494
+  if((lineValue[2] > SIGN2 && lineValue[2] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) rightCode = true;
493
   else rightCode = false;
495
   else rightCode = false;
494
 
496
 
495
   //Zufallszahl erzeugen
497
   //Zufallszahl erzeugen
496
   uint8_t randy;                                                          //geradeaus => 0
498
   uint8_t randy;                                                          //geradeaus => 0
497
   if(leftCode == true && rightCode == true) randy = random(1, 3);         //1, 2
499
   if(leftCode == true && rightCode == true) randy = random(1, 3);         //1, 2
498
-  else if(leftCode == true && rightCode == false) randy = 1;
499
-  // else if(leftCode == true && rightCode == false) 
500
-  // {
501
-  //   randy = random(0, 2);                                                 //0, 1
502
-  //   if(randy == 0) randy = random(0, 2);                                  //erhöht Wahrscheinlickeit abzubiegen
503
-  // }
504
-  else if(leftCode == false && rightCode == true) randy = 2;
505
-  // else if(leftCode == false && rightCode == true)
506
-  // {
507
-  //   randy = random(3);                                                    //0, (1), 2
508
-  //   if(randy == 0) randy = random(3);                                     //erhöht Wahrscheinlickeit abzubiegen
509
-  //   while(randy == 1) randy = random(3);                                  //!1 => 0, 2
510
-  // }
500
+  else if(leftCode == true && rightCode == false) //randy = 1;
501
+  {
502
+    randy = random(0, 2);                                                 //0, 1
503
+    //if(randy == 0) randy = random(0, 2);                                  //erhöht Wahrscheinlickeit abzubiegen
504
+  }
505
+  else if(leftCode == false && rightCode == true) //randy = 2;
506
+  {
507
+    randy = random(0, 2);                                                 //0, 1
508
+    //if(randy == 0) randy = random(0, 2);                                  //erhöht Wahrscheinlickeit abzubiegen
509
+    if(randy == 1) randy = 2;                                             //!1 => 2
510
+  }
511
 
511
 
512
   //links Abbiegen (von der Verbindungsstrecke)
512
   //links Abbiegen (von der Verbindungsstrecke)
513
   if(randy == 1 && rightCode == true) 
513
   if(randy == 1 && rightCode == true) 
520
     while(eventTime < 300)
520
     while(eventTime < 300)
521
     {
521
     {
522
       TimeUpdate();
522
       TimeUpdate();
523
-      //Serial1.println(eventTime); 
524
       motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
523
       motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
525
     }
524
     }
526
     LineUpdate();
525
     LineUpdate();
527
-    //Serial1.println("Linie suchen"); 
528
     while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)
526
     while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)
529
     {
527
     {
530
       LineUpdate();
528
       LineUpdate();
534
     turnAngle = 0;  
532
     turnAngle = 0;  
535
     rotationAngle = 0;
533
     rotationAngle = 0;
536
     GyroUpdate();
534
     GyroUpdate();
537
-    //Serial1.println("Drehen"); 
538
     while(rotationAngle < 90)
535
     while(rotationAngle < 90)
539
     {
536
     {
540
       GyroUpdate();
537
       GyroUpdate();
541
       LineUpdate();
538
       LineUpdate();
542
       if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) motors.setSpeeds(0, FULLSPEEDRIGHT); 
539
       if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) motors.setSpeeds(0, FULLSPEEDRIGHT); 
543
-      else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
540
+      else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(HALFSPEEDLEFT, FULLSPEEDRIGHT); 
544
       else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
541
       else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
545
     }
542
     }
546
     //geradeaus fahren
543
     //geradeaus fahren
561
       GyroUpdate();
558
       GyroUpdate();
562
       EncoderUpdate();
559
       EncoderUpdate();
563
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
560
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
564
-      if(driveRotation[1] > 1) break;
561
+      //if(driveRotation[1] > 1) break;
565
     }
562
     }
566
     driveRotation[1] = 0;
563
     driveRotation[1] = 0;
567
     GyroUpdate();
564
     GyroUpdate();
570
       GyroUpdate();
567
       GyroUpdate();
571
       EncoderUpdate();
568
       EncoderUpdate();
572
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
569
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
573
-      if(driveRotation[1] > 1) break;
570
+      //if(driveRotation[1] > 1) break;
574
     }
571
     }
575
     //geradeaus fahren
572
     //geradeaus fahren
576
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
573
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
582
       LineUpdate();
579
       LineUpdate();
583
       if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
580
       if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
584
     }
581
     }
582
+    lastUpdate = millis();
583
+    TimeUpdate();
584
+    while(eventTime < 1000)
585
+    {
586
+      TimeUpdate();
587
+      LineUpdate();
588
+      Spurhalten();
589
+    }
585
   }
590
   }
586
 
591
 
587
   //rechts Abbiegen
592
   //rechts Abbiegen
588
   else if(randy == 2 && rightCode == true)
593
   else if(randy == 2 && rightCode == true)
589
   {
594
   {
595
+    //Serial1.println("rechts Abbiegen"); 
590
     //rechts drehen
596
     //rechts drehen
591
     turnAngle = 0;  
597
     turnAngle = 0;  
592
     rotationAngle = 0;
598
     rotationAngle = 0;
598
       EncoderUpdate();
604
       EncoderUpdate();
599
       LineUpdate();
605
       LineUpdate();
600
       motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
606
       motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
601
-      if(driveRotation[0] > 1 || (lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0)) break;
607
+      if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) break;
602
     }
608
     }
603
     GyroUpdate();
609
     GyroUpdate();
604
     lastUpdate = millis();
610
     lastUpdate = millis();
618
   //nicht Abbiegen, geradeaus fahren
624
   //nicht Abbiegen, geradeaus fahren
619
   else 
625
   else 
620
   {
626
   {
627
+    //Serial1.println("nicht Abbiegen");
621
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
628
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
622
     lastUpdate = millis();
629
     lastUpdate = millis();
623
     TimeUpdate();
630
     TimeUpdate();
629
     }
636
     }
630
   }
637
   }
631
   //Serial1.println("Abbiegen beendet");
638
   //Serial1.println("Abbiegen beendet");
632
-  Serial1.println(0); 
639
+  Serial1.print(0); 
633
 }
640
 }
634
 
641
 
635
 //Funktion Spurhalten
642
 //Funktion Spurhalten
641
     ledYellow(1); 
648
     ledYellow(1); 
642
     //Serial1.println("Spur nach rechts korrigieren");  
649
     //Serial1.println("Spur nach rechts korrigieren");  
643
     motors.setSpeeds(FULLSPEEDLEFT/eventSpeed, SLOWSPEEDRIGHT/eventSpeed);
650
     motors.setSpeeds(FULLSPEEDLEFT/eventSpeed, SLOWSPEEDRIGHT/eventSpeed);
644
-    delay(100);    
651
+    lastUpdate = millis();
652
+    TimeUpdate();
653
+    while(eventTime < 100)
654
+    {
655
+      TimeUpdate();
656
+      LineUpdate();
657
+      if(lineValue[2] > MARKLINE2) break;
658
+    }   
645
   }
659
   }
646
 
660
 
647
   //rechte Linie erreicht, nach links fahren
661
   //rechte Linie erreicht, nach links fahren
649
   {
663
   {
650
     ledYellow(1); 
664
     ledYellow(1); 
651
     //Serial1.println("Spur nach links korrigieren");  
665
     //Serial1.println("Spur nach links korrigieren");  
652
-    motors.setSpeeds(SLOWSPEEDLEFT/eventSpeed, FULLSPEEDRIGHT/eventSpeed);  
653
-    delay(100);  
654
-  }
655
-
656
-  //Linie überfahren, zurücksetzen
657
-  else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1)                 
658
-  { 
659
-    ledRed(1); 
660
-    //Serial1.println("Spurfinden"); 
661
-    Serial1.println(1); 
666
+    motors.setSpeeds(SLOWSPEEDLEFT/eventSpeed, FULLSPEEDRIGHT/eventSpeed);   
662
     lastUpdate = millis();
667
     lastUpdate = millis();
663
-    while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)                 //Zumo fährt solange rückwärst bis er wieder auf der Spur steht
668
+    TimeUpdate();
669
+    while(eventTime < 100)
664
     {
670
     {
665
       TimeUpdate();
671
       TimeUpdate();
666
       LineUpdate();
672
       LineUpdate();
667
-      motors.setSpeeds(-FULLSPEEDLEFT/eventSpeed, -FULLSPEEDRIGHT/eventSpeed);
668
-      if(eventTime > 3000) break;
669
-    }
670
-    delay(100);    
671
-    //Serial1.println("Spur gefunden"); 
672
-    Serial1.println(0);  
673
-  }  
673
+      if(lineValue[0] > MARKLINE0) break;
674
+    }   
675
+  }
674
 
676
 
675
   //normale Fahrt
677
   //normale Fahrt
676
   else                                                                
678
   else                                                                
680
   }
682
   }
681
 }
683
 }
682
 
684
 
685
+//Funktion Spurfinden
686
+void Spurfinden()             
687
+{ 
688
+  ledRed(1); 
689
+  //Serial1.println("Spurfinden"); 
690
+  Serial1.print(1); 
691
+  lastUpdate = millis();
692
+  while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)                 //Zumo fährt solange rückwärst bis er wieder auf der Spur steht
693
+  {
694
+    TimeUpdate();
695
+    LineUpdate();
696
+    motors.setSpeeds(-FULLSPEEDLEFT, -FULLSPEEDRIGHT);
697
+    if(eventTime > 3000) break;
698
+  } 
699
+  //Serial1.println("Spur gefunden"); 
700
+  Serial1.print(0);  
701
+}  
702
+
683
 //Funktion Serielle Ausgabe
703
 //Funktion Serielle Ausgabe
684
 void SerielleAusgabe()                                                     
704
 void SerielleAusgabe()                                                     
685
 {
705
 {
698
 
718
 
699
 void loop() 
719
 void loop() 
700
 {
720
 {
701
-  //LoopTiming();                             //Zykluszeit beträgt max. 30ms im Idle
721
+  //LoopTiming();                             //Zykluszeit beträgt max. 20ms im Idle
702
   ledGreen(0);
722
   ledGreen(0);
703
   ledYellow(0);
723
   ledYellow(0);
704
   ledRed(0);
724
   ledRed(0);
705
 
725
 
706
-  //Abfragen der Sensordaten
707
-  LineUpdate();                                         
726
+  //Abfragen der Sensordaten                                 
708
   ProxUpdate();
727
   ProxUpdate();
709
   EncoderUpdate();
728
   EncoderUpdate();
710
   GyroUpdate();
729
   GyroUpdate();
711
   CompassUpdate();
730
   CompassUpdate();
731
+  LineUpdate();      
712
   TimeUpdate();
732
   TimeUpdate();
713
 
733
 
714
   //Funktionsauswahl
734
   //Funktionsauswahl
721
   if(alarm == true)                                    
741
   if(alarm == true)                                    
722
   {
742
   {
723
     //Serial1.println("Verstanden");
743
     //Serial1.println("Verstanden");
724
-    eventSpeed = 2;
725
-    if(moveRate > 1000 || proxValue[1] == 6 || proxValue[2] == 6 || lineValue[0] > SIGN0 || lineValue[2] > SIGN2) motors.setSpeeds(0, 0);  
744
+    eventSpeed = 1.4;
745
+    if(moveRate > 1500 || (proxValue[1] == 6 && proxValue[2] == 6) || lineValue[0] > SIGN0 || lineValue[2] > SIGN2 || lineValue[1] > MARKLINE1) motors.setSpeeds(0, 0);  
726
     else Spurhalten();
746
     else Spurhalten();
727
   }
747
   }
728
   //verfügbare Funktionen im Normalfall
748
   //verfügbare Funktionen im Normalfall
729
   else                                                              
749
   else                                                              
730
   {
750
   {
731
-    eventSpeed = 1;
751
+    eventSpeed = 1.0;
732
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
752
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
733
-    if(proxValue[2] == 6) Hindernisumfahren();
734
-    else if(lineValue[0] > SIGN0 && lineValue[0] < 1000 || lineValue[2] > SIGN2 && lineValue[2] < 1000) Abbiegen();
753
+    if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
754
+    else if((lineValue[0] > SIGN0 && lineValue[0] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) Abbiegen();
755
+    else if((lineValue[2] > SIGN2 && lineValue[2] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) Abbiegen();
756
+    else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) Spurfinden();
735
     else Spurhalten();
757
     else Spurhalten();
736
   }
758
   }
737
-  //LoopTiming();                                                       
759
+  //LoopTiming();                                                     
738
 }
760
 }
739
-

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


+ 113 - 93
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 13.04.2018 
2
+//Datum: erstellt am 19.07.2017, zuletzt geändert am 04.05.2018 
3
 //Projektbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
3
 //Projektbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
4
 //der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
4
 //der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
5
 //Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
5
 //Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
23
 
23
 
24
 #define   MARKLINE0       150
24
 #define   MARKLINE0       150
25
 #define   MARKLINE1       100
25
 #define   MARKLINE1       100
26
-#define   MARKLINE2       170
27
-#define   SIGN0           400
28
-#define   SIGN1           350
29
-#define   SIGN2           450
26
+#define   MARKLINE2       120
27
+#define   SIGN0           500
28
+#define   SIGN1           300
29
+#define   SIGN2           500
30
 #define   MAXSPEED        400
30
 #define   MAXSPEED        400
31
-#define   FULLSPEEDLEFT   107
32
-#define   HALFSPEEDLEFT   54
31
+#define   FULLSPEEDLEFT   106
32
+#define   HALFSPEEDLEFT   53
33
 #define   SLOWSPEEDLEFT   27
33
 #define   SLOWSPEEDLEFT   27
34
 #define   FULLSPEEDRIGHT  100
34
 #define   FULLSPEEDRIGHT  100
35
 #define   HALFSPEEDRIGHT  50
35
 #define   HALFSPEEDRIGHT  50
67
 //Setup Bluetoothverbindung
67
 //Setup Bluetoothverbindung
68
 void BlueSetup()
68
 void BlueSetup()
69
 {
69
 {
70
-  Serial1.begin(9600);                      //Initialisierung mit Datengeschwindigkeit(Baud)
71
-  Serial1.setTimeout(10);                   //verkürzt Serial(1).read auf 10 ms statt 1000 ms
72
-  if(Serial1.available()) Serial.println("Bluetoothverbindung hergestellt");      
70
+  Serial1.begin(9600);                              //Initialisierung mit Datengeschwindigkeit(Baud)
71
+  Serial1.setTimeout(10);                           //verkürzt Serial(1).read auf 10 ms statt 1000 ms
72
+  if(Serial1.available()) Serial.println("Bluetoothverbindung hergestellt");   
73
+  if(Serial1.available() > 0) Serial1.read();       //Verwerfen der alten Informationen aus dem Puffer
73
 }           
74
 }           
74
 
75
 
75
 //Setup Liniensensoren
76
 //Setup Liniensensoren
78
   ledYellow(1);
79
   ledYellow(1);
79
   lineSensors.initThreeSensors();           //Initialisierung von 3 Sensoren (max 5)
80
   lineSensors.initThreeSensors();           //Initialisierung von 3 Sensoren (max 5)
80
   
81
   
81
-  // //Kalibrierung
82
-  // uint32_t total[3] = {0, 0, 0};  
83
-  // for(uint8_t i = 0; i < 120; i++)                                
84
-  // {
85
-  //   if (i > 30 && i <= 90) motors.setSpeeds(FULLSPEEDLEFT, -FULLSPEEDRIGHT);
86
-  //   else motors.setSpeeds(-FULLSPEEDLEFT, FULLSPEEDRIGHT);
87
-  //   lineSensors.read(lineOffset);  
88
-  //   total[0] += lineOffset[0];
89
-  //   total[1] += lineOffset[1];
90
-  //   total[2] += lineOffset[2];
91
-    lineSensors.calibrate();                                      
92
-  // }
93
-  // motors.setSpeeds(0, 0);
94
-  // lineOffset[0] = total[0] / 120;
95
-  // lineOffset[1] = total[1] / 120;
96
-  // lineOffset[2] = total[2] / 120;
82
+  //Kalibrierung
83
+  uint32_t total[3] = {0, 0, 0};  
84
+  for(uint8_t i = 0; i < 120; i++)                                
85
+  {
86
+    if (i > 30 && i <= 90) motors.setSpeeds(FULLSPEEDLEFT, -FULLSPEEDRIGHT);
87
+    else motors.setSpeeds(-FULLSPEEDLEFT, FULLSPEEDRIGHT);
88
+    lineSensors.read(lineOffset);  
89
+    total[0] += lineOffset[0];
90
+    total[1] += lineOffset[1];
91
+    total[2] += lineOffset[2];
92
+   lineSensors.calibrate();                                      
93
+  }
94
+  motors.setSpeeds(0, 0);
95
+  lineOffset[0] = total[0] / 120;
96
+  lineOffset[1] = total[1] / 120;
97
+  lineOffset[2] = total[2] / 120;
97
   ledYellow(0);
98
   ledYellow(0);
98
 
99
 
99
-  lineOffset[0] = 240;
100
-  lineOffset[1] = 120;
101
-  lineOffset[2] = 220;
100
+  // lineOffset[0] = 240;
101
+  // lineOffset[1] = 120;
102
+  // lineOffset[2] = 220;
102
 }
103
 }
103
 
104
 
104
 //Setup Abstandssensoren
105
 //Setup Abstandssensoren
118
     ledRed(1);
119
     ledRed(1);
119
     while(1)
120
     while(1)
120
     {
121
     {
121
-      //Serial1.println("Fehler Drehbewegungssensors");
122
-      delay(1000);
122
+      Serial.println("Fehler Drehbewegungssensors");
123
+      delay(5000);
123
     }
124
     }
124
   }
125
   }
125
   gyro.writeReg(L3G::CTRL1, 0b11111111);                          //Ausgaberate 800Hz, Tiefpassfilter 100Hz
126
   gyro.writeReg(L3G::CTRL1, 0b11111111);                          //Ausgaberate 800Hz, Tiefpassfilter 100Hz
151
     ledRed(1);
152
     ledRed(1);
152
     while(1)
153
     while(1)
153
     {
154
     {
154
-      //Serial1.println("Fehler Beschleunigungssensors");
155
-      delay(1000);
155
+      Serial.println("Fehler Beschleunigungssensors");
156
+      delay(5000);
156
     }
157
     }
157
   }
158
   }
158
   compass.enableDefault();  
159
   compass.enableDefault();  
308
 void Kontaktvermeiden()                                            
309
 void Kontaktvermeiden()                                            
309
 {
310
 {
310
   //Serial1.println("Kontaktvermeiden");
311
   //Serial1.println("Kontaktvermeiden");
311
-  Serial1.println(1); 
312
+  Serial1.print(1); 
312
   ledRed(1);
313
   ledRed(1);
313
-
314
   motors.setSpeeds(0, 0);
314
   motors.setSpeeds(0, 0);
315
-  delay(500);
315
+  delay(1000);
316
   while(proxValue[1] == 0 || proxValue[2] == 0)
316
   while(proxValue[1] == 0 || proxValue[2] == 0)
317
   {
317
   {
318
     ProxUpdate();
318
     ProxUpdate();
319
     motors.setSpeeds(-HALFSPEEDLEFT, -HALFSPEEDRIGHT);
319
     motors.setSpeeds(-HALFSPEEDLEFT, -HALFSPEEDRIGHT);
320
     if(lineValue[0] > MARKLINE0 || lineValue[2] > MARKLINE2) break;
320
     if(lineValue[0] > MARKLINE0 || lineValue[2] > MARKLINE2) break;
321
   }
321
   }
322
-  delay(500); 
322
+  motors.setSpeeds(0, 0);
323
   //Serial1.println("Vermeiden beendet");
323
   //Serial1.println("Vermeiden beendet");
324
-  Serial1.println(0); 
324
+  Serial1.print(0); 
325
 }
325
 }
326
 
326
 
327
 //Funktion Hindernisumfahrung
327
 //Funktion Hindernisumfahrung
328
 void Hindernisumfahren()                                              
328
 void Hindernisumfahren()                                              
329
 {
329
 {
330
   //Serial1.println("Hindernisumfahren"); 
330
   //Serial1.println("Hindernisumfahren"); 
331
-  Serial1.println(1); 
331
+  Serial1.print(1); 
332
   ledYellow(1);
332
   ledYellow(1);
333
 
333
 
334
   //Schritt 1: Spurwechsel links   
334
   //Schritt 1: Spurwechsel links   
430
   }
430
   }
431
   //geradeaus fahren
431
   //geradeaus fahren
432
   //Serial1.println("Umfahren beendet");
432
   //Serial1.println("Umfahren beendet");
433
-  Serial1.println(0); 
433
+  Serial1.print(0); 
434
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT);
434
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT);
435
 }
435
 }
436
 
436
 
439
 {
439
 {
440
   ledYellow(1); 
440
   ledYellow(1); 
441
   //Serial1.println("Abbiegen");  
441
   //Serial1.println("Abbiegen");  
442
-  Serial1.println(1); 
442
+  Serial1.print(1); 
443
 
443
 
444
   //Markierung analysieren
444
   //Markierung analysieren
445
   LineUpdate(); 
445
   LineUpdate(); 
446
   bool  leftCode;                                                         //links => 1
446
   bool  leftCode;                                                         //links => 1
447
   bool  rightCode;                                                        //rechts => 2
447
   bool  rightCode;                                                        //rechts => 2
448
-  if(lineValue[0] > SIGN0) leftCode = true;
448
+  if((lineValue[0] > SIGN0 && lineValue[0] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) leftCode = true;
449
   else leftCode = false;
449
   else leftCode = false;
450
-  if(lineValue[2] > SIGN2) rightCode = true;
450
+  if((lineValue[2] > SIGN2 && lineValue[2] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) rightCode = true;
451
   else rightCode = false;
451
   else rightCode = false;
452
 
452
 
453
   //Zufallszahl erzeugen
453
   //Zufallszahl erzeugen
454
   uint8_t randy;                                                          //geradeaus => 0
454
   uint8_t randy;                                                          //geradeaus => 0
455
   if(leftCode == true && rightCode == true) randy = random(1, 3);         //1, 2
455
   if(leftCode == true && rightCode == true) randy = random(1, 3);         //1, 2
456
-  else if(leftCode == true && rightCode == false) randy = 1;
457
-  // else if(leftCode == true && rightCode == false) 
458
-  // {
459
-  //   randy = random(0, 2);                                                 //0, 1
460
-  //   if(randy == 0) randy = random(0, 2);                                  //erhöht Wahrscheinlickeit abzubiegen
461
-  // }
462
-  else if(leftCode == false && rightCode == true) randy = 2;
463
-  // else if(leftCode == false && rightCode == true)
464
-  // {
465
-  //   randy = random(3);                                                    //0, (1), 2
466
-  //   if(randy == 0) randy = random(3);                                     //erhöht Wahrscheinlickeit abzubiegen
467
-  //   while(randy == 1) randy = random(3);                                  //!1 => 0, 2
468
-  // }
456
+  else if(leftCode == true && rightCode == false) //randy = 1;
457
+  {
458
+    randy = random(0, 2);                                                 //0, 1
459
+    //if(randy == 0) randy = random(0, 2);                                  //erhöht Wahrscheinlickeit abzubiegen
460
+  }
461
+  else if(leftCode == false && rightCode == true) //randy = 2;
462
+  {
463
+    randy = random(0, 2);                                                 //0, 1
464
+    //if(randy == 0) randy = random(0, 2);                                  //erhöht Wahrscheinlickeit abzubiegen
465
+    if(randy == 1) randy = 2;                                             //!1 => 2
466
+  }
469
 
467
 
470
   //links Abbiegen (von der Verbindungsstrecke)
468
   //links Abbiegen (von der Verbindungsstrecke)
471
   if(randy == 1 && rightCode == true) 
469
   if(randy == 1 && rightCode == true) 
478
     while(eventTime < 300)
476
     while(eventTime < 300)
479
     {
477
     {
480
       TimeUpdate();
478
       TimeUpdate();
481
-      //Serial1.println(eventTime); 
482
       motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
479
       motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
483
     }
480
     }
484
     LineUpdate();
481
     LineUpdate();
485
-    //Serial1.println("Linie suchen"); 
486
     while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)
482
     while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)
487
     {
483
     {
488
       LineUpdate();
484
       LineUpdate();
492
     turnAngle = 0;  
488
     turnAngle = 0;  
493
     rotationAngle = 0;
489
     rotationAngle = 0;
494
     GyroUpdate();
490
     GyroUpdate();
495
-    //Serial1.println("Drehen"); 
496
     while(rotationAngle < 90)
491
     while(rotationAngle < 90)
497
     {
492
     {
498
       GyroUpdate();
493
       GyroUpdate();
499
       LineUpdate();
494
       LineUpdate();
500
       if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) motors.setSpeeds(0, FULLSPEEDRIGHT); 
495
       if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) motors.setSpeeds(0, FULLSPEEDRIGHT); 
501
-      else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
496
+      else if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) motors.setSpeeds(HALFSPEEDLEFT, FULLSPEEDRIGHT); 
502
       else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
497
       else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
503
     }
498
     }
504
     //geradeaus fahren
499
     //geradeaus fahren
519
       GyroUpdate();
514
       GyroUpdate();
520
       EncoderUpdate();
515
       EncoderUpdate();
521
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
516
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
522
-      if(driveRotation[1] > 1) break;
517
+      //if(driveRotation[1] > 1) break;
523
     }
518
     }
524
     driveRotation[1] = 0;
519
     driveRotation[1] = 0;
525
     GyroUpdate();
520
     GyroUpdate();
528
       GyroUpdate();
523
       GyroUpdate();
529
       EncoderUpdate();
524
       EncoderUpdate();
530
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
525
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
531
-      if(driveRotation[1] > 1) break;
526
+      //if(driveRotation[1] > 1) break;
532
     }
527
     }
533
     //geradeaus fahren
528
     //geradeaus fahren
534
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
529
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
540
       LineUpdate();
535
       LineUpdate();
541
       if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
536
       if(lineValue[2] > MARKLINE2 && lineValue[2] < SIGN2) break;
542
     }
537
     }
538
+    lastUpdate = millis();
539
+    TimeUpdate();
540
+    while(eventTime < 1000)
541
+    {
542
+      TimeUpdate();
543
+      LineUpdate();
544
+      Spurhalten();
545
+    }
543
   }
546
   }
544
 
547
 
545
   //rechts Abbiegen
548
   //rechts Abbiegen
546
   else if(randy == 2 && rightCode == true)
549
   else if(randy == 2 && rightCode == true)
547
   {
550
   {
551
+    //Serial1.println("rechts Abbiegen"); 
548
     //rechts drehen
552
     //rechts drehen
549
     turnAngle = 0;  
553
     turnAngle = 0;  
550
     rotationAngle = 0;
554
     rotationAngle = 0;
556
       EncoderUpdate();
560
       EncoderUpdate();
557
       LineUpdate();
561
       LineUpdate();
558
       motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
562
       motors.setSpeeds(FULLSPEEDLEFT, SLOWSPEEDRIGHT); 
559
-      if(driveRotation[0] > 1 || (lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0)) break;
563
+      if(lineValue[0] > MARKLINE0 && lineValue[0] < SIGN0) break;
560
     }
564
     }
561
     GyroUpdate();
565
     GyroUpdate();
562
     lastUpdate = millis();
566
     lastUpdate = millis();
576
   //nicht Abbiegen, geradeaus fahren
580
   //nicht Abbiegen, geradeaus fahren
577
   else 
581
   else 
578
   {
582
   {
583
+    //Serial1.println("nicht Abbiegen");
579
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
584
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
580
     lastUpdate = millis();
585
     lastUpdate = millis();
581
     TimeUpdate();
586
     TimeUpdate();
587
     }
592
     }
588
   }
593
   }
589
   //Serial1.println("Abbiegen beendet");
594
   //Serial1.println("Abbiegen beendet");
590
-  Serial1.println(0); 
595
+  Serial1.print(0); 
591
 }
596
 }
592
 
597
 
593
 //Funktion Spurhalten
598
 //Funktion Spurhalten
599
     ledYellow(1); 
604
     ledYellow(1); 
600
     //Serial1.println("Spur nach rechts korrigieren");  
605
     //Serial1.println("Spur nach rechts korrigieren");  
601
     motors.setSpeeds(FULLSPEEDLEFT/eventSpeed, SLOWSPEEDRIGHT/eventSpeed);
606
     motors.setSpeeds(FULLSPEEDLEFT/eventSpeed, SLOWSPEEDRIGHT/eventSpeed);
602
-    delay(100);    
607
+    lastUpdate = millis();
608
+    TimeUpdate();
609
+    while(eventTime < 100)
610
+    {
611
+      TimeUpdate();
612
+      LineUpdate();
613
+      if(lineValue[2] > MARKLINE2) break;
614
+    }   
603
   }
615
   }
604
 
616
 
605
   //rechte Linie erreicht, nach links fahren
617
   //rechte Linie erreicht, nach links fahren
607
   {
619
   {
608
     ledYellow(1); 
620
     ledYellow(1); 
609
     //Serial1.println("Spur nach links korrigieren");  
621
     //Serial1.println("Spur nach links korrigieren");  
610
-    motors.setSpeeds(SLOWSPEEDLEFT/eventSpeed, FULLSPEEDRIGHT/eventSpeed);  
611
-    delay(100);  
612
-  }
613
-
614
-  //Linie überfahren, zurücksetzen
615
-  else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1)                 
616
-  { 
617
-    ledRed(1); 
618
-    //Serial1.println("Spurfinden"); 
619
-    Serial1.println(1); 
622
+    motors.setSpeeds(SLOWSPEEDLEFT/eventSpeed, FULLSPEEDRIGHT/eventSpeed);   
620
     lastUpdate = millis();
623
     lastUpdate = millis();
621
-    while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)                 //Zumo fährt solange rückwärst bis er wieder auf der Spur steht
624
+    TimeUpdate();
625
+    while(eventTime < 100)
622
     {
626
     {
623
       TimeUpdate();
627
       TimeUpdate();
624
       LineUpdate();
628
       LineUpdate();
625
-      motors.setSpeeds(-FULLSPEEDLEFT/eventSpeed, -FULLSPEEDRIGHT/eventSpeed);
626
-      if(eventTime > 3000) break;
627
-    }
628
-    delay(100);    
629
-    //Serial1.println("Spur gefunden"); 
630
-    Serial1.println(0);  
631
-  }  
629
+      if(lineValue[0] > MARKLINE0) break;
630
+    }   
631
+  }
632
 
632
 
633
   //normale Fahrt
633
   //normale Fahrt
634
   else                                                                
634
   else                                                                
638
   }
638
   }
639
 }
639
 }
640
 
640
 
641
+//Funktion Spurfinden
642
+void Spurfinden()             
643
+{ 
644
+  ledRed(1); 
645
+  //Serial1.println("Spurfinden"); 
646
+  Serial1.print(1); 
647
+  lastUpdate = millis();
648
+  while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)                 //Zumo fährt solange rückwärst bis er wieder auf der Spur steht
649
+  {
650
+    TimeUpdate();
651
+    LineUpdate();
652
+    motors.setSpeeds(-FULLSPEEDLEFT, -FULLSPEEDRIGHT);
653
+    if(eventTime > 3000) break;
654
+  } 
655
+  //Serial1.println("Spur gefunden"); 
656
+  Serial1.print(0);  
657
+}  
658
+
641
 //Funktion Serielle Ausgabe
659
 //Funktion Serielle Ausgabe
642
 void SerielleAusgabe()                                                     
660
 void SerielleAusgabe()                                                     
643
 {
661
 {
656
 
674
 
657
 void loop() 
675
 void loop() 
658
 {
676
 {
659
-  //LoopTiming();                             //Zykluszeit beträgt max. 30ms im Idle
677
+  //LoopTiming();                             //Zykluszeit beträgt max. 20ms im Idle
660
   ledGreen(0);
678
   ledGreen(0);
661
   ledYellow(0);
679
   ledYellow(0);
662
   ledRed(0);
680
   ledRed(0);
663
 
681
 
664
-  //Abfragen der Sensordaten
665
-  LineUpdate();                                         
682
+  //Abfragen der Sensordaten                                 
666
   ProxUpdate();
683
   ProxUpdate();
667
   EncoderUpdate();
684
   EncoderUpdate();
668
   GyroUpdate();
685
   GyroUpdate();
669
   CompassUpdate();
686
   CompassUpdate();
687
+  LineUpdate();      
670
   TimeUpdate();
688
   TimeUpdate();
671
 
689
 
672
   //Funktionsauswahl
690
   //Funktionsauswahl
679
   if(alarm == true)                                    
697
   if(alarm == true)                                    
680
   {
698
   {
681
     //Serial1.println("Verstanden");
699
     //Serial1.println("Verstanden");
682
-    eventSpeed = 2;
683
-    if(moveRate > 1000 || proxValue[1] == 6 || proxValue[2] == 6 || lineValue[0] > SIGN0 || lineValue[2] > SIGN2) motors.setSpeeds(0, 0);  
700
+    eventSpeed = 1.4;
701
+    if(moveRate > 1500 || (proxValue[1] == 6 && proxValue[2] == 6) || lineValue[0] > SIGN0 || lineValue[2] > SIGN2 || lineValue[1] > MARKLINE1) motors.setSpeeds(0, 0);  
684
     else Spurhalten();
702
     else Spurhalten();
685
   }
703
   }
686
   //verfügbare Funktionen im Normalfall
704
   //verfügbare Funktionen im Normalfall
687
   else                                                              
705
   else                                                              
688
   {
706
   {
689
-    eventSpeed = 1;
707
+    eventSpeed = 1.0;
690
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
708
     //if(abs(moveRate) > 1500 && eventTime > 1000) Kontaktvermeiden();           
691
-    if(proxValue[2] == 6) Hindernisumfahren();
692
-    else if(lineValue[0] > SIGN0 && lineValue[0] < 1000 || lineValue[2] > SIGN2 && lineValue[2] < 1000) Abbiegen();
709
+    if(proxValue[1] == 6 && proxValue[2] == 6) Hindernisumfahren();
710
+    else if((lineValue[0] > SIGN0 && lineValue[0] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) Abbiegen();
711
+    else if((lineValue[2] > SIGN2 && lineValue[2] < 1400) && (lineValue[1] > SIGN1 && lineValue[1] < 700)) Abbiegen();
712
+    else if(lineValue[1] > MARKLINE1 && lineValue[1] < SIGN1) Spurfinden();
693
     else Spurhalten();
713
     else Spurhalten();
694
   }
714
   }
695
-  //LoopTiming();                                                       
696
-}
715
+  //LoopTiming();                                                     
716
+}