mirror of
https://github.com/modelec/MarcelMoteurSTM32.git
synced 2026-01-18 16:47:23 +01:00
fonctions setup et loop fonctionnelles
This commit is contained in:
@@ -4,13 +4,14 @@
|
||||
* Created on: Feb 17, 2025
|
||||
* Author: CHAUVEAU Maxime
|
||||
*/
|
||||
#include "main.h"
|
||||
#include "motors.h"
|
||||
|
||||
#ifndef FUNCTIONS_H_
|
||||
#define FUNCTIONS_H_
|
||||
|
||||
void Cpploop(Motor *motor);
|
||||
#include "main.h"
|
||||
#include "motors.h"
|
||||
|
||||
bool isDelayPassed(uint32_t delay);
|
||||
void handleEncoderProgression(uint16_t totalDistance, uint16_t newDistance, bool direction);
|
||||
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* modelec.h
|
||||
*
|
||||
* Created on: Mar 14, 2025
|
||||
* Author: allan
|
||||
*/
|
||||
|
||||
#ifndef INC_MODELEC_H_
|
||||
#define INC_MODELEC_H_
|
||||
|
||||
#include "stm32l0xx_hal.h"
|
||||
|
||||
// Fonction de setup appelee au debut du main.c
|
||||
void ModelecOdometrySetup();
|
||||
|
||||
// Fonction de loop appelee en boucle dans le main.c
|
||||
void ModelecOdometryLoop();
|
||||
|
||||
|
||||
#endif /* INC_MODELEC_H_ */
|
||||
@@ -22,21 +22,6 @@ bool isDelayPassed(uint32_t delay) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Cpploop(Motor *motor){
|
||||
|
||||
GPIOC->ODR ^= (1<<10);
|
||||
|
||||
//On actualise toute les 10ms et on effectue tous les controles périodiques
|
||||
if(isDelayPassed(10)) {
|
||||
if(encoder1.getTotalDistance() > 10) {
|
||||
motor->stop();
|
||||
}
|
||||
//On met à jour le statut des moteurs
|
||||
motor->update();
|
||||
}
|
||||
}
|
||||
|
||||
void handleEncoderProgression(uint16_t totalDistance, uint16_t newDistance, bool direction){
|
||||
char msg[128];
|
||||
if(direction == 0){
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "modelec.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -31,6 +30,9 @@
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
void ModelecOdometrySetup();
|
||||
|
||||
void ModelecOdometryLoop();
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
@@ -106,7 +108,8 @@ int main(void)
|
||||
while (1)
|
||||
{
|
||||
ModelecOdometryLoop();
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
}
|
||||
|
||||
@@ -6,40 +6,52 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "modelec.h"
|
||||
#include "encoder.h"
|
||||
#include "motors.h"
|
||||
#include "functions.h"
|
||||
#include "main.h"
|
||||
#include "stm32l0xx_hal.h"
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
extern "C" {
|
||||
// Variables globales
|
||||
Motor motor(TIM3);
|
||||
Encoder encoder1(60000, 600, &GPIOC->IDR, &GPIOC->IDR, (1<<0), (1<<1), &handleEncoderProgression);
|
||||
Encoder encoder2(60000, 600, &GPIOC->IDR, &GPIOC->IDR, (1<<2), (1<<3), &handleEncoderProgression);
|
||||
|
||||
// Variables globales
|
||||
Motor motor(TIM3);
|
||||
Encoder encoder1(60000, 600, &GPIOC->IDR, &GPIOC->IDR, (1<<0), (1<<1), &handleEncoderProgression);
|
||||
Encoder encoder2(60000, 600, &GPIOC->IDR, &GPIOC->IDR, (1<<2), (1<<3), &handleEncoderProgression);
|
||||
extern TIM_HandleTypeDef htim3;
|
||||
extern UART_HandleTypeDef huart2;
|
||||
|
||||
extern TIM_HandleTypeDef htim3;
|
||||
extern UART_HandleTypeDef huart2;
|
||||
// Fonction de setup appelee au debut du main.c
|
||||
void ModelecOdometrySetup(){
|
||||
HAL_UART_Transmit(&huart2, (uint8_t *)"SETUP COMPLETE\n", 15, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
// Fonction de setup appelee au debut du main.c
|
||||
void ModelecOdometrySetup(){
|
||||
HAL_UART_Transmit(&huart2, (uint8_t *)"SETUP COMPLETE\n", 15, HAL_MAX_DELAY);
|
||||
}
|
||||
// Fonction de loop appelee en boucle dans le main.c
|
||||
void ModelecOdometryLoop(){
|
||||
GPIOC->ODR ^= (1<<10);
|
||||
|
||||
// Fonction de loop appelee en boucle dans le main.c
|
||||
void ModelecOdometryLoop(){
|
||||
//On actualise toute les 10ms et on effectue tous les controles périodiques
|
||||
if(isDelayPassed(10)) {
|
||||
if(encoder1.getTotalDistance() > 10) {
|
||||
motor.stop();
|
||||
}
|
||||
//On met à jour le statut des moteurs
|
||||
motor.update();
|
||||
}
|
||||
}
|
||||
|
||||
Cpploop(&motor);
|
||||
}
|
||||
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
if(GPIO_Pin == GPIO_PIN_0 || GPIO_Pin == GPIO_PIN_1) {
|
||||
encoder1.trigger(); // trigger de l'encodeur 1
|
||||
} else if (GPIO_Pin == GPIO_PIN_2 || GPIO_Pin == GPIO_PIN_3) {
|
||||
encoder2.trigger(); // trigger de l'encodeur 2
|
||||
}
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
if(GPIO_Pin == GPIO_PIN_0 || GPIO_Pin == GPIO_PIN_1) {
|
||||
encoder1.trigger(); // trigger de l'encodeur 1
|
||||
} else if (GPIO_Pin == GPIO_PIN_2 || GPIO_Pin == GPIO_PIN_3) {
|
||||
encoder2.trigger(); // trigger de l'encodeur 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user