ソースを参照

basic drift compensation

Etienne Landon 6 年 前
コミット
8c1d3c435e
1 ファイル変更4 行追加4 行削除
  1. 4 4
      CG_MarioKart.ino

+ 4 - 4
CG_MarioKart.ino

@@ -65,8 +65,8 @@ void loop() {
   //Read and scale analog inputs
   maxSpeed = map (analogRead(maxSpeed_pin), 0, 1024, 0, 255);
   driftCorrection = analogRead(driftCorrection_pin) ;
-  driftCorrection -= 512;
-  driftCorrection /= 8 ;
+  driftCorrection = driftCorrection / 512 - 1 ; // -1..1
+  driftCorrection *= 0.5 ;
 
   Serial.print("maxSpeed:"); //Serial debugging stuff
   Serial.println(maxSpeed);
@@ -102,8 +102,8 @@ void loop() {
   if (turn>0) { speeds[0] = move; speeds[1] = move - turn  ; }
   if (turn<=0) { speeds[0] = move + turn ; speeds[1] = move   ;  }
 
-//  if (driftCorrection>0) { speeds[0] -= driftCorrection*; speeds[1] = move - turn  ; }
-//  if (driftCorrection<=0) { speeds[0] = move + turn ; speeds[1] = move   ;  }
+  if (driftCorrection>0) { speeds[0] *= 1-driftCorrection ; }
+  if (driftCorrection<=0) { speeds[1] *= 1+driftCorrection ; }
 //  
   Serial.print("speeds: "); //Serial debugging stuff
   Serial.print(speeds[0]);