소스 검색

fix cumulative offset errors

Tuan Nguyen 1 년 전
부모
커밋
794cdc373d
1개의 변경된 파일5개의 추가작업 그리고 3개의 파일을 삭제
  1. 5 3
      esp32/esp32.ino

+ 5 - 3
esp32/esp32.ino

@@ -247,10 +247,12 @@ void movePolar(float theta, float rho)
     else if (rho > 1.0) 
         rho = 1.0;
 
-    float rotSteps = theta * (rot_total_steps / (2.0 * M_PI));
-    float inOutSteps = rho * inOut_total_steps;
+    long rotSteps = (long)(theta * (rot_total_steps / (2.0f * M_PI)));
     float revolutions = theta / (2.0 * M_PI);
-    float offsetSteps = revolutions * rot_total_steps / gearRatio;
+    long offsetSteps = (long)(revolutions * (rot_total_steps / gearRatio));
+
+    // Now inOutSteps is always derived from the absolute rho, not incrementally
+    long inOutSteps = (long)(rho * inOut_total_steps);
 
     inOutSteps -= offsetSteps;