Benutzer-Werkzeuge

Webseiten-Werkzeuge


hello_mbot_kalibrierung

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
hello_mbot_kalibrierung [2025/02/19 16:06] torsten.roehlhello_mbot_kalibrierung [2025/02/19 19:55] (aktuell) – [Bedienung] torsten.roehl
Zeile 112: Zeile 112:
 // Allgemein // Allgemein
 int speed = 100; // Motor speed int speed = 100; // Motor speed
-unsigned long time90degree = 20// wird überschrieben! +unsigned long time90degree; 
-// turn90Degree+ 
 +// turn90Degree...
 bool t90d_isTurning = false; bool t90d_isTurning = false;
 unsigned long t90d_turnStartTime = 0; unsigned long t90d_turnStartTime = 0;
-//actionCalibration...+// actionCalibration...
 unsigned long ac_turnStartTimeLeft  = 0; unsigned long ac_turnStartTimeLeft  = 0;
 unsigned long ac_turnTimeLeft = 0; unsigned long ac_turnTimeLeft = 0;
 unsigned long ac_turnStartTimeRight = 0; unsigned long ac_turnStartTimeRight = 0;
 unsigned long ac_turnTimeRight = 0; unsigned long ac_turnTimeRight = 0;
-static bool ac_isTurning = false; +bool ac_isTurning = false; 
-static bool ac_isLeftTurning = false; +bool ac_isLeftTurning = false; 
-static bool ac_isRightTurning = false; +bool ac_isRightTurning = false; 
-static bool ac_calibrationDone = false;+bool ac_calibrationDone = false;
 //actionTest... //actionTest...
-static bool at_doneLeft = false; +bool at_doneLeft = false; 
-static bool at_doneRight = false; +bool at_doneRight = false; 
-static bool at_testComplete = false;+bool at_testComplete = false;
  
 enum State { enum State {
Zeile 168: Zeile 169:
  
 bool turn90Degree(bool left) { bool turn90Degree(bool left) {
 +  // step: ...start turning
   if (!t90d_isTurning) {   if (!t90d_isTurning) {
     motor1.stop();     motor1.stop();
     motor2.stop();     motor2.stop();
     t90d_isTurning     = true;     t90d_isTurning     = true;
-    int dir           = 1+    int dir = left ? -1; 
-    if (!left) +
-      dir = -1;+
     motor1.run(dir * speed);     motor1.run(dir * speed);
     motor2.run(dir * speed);     motor2.run(dir * speed);
     t90d_turnStartTime = millis();     t90d_turnStartTime = millis();
 +    return false;
   }   }
 +  // step: ...in progress
 +  if (millis() - t90d_turnStartTime < time90degree)
 +    return false;
  
-  if (t90d_isTurning && millis() - t90d_turnStartTime >= time90degree) { +  // step: ... finished 
-    motor1.stop(); +  motor1.stop(); 
-    motor2.stop(); +  motor2.stop(); 
-    t90d_isTurning = false; +  t90d_isTurning = false;
-    return true; +
-  }+
  
-  return false;+  return true;
 } }
  
Zeile 227: Zeile 230:
 void actionCalibration() { void actionCalibration() {
  
-  if (!ac_calibrationDone) { +  if (ac_calibrationDone) 
-    led.setColorAt(1, 255, 0, 0); +    return;
-    led.setColorAt(0, 255, 0, 0); +
-    led.show(); +
-    int sensorState = lineFinder.readSensors();+
  
-    // step - start turning left +  led.setColorAt(1, 255, 0, 0); 
-    if (!ac_isTurning) { +  led.setColorAt(0, 255, 0, 0); 
-      motor1.stop(); +  led.show(); 
-      motor2.stop(); +  int sensorState = lineFinder.readSensors();
-      motor1.run(speed); +
-      motor2.run(speed); +
-      ac_turnStartTimeLeft = millis(); +
-      ac_isTurning = true; +
-      ac_isRightTurning = true; +
-      do { +
-        sensorState = lineFinder.readSensors(); +
-      } while ( sensorState != S1_OUT_S2_OUT); +
-    }+
  
-    // step - end turning left ... start turning right +  // step - start turning left 
-    if (ac_isRightTurning && sensorState == S1_IN_S2_IN) { +  if (!ac_isTurning) { 
-      motor1.stop(); +    motor1.stop(); 
-      motor2.stop(); +    motor2.stop(); 
-      ac_turnTimeLeft = millis() - ac_turnStartTimeLeft;+    motor1.run(speed); 
 +    motor2.run(speed); 
 +    ac_turnStartTimeLeft = millis(); 
 +    ac_isTurning = true; 
 +    ac_isRightTurning = true; 
 +    do { 
 +      sensorState = lineFinder.readSensors(); 
 +    } while ( sensorState != S1_OUT_S2_OUT); 
 +  }
  
-      motor1.run(-speed); +  // step - end turning left ... start turning right 
-      motor2.run(-speed); +  if (ac_isRightTurning && sensorState == S1_IN_S2_IN) { 
-      ac_turnStartTimeRight millis()+    motor1.stop(); 
-      do +    motor2.stop(); 
-        sensorState = lineFinder.readSensors(); +    ac_turnTimeLeft millis() - ac_turnStartTimeLeft;
-      } while sensorState != S1_OUT_S2_OUT); +
-      ac_isRightTurning false; +
-      ac_isLeftTurning = true; +
-    }+
  
-    // step - end turing right +    motor1.run(-speed); 
-    if (ac_isLeftTurning && sensorState == S1_IN_S2_IN) { +    motor2.run(-speed); 
-      motor1.stop(); +    ac_turnStartTimeRight = millis(); 
-      motor2.stop(); +    do { 
-      ac_turnTimeRight = millis() - ac_turnStartTimeRight+      sensorState lineFinder.readSensors(); 
-      time90degree = (ac_turnTimeLeft + ac_turnTimeRight) / 2.0; +    } while sensorState != S1_OUT_S2_OUT); 
-      ac_calibrationDone true; +    ac_isRightTurning = false
-      led.setColorAt(1, 0, 0, 0); +    ac_isLeftTurning = true;
-      led.setColorAt(0, 0, 0, 0); +
-      led.show()+
-      buzzer.tone(1200, 600); +
-    }+
   }   }
 +
 +  // step - end turing right
 +  if (ac_isLeftTurning && sensorState == S1_IN_S2_IN) {
 +    motor1.stop();
 +    motor2.stop();
 +    ac_turnTimeRight = millis() - ac_turnStartTimeRight;
 +    time90degree = (ac_turnTimeLeft + ac_turnTimeRight) / 2.0;
 +    ac_calibrationDone = true;
 +    led.setColorAt(1, 0, 0, 0);
 +    led.setColorAt(0, 0, 0, 0);
 +    led.show();
 +    buzzer.tone(1200, 600);
 +  }
 +
 } }
 void actionTest() { void actionTest() {
  
-  if (!at_doneLeft) {+  if (!at_doneLeft) { // Links-Drehung
     at_doneLeft = turn90Degree(true);     at_doneLeft = turn90Degree(true);
- 
     led.setColorAt(1, 0, 255, 0);     led.setColorAt(1, 0, 255, 0);
     led.setColorAt(0, 0, 255, 0);     led.setColorAt(0, 0, 255, 0);
     led.show();     led.show();
 +    return;
   }   }
-  else if (at_doneLeft && !at_doneRight) {+ 
 +  if (!at_doneRight) { // Rechts-Drehung
     at_doneRight = turn90Degree(false);     at_doneRight = turn90Degree(false);
 +    return;
   }   }
-  else if (at_doneLeft && at_doneRight && !at_testComplete) {+ 
 +  if (!at_testComplete) { // fertig
     motor1.stop();     motor1.stop();
     motor2.stop();     motor2.stop();
Zeile 297: Zeile 305:
     buzzer.tone(1200, 600);     buzzer.tone(1200, 600);
     at_testComplete = true;     at_testComplete = true;
 +    return;
   }   }
 } }
Zeile 319: Zeile 328:
   at_doneRight = false;   at_doneRight = false;
   at_testComplete = false;   at_testComplete = false;
- 
 } }
 </Code> </Code>
Zeile 337: Zeile 345:
  
 ⚡ **Schritt 3:**   ⚡ **Schritt 3:**  
-▶ **Nach dem Testlauf** kehrt der mBot in den **Ruhezustand** zurück.  +▶ **Nach dem Testlauf** kehrt der mBot durch Drückens des Tasters in den **Ruhezustand** zurück.  
    * Der Vorgang kann **von vorne** gestartet werden.    * Der Vorgang kann **von vorne** gestartet werden.
  
hello_mbot_kalibrierung.1739981162.txt.gz · Zuletzt geändert: 2025/02/19 16:06 von torsten.roehl