From 89850bfc2f6bf437076e24ad581b36f963c64fad Mon Sep 17 00:00:00 2001 From: Cavailles Kevin Date: Sat, 14 Nov 2020 16:13:49 +0100 Subject: [PATCH] =?UTF-8?q?main=20commenc=C3=A9=20+=20emetteur=5Frf=20chan?= =?UTF-8?q?g=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keil_project/Services/emetteur_rf.c | 9 +++-- keil_project/Services/emetteur_rf.h | 2 +- keil_project/Src/main.c | 61 ++++++++++++++++++++--------- 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/keil_project/Services/emetteur_rf.c b/keil_project/Services/emetteur_rf.c index 31e5a1c..f796547 100644 --- a/keil_project/Services/emetteur_rf.c +++ b/keil_project/Services/emetteur_rf.c @@ -42,11 +42,14 @@ void emetteur_rf_init(void){ LL_USART_SetBaudRate(uart_port, periph_speed, baudrate); */} -void emetteur_send_bytes(USART_TypeDef * uart_port,char* buf, int len){ + + + +void emetteur_send_bytes(char* buf, int len){ for(int i = 0; i < len; i++){ LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_11); - LL_USART_TransmitData8(uart_port, buf[i]); - while(!LL_USART_IsActiveFlag_TXE(uart_port)); + LL_USART_TransmitData8(USART1, buf[i]); + while(!LL_USART_IsActiveFlag_TXE(USART1)); LL_GPIO_ResetOutputPin(GPIOA,LL_GPIO_PIN_11); } } diff --git a/keil_project/Services/emetteur_rf.h b/keil_project/Services/emetteur_rf.h index 295fe4b..7a4592d 100644 --- a/keil_project/Services/emetteur_rf.h +++ b/keil_project/Services/emetteur_rf.h @@ -8,7 +8,7 @@ #include "stm32f1xx_ll_gpio.h" void emetteur_rf_init(void); -void emetteur_send_bytes(USART_TypeDef * uart_port,char* buf, int len); +void emetteur_send_bytes(char* buf, int len); diff --git a/keil_project/Src/main.c b/keil_project/Src/main.c index 46d750c..01bbc70 100644 --- a/keil_project/Src/main.c +++ b/keil_project/Src/main.c @@ -21,6 +21,7 @@ #include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config #include "stm32f1xx_ll_bus.h" + #include "RFInput.h" #include "IncrEncoder.h" #include "DcMotor.h" @@ -28,6 +29,9 @@ #include "alimentation.h" #include "accelerometer.h" +#define CONTROL_LOOP_PERIOD 250 +#define MSG_TRANSFER_PERIOD 3000 + void SystemClock_Config(void); /* Private functions ---------------------------------------------------------*/ @@ -38,18 +42,18 @@ void SystemClock_Config(void); * @retval None */ -int val = 0; -int val2 = 0; + int counter = 0; -float level; -int level_enough; -double xx,yy; -int bon; +int battery_level_good = 0; +int angle_roulis_good = 0; +int angle_sail = 0; +int RF_Input_Duty = 0; +int TX_Flag = 0, CONTROL_LOOP_Flag = 0; + int main(void) { /* Configure the system clock to 72 MHz */ - SystemClock_Config(); - + SystemClock_Config(); //alimentation_init(); RF_INPUT_Init(); DC_MOTOR_Init(); @@ -59,20 +63,39 @@ int main(void) /* Infinite loop */ while (1) { - LL_mDelay(100); - //counter = (counter + 1) % 100; - //DC_MOTOR_SetSpeed(counter); - //val = RF_INPUT_GetPeriodUs(); - //val2 = RF_INPUT_GetDutyTimeUs(); - //SAIL_SetAngle(counter); - //level = get_battery_level(); - //level_enough = is_level_enough(); - xx = accelero_get_x(); - //yy = accelero_get_y(); - //bon = accelero_angle_bon(); + if(CONTROL_LOOP_Flag){ + battery_level_good = is_level_enough(); + angle_roulis_good = accelero_angle_bon(); + + if(!angle_roulis_good){ + SAIL_SetAngle(90); + DC_MOTOR_SetSpeed(0); + }else{ + angle_sail = INCR_ENCODER_GetAngle(); + SAIL_SetAngle(angle_sail/2); + RF_Input_Duty = RF_INPUT_GetDutyTimeRelative(); + DC_MOTOR_SetSpeed(RF_Input_Duty); + } + + CONTROL_LOOP_Flag = 0; + } + if(TX_Flag){ + + TX_Flag = 0; + } } } +void SysTick_Handler(void) +{ + if(counter % CONTROL_LOOP_PERIOD == 0){ + CONTROL_LOOP_Flag = 1; + } + if(counter % MSG_TRANSFER_PERIOD == 0){ + TX_Flag = 1; + } + counter = (counter+1) % (CONTROL_LOOP_PERIOD*MSG_TRANSFER_PERIOD) ; +}