Skip to content

Commit

Permalink
1.引入电源管理系统 2.增加校准用时,提高校准精度
Browse files Browse the repository at this point in the history
  • Loading branch information
g122622 committed Apr 29, 2024
1 parent 7bbb390 commit d7bc818
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
32 changes: 32 additions & 0 deletions main/BMS/BMSTick.h
Original file line number Diff line number Diff line change
@@ -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);
}
}
15 changes: 13 additions & 2 deletions main/LED/StatusLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
{
Expand All @@ -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
2 changes: 1 addition & 1 deletion main/globalStates/controllerState.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions main/mpu6050/motionData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 4 additions & 6 deletions main/tasks/BMSTaskLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
}
}

Expand Down

0 comments on commit d7bc818

Please sign in to comment.