Browse Source

General improvements

fstange 6 years ago
parent
commit
1494cee6b1
2 changed files with 23 additions and 21 deletions
  1. 6 4
      README.md
  2. 17 17
      Zumo32U4/Hauptprojekt/Hauptprojekt.ino

+ 6 - 4
README.md

@@ -24,7 +24,9 @@ buzzer, and indicator LEDs allow the robot to provide feedback. <br/>
 
 ## Genutze Sensoren
 
-- Abstandssensoren
-- Liniensensoren
-- Beschleunigungssensor
-- Drehbewegungssensor
+- Abstandssensoren (4)
+- Liniensensoren (3)
+- Beschleunigungssensor (x-Achse)
+- Drehbewegungssensor (z-Achse)
+- Motorencoder (2)
+

+ 17 - 17
Zumo32U4/Hauptprojekt/Hauptprojekt.ino

@@ -1,5 +1,5 @@
 //Verfassser: Felix Stange 4056379 MET2016
-//Datum: 19.07.2017 erstellt, 18.10.2017 zuletzt geändert
+//Datum: 19.07.2017 erstellt, 20.10.2017 zuletzt geändert
 //Projekt: Der Zumo fährt automatisch zwischen 2 Linien ohne diese zu überfahren mithilfe der 
 //Liniensensoren (3), ähnlich einer Spurhalteautomatik (dunkler Belag und helle Streifen). 
 //Außerdem werden Kollisionen verhindert durch Nutzung der vorderen Abstandssensoren. Kommt es 
@@ -17,7 +17,7 @@ Zumo32U4ProximitySensors  proxSensors;  //Abstandssensoren
 Zumo32U4LineSensors       lineSensors;  //Liniensensoren
 Zumo32U4Motors            motors;
 Zumo32U4ButtonA           buttonA;
-Zumo32U4Encoders          encoders;
+Zumo32U4Encoders          encoders;     //Motorencoder
 LSM303                    compass;      //Beschleunigungssensor x-Achse
 L3G                       gyro;         //Drehbewegungssensor z-Achse
 
@@ -27,10 +27,8 @@ uint16_t  lineRaw[3];
 
 uint8_t   proxValue[4];                 //von links (0) nach rechts (3)
 
-int16_t   countsLeft;                   //Encoder links
-int16_t   wayLeft;
-int16_t   countsRight;                  //Encoder rechts
-int16_t   wayRight;
+int16_t   encoderCounts[2];             //von links (0) nach rechts (1)
+int16_t   driveRotation[2];
 
 int32_t   rotationAngle = 0;            //Drehwinkel
 int32_t   turnAngle = 0; 
@@ -150,6 +148,7 @@ void setup()
   Serial1.println("Zumo ready to start, press A");
   ledGreen(1);
   buttonA.waitForButton();
+  randomSeed(millis());
   delay(500);
 }
 
@@ -203,10 +202,10 @@ void CompassUpdate()
 //Update Encoder
 void EncoderUpdate()
 {
-  countsLeft = encoders.getCountsLeft();
-  wayLeft = countsRight / 910;                                //12cpr (Motorwelle) * 75,81:1 (Getriebe) = 909,7cpr (Antriebszahnrad)
-  countsRight = encoders.getCountsRight();
-  wayRight = countsRight / 910;
+  encoderCounts[0] = encoders.getCountsLeft();
+  driveRotation[0] = encoderCounts[0] / 910;                                //12cpr (Motorwelle) * 75,81:1 (Getriebe) = 909,7cpr (Antriebszahnrad)
+  encoderCounts[1] = encoders.getCountsRight();
+  driveRotation[1] = encoderCounts[1] / 910;
 }
 
 /*-----------------------------------------------------------------*/
@@ -357,9 +356,9 @@ void Crossroad()
   if(randy == 1 && leftCode == true) 
   {
     //zur Kreuzungsmitte fahren
-    wayLeft = 0;
-    wayRight = 0;
-    while(wayLeft != 1 && wayRight != 1)
+    driveRotation[0] = 0;
+    driveRotation[1] = 0;
+    while(driveRotation[0] != 1 && driveRotation[1] != 1)
     {
       EncoderUpdate();
       motors.setSpeeds(maxSpeed/2, maxSpeed/2);
@@ -405,7 +404,7 @@ void SerialOutput()
     PSTR("Abstand: %3d %3d %3d %3d   Linie: %6d %6d %6d   Richtung: %3c   Weg: %6d %6d   Winkel: %6d"),
     proxValue[0], proxValue[1], proxValue[2], proxValue[3], 
     lineValue[0], lineValue[1], lineValue[2],
-    dir, wayLeft, wayRight, rotationAngle);
+    dir, driveRotation[0], driveRotation[1], rotationAngle);
   Serial1.println(report);
 }
 
@@ -425,10 +424,11 @@ void loop()
   EncoderUpdate();
 
   //Funktionsauswahl
-/*   if(moveRate > 1000) CollisionDetection();         
+  if(moveRate > 1000) CollisionDetection();         
+  else if(proxValue[0] == 6 || proxValue[1] == 6) motors.setSpeeds(0, 0);  
   else if(proxValue[0] > 4 || proxValue[1] > 4) ObstacleAvoidance();
-  else if((lineValue[0] > 500 && lineValue[0] < 1500) || (lineValue[2] > 500 && lineValue[2] < 1500) Crossroad();
-  else TrackKeeper(); */
+  else if((lineValue[0] > 500 && lineValue[0] < 1500) || (lineValue[2] > 500 && lineValue[2] < 1500)) Crossroad();
+  else TrackKeeper();
 
   //Ausgabe über Bluetoothverbindung
   SerialOutput();