From d7bc818b86c335b19c627cb956f3d0ed6b612a69 Mon Sep 17 00:00:00 2001 From: g122622 <3300925806@qq.com> Date: Mon, 29 Apr 2024 18:51:51 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=BC=95=E5=85=A5=E7=94=B5=E6=BA=90=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=B3=BB=E7=BB=9F=202.=E5=A2=9E=E5=8A=A0=E6=A0=A1?= =?UTF-8?q?=E5=87=86=E7=94=A8=E6=97=B6=EF=BC=8C=E6=8F=90=E9=AB=98=E6=A0=A1?= =?UTF-8?q?=E5=87=86=E7=B2=BE=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/BMS/BMSTick.h | 32 +++++++++++++++++++++++++++++ main/LED/StatusLED.h | 15 ++++++++++++-- main/globalStates/controllerState.h | 2 +- main/mpu6050/motionData.h | 4 ++-- main/tasks/BMSTaskLoop.h | 10 ++++----- 5 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 main/BMS/BMSTick.h diff --git a/main/BMS/BMSTick.h b/main/BMS/BMSTick.h new file mode 100644 index 0000000..41bcd7d --- /dev/null +++ b/main/BMS/BMSTick.h @@ -0,0 +1,32 @@ +/* + * File: \BMSTick.h + * Project: BMS + * Created Date: 2024-04-28 22:52:22 + * Author: Guoyi + * ----- + * Last Modified: 2024-04-28 23:10:33 + * Modified By: Guoyi + * ----- + * Copyright (c) 2024 Guoyi Inc. + * + * ------------------------------------ + */ + +#include "../BMS/ADC/batteryVoltage.h" +#include "../globalStates/BMSState.h" +#include "../globalStates/controllerState.h" +#include "FlightController/motor/motor.h" +#include "LED/StatusLED.h" + +#define BATTERY_VOLTAGE_LOW_THR (3200) +#define BATTERY_VOLTAGE_EXTREMELY_LOW_THR (3000) + +void BMSTick() +{ + batteryVoltage = BMS_ADC_ReadBatteryVoltage(); + if (batteryVoltage != -1 && batteryVoltage < BATTERY_VOLTAGE_EXTREMELY_LOW_THR){ + flightState = 0; + stopAllMotors(); // 多余的一步。在这里是为了万无一失,确保关停所有电机。 + flashStatusLED(10, 500); + } +} diff --git a/main/LED/StatusLED.h b/main/LED/StatusLED.h index 02d35be..c22dbd8 100644 --- a/main/LED/StatusLED.h +++ b/main/LED/StatusLED.h @@ -4,7 +4,7 @@ * Created Date: 2024-04-28 15:07:32 * Author: Guoyi * ----- - * Last Modified: 2024-04-28 15:19:25 + * Last Modified: 2024-04-28 23:00:13 * Modified By: Guoyi * ----- * Copyright (c) 2024 Guoyi Inc. @@ -19,7 +19,7 @@ #include "freertos/task.h" #include "driver/gpio.h" -static gpio_num_t gpio_led_num = GPIO_NUM_32; // 连接LED的GPIO +static gpio_num_t gpio_led_num = GPIO_NUM_23; // 连接LED的GPIO void StatusLED_Init() { @@ -37,4 +37,15 @@ void disableStatusLED() gpio_set_level(gpio_led_num, 0); } +void flashStatusLED(int count, int duration) +{ + for (int i = 0; i < count; i++) + { + enableStatusLED(); + vTaskDelay(duration / portTICK_PERIOD_MS); + disableStatusLED(); + vTaskDelay(duration / portTICK_PERIOD_MS); + } +} + #endif diff --git a/main/globalStates/controllerState.h b/main/globalStates/controllerState.h index 8140f06..a07bbe6 100644 --- a/main/globalStates/controllerState.h +++ b/main/globalStates/controllerState.h @@ -4,7 +4,7 @@ * Created Date: 2024-04-05 21:25:11 * Author: Guoyi * ----- - * Last Modified: 2024-04-28 00:38:58 + * Last Modified: 2024-04-28 23:08:52 * Modified By: Guoyi * ----- * Copyright (c) 2024 Guoyi Inc. diff --git a/main/mpu6050/motionData.h b/main/mpu6050/motionData.h index c3fe632..7e98f72 100644 --- a/main/mpu6050/motionData.h +++ b/main/mpu6050/motionData.h @@ -4,7 +4,7 @@ * Created Date: 2024-03-07 22:51:03 * Author: Guoyi * ----- - * Last Modified: 2024-04-28 15:19:41 + * Last Modified: 2024-04-29 18:50:44 * Modified By: Guoyi * ----- * Copyright (c) 2024 Guoyi Inc. @@ -73,7 +73,7 @@ void MotionData_Calibrate() // 开始校准 enableStatusLED(); float gyroZ_SUM = 0; - for (int i = 0; i < 10; i++) + for (int i = 0; i < 30; i++) { vTaskDelay(30 / portTICK_PERIOD_MS); // F3D accel = getAccelData(); diff --git a/main/tasks/BMSTaskLoop.h b/main/tasks/BMSTaskLoop.h index b6fe300..7079de5 100644 --- a/main/tasks/BMSTaskLoop.h +++ b/main/tasks/BMSTaskLoop.h @@ -4,7 +4,7 @@ * Created Date: 2024-04-24 17:28:06 * Author: Guoyi * ----- - * Last Modified: 2024-04-27 13:00:59 + * Last Modified: 2024-04-28 23:02:35 * Modified By: * ----- * Copyright (c) 2024 Guoyi Inc. @@ -17,17 +17,15 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" - -#include "../BMS/ADC/batteryVoltage.h" -#include "../globalStates/BMSState.h" +#include "BMS/BMSTick.h" void BMSTaskLoop(void *argument) { BMS_ADC_Init(); while (1) { - batteryVoltage = BMS_ADC_ReadBatteryVoltage(); - vTaskDelay(500 / portTICK_PERIOD_MS); + vTaskDelay(50 / portTICK_PERIOD_MS); + BMSTick(); } }