加了点保护

This commit is contained in:
ws 2025-06-30 14:28:32 +08:00
parent 4db4582450
commit 3db9ee683f
18 changed files with 368 additions and 149 deletions

View File

@ -64,7 +64,7 @@ void MX_GPIO_Init(void)
/*Configure GPIO pin : BALL_Pin */
GPIO_InitStruct.Pin = BALL_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(BALL_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : up_ball_Pin */

View File

@ -82,3 +82,15 @@
[info] Log at : 2025/6/28|01:19:54|GMT+0800
[info] Log at : 2025/6/28|14:29:33|GMT+0800
[info] Log at : 2025/6/28|16:39:11|GMT+0800
[info] Log at : 2025/6/28|16:39:57|GMT+0800
[info] Log at : 2025/6/28|18:37:20|GMT+0800
[info] Log at : 2025/6/29|15:33:54|GMT+0800
[info] Log at : 2025/6/30|10:24:59|GMT+0800

View File

@ -1,8 +1,76 @@
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil\ARM\ARMCC\Bin'
Build target 'R1'
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...
compiling shootTask.cpp...
linking...
Program Size: Code=31188 RO-data=1832 RW-data=268 ZI-data=32252
Program Size: Code=32916 RO-data=1832 RW-data=276 ZI-data=32220
FromELF: creating hex file...
"R1\R1.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:06
Build Time Elapsed: 00:04:01

View File

@ -1 +1 @@
2025/6/28 1:27:37
2025/6/30 14:27:15

View File

@ -158,22 +158,42 @@
<Ww>
<count>0</count>
<WinNumber>1</WinNumber>
<ItemText>rc_ctrl,0x0A</ItemText>
<ItemText>shoot,0x0A</ItemText>
</Ww>
<Ww>
<count>1</count>
<WinNumber>1</WinNumber>
<ItemText>shoot,0x0A</ItemText>
<ItemText>nucData,0x0A</ItemText>
</Ww>
<Ww>
<count>2</count>
<WinNumber>1</WinNumber>
<ItemText>ball,0x0A</ItemText>
<ItemText>nucbuf</ItemText>
</Ww>
<Ww>
<count>3</count>
<WinNumber>1</WinNumber>
<ItemText>nuc_v,0x0A</ItemText>
<ItemText>wzcsb,0x0A</ItemText>
</Ww>
<Ww>
<count>4</count>
<WinNumber>1</WinNumber>
<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>
@ -942,7 +962,7 @@
<Group>
<GroupName>User/device</GroupName>
<tvExp>0</tvExp>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
@ -1034,7 +1054,7 @@
<Group>
<GroupName>User/module</GroupName>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
@ -1066,7 +1086,7 @@
<Group>
<GroupName>User/task</GroupName>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>

View File

@ -55,3 +55,10 @@ r1上层
+ 图传多距离
+ 传球档
+ 旋钮+看图传点位调整
+ 修复
+ 6.29 发射误操作导致没有拟合作用就射了(已修复)
+ 6.29 串口不稳定 重新拔插一下
+ 6.29 nuc位置更新慢
+ 6.29 添加光电上电保护防止跳尺(已添加)

View File

@ -16,7 +16,7 @@
#endif
#define ONE_CONTROL 0
#define ONE_CONTROL 1
//是否使用大疆DT7遥控器
#ifndef DT7

View File

@ -20,53 +20,53 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
}
/* Exported functions ------------------------------------------------------- */
int8_t BSP_GPIO_RegisterCallback(uint16_t pin, void (*callback)(void)) {
if (callback == NULL) return BSP_ERR_NULL;
// int8_t BSP_GPIO_RegisterCallback(uint16_t pin, void (*callback)(void)) {
// if (callback == NULL) return BSP_ERR_NULL;
for (uint8_t i = 0; i < 16; i++) {
if (pin & (1 << i)) {
GPIO_Callback[i] = callback;
break;
}
}
return BSP_OK;
}
// for (uint8_t i = 0; i < 16; i++) {
// if (pin & (1 << i)) {
// GPIO_Callback[i] = callback;
// break;
// }
// }
// return BSP_OK;
// }
int8_t BSP_GPIO_EnableIRQ(uint16_t pin) {
switch (pin) {
// int8_t BSP_GPIO_EnableIRQ(uint16_t pin) {
// switch (pin) {
// case USER_KEY_Pin:
// HAL_NVIC_EnableIRQ(USER_KEY_EXTI_IRQn);
// case KEY_Pin:
// HAL_NVIC_EnableIRQ(KEY_Pin);
// break;
/*
case XXX_Pin:
HAL_NVIC_EnableIRQ(XXX_IRQn);
break;
*/
// /*
// case XXX_Pin:
// HAL_NVIC_EnableIRQ(XXX_IRQn);
// break;
// */
default:
return BSP_ERR;
}
return BSP_OK;
}
// default:
// return BSP_ERR;
// }
// return BSP_OK;
// }
int8_t BSP_GPIO_DisableIRQ(uint16_t pin) {
switch (pin) {
// int8_t BSP_GPIO_DisableIRQ(uint16_t pin) {
// switch (pin) {
// case USER_KEY_Pin:
// HAL_NVIC_DisableIRQ(USER_KEY_EXTI_IRQn);
// case KEY_Pin:
// HAL_NVIC_DisableIRQ(KEY_IRQn);
// break;
/*
case XXX_Pin:
HAL_NVIC_EnableIRQ(XXX_IRQn);
break;
*/
// /*
// case XXX_Pin:
// HAL_NVIC_EnableIRQ(XXX_IRQn);
// break;
// */
default:
return BSP_ERR;
}
return BSP_OK;
}
// default:
// return BSP_ERR;
// }
// return BSP_OK;
// }

View File

@ -24,15 +24,8 @@ void detect_ball(void)
void detect_init(void)
{
BSP_GPIO_RegisterCallback(KEY_Pin, detect_exit);
BSP_GPIO_RegisterCallback(BALL_Pin, detect_ball);
// BSP_GPIO_RegisterCallback(KEY_Pin, detect_exit);
// BSP_GPIO_RegisterCallback(BALL_Pin, detect_ball);
// 启用按键中断
if (BSP_GPIO_EnableIRQ(KEY_Pin) != BSP_OK) {
// 错误处理
}
if (BSP_GPIO_EnableIRQ(BALL_Pin) != BSP_OK) {
// 错误处理
}
}

View File

@ -4,23 +4,49 @@
static osThreadId_t thread_alert;
uint8_t nucbuf[32];
static volatile uint32_t drop_message = 0;
uint8_t nucbuf[16];
uint8_t packet[32]; // 假设最大数据包长度为 32 字节
static void NUC_IdleCallback(void) {
static void NUC_CBLTCallback(void)
{
osThreadFlagsSet(thread_alert, SIGNAL_NUC_RAW_REDY);
}
static void NUC_ERRORCALLBACK(void)
{
NUC_Restart();
uint32_t error_code = HAL_UART_GetError(BSP_UART_GetHandle(BSP_UART_AI));
}
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);
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_RX_CPLT_CB,
NUC_CBLTCallback);
BSP_UART_RegisterCallback(BSP_UART_AI, BSP_UART_ERROR_CB,
NUC_ERRORCALLBACK);
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),
(uint8_t *)nucbuf,
@ -198,3 +224,7 @@ int8_t NUC_HandleOffline(NUC_t *cmd)
memset(cmd, 0, sizeof(*cmd));
return 0;
}

View File

@ -165,5 +165,7 @@ fp32 abs_limit_min_max_fp(fp32 *num, fp32 Limit_min,fp32 Limit_max)
return Limit_min;
}
return *num; // 如果在范围内,直接返回原值
}

View File

@ -18,16 +18,14 @@ extern int ball_exit;
Ball ::Ball()
{
detect_init();
// 小米电机
feedback = get_CyberGear_point();
// 小米电机初始化
xiaomi.position = I_ANGLE; //
xiaomi.speed = 25; //
xiaomi.K_P = 80; // 位置增益
xiaomi.K_D = 50; // 位置阻尼
xiaomi.speed = 35; //
xiaomi.K_P = 40; // 位置增益
xiaomi.K_D = 100; // 位置阻尼
xiaomi.K_C = 12; // 力矩
xiaomi.Pmax = 1; // 好像没啥用
@ -218,6 +216,7 @@ void Ball::ball_control()
hand_thread = osThreadFlagsGet(); // 获取任务通知标志位
ball_state = HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin); // 读取光电状态(有球 1无球 0)
// 进攻
if (ready_key == SIDE)
{

View File

@ -9,9 +9,13 @@
#include "vofa.h"
#include "buzzer.h"
#include "bsp_buzzer.h"
#include <math.h>
extern RC_ctrl_t rc_ctrl;
NUC_t nuc_v;
float vofa[8];
double test_distance;
// sw[7]👆 1694 中 1000 👇306
// sw[2]👆 1694 👇306
@ -26,17 +30,18 @@ const fp32 Shoot::M2006_speed_PID[3] = {5, 0, 0.01};
const fp32 Shoot::M2006_angle_PID[3] = {15, 0.1, 0};
#define TO_TOP 10.0f
#define TO_BOTTOM 5.0f
#define TO_BOTTOM 6.0f
#define INIT_POS -130
#define TOP_POS -211
#define BOTTOM_POS 0
#define GO_ERROR 1.0f
#define Tigger_DO 0
#define Tigger_ZERO 100
#define Tigger_ZERO 120
#define Tigger_ERROR 3
float knob_increment;
double last_distance = 4.0f; // 4米做测试吧
Shoot::Shoot()
{
@ -77,11 +82,26 @@ void Shoot::trigger_control()
CAN_cmd_200(result, 0, 0, 0, &hcan1);
}
float shoot_fitting(float x)
{
return 0.2006334f * x * x + 25.788123f * x + -169.32157 + 3.8f;
}
float pass_fitting(float x)
{
return 1.1790172f * x * x + 15.983755f * x + -172.04664f + 1.6f;
}
void Shoot::distanceGet(const NUC_t &nuc_v)
{
// 判断数据是否在合理范围
if (nuc_v.vision.x >= 0.0f && nuc_v.vision.x <= 7.5f)
{
last_distance = LowPassFilter2p_Apply(&distance_filter, nuc_v.vision.x);
}
distance = LowPassFilter2p_Apply(&distance_filter, nuc_v.vision.x); // 对视觉距离进行滤波处理
// distance=nuc_v.vision.x; // 获取自瞄数据
// 否则不更新,保持上一次的值
distance = last_distance;
}
int Shoot::GO_SendData(float pos, float limit)
@ -128,8 +148,95 @@ 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()
{
// 底部光电检测假设0为到位1为未到位根据实际硬件调整
int bottom_sensor = HAL_GPIO_ReadPin(BALL_GPIO_Port, BALL_Pin); // 0为到位
static bool is_ready = false;
// 只要检测到到位就解除保护
if (!is_ready)
{
if (bottom_sensor == 0)
{
is_ready = true;
// 可选:蜂鸣器提示“归零成功”
}
else
{
// 未到位,所有按键无效,直接返回
return;
}
}
// 以下为原有遥控按键逻辑
if (rc_ctrl.sw[1] == 200)
{
rc_key = UP1;
@ -144,16 +251,12 @@ void Shoot::rc_mode()
}
if (rc_ctrl.sw[0] == 1800)
{
mode_key = TEST;
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;
@ -163,34 +266,16 @@ void Shoot::rc_mode()
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);
}
@ -206,6 +291,7 @@ void Shoot::shoot_control()
{
case VSION:
fire_pos = distance; // 视觉拟合的力
// fire_pos =shoot_fitting(test_distance);
switch (rc_key)
{
case DOWN1:
@ -243,7 +329,7 @@ void Shoot::shoot_control()
break;
}
break;
case TEST:
case PASS:
// 实时可调蓄力位置
fire_pos = INIT_POS + knob_increment; // 根据旋钮值调整发射位置
@ -369,8 +455,7 @@ void Shoot::RemoveError()
#if ONE_CONTROL
int asd = 0;
int shoot_wait = 0;
void Shoot::shoot_control()
{
@ -385,7 +470,7 @@ void Shoot::shoot_control()
switch (mode_key)
{
case VSION:
fire_pos = distance; // 视觉拟合的力
fire_pos = shoot_fitting(distance); // 视觉拟合的力
switch (rc_key)
{
case MIDDLE1:
@ -400,22 +485,25 @@ void Shoot::shoot_control()
limit_speed = TO_BOTTOM;
if (feedback.fd_gopos >= fire_pos - GO_ERROR && feedback.fd_gopos <= fire_pos + GO_ERROR)
{
shoot_wait = 1;
BSP_Buzzer_Start();
BSP_Buzzer_Set(1, 5000);
BSP_Buzzer_Set(1, 500);
}
}
break;
case DOWN1:
if (shoot_thread & EXTEND_OK)
if (shoot_thread & EXTEND_OK && shoot_wait == 1)
{
t_posSet = Tigger_ZERO;
if (feedback.fd_tpos >= Tigger_ZERO - 20)
{
BSP_Buzzer_Stop();
currentState = SHOOT_IDLE;
osThreadFlagsClear(EXTEND_OK);
shoot_wait = 0;
}
}
break;
@ -430,11 +518,12 @@ void Shoot::shoot_control()
break;
// 无自瞄拟合测试
case TEST:
// 传球
case PASS:
switch (rc_key)
{
case MIDDLE1:
fire_pos = pass_fitting(distance);
if ((shoot_thread & READY_TELL) && !(shoot_thread & EXTEND_OK))
{
// 只收到READY_TELL且未收到EXTEND_OK时顶部蓄力流程
@ -443,13 +532,14 @@ void Shoot::shoot_control()
else if (shoot_thread & EXTEND_OK)
{
// 只收到EXTEND_OK时允许调节蓄力位置
fire_pos = INIT_POS + knob_increment;
// fire_pos = INIT_POS + knob_increment;
go1.Pos = fire_pos;
limit_speed = TO_BOTTOM;
if (feedback.fd_gopos >= fire_pos - GO_ERROR && feedback.fd_gopos <= fire_pos + GO_ERROR)
{
shoot_wait = 1;
BSP_Buzzer_Start();
BSP_Buzzer_Set(1, 5000);
BSP_Buzzer_Set(1, 500);
}
}
// 没收到READY_TELL不做任何蓄力
@ -457,13 +547,18 @@ void Shoot::shoot_control()
case DOWN1:
if (shoot_thread & EXTEND_OK )
{
if (shoot_wait == 1)
{
t_posSet = Tigger_ZERO;
if (feedback.fd_tpos >= Tigger_ZERO - 20)
{
BSP_Buzzer_Stop();
currentState = SHOOT_IDLE;
osThreadFlagsClear(EXTEND_OK);
shoot_wait = 0;
}
}
}
break;

View File

@ -41,8 +41,10 @@ typedef enum
WAIT,
TEST,
VSION,
PASS,
OFFENSIVE,
DEFENSE
}rc_mode;
// 光电传感器读取宏

View File

@ -33,7 +33,8 @@ void FunctionBall(void *argument)
task_struct.stack_water_mark.ball = osThreadGetStackSpace(osThreadGetId());
#endif
abc=HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin);
//abc=HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin);
abc=HAL_GPIO_ReadPin(BALL_GPIO_Port, BALL_Pin); // 0为到位
ball.rc_mode(); // 遥控器模式

View File

@ -6,12 +6,9 @@
#include <cmsis_os2.h>
#include <stdio.h>
#ifdef DEBUG
NUC_t cmd_fromnuc;
//int send[3]={1,2,3};
float send[3]={1,2,3};
#endif
@ -34,7 +31,7 @@ void Function_nuc(void *argument)
#endif
NUC_StartReceiving();
NUC_RawParse(&cmd_fromnuc);
//NUC_RawParse(&cmd_fromnuc);
//NUC_SendPacket(&send, sizeof(send)); // 发送数据包
//掉线处理有空写
// if(NUC_WaitDmaCplt())
@ -47,8 +44,16 @@ 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);
}
else
{
NUC_HandleOffline(&cmd_fromnuc);
}
osDelay(2);
tick += delay_tick; /* 计算下一个唤醒时刄1ķ*/

View File

@ -16,7 +16,7 @@ void FunctionShoot(void *argument)
{
(void)argument; /* 未使用argument消除警告 */
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CTRL_SHOOT;
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_SHOOT;
osDelay(3000);//等待M2006电机启动
uint32_t tick = osKernelGetTickCount();

View File

@ -13,10 +13,7 @@ extern "C" {
/* Exported constants ------------------------------------------------------- */
/* 所有任务都要define一个“任务运行频率”和“初始化延时” */
#define TASK_FREQ_CTRL_GIMBAL (250u)
#define TASK_FREQ_CTRL_SHOOT (500u)
#define TASK_FREQ_CTRL_COMMAND (500u)
#define TASK_FREQ_MONITOR (2u)
#define TASK_FREQ_SHOOT (500u)
#define TASK_FREQ_CAN (1500u)
#define TASK_FREQ_AI (500u)
#define TASK_FREQ_BALL (500u)
@ -42,8 +39,6 @@ typedef struct
//osThreadId_t rc;
osThreadId_t nuc;
osThreadId_t shoot;
osThreadId_t gimbal;
//osThreadId_t handling;
osThreadId_t ball;
}thread;
@ -64,32 +59,23 @@ typedef struct
#ifdef DEBUG
struct {
UBaseType_t can;
//UBaseType_t rc;
UBaseType_t nuc;
UBaseType_t shoot;
UBaseType_t gimbal;
//UBaseType_t handling;
UBaseType_t ball;
} stack_water_mark; /* stack使用 */
struct {
float can;
//float rc;
float nuc;
float shoot;
float gimbal;
//float handling;
float ball;
} freq; /* 任务运行频率 */
struct {
float can;
//float rc;
float nuc;
float shoot;
float gimbal;
//float handling;
float ball;
} last_up_time; /* 任务最近运行时 */
#endif
@ -106,7 +92,6 @@ extern const osEventFlagsAttr_t attr_event;
/* Exported functions prototypes -------------------------------------------- */
void FunctionTake(void *argument);
void FunctionShoot(void *argument);
void FunctionCan(void *argument);
void FunctionRc(void *argument);