可以小防护一下错误操作 还有bug
This commit is contained in:
parent
e17113c679
commit
a939a4d8f3
12
MDK-ARM/.vscode/keil-assistant.log
vendored
12
MDK-ARM/.vscode/keil-assistant.log
vendored
@ -108,3 +108,15 @@
|
||||
|
||||
[info] Log at : 2025/7/6|23:12:04|GMT+0800
|
||||
|
||||
[info] Log at : 2025/7/7|04:53:38|GMT+0800
|
||||
|
||||
[info] Log at : 2025/7/7|08:44:07|GMT+0800
|
||||
|
||||
[info] Log at : 2025/7/7|14:20:11|GMT+0800
|
||||
|
||||
[info] Log at : 2025/7/8|02:49:12|GMT+0800
|
||||
|
||||
[info] Log at : 2025/7/8|13:15:42|GMT+0800
|
||||
|
||||
[info] Log at : 2025/7/8|18:00:22|GMT+0800
|
||||
|
||||
|
10
MDK-ARM/.vscode/uv4.log
vendored
10
MDK-ARM/.vscode/uv4.log
vendored
@ -3,16 +3,16 @@ Build target 'R1'
|
||||
compiling userTask.c...
|
||||
compiling remote_control.c...
|
||||
compiling initTask.c...
|
||||
compiling nucTask.cpp...
|
||||
compiling encodeCan.cpp...
|
||||
compiling ballTask.cpp...
|
||||
compiling djiMotor.c...
|
||||
compiling main.c...
|
||||
compiling shootTask.cpp...
|
||||
compiling nucTask.cpp...
|
||||
compiling djiMotor.c...
|
||||
compiling ballTask.cpp...
|
||||
compiling shoot.cpp...
|
||||
compiling ball.cpp...
|
||||
linking...
|
||||
Program Size: Code=32720 RO-data=1832 RW-data=268 ZI-data=32220
|
||||
Program Size: Code=32016 RO-data=1832 RW-data=276 ZI-data=32260
|
||||
FromELF: creating hex file...
|
||||
"R1\R1.axf" - 0 Error(s), 0 Warning(s).
|
||||
Build Time Elapsed: 00:00:09
|
||||
Build Time Elapsed: 00:00:10
|
||||
|
2
MDK-ARM/.vscode/uv4.log.lock
vendored
2
MDK-ARM/.vscode/uv4.log.lock
vendored
@ -1 +1 @@
|
||||
2025/7/6 23:29:24
|
||||
2025/7/8 19:42:52
|
@ -173,32 +173,17 @@
|
||||
<Ww>
|
||||
<count>3</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>ball_exit,0x0A</ItemText>
|
||||
<ItemText>nucbuf,0x10</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>4</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>nucbuf</ItemText>
|
||||
<ItemText>drop_message,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>5</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>nuc_v</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>6</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>test_exit,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>7</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>ttttt1,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>8</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>ball_exit,0x0A</ItemText>
|
||||
<ItemText>cmd_fromnuc</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<MemoryWindow4>
|
||||
@ -967,7 +952,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>User/device</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
@ -1059,7 +1044,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>User/module</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
|
@ -16,7 +16,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
#define ONE_CONTROL 1
|
||||
#define ONE_CONTROL 0
|
||||
|
||||
//是否使用大疆DT7遥控器
|
||||
#ifndef DT7
|
||||
@ -43,6 +43,8 @@
|
||||
#define EXTEND_OK (1<<3)
|
||||
//等待ok
|
||||
#define WAIT_OK (1<<4)
|
||||
//可以防守收回
|
||||
#define DEF_READY (1<<5)
|
||||
|
||||
//要发送ok了
|
||||
#define BALL_SEND (1<<6)
|
||||
|
@ -6,7 +6,7 @@ static osThreadId_t thread_alert;
|
||||
|
||||
volatile uint32_t drop_message = 0;
|
||||
|
||||
uint8_t nucbuf[16];
|
||||
uint8_t nucbuf[20];
|
||||
uint8_t packet[32]; // 假设最大数据包长度为 32 字节
|
||||
|
||||
static void NUC_CBLTCallback(void)
|
||||
@ -82,6 +82,62 @@ int8_t NUC_SendPacket(void *data, uint16_t length) {
|
||||
return DEVICE_OK; // 发送成功
|
||||
}
|
||||
|
||||
// int8_t NUC_RawParse(NUC_t *n) {
|
||||
// if (n == NULL) return DEVICE_ERR_NULL;
|
||||
// union {
|
||||
// float x[3];
|
||||
// char data[12];
|
||||
// } instance; // 方便在浮点数和字符数组之间进行数据转换
|
||||
|
||||
// // 校验数据包头
|
||||
// if(nucbuf[0]!=HEAD) goto error; //发送ID不是底盘
|
||||
// else
|
||||
// {
|
||||
// n->status_fromnuc = nucbuf[1];
|
||||
// n->ctrl_status = nucbuf[2];
|
||||
// switch (n->status_fromnuc) {
|
||||
// case VISION:
|
||||
// /* 协议格式
|
||||
// 0xFF HEAD
|
||||
// 0x07
|
||||
// 控制帧
|
||||
// 0x01 相机帧
|
||||
// x fp32
|
||||
// 0xFE TAIL
|
||||
// */
|
||||
// if (nucbuf[7] != TAIL) goto error;
|
||||
|
||||
// instance.data[3] = nucbuf[6];
|
||||
// instance.data[2] = nucbuf[5];
|
||||
// instance.data[1] = nucbuf[4];
|
||||
// instance.data[0] = nucbuf[3];
|
||||
// n->vision.x = instance.x[0];
|
||||
|
||||
// instance.data[7] = nucbuf[10];
|
||||
// instance.data[6] = nucbuf[9];
|
||||
// instance.data[5] = nucbuf[8];
|
||||
// instance.data[4] = nucbuf[7];
|
||||
// n->vision.y = instance.x[1];
|
||||
|
||||
|
||||
// break;
|
||||
// }
|
||||
// return DEVICE_OK;
|
||||
// }
|
||||
|
||||
|
||||
// error:
|
||||
// drop_message++;
|
||||
// return DEVICE_ERR;
|
||||
// }
|
||||
|
||||
|
||||
/* 协议格式
|
||||
0xFF HEAD
|
||||
x fp32
|
||||
y fp32
|
||||
0xFE TAIL
|
||||
*/
|
||||
int8_t NUC_RawParse(NUC_t *n) {
|
||||
if (n == NULL) return DEVICE_ERR_NULL;
|
||||
union {
|
||||
@ -93,42 +149,23 @@ int8_t NUC_RawParse(NUC_t *n) {
|
||||
if(nucbuf[0]!=HEAD) goto error; //发送ID不是底盘
|
||||
else
|
||||
{
|
||||
n->status_fromnuc = nucbuf[1];
|
||||
n->ctrl_status = nucbuf[2];
|
||||
switch (n->status_fromnuc) {
|
||||
case VISION:
|
||||
/* 协议格式
|
||||
0xFF HEAD
|
||||
0x07
|
||||
控制帧
|
||||
0x01 相机帧
|
||||
x fp32
|
||||
0xFE TAIL
|
||||
*/
|
||||
if (nucbuf[7] != TAIL) goto error;
|
||||
|
||||
instance.data[3] = nucbuf[6];
|
||||
instance.data[2] = nucbuf[5];
|
||||
instance.data[1] = nucbuf[4];
|
||||
instance.data[0] = nucbuf[3];
|
||||
if (nucbuf[9] != TAIL) goto error;
|
||||
|
||||
instance.data[3] = nucbuf[4];
|
||||
instance.data[2] = nucbuf[3];
|
||||
instance.data[1] = nucbuf[2];
|
||||
instance.data[0] = nucbuf[1];
|
||||
n->vision.x = instance.x[0];
|
||||
|
||||
instance.data[7] = nucbuf[10];
|
||||
instance.data[6] = nucbuf[9];
|
||||
instance.data[5] = nucbuf[8];
|
||||
instance.data[4] = nucbuf[7];
|
||||
instance.data[7] = nucbuf[8];
|
||||
instance.data[6] = nucbuf[7];
|
||||
instance.data[5] = nucbuf[6];
|
||||
instance.data[4] = nucbuf[5];
|
||||
n->vision.y = instance.x[1];
|
||||
|
||||
instance.data[11] = nucbuf[11];
|
||||
instance.data[10] = nucbuf[12];
|
||||
instance.data[9] = nucbuf[13];
|
||||
instance.data[8] = nucbuf[14];
|
||||
n->vision.z = instance.x[2];
|
||||
break;
|
||||
}
|
||||
return DEVICE_OK;
|
||||
}
|
||||
|
||||
|
||||
error:
|
||||
drop_message++;
|
||||
|
@ -10,10 +10,11 @@ extern RC_ctrl_t rc_ctrl;
|
||||
extern int ball_exit;
|
||||
|
||||
// 伸缩
|
||||
//外死点168 外163 中150 内127 限位124.8
|
||||
#define I_ANGLE 124.8
|
||||
#define O_ANGLE 168
|
||||
#define WAIT_POS 150
|
||||
//外死点132 外130 中119.12 内92 限位90
|
||||
|
||||
#define I_ANGLE 92
|
||||
#define O_ANGLE 130
|
||||
#define WAIT_POS 119
|
||||
|
||||
// PE11 气缸git stash apply
|
||||
|
||||
@ -221,6 +222,7 @@ void Ball::ball_control()
|
||||
// 进攻
|
||||
if (ready_key == SIDE)
|
||||
{
|
||||
osThreadFlagsClear(DEF_READY);
|
||||
switch (rc_key)
|
||||
{
|
||||
case MIDDLE2:
|
||||
@ -241,10 +243,20 @@ void Ball::ball_control()
|
||||
// 防守
|
||||
else if(ready_key == DEF)
|
||||
{
|
||||
xiaomi.position = I_ANGLE; // 保持收回
|
||||
if(hand_thread & DEF_READY)
|
||||
{
|
||||
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); // 确保下气缸关闭
|
||||
|
||||
osThreadFlagsClear(EXTEND_OK);
|
||||
osThreadFlagsClear(READY_TELL); // 蓄力标志位
|
||||
osThreadFlagsClear(HANDING_FINISH);
|
||||
|
||||
|
||||
Send_control();
|
||||
}
|
||||
|
||||
@ -259,7 +271,7 @@ void Ball::ballDown(void)
|
||||
{
|
||||
case BALL_IDLE:
|
||||
xiaomi.position = I_ANGLE; // 保持收回
|
||||
if (feedback->position_deg >= I_ANGLE - 0.8 && feedback->position_deg <= I_ANGLE + 0.8)
|
||||
if (feedback->position_deg >= I_ANGLE - 1 && feedback->position_deg <= I_ANGLE + 1)
|
||||
{
|
||||
currentState1 = EXTEND_DOWN;
|
||||
}
|
||||
@ -278,7 +290,7 @@ void Ball::ballDown(void)
|
||||
|
||||
case EXTEND_OUT:
|
||||
xiaomi.position = O_ANGLE; // 保持伸出
|
||||
if (feedback->position_deg >= O_ANGLE - 0.2 && feedback->position_deg <= O_ANGLE + 0.2)
|
||||
if (feedback->position_deg >= O_ANGLE - 1 && feedback->position_deg <= O_ANGLE + 1)
|
||||
{
|
||||
|
||||
osThreadFlagsSet(task_struct.thread.shoot, EXTEND_OK);
|
||||
|
@ -32,16 +32,18 @@ const fp32 Shoot::M2006_angle_PID[3] = {15, 0.1, 0};
|
||||
#define TO_TOP 10.0f
|
||||
#define TO_BOTTOM 6.0f
|
||||
|
||||
#define INIT_POS -130
|
||||
#define INIT_POS -135
|
||||
#define TOP_POS -211
|
||||
#define BOTTOM_POS 0
|
||||
#define WAIT_POS -150
|
||||
#define GO_ERROR 1.0f
|
||||
#define Tigger_DO 0
|
||||
#define Tigger_ZERO 120
|
||||
#define Tigger_ZERO 138
|
||||
#define Tigger_ERROR 3
|
||||
|
||||
float knob_increment;
|
||||
double last_distance = 4.0f; // 4米做测试吧
|
||||
double last_pass = 4.0f; // 4米做测试吧
|
||||
|
||||
Shoot::Shoot()
|
||||
{
|
||||
@ -71,6 +73,7 @@ Shoot::Shoot()
|
||||
currentState = SHOOT_IDLE;
|
||||
|
||||
LowPassFilter2p_Init(&distance_filter, 500.0f, 80.0f); // 给distance 做滤波
|
||||
LowPassFilter2p_Init(&pass_filter, 500.0f, 80.0f); // 给distance 做滤波
|
||||
}
|
||||
|
||||
void Shoot::trigger_control()
|
||||
@ -82,11 +85,17 @@ 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-3.8f;
|
||||
// }
|
||||
|
||||
float shoot_fitting(float x)
|
||||
{
|
||||
return 0.2006334f * x * x + 25.788123f * x + -169.32157 + 3.8f-3.8f;
|
||||
return 0.67076341f * x * x + 20.212423f * x + -154.53966f;
|
||||
}
|
||||
|
||||
|
||||
float pass_fitting(float x)
|
||||
{
|
||||
return 1.1790172f * x * x + 15.983755f * x + -172.04664f + 1.6f;
|
||||
@ -100,8 +109,13 @@ void Shoot::distanceGet(const NUC_t &nuc_v)
|
||||
last_distance = LowPassFilter2p_Apply(&distance_filter, nuc_v.vision.x);
|
||||
}
|
||||
|
||||
if(nuc_v.vision.y >= 0.0f && nuc_v.vision.y <= 7.5f)
|
||||
{
|
||||
last_pass = LowPassFilter2p_Apply(&pass_filter, nuc_v.vision.y);
|
||||
}
|
||||
// 否则不更新,保持上一次的值
|
||||
distance = last_distance;
|
||||
pass_distance =last_pass;
|
||||
}
|
||||
|
||||
int Shoot::GO_SendData(float pos, float limit)
|
||||
@ -225,8 +239,10 @@ void Shoot::shoot_control()
|
||||
switch (mode_key)
|
||||
{
|
||||
case VSION:
|
||||
fire_pos = distance; // 视觉拟合的力
|
||||
// fire_pos =shoot_fitting(test_distance);
|
||||
//fire_pos = distance; // 视觉拟合的力
|
||||
fire_pos =shoot_fitting(distance);
|
||||
//fire_pos = INIT_POS + knob_increment; // 根据旋钮值调整发射位置
|
||||
|
||||
switch (rc_key)
|
||||
{
|
||||
case DOWN1:
|
||||
@ -460,7 +476,8 @@ void Shoot::shoot_control()
|
||||
switch (rc_key)
|
||||
{
|
||||
case MIDDLE1:
|
||||
fire_pos = pass_fitting(distance);
|
||||
//fire_pos = pass_fitting(distance);
|
||||
fire_pos = pass_fitting(pass_distance);
|
||||
if ((shoot_thread & READY_TELL) && !(shoot_thread & EXTEND_OK))
|
||||
{
|
||||
// 只收到READY_TELL且未收到EXTEND_OK时,顶部蓄力流程
|
||||
@ -517,10 +534,21 @@ void Shoot::shoot_control()
|
||||
}
|
||||
else if (ready_key == DEFENSE)
|
||||
{
|
||||
control_pos = TOP_POS - 2.0f; //-209
|
||||
control_pos = WAIT_POS; //-209
|
||||
go1.Pos = control_pos;
|
||||
limit_speed = TO_TOP; // 快速上去
|
||||
if(feedback.fd_gopos < -149)
|
||||
{
|
||||
t_posSet = Tigger_ZERO; // 扳机松开
|
||||
osThreadFlagsSet(task_struct.thread.ball, DEF_READY);
|
||||
|
||||
}
|
||||
|
||||
osThreadFlagsClear(EXTEND_OK);
|
||||
osThreadFlagsClear(READY_TELL); // 蓄力标志位
|
||||
osThreadFlagsClear(HANDING_FINISH);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -543,10 +571,14 @@ void Shoot ::ball_receive()
|
||||
case SHOOT_IDLE:
|
||||
// 初始状态:钩子移动到顶部,钩住拉簧
|
||||
if (shoot_thread & READY_TELL) // 如果收到等待通知
|
||||
{
|
||||
t_posSet = Tigger_ZERO;
|
||||
if(trigger_Motor->total_angle > Tigger_ZERO-5 )
|
||||
{
|
||||
control_pos = TOP_POS;
|
||||
limit_speed = TO_TOP; // 快速上去
|
||||
t_posSet = Tigger_ZERO;
|
||||
|
||||
}
|
||||
if (feedback.fd_gopos < -209)
|
||||
{
|
||||
currentState = GO_TOP; // 切换到准备发射状态
|
||||
|
@ -87,6 +87,7 @@ public:
|
||||
|
||||
//滤波器
|
||||
LowPassFilter2p_t distance_filter; // 用于滤波视觉距离
|
||||
LowPassFilter2p_t pass_filter;
|
||||
|
||||
//==========================公共变量==========================
|
||||
int16_t rc_key; //遥控器按键
|
||||
@ -97,6 +98,7 @@ public:
|
||||
|
||||
volatile uint32_t shoot_thread;//接收传回的线程通知
|
||||
fp32 distance; //视觉距离
|
||||
fp32 pass_distance; //视觉距离
|
||||
|
||||
private:
|
||||
//扳机2006
|
||||
|
@ -40,6 +40,9 @@ void FunctionBall(void *argument)
|
||||
|
||||
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user