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,7 +1,7 @@
1 1
 # 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
2 2
 # 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
3 3
 //Verfassser: Felix Stange, 4056379, MET2016 
4
-//Datum: erstellt am 19.07.2017, zuletzt geändert am 13.04.2018 
4
+//Datum: erstellt am 19.07.2017, zuletzt geändert am 04.05.2018 
5 5
 //Projektbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
6 6
 //der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
7 7
 //Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
@@ -58,6 +58,7 @@ void BlueSetup()
58 58
   Serial1.begin(9600); //Initialisierung mit Datengeschwindigkeit(Baud)
59 59
   Serial1.setTimeout(10); //verkürzt Serial(1).read auf 10 ms statt 1000 ms
60 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 64
 //Setup Liniensensoren
@@ -66,27 +67,27 @@ void LineSetup()
66 67
   ledYellow(1);
67 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 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 93
 //Setup Abstandssensoren
@@ -106,8 +107,8 @@ void GyroSetup()
106 107
     ledRed(1);
107 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 114
   gyro.writeReg(L3G::CTRL1, 0b11111111); //Ausgaberate 800Hz, Tiefpassfilter 100Hz
@@ -139,8 +140,8 @@ void CompassSetup()
139 140
     ledRed(1);
140 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 147
   compass.enableDefault();
@@ -296,27 +297,26 @@ void EncoderUpdate()
296 297
 void Kontaktvermeiden()
297 298
 {
298 299
   //Serial1.println("Kontaktvermeiden");
299
-  Serial1.println(1);
300
+  Serial1.print(1);
300 301
   ledRed(1);
301
-
302 302
   motors.setSpeeds(0, 0);
303
-  delay(500);
303
+  delay(1000);
304 304
   while(proxValue[1] == 0 || proxValue[2] == 0)
305 305
   {
306 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 311
   //Serial1.println("Vermeiden beendet");
312
-  Serial1.println(0);
312
+  Serial1.print(0);
313 313
 }
314 314
 
315 315
 //Funktion Hindernisumfahrung
316 316
 void Hindernisumfahren()
317 317
 {
318 318
   //Serial1.println("Hindernisumfahren"); 
319
-  Serial1.println(1);
319
+  Serial1.print(1);
320 320
   ledYellow(1);
321 321
 
322 322
   //Schritt 1: Spurwechsel links   
@@ -329,14 +329,14 @@ void Hindernisumfahren()
329 329
     GyroUpdate();
330 330
     LineUpdate();
331 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 334
   //geradeaus über Mittellinie fahren
335 335
   LineUpdate();
336
-  while(lineValue[2] < 170)
336
+  while(lineValue[2] < 120)
337 337
   {
338 338
     LineUpdate();
339
-    motors.setSpeeds(107, 100);
339
+    motors.setSpeeds(106, 100);
340 340
     //if(lineValue[0] > MARKLINE0) break;
341 341
   }
342 342
   //rechts drehen
@@ -345,12 +345,12 @@ void Hindernisumfahren()
345 345
   {
346 346
     GyroUpdate();
347 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 352
   //geradeaus fahren
353
-  motors.setSpeeds(107, 100);
353
+  motors.setSpeeds(106, 100);
354 354
 
355 355
   //Gegenverkehr beachten
356 356
   ProxUpdate();
@@ -395,15 +395,15 @@ void Hindernisumfahren()
395 395
   {
396 396
     GyroUpdate();
397 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 401
   //geradeaus über Mittellinie fahren
402 402
   LineUpdate();
403 403
   while(lineValue[0] < 150)
404 404
   {
405 405
     LineUpdate();
406
-    motors.setSpeeds(107, 100);
406
+    motors.setSpeeds(106, 100);
407 407
     //if(lineValue[0] > MARKLINE0) break;
408 408
   }
409 409
   //links drehen
@@ -412,14 +412,14 @@ void Hindernisumfahren()
412 412
   {
413 413
     GyroUpdate();
414 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 417
     else motors.setSpeeds(27, 100);
418 418
   }
419 419
   //geradeaus fahren
420 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 425
 //Funktion Abbiegen
@@ -427,70 +427,65 @@ void Abbiegen()
427 427
 {
428 428
   ledYellow(1);
429 429
   //Serial1.println("Abbiegen");  
430
-  Serial1.println(1);
430
+  Serial1.print(1);
431 431
 
432 432
   //Markierung analysieren
433 433
   LineUpdate();
434 434
   bool leftCode; //links => 1
435 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 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 439
   else rightCode = false;
440 440
 
441 441
   //Zufallszahl erzeugen
442 442
   uint8_t randy; //geradeaus => 0
443 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 456
   //links Abbiegen (von der Verbindungsstrecke)
459 457
   if(randy == 1 && rightCode == true)
460 458
   {
461 459
     //Serial1.println("links Abbiegen von der Verbindungsstrecke"); 
462 460
     //geradeaus zur Mittellinie fahren
463
-    motors.setSpeeds(107, 100 +10);
461
+    motors.setSpeeds(106, 100 +10);
464 462
     lastUpdate = millis();
465 463
     TimeUpdate();
466 464
     while(eventTime < 300)
467 465
     {
468 466
       TimeUpdate();
469
-      //Serial1.println(eventTime); 
470
-      motors.setSpeeds(107, 100 +10);
467
+      motors.setSpeeds(106, 100 +10);
471 468
     }
472 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 472
       LineUpdate();
477
-      motors.setSpeeds(107, 100);
473
+      motors.setSpeeds(106, 100);
478 474
     }
479 475
     //links drehen
480 476
     turnAngle = 0;
481 477
     rotationAngle = 0;
482 478
     GyroUpdate();
483
-    //Serial1.println("Drehen"); 
484 479
     while(rotationAngle < 90)
485 480
     {
486 481
       GyroUpdate();
487 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 485
       else motors.setSpeeds(27, 100);
491 486
     }
492 487
     //geradeaus fahren
493
-    motors.setSpeeds(107, 100);
488
+    motors.setSpeeds(106, 100);
494 489
   }
495 490
 
496 491
   //links Abbiegen (vom Rundkurs)
@@ -507,7 +502,7 @@ void Abbiegen()
507 502
       GyroUpdate();
508 503
       EncoderUpdate();
509 504
       motors.setSpeeds(27, 100);
510
-      if(driveRotation[1] > 1) break;
505
+      //if(driveRotation[1] > 1) break;
511 506
     }
512 507
     driveRotation[1] = 0;
513 508
     GyroUpdate();
@@ -516,23 +511,32 @@ void Abbiegen()
516 511
       GyroUpdate();
517 512
       EncoderUpdate();
518 513
       motors.setSpeeds(27, 100);
519
-      if(driveRotation[1] > 1) break;
514
+      //if(driveRotation[1] > 1) break;
520 515
     }
521 516
     //geradeaus fahren
522
-    motors.setSpeeds(107, 100);
517
+    motors.setSpeeds(106, 100);
523 518
     lastUpdate = millis();
524 519
     TimeUpdate();
525 520
     while(eventTime < 1000)
526 521
     {
527 522
       TimeUpdate();
528 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 536
   //rechts Abbiegen
534 537
   else if(randy == 2 && rightCode == true)
535 538
   {
539
+    //Serial1.println("rechts Abbiegen"); 
536 540
     //rechts drehen
537 541
     turnAngle = 0;
538 542
     rotationAngle = 0;
@@ -543,8 +547,8 @@ void Abbiegen()
543 547
       GyroUpdate();
544 548
       EncoderUpdate();
545 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 553
     GyroUpdate();
550 554
     lastUpdate = millis();
@@ -554,17 +558,18 @@ void Abbiegen()
554 558
       GyroUpdate();
555 559
       LineUpdate();
556 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 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 568
   //nicht Abbiegen, geradeaus fahren
565 569
   else
566 570
   {
567
-    motors.setSpeeds(107, 100);
571
+    //Serial1.println("nicht Abbiegen");
572
+    motors.setSpeeds(106, 100);
568 573
     lastUpdate = millis();
569 574
     TimeUpdate();
570 575
     while(eventTime < 1000)
@@ -575,57 +580,70 @@ void Abbiegen()
575 580
     }
576 581
   }
577 582
   //Serial1.println("Abbiegen beendet");
578
-  Serial1.println(0);
583
+  Serial1.print(0);
579 584
 }
580 585
 
581 586
 //Funktion Spurhalten
582 587
 void Spurhalten()
583 588
 {
584 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 592
     ledYellow(1);
588 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 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 608
     ledYellow(1);
597 609
     //Serial1.println("Spur nach links korrigieren");  
598 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 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 615
       TimeUpdate();
612 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 621
   //normale Fahrt
622 622
   else
623 623
   {
624 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 647
 //Funktion Serielle Ausgabe
630 648
 void SerielleAusgabe()
631 649
 {
@@ -644,17 +662,17 @@ void SerielleAusgabe()
644 662
 
645 663
 void loop()
646 664
 {
647
-  //LoopTiming();                             //Zykluszeit beträgt max. 30ms im Idle
665
+  //LoopTiming();                             //Zykluszeit beträgt max. 20ms im Idle
648 666
   ledGreen(0);
649 667
   ledYellow(0);
650 668
   ledRed(0);
651 669
 
652
-  //Abfragen der Sensordaten
653
-  LineUpdate();
670
+  //Abfragen der Sensordaten                                 
654 671
   ProxUpdate();
655 672
   EncoderUpdate();
656 673
   GyroUpdate();
657 674
   CompassUpdate();
675
+  LineUpdate();
658 676
   TimeUpdate();
659 677
 
660 678
   //Funktionsauswahl
@@ -667,18 +685,20 @@ void loop()
667 685
   if(alarm == true)
668 686
   {
669 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 690
     else Spurhalten();
673 691
   }
674 692
   //verfügbare Funktionen im Normalfall
675 693
   else
676 694
   {
677
-    eventSpeed = 1;
695
+    eventSpeed = 1.0;
678 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 701
     else Spurhalten();
682 702
   }
683
-  //LoopTiming();                                                       
703
+  //LoopTiming();                                                     
684 704
 }

+ 129 - 108
ArduinoOutput/sketch/Hauptprojekt.ino.cpp

@@ -2,7 +2,7 @@
2 2
 #line 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
3 3
 #line 1 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
4 4
 //Verfassser: Felix Stange, 4056379, MET2016 
5
-//Datum: erstellt am 19.07.2017, zuletzt geändert am 13.04.2018 
5
+//Datum: erstellt am 19.07.2017, zuletzt geändert am 04.05.2018 
6 6
 //Projektbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
7 7
 //der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
8 8
 //Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
@@ -26,13 +26,13 @@ L3G                       gyro;         //Drehbewegungssensor z-Achse
26 26
 
27 27
 #define   MARKLINE0       150
28 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 33
 #define   MAXSPEED        400
34
-#define   FULLSPEEDLEFT   107
35
-#define   HALFSPEEDLEFT   54
34
+#define   FULLSPEEDLEFT   106
35
+#define   HALFSPEEDLEFT   53
36 36
 #define   SLOWSPEEDLEFT   27
37 37
 #define   FULLSPEEDRIGHT  100
38 38
 #define   HALFSPEEDRIGHT  50
@@ -70,48 +70,51 @@ bool      alarm = false;                //zeigt Manöver abhängig von btData
70 70
 //Setup Bluetoothverbindung
71 71
 #line 68 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
72 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 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 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 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 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 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 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 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 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 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 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 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 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 98
 void Kontaktvermeiden();
99 99
 #line 328 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
100 100
 void Hindernisumfahren();
101 101
 #line 438 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
102 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 104
 void Spurhalten();
105 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 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 110
 void loop();
109 111
 #line 68 "c:\\Users\\Carolin\\Downloads\\VSCode\\Zumo32U4\\Zumo32U4\\Hauptprojekt\\Hauptprojekt.ino"
110 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 120
 //Setup Liniensensoren
@@ -120,27 +123,27 @@ void LineSetup()
120 123
   ledYellow(1);
121 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 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 149
 //Setup Abstandssensoren
@@ -160,8 +163,8 @@ void GyroSetup()
160 163
     ledRed(1);
161 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 170
   gyro.writeReg(L3G::CTRL1, 0b11111111);                          //Ausgaberate 800Hz, Tiefpassfilter 100Hz
@@ -193,8 +196,8 @@ void CompassSetup()
193 196
     ledRed(1);
194 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 203
   compass.enableDefault();  
@@ -350,27 +353,26 @@ void EncoderUpdate()
350 353
 void Kontaktvermeiden()                                            
351 354
 {
352 355
   //Serial1.println("Kontaktvermeiden");
353
-  Serial1.println(1); 
356
+  Serial1.print(1); 
354 357
   ledRed(1);
355
-
356 358
   motors.setSpeeds(0, 0);
357
-  delay(500);
359
+  delay(1000);
358 360
   while(proxValue[1] == 0 || proxValue[2] == 0)
359 361
   {
360 362
     ProxUpdate();
361 363
     motors.setSpeeds(-HALFSPEEDLEFT, -HALFSPEEDRIGHT);
362 364
     if(lineValue[0] > MARKLINE0 || lineValue[2] > MARKLINE2) break;
363 365
   }
364
-  delay(500); 
366
+  motors.setSpeeds(0, 0);
365 367
   //Serial1.println("Vermeiden beendet");
366
-  Serial1.println(0); 
368
+  Serial1.print(0); 
367 369
 }
368 370
 
369 371
 //Funktion Hindernisumfahrung
370 372
 void Hindernisumfahren()                                              
371 373
 {
372 374
   //Serial1.println("Hindernisumfahren"); 
373
-  Serial1.println(1); 
375
+  Serial1.print(1); 
374 376
   ledYellow(1);
375 377
 
376 378
   //Schritt 1: Spurwechsel links   
@@ -472,7 +474,7 @@ void Hindernisumfahren()
472 474
   }
473 475
   //geradeaus fahren
474 476
   //Serial1.println("Umfahren beendet");
475
-  Serial1.println(0); 
477
+  Serial1.print(0); 
476 478
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT);
477 479
 }
478 480
 
@@ -481,33 +483,31 @@ void Abbiegen()
481 483
 {
482 484
   ledYellow(1); 
483 485
   //Serial1.println("Abbiegen");  
484
-  Serial1.println(1); 
486
+  Serial1.print(1); 
485 487
 
486 488
   //Markierung analysieren
487 489
   LineUpdate(); 
488 490
   bool  leftCode;                                                         //links => 1
489 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 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 495
   else rightCode = false;
494 496
 
495 497
   //Zufallszahl erzeugen
496 498
   uint8_t randy;                                                          //geradeaus => 0
497 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 512
   //links Abbiegen (von der Verbindungsstrecke)
513 513
   if(randy == 1 && rightCode == true) 
@@ -520,11 +520,9 @@ void Abbiegen()
520 520
     while(eventTime < 300)
521 521
     {
522 522
       TimeUpdate();
523
-      //Serial1.println(eventTime); 
524 523
       motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
525 524
     }
526 525
     LineUpdate();
527
-    //Serial1.println("Linie suchen"); 
528 526
     while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)
529 527
     {
530 528
       LineUpdate();
@@ -534,13 +532,12 @@ void Abbiegen()
534 532
     turnAngle = 0;  
535 533
     rotationAngle = 0;
536 534
     GyroUpdate();
537
-    //Serial1.println("Drehen"); 
538 535
     while(rotationAngle < 90)
539 536
     {
540 537
       GyroUpdate();
541 538
       LineUpdate();
542 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 541
       else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
545 542
     }
546 543
     //geradeaus fahren
@@ -561,7 +558,7 @@ void Abbiegen()
561 558
       GyroUpdate();
562 559
       EncoderUpdate();
563 560
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
564
-      if(driveRotation[1] > 1) break;
561
+      //if(driveRotation[1] > 1) break;
565 562
     }
566 563
     driveRotation[1] = 0;
567 564
     GyroUpdate();
@@ -570,7 +567,7 @@ void Abbiegen()
570 567
       GyroUpdate();
571 568
       EncoderUpdate();
572 569
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
573
-      if(driveRotation[1] > 1) break;
570
+      //if(driveRotation[1] > 1) break;
574 571
     }
575 572
     //geradeaus fahren
576 573
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
@@ -582,11 +579,20 @@ void Abbiegen()
582 579
       LineUpdate();
583 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 592
   //rechts Abbiegen
588 593
   else if(randy == 2 && rightCode == true)
589 594
   {
595
+    //Serial1.println("rechts Abbiegen"); 
590 596
     //rechts drehen
591 597
     turnAngle = 0;  
592 598
     rotationAngle = 0;
@@ -598,7 +604,7 @@ void Abbiegen()
598 604
       EncoderUpdate();
599 605
       LineUpdate();
600 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 609
     GyroUpdate();
604 610
     lastUpdate = millis();
@@ -618,6 +624,7 @@ void Abbiegen()
618 624
   //nicht Abbiegen, geradeaus fahren
619 625
   else 
620 626
   {
627
+    //Serial1.println("nicht Abbiegen");
621 628
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
622 629
     lastUpdate = millis();
623 630
     TimeUpdate();
@@ -629,7 +636,7 @@ void Abbiegen()
629 636
     }
630 637
   }
631 638
   //Serial1.println("Abbiegen beendet");
632
-  Serial1.println(0); 
639
+  Serial1.print(0); 
633 640
 }
634 641
 
635 642
 //Funktion Spurhalten
@@ -641,7 +648,14 @@ void Spurhalten()
641 648
     ledYellow(1); 
642 649
     //Serial1.println("Spur nach rechts korrigieren");  
643 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 661
   //rechte Linie erreicht, nach links fahren
@@ -649,28 +663,16 @@ void Spurhalten()
649 663
   {
650 664
     ledYellow(1); 
651 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 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 671
       TimeUpdate();
666 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 677
   //normale Fahrt
676 678
   else                                                                
@@ -680,6 +682,24 @@ void Spurhalten()
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 703
 //Funktion Serielle Ausgabe
684 704
 void SerielleAusgabe()                                                     
685 705
 {
@@ -698,17 +718,17 @@ void SerielleAusgabe()
698 718
 
699 719
 void loop() 
700 720
 {
701
-  //LoopTiming();                             //Zykluszeit beträgt max. 30ms im Idle
721
+  //LoopTiming();                             //Zykluszeit beträgt max. 20ms im Idle
702 722
   ledGreen(0);
703 723
   ledYellow(0);
704 724
   ledRed(0);
705 725
 
706
-  //Abfragen der Sensordaten
707
-  LineUpdate();                                         
726
+  //Abfragen der Sensordaten                                 
708 727
   ProxUpdate();
709 728
   EncoderUpdate();
710 729
   GyroUpdate();
711 730
   CompassUpdate();
731
+  LineUpdate();      
712 732
   TimeUpdate();
713 733
 
714 734
   //Funktionsauswahl
@@ -721,19 +741,20 @@ void loop()
721 741
   if(alarm == true)                                    
722 742
   {
723 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 746
     else Spurhalten();
727 747
   }
728 748
   //verfügbare Funktionen im Normalfall
729 749
   else                                                              
730 750
   {
731
-    eventSpeed = 1;
751
+    eventSpeed = 1.0;
732 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 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,5 +1,5 @@
1 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 3
 //Projektbeschreibung: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe 
4 4
 //der Liniensensoren (3), ähnlich einer Spurhalteautomatik (heller Belag und dunkle Streifen). 
5 5
 //Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
@@ -23,13 +23,13 @@ L3G                       gyro;         //Drehbewegungssensor z-Achse
23 23
 
24 24
 #define   MARKLINE0       150
25 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 30
 #define   MAXSPEED        400
31
-#define   FULLSPEEDLEFT   107
32
-#define   HALFSPEEDLEFT   54
31
+#define   FULLSPEEDLEFT   106
32
+#define   HALFSPEEDLEFT   53
33 33
 #define   SLOWSPEEDLEFT   27
34 34
 #define   FULLSPEEDRIGHT  100
35 35
 #define   HALFSPEEDRIGHT  50
@@ -67,9 +67,10 @@ bool      alarm = false;                //zeigt Manöver abhängig von btData
67 67
 //Setup Bluetoothverbindung
68 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 76
 //Setup Liniensensoren
@@ -78,27 +79,27 @@ void LineSetup()
78 79
   ledYellow(1);
79 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 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 105
 //Setup Abstandssensoren
@@ -118,8 +119,8 @@ void GyroSetup()
118 119
     ledRed(1);
119 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 126
   gyro.writeReg(L3G::CTRL1, 0b11111111);                          //Ausgaberate 800Hz, Tiefpassfilter 100Hz
@@ -151,8 +152,8 @@ void CompassSetup()
151 152
     ledRed(1);
152 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 159
   compass.enableDefault();  
@@ -308,27 +309,26 @@ void EncoderUpdate()
308 309
 void Kontaktvermeiden()                                            
309 310
 {
310 311
   //Serial1.println("Kontaktvermeiden");
311
-  Serial1.println(1); 
312
+  Serial1.print(1); 
312 313
   ledRed(1);
313
-
314 314
   motors.setSpeeds(0, 0);
315
-  delay(500);
315
+  delay(1000);
316 316
   while(proxValue[1] == 0 || proxValue[2] == 0)
317 317
   {
318 318
     ProxUpdate();
319 319
     motors.setSpeeds(-HALFSPEEDLEFT, -HALFSPEEDRIGHT);
320 320
     if(lineValue[0] > MARKLINE0 || lineValue[2] > MARKLINE2) break;
321 321
   }
322
-  delay(500); 
322
+  motors.setSpeeds(0, 0);
323 323
   //Serial1.println("Vermeiden beendet");
324
-  Serial1.println(0); 
324
+  Serial1.print(0); 
325 325
 }
326 326
 
327 327
 //Funktion Hindernisumfahrung
328 328
 void Hindernisumfahren()                                              
329 329
 {
330 330
   //Serial1.println("Hindernisumfahren"); 
331
-  Serial1.println(1); 
331
+  Serial1.print(1); 
332 332
   ledYellow(1);
333 333
 
334 334
   //Schritt 1: Spurwechsel links   
@@ -430,7 +430,7 @@ void Hindernisumfahren()
430 430
   }
431 431
   //geradeaus fahren
432 432
   //Serial1.println("Umfahren beendet");
433
-  Serial1.println(0); 
433
+  Serial1.print(0); 
434 434
   motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT);
435 435
 }
436 436
 
@@ -439,33 +439,31 @@ void Abbiegen()
439 439
 {
440 440
   ledYellow(1); 
441 441
   //Serial1.println("Abbiegen");  
442
-  Serial1.println(1); 
442
+  Serial1.print(1); 
443 443
 
444 444
   //Markierung analysieren
445 445
   LineUpdate(); 
446 446
   bool  leftCode;                                                         //links => 1
447 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 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 451
   else rightCode = false;
452 452
 
453 453
   //Zufallszahl erzeugen
454 454
   uint8_t randy;                                                          //geradeaus => 0
455 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 468
   //links Abbiegen (von der Verbindungsstrecke)
471 469
   if(randy == 1 && rightCode == true) 
@@ -478,11 +476,9 @@ void Abbiegen()
478 476
     while(eventTime < 300)
479 477
     {
480 478
       TimeUpdate();
481
-      //Serial1.println(eventTime); 
482 479
       motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT+10); 
483 480
     }
484 481
     LineUpdate();
485
-    //Serial1.println("Linie suchen"); 
486 482
     while(lineValue[0] < MARKLINE0 && lineValue[2] < MARKLINE2)
487 483
     {
488 484
       LineUpdate();
@@ -492,13 +488,12 @@ void Abbiegen()
492 488
     turnAngle = 0;  
493 489
     rotationAngle = 0;
494 490
     GyroUpdate();
495
-    //Serial1.println("Drehen"); 
496 491
     while(rotationAngle < 90)
497 492
     {
498 493
       GyroUpdate();
499 494
       LineUpdate();
500 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 497
       else motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT);
503 498
     }
504 499
     //geradeaus fahren
@@ -519,7 +514,7 @@ void Abbiegen()
519 514
       GyroUpdate();
520 515
       EncoderUpdate();
521 516
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
522
-      if(driveRotation[1] > 1) break;
517
+      //if(driveRotation[1] > 1) break;
523 518
     }
524 519
     driveRotation[1] = 0;
525 520
     GyroUpdate();
@@ -528,7 +523,7 @@ void Abbiegen()
528 523
       GyroUpdate();
529 524
       EncoderUpdate();
530 525
       motors.setSpeeds(SLOWSPEEDLEFT, FULLSPEEDRIGHT); 
531
-      if(driveRotation[1] > 1) break;
526
+      //if(driveRotation[1] > 1) break;
532 527
     }
533 528
     //geradeaus fahren
534 529
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
@@ -540,11 +535,20 @@ void Abbiegen()
540 535
       LineUpdate();
541 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 548
   //rechts Abbiegen
546 549
   else if(randy == 2 && rightCode == true)
547 550
   {
551
+    //Serial1.println("rechts Abbiegen"); 
548 552
     //rechts drehen
549 553
     turnAngle = 0;  
550 554
     rotationAngle = 0;
@@ -556,7 +560,7 @@ void Abbiegen()
556 560
       EncoderUpdate();
557 561
       LineUpdate();
558 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 565
     GyroUpdate();
562 566
     lastUpdate = millis();
@@ -576,6 +580,7 @@ void Abbiegen()
576 580
   //nicht Abbiegen, geradeaus fahren
577 581
   else 
578 582
   {
583
+    //Serial1.println("nicht Abbiegen");
579 584
     motors.setSpeeds(FULLSPEEDLEFT, FULLSPEEDRIGHT); 
580 585
     lastUpdate = millis();
581 586
     TimeUpdate();
@@ -587,7 +592,7 @@ void Abbiegen()
587 592
     }
588 593
   }
589 594
   //Serial1.println("Abbiegen beendet");
590
-  Serial1.println(0); 
595
+  Serial1.print(0); 
591 596
 }
592 597
 
593 598
 //Funktion Spurhalten
@@ -599,7 +604,14 @@ void Spurhalten()
599 604
     ledYellow(1); 
600 605
     //Serial1.println("Spur nach rechts korrigieren");  
601 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 617
   //rechte Linie erreicht, nach links fahren
@@ -607,28 +619,16 @@ void Spurhalten()
607 619
   {
608 620
     ledYellow(1); 
609 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 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 627
       TimeUpdate();
624 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 633
   //normale Fahrt
634 634
   else                                                                
@@ -638,6 +638,24 @@ void Spurhalten()
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 659
 //Funktion Serielle Ausgabe
642 660
 void SerielleAusgabe()                                                     
643 661
 {
@@ -656,17 +674,17 @@ void SerielleAusgabe()
656 674
 
657 675
 void loop() 
658 676
 {
659
-  //LoopTiming();                             //Zykluszeit beträgt max. 30ms im Idle
677
+  //LoopTiming();                             //Zykluszeit beträgt max. 20ms im Idle
660 678
   ledGreen(0);
661 679
   ledYellow(0);
662 680
   ledRed(0);
663 681
 
664
-  //Abfragen der Sensordaten
665
-  LineUpdate();                                         
682
+  //Abfragen der Sensordaten                                 
666 683
   ProxUpdate();
667 684
   EncoderUpdate();
668 685
   GyroUpdate();
669 686
   CompassUpdate();
687
+  LineUpdate();      
670 688
   TimeUpdate();
671 689
 
672 690
   //Funktionsauswahl
@@ -679,18 +697,20 @@ void loop()
679 697
   if(alarm == true)                                    
680 698
   {
681 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 702
     else Spurhalten();
685 703
   }
686 704
   //verfügbare Funktionen im Normalfall
687 705
   else                                                              
688 706
   {
689
-    eventSpeed = 1;
707
+    eventSpeed = 1.0;
690 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 713
     else Spurhalten();
694 714
   }
695
-  //LoopTiming();                                                       
696
-}
715
+  //LoopTiming();                                                     
716
+}