diff --git a/include/main.h b/include/main.h index 13718c0..ea1c8b4 100644 --- a/include/main.h +++ b/include/main.h @@ -35,4 +35,9 @@ enum Direction #define TRIG_PIN 18 #define ECHO_PIN 5 +// Constantes pour les roues +#define WHEEL_DIAMETER 5.5 // cm +#define STEPS_PER_REV 200 * 16 // microsteps +#define WHEEL_BASE 7.2 // cm + #endif // MAIN_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 427da91..7a22fe0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,7 @@ #include #include + +// Définitions des constantes dans main.h #include "main.h" // UART (bus unique) @@ -52,17 +54,15 @@ void moveAsyncSteps(int32_t steps, int32_t speed, bool forwardDir) movementInProgress = true; lastDirection = forwardDir ? FORWARD : BACKWARD; } + void rotateAsync(float angleDeg, int32_t speed, bool toRight) { // Informations sur les roues - const float wheelBase = 10.0; // cm - const float wheelDiameter = 6.0; // cm - const int stepsPerRev = 200 * 16; // microsteps - const float wheelCirc = PI * wheelDiameter; + const float wheelCirc = PI * WHEEL_DIAMETER; - float rotationCirc = PI * wheelBase; + float rotationCirc = PI * WHEEL_BASE; float distPerWheel = (angleDeg / 360.0) * rotationCirc; - int32_t steps = (distPerWheel / wheelCirc) * stepsPerRev; + int32_t steps = (distPerWheel / wheelCirc) * STEPS_PER_REV; // Le nombre de pas à faire steps_target = steps; @@ -212,6 +212,7 @@ void setup() stopMotors(); moveAsyncSteps(500, 200, false); + // rotateAsync(90, 200, true); Serial.println("Setup complete"); }