From 0f55fed9d621b6f8a5efd71369320d8905c058fc Mon Sep 17 00:00:00 2001 From: NeoZng Date: Thu, 20 Apr 2023 09:54:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=A4=A7=E4=BA=86=E5=AE=9E=E6=97=B6?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=9A=84=E6=A0=88=E7=A9=BA=E9=97=B4,?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=86=E8=A7=89=E9=80=9A=E4=BF=A1=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E4=B8=B4=E6=97=B6=E5=8F=98=E9=87=8F=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inc/FreeRTOSConfig.h | 2 +- Src/freertos.c | 20 +++++++++++++------- application/gimbal/gimbal.c | 4 ++-- modules/master_machine/master_process.c | 10 ++++++---- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Inc/FreeRTOSConfig.h b/Inc/FreeRTOSConfig.h index 4c31057..c8e8b44 100644 --- a/Inc/FreeRTOSConfig.h +++ b/Inc/FreeRTOSConfig.h @@ -64,7 +64,7 @@ #define configTICK_RATE_HZ ((TickType_t)1000) #define configMAX_PRIORITIES ( 7 ) #define configMINIMAL_STACK_SIZE ((uint16_t)128) -#define configTOTAL_HEAP_SIZE ((size_t)15360) +#define configTOTAL_HEAP_SIZE ((size_t)30000) #define configMAX_TASK_NAME_LEN ( 32 ) #define configUSE_16_BIT_TICKS 0 #define configUSE_MUTEXES 1 diff --git a/Src/freertos.c b/Src/freertos.c index d4c2165..cb06e51 100644 --- a/Src/freertos.c +++ b/Src/freertos.c @@ -52,6 +52,12 @@ /* USER CODE END Variables */ osThreadId defaultTaskHandle; +osThreadId insTaskHandle; +osThreadId ledTaskHandle; +osThreadId robotTaskHandle; +osThreadId motorTaskHandle; +osThreadId daemonTaskHandle; +osThreadId uiTaskHandle; /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN FunctionPrototypes */ @@ -119,16 +125,16 @@ void MX_FREERTOS_Init(void) { /* USER CODE BEGIN RTOS_THREADS */ /* add threads, ... */ osThreadDef(instask, StartINSTASK, osPriorityNormal, 0, 1024); - defaultTaskHandle = osThreadCreate(osThread(instask), NULL); + insTaskHandle = osThreadCreate(osThread(instask), NULL); - osThreadDef(motortask, StartMOTORTASK, osPriorityNormal, 0, 256); - defaultTaskHandle = osThreadCreate(osThread(motortask), NULL); + osThreadDef(motortask, StartMOTORTASK, osPriorityNormal, 0, 512); + motorTaskHandle = osThreadCreate(osThread(motortask), NULL); - osThreadDef(daemontask, StartDAEMONTASK, osPriorityNormal, 0, 512); - defaultTaskHandle = osThreadCreate(osThread(daemontask), NULL); + osThreadDef(daemontask, StartDAEMONTASK, osPriorityNormal, 0, 128); + daemonTaskHandle = osThreadCreate(osThread(daemontask), NULL); osThreadDef(robottask, StartROBOTTASK, osPriorityNormal, 0, 1024); - defaultTaskHandle = osThreadCreate(osThread(robottask), NULL); + robotTaskHandle = osThreadCreate(osThread(robottask), NULL); /* USER CODE END RTOS_THREADS */ } @@ -191,7 +197,7 @@ void StartROBOTTASK(void const * argument) { // 200Hz RobotTask(); - osDelay(10);//syh此处暂时将时间改?10ms,原因在于未使用缓冲区发送,发?时延时5ms + osDelay(5);//syh此处暂时将时间改�?10ms,原因在于未使用缓冲区发送,发�?�时延时5ms } } /* USER CODE END Application */ diff --git a/application/gimbal/gimbal.c b/application/gimbal/gimbal.c index e56ac57..f95c3db 100644 --- a/application/gimbal/gimbal.c +++ b/application/gimbal/gimbal.c @@ -53,8 +53,8 @@ void GimbalInit() .cali_mode = BMI088_CALIBRATE_ONLINE_MODE, .work_mode = BMI088_BLOCK_PERIODIC_MODE, }; - imu = BMI088Register(&imu_config); - // gimba_IMU_data = INS_Init(); // IMU先初始化,获取姿态数据指针赋给yaw电机的其他数据来源 + // imu = BMI088Register(&imu_config); + gimba_IMU_data = INS_Init(); // IMU先初始化,获取姿态数据指针赋给yaw电机的其他数据来源 // YAW Motor_Init_Config_s yaw_config = { .can_init_config = { diff --git a/modules/master_machine/master_process.c b/modules/master_machine/master_process.c index e0c9ea8..f5ec0a7 100644 --- a/modules/master_machine/master_process.c +++ b/modules/master_machine/master_process.c @@ -78,11 +78,13 @@ Vision_Recv_s *VisionInit(UART_HandleTypeDef *_handle) */ void VisionSend(Vision_Send_s *send) { - uint16_t flag_register; - uint8_t send_buff[VISION_SEND_SIZE]; - uint16_t tx_len; + // buff和txlen必须为static,才能保证在函数退出后不被释放,使得DMA正确完成发送 + // 析构后的陷阱需要特别注意! + static uint16_t flag_register; + static uint8_t send_buff[VISION_SEND_SIZE]; + static uint16_t tx_len; // TODO: code to set flag_register - flag_register = 30<<8|0b00000001; + flag_register = 30 << 8 | 0b00000001; // 将数据转化为seasky协议的数据包 get_protocol_send_data(0x02, flag_register, &send->yaw, 3, send_buff, &tx_len); USARTSend(vision_usart_instance, send_buff, tx_len, USART_TRANSFER_DMA); // 和视觉通信使用IT,防止和接收使用的DMA冲突