Skip to content

Commit

Permalink
支持监控无人机的CPU和内存使用率
Browse files Browse the repository at this point in the history
  • Loading branch information
g122622 committed May 8, 2024
1 parent 58f654d commit f49db8d
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 15 deletions.
4 changes: 2 additions & 2 deletions main/BMS/ADC/batteryVoltage.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 2024-04-24 13:47:31
* Author: Guoyi
* -----
* Last Modified: 2024-04-27 13:02:40
* Last Modified: 2024-05-08 15:27:07
* Modified By:
* -----
* Copyright (c) 2024 Guoyi Inc.
Expand All @@ -20,7 +20,7 @@
#include "esp_adc/adc_cali.h"
#include "esp_adc/adc_cali_scheme.h"

const static char *BMS_ADC_LOG_TAG = "BMS_ADC";
static const char *BMS_ADC_LOG_TAG = "BMS_ADC";

/*---------------------------------------------------------------
ADC General Macros
Expand Down
20 changes: 12 additions & 8 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-05-08 00:04:25
* Last Modified: 2024-05-08 16:13:53
* Modified By: Guoyi
* -----
* Copyright (c) 2024 Guoyi Inc.
Expand All @@ -23,31 +23,35 @@ static gpio_num_t gpio_led_num = GPIO_NUM_23; // 连接LED的GPIO
static int s_count = 0;
static int s_duration = 0;

static TaskHandle_t flashStatusLEDTaskHandle;
static SemaphoreHandle_t semapHandle;
void enableStatusLED();
void disableStatusLED();

static void flashStatusLEDTask(void *argument)
{
while (1)
{
xSemaphoreTake(semapHandle, portMAX_DELAY);
for (int i = 0; i < *(int *)argument; i++)
for (int i = 0; i < s_count; i++)
{
enableStatusLED();
vTaskDelay(*(int *)(argument + 1) / portTICK_PERIOD_MS);
vTaskDelay(s_duration / portTICK_PERIOD_MS);
disableStatusLED();
vTaskDelay(*(int *)(argument + 1) / portTICK_PERIOD_MS);
vTaskDelay(s_duration / portTICK_PERIOD_MS);
}
}
}
static TaskHandle_t flashStatusLEDTaskHandle;
static SemaphoreHandle_t semapHandle;


void StatusLED_Init()
{
// 设置控制LED的GPIO为输出模式
gpio_set_direction(gpio_led_num, GPIO_MODE_OUTPUT);
xTaskCreatePinnedToCore(flashStatusLEDTask, "flashStatusLEDTask",
4096, NULL, 3, flashStatusLEDTaskHandle, 0);
// 创建信号量,用于拉起LED频闪任务
semapHandle = xSemaphoreCreateBinary();
xTaskCreatePinnedToCore(flashStatusLEDTask, "flashStatusLEDTask",
1024, NULL, 3, flashStatusLEDTaskHandle, 0);
}

void enableStatusLED()
Expand Down
7 changes: 6 additions & 1 deletion main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
/* 各任务 */
#include "tasks/controllerTickLoop.h"
#include "tasks/BMSTaskLoop.h"
#include "tasks/perfMonitorTaskLoop.h"

// 任务优先级数值越小,任务优先级越低
#define tskHIGH_PRIORITY 10
#define tskMEDIUM_PRIORITY 5
#define tskLOW_PRIORITY 3

TaskHandle_t controllerTickLoopHandle = NULL;
TaskHandle_t BMSTaskLoopHandle = NULL;
TaskHandle_t perfMonitorTaskLoopHandle = NULL;

/* 启动任务 */
void Tasks_Init()
Expand All @@ -47,10 +50,12 @@ void Tasks_Init()
4096, NULL, tskHIGH_PRIORITY, controllerTickLoopHandle, 1);
xTaskCreatePinnedToCore(BMSTaskLoop, "BMSTaskLoop",
4096, NULL, tskMEDIUM_PRIORITY, BMSTaskLoopHandle, 1);
// xTaskCreatePinnedToCore(perfMonitorTaskLoop, "perfMonitorTaskLoop",
// 4096, NULL, tskLOW_PRIORITY, perfMonitorTaskLoopHandle, 1);
}

void app_main(void)
{
{
/* 初始化各组件 */
StatusLED_Init();
Bleprph_Init();
Expand Down
4 changes: 2 additions & 2 deletions main/mpu6050/mpu6050.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 2024-03-07 19:55:56
* Author: Guoyi
* -----
* Last Modified: 2024-05-07 13:56:23
* Last Modified: 2024-05-08 13:42:51
* Modified By: Guoyi
* -----
* Copyright (c) 2024 Guoyi Inc.
Expand Down Expand Up @@ -58,7 +58,7 @@ void MPU6050_Init()
uint8_t flag = ESP_OK;
flag = MPU6050_register_write_byte(PWR_MGMT_1, 0x00); // 解除休眠状态
flag = MPU6050_register_write_byte(SMPLRT_DIV, 0x00); // 陀螺仪采样率。1KHz
flag = MPU6050_register_write_byte(CONFIG, 0x05); // 启用低通滤波。等级为0x05
flag = MPU6050_register_write_byte(CONFIG, 0x06); // 启用低通滤波。等级为0x05
flag = MPU6050_register_write_byte(GYRO_CONFIG, 0x0); // 陀螺仪自检及测量范围。不自检,250deg/s
flag = MPU6050_register_write_byte(ACCEL_CONFIG, 0x01); // 加速计自检、测量范围及高通滤波频率。不自检,2G,5Hz
if (flag != ESP_OK)
Expand Down
4 changes: 2 additions & 2 deletions main/tasks/controllerTickLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 2024-03-11 13:27:21
* Author: Guoyi
* -----
* Last Modified: 2024-04-29 23:01:23
* Last Modified: 2024-05-08 16:33:14
* Modified By: Guoyi
* -----
* Copyright (c) 2024 Guoyi Inc.
Expand All @@ -26,7 +26,7 @@

void controllerTickLoop(void *argument)
{
vTaskDelay(5000 / portTICK_PERIOD_MS); // 等待5000秒之后,开始初始化mpu6050,并进行校准
vTaskDelay(1000 / portTICK_PERIOD_MS); // 等待1秒之后,开始初始化mpu6050,并进行校准
MotionData_Init();
vTaskDelay(200 / portTICK_PERIOD_MS);
while (1)
Expand Down
49 changes: 49 additions & 0 deletions main/tasks/perfMonitorTaskLoop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* File: \PerfMonitorTaskLoop.h
* Project: tasks
* Created Date: 2024-05-08 15:32:21
* Author: Guoyi
* -----
* Last Modified: 2024-05-08 16:28:19
* Modified By: Guoyi
* -----
* Copyright (c) 2024 Guoyi Inc.
*
* ------------------------------------
*/

#ifndef TASKS_PERFMON_H
#define TASKS_PERFMON_H

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <stdio.h>
#include <string.h>
#include "esp_log.h"

#define STR_BUF_LEN 1024

void perfMonitorTaskLoop(void *argument)
{
uint8_t CPU_RunInfo[STR_BUF_LEN]; // 保存任务运行时间信息
while (1)
{
memset(CPU_RunInfo, 0, STR_BUF_LEN); /* 信息缓冲区清零 */
vTaskList((char *)&CPU_RunInfo); // 获取任务运行时间信息
printf("----------------------------------------------------\r\n");
printf("task_name\tstate\tpri\tcore\tfreemem\tid\r\n");
printf("%s", CPU_RunInfo);
printf("----------------------------------------------------\r\n");
memset(CPU_RunInfo, 0, STR_BUF_LEN); /* 信息缓冲区清零 */
vTaskGetRunTimeStats((char *)&CPU_RunInfo);
printf("task_name\trun_cnt\tusage_rate\r\n");
printf("%s", CPU_RunInfo);
printf("----------------------------------------------------\r\n");
printf("[esp_get_free_heap_size bytes] %ld\n", esp_get_free_heap_size());
printf("[xPortGetFreeHeapSize] %d\n", xPortGetFreeHeapSize());
printf("----------------------------------------------------\r\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}

#endif

0 comments on commit f49db8d

Please sign in to comment.