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 13:34] torsten.roehlhello_mbot_kalibrierung [2025/02/19 19:55] (aktuell) – [Bedienung] torsten.roehl
Zeile 97: Zeile 97:
 ==== Quellcode (engl. Sourcecode) ==== ==== Quellcode (engl. Sourcecode) ====
  
-FIXME  Code noch nicht fertig!+
 <Code c linenums:1 | Listing 1:MinimalesProgramm.ino> <Code c linenums:1 | Listing 1:MinimalesProgramm.ino>
 #include "MeMCore.h" #include "MeMCore.h"
  
 +// Hardware
 +MeBuzzer buzzer;
 MeLineFollower lineFinder(PORT_2); MeLineFollower lineFinder(PORT_2);
 MeRGBLed led(0, 2);   // must be fixed! MeRGBLed led(0, 2);   // must be fixed!
Zeile 108: Zeile 110:
 int threshold  = 500; // Analoger Schwellenwert! int threshold  = 500; // Analoger Schwellenwert!
 int buttonCount; int buttonCount;
 +// Allgemein
 +int speed = 100; // Motor speed
 unsigned long time90degree; unsigned long time90degree;
-bool isTurning = false; 
  
-int speed 250; // Motor speed +// turn90Degree... 
-unsigned long turnStartTime = 0; +bool t90d_isTurning false; 
-unsigned long turnTime = 0; +unsigned long t90d_turnStartTime = 0; 
-unsigned long backTurnStartTime = 0; +// actionCalibration... 
-unsigned long backTurnTime = 0;+unsigned long ac_turnStartTimeLeft  = 0; 
 +unsigned long ac_turnTimeLeft = 0; 
 +unsigned long ac_turnStartTimeRight = 0; 
 +unsigned long ac_turnTimeRight = 0
 +bool ac_isTurning = false; 
 +bool ac_isLeftTurning = false; 
 +bool ac_isRightTurning = false; 
 +bool ac_calibrationDone = false; 
 +//actionTest... 
 +bool at_doneLeft = false; 
 +bool at_doneRight = false; 
 +bool at_testComplete = false;
  
 enum State { enum State {
Zeile 155: Zeile 169:
  
 bool turn90Degree(bool left) { bool turn90Degree(bool left) {
-  if (!isTurning) { +  // step: ...start turning 
-    turnStartTime = millis(); +  if (!t90d_isTurning) {
-    isTurning     = true; +
-    dir           = 1; +
-    if(!left) +
-        dir = -1; +
-     +
-    motor1.run(dir*speed); +
-    motor2.run(dir*speed);     +
-  } +
- +
-  if (isTurning && millis() - turnStartTime >= time90degree) {+
     motor1.stop();     motor1.stop();
     motor2.stop();     motor2.stop();
-    isTurning false+    t90d_isTurning     true; 
-    return true;+    int dir = left ? 1 : -1; 
 + 
 +    motor1.run(dir * speed); 
 +    motor2.run(dir * speed); 
 +    t90d_turnStartTime = millis()
 +    return false;
   }   }
 +  // step: ...in progress
 +  if (millis() - t90d_turnStartTime < time90degree)
 +    return false;
  
-  return false;+  // step: ... finished 
 +  motor1.stop(); 
 +  motor2.stop(); 
 +  t90d_isTurning = false
 + 
 +  return true;
 } }
  
Zeile 212: Zeile 229:
  
 void actionCalibration() { void actionCalibration() {
 +
 +  if (ac_calibrationDone)
 +    return;
  
   led.setColorAt(1, 255, 0, 0);   led.setColorAt(1, 255, 0, 0);
   led.setColorAt(0, 255, 0, 0);   led.setColorAt(0, 255, 0, 0);
   led.show();   led.show();
 +  int sensorState = lineFinder.readSensors();
  
-  static bool isTurning false+  // step - start turning left 
-  static bool isBackTurning false+  if (!ac_isTurning) { 
-  static bool calibrationDone false;+    motor1.stop(); 
 +    motor2.stop(); 
 +    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); 
 +  }
  
-  if (!calibrationDone) { +  // step - end turning left ... start turning right 
-    int sensorState = lineFinder.readSensors();+  if (ac_isRightTurning && sensorState == S1_IN_S2_IN) { 
 +    motor1.stop(); 
 +    motor2.stop(); 
 +    ac_turnTimeLeft = millis() - ac_turnStartTimeLeft;
  
-    // step - start turning +    motor1.run(-speed); 
-    if (!isTurning) { +    motor2.run(-speed); 
-      motor1.run(speed); +    ac_turnStartTimeRight = millis(); 
-      motor2.run(speed); +    do { 
-      turnStartTime = millis(); +      sensorState = lineFinder.readSensors(); 
-      isTurning = true;      +    } while ( sensorState != S1_OUT_S2_OUT); 
-      do { +    ac_isRightTurning false
-          int sensorState = lineFinder.readSensors();          +    ac_isLeftTurning true;
-      } while ( sensorState != S1_OUT_S2_OUT); +
-    +
-     +
-    // step - end left turn +
-    if (sensorState == S1_IN_S2_IN) {     +
-     motor1.run(-speed); +
-     motor2.run(-speed); +
-     // todo      +
-         +
-      do { +
-          int sensorState = lineFinder.readSensors();          +
-      } while ( sensorState != S1_OUT_S2_OUT)+
-    +
-     +
-    // step - end right turn +
-    if (isBackTurning && sensorState == S1_IN_S2_IN) {       +
-       motor1.stop(); +
-       motor2.stop(); +
-       // todo +
-    }+
   }   }
 +
 +  // 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() {
-  led.setColorAt(1, 0, 255, 0); 
-  led.setColorAt(0, 0, 255, 0); 
-  led.show(); 
  
-  static bool doneLeft false+  if (!at_doneLeft) { // Links-Drehung 
-  static bool doneRight = false;+    at_doneLeft turn90Degree(true)
 +    led.setColorAt(1, 0, 255, 0); 
 +    led.setColorAt(0, 0, 255, 0); 
 +    led.show(); 
 +    return; 
 +  }
  
-  if (!doneLeft) { +  if (!at_doneRight) { // Rechts-Drehung 
-    doneLeft = turn90Degree(true);+    at_doneRight = turn90Degree(false)
 +    return;
   }   }
-  else if (doneLeft && !doneRight) { + 
-    doneRight = turn90Degree(false); +  if (!at_testComplete) { // fertig 
-  } +    motor1.stop(); 
-  else if (doneLeft && doneRight{ +    motor2.stop(); 
-    state STATE_OFF;+    led.setColorAt(1, 0, 0, 0); 
 +    led.setColorAt(0, 0, 0, 0); 
 +    led.show(); 
 +    buzzer.tone(1200, 600); 
 +    at_testComplete true; 
 +    return;
   }   }
 } }
Zeile 277: Zeile 313:
   led.setColorAt(0, 0, 0, 0);   led.setColorAt(0, 0, 0, 0);
   led.show();   led.show();
 +
 +  // reset
   motor1.stop();   motor1.stop();
   motor2.stop();   motor2.stop();
-  + 
 +  // reset state calibration 
 +  ac_isTurning = false; 
 +  ac_isLeftTurning = false; 
 +  ac_isRightTurning = false; 
 +  ac_calibrationDone = false; 
 + 
 +  // reset state test 
 +  at_doneLeft = false; 
 +  at_doneRight = false; 
 +  at_testComplete = false; 
 +}
 </Code> </Code>
 ==== Bedienung ==== ==== Bedienung ====
Zeile 296: 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.1739972051.txt.gz · Zuletzt geändert: 2025/02/19 13:34 von torsten.roehl