diff --git a/Core/Inc/functions.h b/Core/Inc/functions.h deleted file mode 100644 index 847805d..0000000 --- a/Core/Inc/functions.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * functions.h - * - * Created on: Feb 17, 2025 - * Author: CHAUVEAU Maxime - */ - -#ifndef FUNCTIONS_H_ -#define FUNCTIONS_H_ - -#include "main.h" -#include "motors.h" - -bool isDelayPassed(uint32_t delay); -void handleEncoderProgression(uint16_t totalDistance, uint16_t newDistance, bool direction); - - -#endif /* FUNCTIONS_H_ */ diff --git a/Core/Inc/motors.h b/Core/Inc/motors.h index 7a2fda7..c07ec5d 100644 --- a/Core/Inc/motors.h +++ b/Core/Inc/motors.h @@ -23,6 +23,7 @@ public: void tournerDroite(int speed); void tournerGauche(int speed); void update(); + }; diff --git a/Core/Src/functions.cpp b/Core/Src/functions.cpp deleted file mode 100644 index 5c50b87..0000000 --- a/Core/Src/functions.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef SRC_FUNCTIONS_C_ -#define SRC_FUNCTIONS_C_ - -#include "functions.h" -#include "motors.h" -#include -#include - -extern UART_HandleTypeDef huart2; - -uint32_t lastTick = 0; // Variable pour mémoriser l'heure de la dernière action -uint32_t delayTime = 0; // Variable pour définir le délai de la prochaine action - -// Fonction pour vérifier si le délai est passé (permet de ne pas bloquer l'exécution) -bool isDelayPassed(uint32_t delay) { - if (HAL_GetTick() - lastTick >= delay) { - lastTick = HAL_GetTick(); // Met à jour lastTick - return true; - } - return false; -} - -void handleEncoderProgression(uint16_t totalDistance, uint16_t newDistance, bool direction){ - char msg[128]; - if(direction == 0){ - sprintf(msg, "Encodeur recule de %d mm, distance totale parcourue : %d mm.\r\n", newDistance, totalDistance); - } else if(direction == 1){ - sprintf(msg, "Encodeur avance de %d mm, distance totale parcourue : %d mm.\r\n", newDistance, totalDistance); - } - HAL_UART_Transmit(&huart2, (uint8_t *)msg, strlen(msg), HAL_MAX_DELAY); -} - - -#endif /* SRC_FUNCTIONS_C_ */ diff --git a/Core/Src/modelec.cpp b/Core/Src/modelec.cpp index a99d7e9..7357ed9 100644 --- a/Core/Src/modelec.cpp +++ b/Core/Src/modelec.cpp @@ -7,7 +7,6 @@ #include "motors.h" -#include "functions.h" #include "main.h" #include "stm32l0xx_hal.h" #include @@ -37,6 +36,16 @@ extern "C" { extern TIM_HandleTypeDef htim21; extern UART_HandleTypeDef huart2; + uint32_t lastTick = 0; // Variable pour mémoriser l'heure de la dernière action + // Fonction pour vérifier si le délai est passé (permet de ne pas bloquer l'exécution) + bool isDelayPassed(uint32_t delay) { + if (HAL_GetTick() - lastTick >= delay) { + lastTick = HAL_GetTick(); // Met à jour lastTick + return true; + } + return false; + } + // Fonction de setup appelee au debut du main.c void ModelecOdometrySetup(){ HAL_UART_Transmit(&huart2, (uint8_t *)"SETUP COMPLETE\n", 15, HAL_MAX_DELAY); diff --git a/Core/Src/motors.cpp b/Core/Src/motors.cpp index 755431b..28df08d 100644 --- a/Core/Src/motors.cpp +++ b/Core/Src/motors.cpp @@ -27,6 +27,7 @@ void Motor::stop() { bool Motor::isStopped() { return currentSpeed == 0; } + void Motor::tournerDroite(int speed) { targetSpeed = (speed <= 626) ? speed : 626; isTurningRight = true;