修复了遥控器设置键值时数值溢出的问题

This commit is contained in:
NeoZng 2022-12-07 21:08:22 +08:00
parent df356cf675
commit 3eba5b1c07
2 changed files with 24 additions and 2 deletions

View File

@ -28,6 +28,9 @@
#include "ins_task.h"
#include "motor_task.h"
#include "led_task.h"
#include "monitor.h"
#include "robot.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@ -57,6 +60,8 @@ void StartINSTASK(void const * argument);
void StartMOTORTASK(void const * argument);
void StartROBOTTASK(void const* argument);
/* USER CODE END FunctionPrototypes */
void StartDefaultTask(void const * argument);
@ -117,6 +122,9 @@ void MX_FREERTOS_Init(void) {
osThreadDef(motortask, StartMOTORTASK, osPriorityNormal, 0, 256);
defaultTaskHandle = osThreadCreate(osThread(motortask), NULL);
osThreadDef(robottask, StartROBOTTASK, osPriorityNormal, 0, 2048);
defaultTaskHandle = osThreadCreate(osThread(robottask), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
@ -138,6 +146,7 @@ void StartDefaultTask(void const * argument)
/* Infinite loop */
for(;;)
{
//1kHz
led_RGB_flow_task();
osDelay(1);
}
@ -150,6 +159,7 @@ void StartINSTASK(void const * argument)
{
while (1)
{
//1kHz
INS_Task();
osDelay(1);
}
@ -160,10 +170,22 @@ void StartMOTORTASK(void const * argument)
{
while (1)
{
//500Hz
MotorControlTask();
osDelay(1);
osDelay(2);
}
}
void StartROBOTTASK(void const * argument)
{
while (1)
{
// 200Hz
RobotTask();
osDelay(5);
}
}
/* USER CODE END Application */

View File

@ -41,7 +41,7 @@ static void sbus_to_rc(volatile const uint8_t *sbus_buf)
// @todo 似乎可以直接用位域操作进行,把key_temp通过强制类型转换变成key类型? 位域方案在下面,尚未测试
// 按键值解算,利用宏+循环减少代码长度
for (uint16_t i = 0x0001, j = 0; i < 0x8001; i *= 2, j++) // 依次查看每一个键
for (uint16_t i = 0x0001, j = 0; i != 0x8000; i *= 2, j++) // 依次查看每一个键
{
// 如果键按下,对应键的key press状态置1,否则为0
rc_ctrl[0].key[KEY_PRESS][j] = rc_ctrl[0].key_temp & i;