mirror of
https://github.com/modelec/PAMI-2025.git
synced 2026-03-18 21:40:36 +01:00
ajout de constantes avec #define
This commit is contained in:
@@ -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
|
||||
13
src/main.cpp
13
src/main.cpp
@@ -1,5 +1,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <TMCStepper.h>
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user