串口收数提示

This commit is contained in:
ws 2025-07-04 13:24:02 +08:00
commit bf3d376b60
13 changed files with 98 additions and 207 deletions

View File

@ -94,3 +94,11 @@
[info] Log at : 2025/6/30|10:24:59|GMT+0800
[info] Log at : 2025/7/1|10:57:51|GMT+0800
[info] Log at : 2025/7/2|02:59:15|GMT+0800
[info] Log at : 2025/7/2|17:15:33|GMT+0800
[info] Log at : 2025/7/4|09:10:46|GMT+0800

View File

@ -5,6 +5,7 @@
"buzzer.h": "c",
"calc_lib.h": "c",
"usertask.h": "c",
"detect.h": "c"
"detect.h": "c",
"nuc.h": "c"
}
}

View File

@ -1,76 +1,13 @@
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil\ARM\ARMCC\Bin'
Rebuild target 'R1'
assembling startup_stm32f407xx.s...
compiling dma.c...
compiling spi.c...
compiling gpio.c...
compiling stm32f4xx_hal_msp.c...
compiling tim.c...
compiling stm32f4xx_it.c...
compiling stm32f4xx_hal_rcc.c...
compiling freertos.c...
compiling main.c...
compiling usart.c...
compiling stm32f4xx_hal_can.c...
compiling crc.c...
compiling can.c...
compiling stm32f4xx_hal_gpio.c...
compiling stm32f4xx_hal_flash_ramfunc.c...
compiling stm32f4xx_hal_flash_ex.c...
compiling stm32f4xx_hal_flash.c...
compiling stm32f4xx_hal_rcc_ex.c...
compiling stm32f4xx_hal_cortex.c...
compiling stm32f4xx_hal_pwr_ex.c...
compiling stm32f4xx_hal_dma.c...
compiling stm32f4xx_hal_crc.c...
compiling stm32f4xx_hal.c...
compiling stm32f4xx_hal_pwr.c...
compiling croutine.c...
compiling stm32f4xx_hal_exti.c...
compiling event_groups.c...
compiling list.c...
compiling stm32f4xx_hal_dma_ex.c...
compiling queue.c...
compiling stream_buffer.c...
compiling timers.c...
compiling tasks.c...
compiling heap_4.c...
compiling system_stm32f4xx.c...
compiling port.c...
compiling stm32f4xx_hal_spi.c...
compiling stm32f4xx_hal_uart.c...
compiling stm32f4xx_hal_tim_ex.c...
compiling stm32f4xx_hal_tim.c...
compiling calc_lib.c...
compiling crc_ccitt.c...
compiling kalman.c...
compiling cmsis_os2.c...
compiling bsp_buzzer.c...
compiling bsp_delay.c...
compiling can_init.c...
compiling can_it.c...
compiling gpio_it.c...
compiling uart_it.c...
compiling filter.c...
compiling pid.c...
compiling user_math.c...
compiling buzzer.c...
compiling userTask.c...
compiling detect.c...
compiling shoot.cpp...
compiling vofa.c...
compiling remote_control.c...
compiling djiMotor.c...
compiling GO_M8010_6_Driver.c...
compiling nuc.c...
compiling ball.cpp...
compiling initTask.c...
compiling ballTask.cpp...
compiling encodeCan.cpp...
compiling nucTask.cpp...
Build target 'R1'
compiling shootTask.cpp...
compiling nuc.c...
compiling initTask.c...
compiling ball.cpp...
compiling nucTask.cpp...
compiling shoot.cpp...
linking...
Program Size: Code=32916 RO-data=1832 RW-data=276 ZI-data=32220
Program Size: Code=32960 RO-data=1832 RW-data=268 ZI-data=32220
FromELF: creating hex file...
"R1\R1.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:04:01
Build Time Elapsed: 00:02:09

View File

@ -1 +1 @@
2025/6/30 14:27:15
2025/7/4 9:21:52

View File

@ -178,7 +178,22 @@
<Ww>
<count>4</count>
<WinNumber>1</WinNumber>
<ItemText>cmd_fromnuc</ItemText>
<ItemText>nuc_v</ItemText>
</Ww>
<Ww>
<count>5</count>
<WinNumber>1</WinNumber>
<ItemText>abc,0x0A</ItemText>
</Ww>
<Ww>
<count>6</count>
<WinNumber>1</WinNumber>
<ItemText>shoot_wait,0x0A</ItemText>
</Ww>
<Ww>
<count>7</count>
<WinNumber>1</WinNumber>
<ItemText>error_code</ItemText>
</Ww>
</WatchWindow1>
<MemoryWindow4>

View File

@ -4,7 +4,7 @@
static osThreadId_t thread_alert;
static volatile uint32_t drop_message = 0;
volatile uint32_t drop_message = 0;
uint8_t nucbuf[16];
uint8_t packet[32]; // 假设最大数据包长度为 32 字节
@ -13,10 +13,11 @@ static void NUC_CBLTCallback(void)
{
osThreadFlagsSet(thread_alert, SIGNAL_NUC_RAW_REDY);
}
uint32_t error_code;
static void NUC_ERRORCALLBACK(void)
{
NUC_Restart();
uint32_t error_code = HAL_UART_GetError(BSP_UART_GetHandle(BSP_UART_AI));
NUC_Restart();
error_code = HAL_UART_GetError(BSP_UART_GetHandle(BSP_UART_AI));
}
@ -33,22 +34,8 @@ int8_t NUC_Init(NUC_t *nuc)
return DEVICE_OK;
}
// static void NUC_IdleCallback(void) {
// osThreadFlagsSet(thread_alert,SIGNAL_NUC_RAW_REDY);
// }
// int8_t NUC_Init(NUC_t *nuc){
// if(nuc == NULL) return DEVICE_ERR_NULL;
// if((thread_alert = osThreadGetId()) == NULL ) return DEVICE_ERR_NULL;
// BSP_UART_RegisterCallback(BSP_UART_AI,BSP_UART_IDLE_LINE_CB,
// NUC_IdleCallback);
// return DEVICE_OK;
// }
int8_t NUC_StartReceiving(void) {
if (HAL_UARTEx_ReceiveToIdle_DMA(BSP_UART_GetHandle(BSP_UART_AI),
if (HAL_UART_Receive_DMA(BSP_UART_GetHandle(BSP_UART_AI),
(uint8_t *)nucbuf,
sizeof(nucbuf)) == HAL_OK)
return DEVICE_OK;
@ -63,7 +50,7 @@ int8_t NUC_Restart(void) {
bool_t NUC_WaitDmaCplt(void) {
return (osThreadFlagsWait(SIGNAL_NUC_RAW_REDY, osFlagsWaitAll,500) ==
return (osThreadFlagsWait(SIGNAL_NUC_RAW_REDY, osFlagsWaitAll,20) ==
SIGNAL_NUC_RAW_REDY);
}
@ -94,7 +81,7 @@ int8_t NUC_SendPacket(void *data, uint16_t length) {
return DEVICE_OK; // 发送成功
}
int wzcsb=0;
int8_t NUC_RawParse(NUC_t *n) {
if (n == NULL) return DEVICE_ERR_NULL;
union {
@ -112,12 +99,10 @@ int8_t NUC_RawParse(NUC_t *n) {
case VISION:
/* 协议格式
0xFF HEAD
0x09
0x07
0x01
x fp32
y fp32
z fp32
0xFE TAIL
*/
if (nucbuf[7] != TAIL) goto error;
@ -146,7 +131,7 @@ int8_t NUC_RawParse(NUC_t *n) {
error:
wzcsb++;
drop_message++;
return DEVICE_ERR;
}

View File

@ -8,6 +8,7 @@ extern "C" {
#include "struct_typedef.h"
#include "device.h"
#include "uart_it.h"
#include "main.h"
// 帧头针尾
#define HEAD (0xFF)
@ -15,7 +16,7 @@ extern "C" {
#define ODOM (0x04)
#define PICK (0x06)
#define VISION (0x09)
#define VISION (0x07)
#define SEND (0X07)
// 写结构体存入视觉信息

View File

@ -11,6 +11,7 @@ extern int ball_exit;
// 外死点168 外163 中150 内127 限位124.8
// 伸缩
//外死点168 外163 中150 内127 限位124.8
#define I_ANGLE 127
#define O_ANGLE 163
#define WAIT_POS 150
@ -78,7 +79,7 @@ void Ball::rc_mode()
}
if (rc_ctrl.sw[5] == 200)
{
ready_key = DE; // 默认不准备
ready_key = DEF; // 默认不准备
}
}
@ -237,14 +238,16 @@ void Ball::ball_control()
ballHadling();
break;
}
Send_control();
}
// 防守
if(ready_key == DEFENSE)
else if(ready_key == DEF)
{
xiaomi.position = I_ANGLE; // 保持收回
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 确保爪气缸关闭
HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭
Send_control();
}
@ -286,6 +289,7 @@ void Ball::ballDown(void)
break;
case EXTEND_FINISH:
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET);
xiaomi.position = O_ANGLE; // 一直保持伸出
// 等待拨杆复位如切到MIDDLE2Idle_control会负责回位
break;
@ -358,6 +362,7 @@ void Ball::ballHadling(void)
break;
case BALL_FORWARD:
osDelay(300); // 不放太快
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_SET); // 打开气缸爪子
osDelay(5);
HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_SET); // 打开下气缸

View File

@ -40,7 +40,7 @@ typedef enum
IN,
OUT,
SIDE,
DE
DEF
}ball_rc_mode;
// 定义光电传感器检测宏

View File

@ -58,7 +58,7 @@ Shoot::Shoot()
go1.K_P = 1.0f,
go1.K_W = 0.05,
go1.Pos = 0, // 上电先到一个舒服的位置
go1.W = 0,
go1.W = 0,
go1.T = 0,
limit_speed = TO_TOP; // 快速上去
@ -148,71 +148,6 @@ int Shoot::GO_SendData(float pos, float limit)
// B键 sw[3]👆 200 开 中 1000 👇1800 关
// sw[5] 👆 200 👇1800
// 左旋 sw[7] 200 --1800
// void Shoot::rc_mode()
// {
// if (rc_ctrl.sw[1] == 200)
// {
// rc_key = UP1;
// }
// if (rc_ctrl.sw[1] == 1800 && rc_ctrl.sw[2] == 200)
// {
// rc_key = MIDDLE1;
// }
// if (rc_ctrl.sw[2] == 1800 && rc_ctrl.sw[1] == 1800)
// {
// rc_key = DOWN1;
// }
// if (rc_ctrl.sw[0] == 1800)
// {
// mode_key = PASS;
// }
// if (rc_ctrl.sw[0] == 200)
// {
// mode_key = VSION;
// }
// // if(rc_ctrl.sw[5]==200)
// // {
// // mode_key=OUT;
// // }
// if (rc_ctrl.sw[5] == 1800)
// {
// ready_key = OFFENSIVE;
// }
// else if (rc_ctrl.sw[5] == 200)
// {
// ready_key = DEFENSE;
// }
// // //旋钮增量
// // static int last_knob_value = 0; // 记录旋钮的上一次值
// // int current_knob_value = rc_ctrl.sw[7]; // 获取当前旋钮值
// // // 计算旋钮增量
// // if (current_knob_value >= 200 && current_knob_value <= 1800) {
// // knob_increment = (current_knob_value - last_knob_value) / 15.0f; // 每80单位对应一个增量
// // } else {
// // knob_increment = 0; // 如果旋钮值超出范围,不产生增量
// // }
// // 旋钮物理范围
// const int knob_min = 200;
// const int knob_max = 1800;
// // 目标映射范围
// const float map_min = 130.0f;
// const float map_max = -60.0f;
// int current_knob_value = rc_ctrl.sw[7];
// // 限制范围
// if (current_knob_value < knob_min)
// current_knob_value = knob_min;
// if (current_knob_value > knob_max)
// current_knob_value = knob_max;
// // 线性映射
// knob_increment = map_min + (map_max - map_min) * (current_knob_value - knob_min) / (knob_max - knob_min);
// }
void Shoot::rc_mode()
{
@ -226,12 +161,12 @@ void Shoot::rc_mode()
if (bottom_sensor == 0)
{
is_ready = true;
// 可选:蜂鸣器提示“归零成功”
BSP_Buzzer_Stop();
}
else
{
// 未到位,所有按键无效,直接返回
BSP_Buzzer_Start();
BSP_Buzzer_Set(1, 5000);
return;
}
}
@ -455,7 +390,6 @@ void Shoot::RemoveError()
#if ONE_CONTROL
int shoot_wait = 0;
void Shoot::shoot_control()
{
@ -503,6 +437,7 @@ void Shoot::shoot_control()
BSP_Buzzer_Stop();
currentState = SHOOT_IDLE;
osThreadFlagsClear(EXTEND_OK);
osThreadFlagsClear(READY_TELL); // 蓄力标志位
shoot_wait = 0;
}
}
@ -546,7 +481,7 @@ void Shoot::shoot_control()
break;
case DOWN1:
if (shoot_thread & EXTEND_OK )
if (shoot_thread & EXTEND_OK)
{
if (shoot_wait == 1)
{
@ -557,6 +492,7 @@ void Shoot::shoot_control()
BSP_Buzzer_Stop();
currentState = SHOOT_IDLE;
osThreadFlagsClear(EXTEND_OK);
osThreadFlagsClear(READY_TELL); // 蓄力标志位
shoot_wait = 0;
}
}

View File

@ -112,6 +112,8 @@ private:
float limit_speed;//go电机限速
int shoot_wait;
};

View File

@ -34,15 +34,12 @@ void FunctionBall(void *argument)
#endif
//abc=HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin);
abc=HAL_GPIO_ReadPin(BALL_GPIO_Port, BALL_Pin); // 0为到位
abc=HAL_GPIO_ReadPin(BALL_GPIO_Port, BALL_Pin); // 0为到位
ball.rc_mode(); // 遥控器模式
ball.ball_control(); // 控制球的动作
// HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_SET); // 确保气缸爪子闭合
// HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_SET); // 确保下气缸关闭
// ball.xiaomi.position = aaaa;
// CAN_XiaoMi(1,&ball.xiaomi,&hcan2);

View File

@ -1,10 +1,11 @@
#include "nucTask.hpp"
#include "nuc.h"
#include "userTask.h"
#include "TopDefine.h"//事件组的一些东西
#include "TopDefine.h" //事件组的一些东西
#include "FreeRTOS.h"
#include <cmsis_os2.h>
#include <stdio.h>
#include "bsp_buzzer.h"
#ifdef DEBUG
@ -14,29 +15,27 @@ NUC_t cmd_fromnuc;
void Function_nuc(void *argument)
{
(void)argument; /* 未使用argument消除警告 */
(void)argument; /* 未使用argument消除警告 */
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_AI;
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_AI;
NUC_Init(&cmd_fromnuc);
NUC_Init(&cmd_fromnuc);
HAL_GPIO_WritePin(LED_G_GPIO_Port,LED_G_Pin,GPIO_PIN_SET);
uint32_t tick = osKernelGetTickCount();
uint32_t tick = osKernelGetTickCount();
while(1)
{
while (1)
{
#ifdef DEBUG
task_struct.stack_water_mark.nuc = osThreadGetStackSpace(osThreadGetId());
#endif
NUC_StartReceiving();
//NUC_RawParse(&cmd_fromnuc);
//NUC_SendPacket(&send, sizeof(send)); // 发送数据包
//掉线处理有空写
// if(NUC_WaitDmaCplt())
// {
// NUC_RawParse(&cmd_fromnuc);
// NUC_RawParse(&cmd_fromnuc);
// NUC_SendPacket(&send, sizeof(send)); // 发送数据包
// 掉线处理有空写
// if(NUC_WaitDmaCplt())
// {
// NUC_RawParse(&cmd_fromnuc);
// }
// else
@ -44,20 +43,25 @@ void Function_nuc(void *argument)
// NUC_HandleOffline(&cmd_fromnuc);
// }
// 假设你在主循环或任务里这样用
if (NUC_RawParse(&cmd_fromnuc) == DEVICE_OK)
{
osMessageQueueReset(task_struct.msgq.nuc); // 清空消息队列
osMessageQueuePut(task_struct.msgq.nuc,&(cmd_fromnuc),0,0);
//BSP_Buzzer_Stop();
HAL_GPIO_WritePin(LED_G_GPIO_Port, LED_G_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED_R_GPIO_Port, LED_R_Pin, GPIO_PIN_RESET);
osMessageQueueReset(task_struct.msgq.nuc); // 清空消息队列
osMessageQueuePut(task_struct.msgq.nuc, &(cmd_fromnuc), 0, 0);
}
else
{
NUC_HandleOffline(&cmd_fromnuc);
// BSP_Buzzer_Start();
// BSP_Buzzer_Set(1, 5000);
HAL_GPIO_WritePin(LED_G_GPIO_Port, LED_G_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED_R_GPIO_Port, LED_R_Pin, GPIO_PIN_SET);
NUC_HandleOffline(&cmd_fromnuc);
}
osDelay(2);
tick += delay_tick; /* 计算下一个唤醒时刄1ķ*/
osDelayUntil(tick);
}
tick += delay_tick; /* 计算下一个唤醒时刄1ķ*/
osDelayUntil(tick);
}
}