diff --git a/Core/Src/usart.c b/Core/Src/usart.c
index c87778f..02e4f0d 100644
--- a/Core/Src/usart.c
+++ b/Core/Src/usart.c
@@ -102,7 +102,7 @@ void MX_USART6_UART_Init(void)
/* USER CODE END USART6_Init 1 */
huart6.Instance = USART6;
- huart6.Init.BaudRate = 4000000;
+ huart6.Init.BaudRate = 115200;
huart6.Init.WordLength = UART_WORDLENGTH_8B;
huart6.Init.StopBits = UART_STOPBITS_1;
huart6.Init.Parity = UART_PARITY_NONE;
diff --git a/MDK-ARM/.vscode/keil-assistant.log b/MDK-ARM/.vscode/keil-assistant.log
index 210b1cd..59862d0 100644
--- a/MDK-ARM/.vscode/keil-assistant.log
+++ b/MDK-ARM/.vscode/keil-assistant.log
@@ -122,3 +122,5 @@
[info] Log at : 2025/5/30|19:34:50|GMT+0800
+[info] Log at : 2025/5/31|14:39:23|GMT+0800
+
diff --git a/MDK-ARM/.vscode/uv4.log b/MDK-ARM/.vscode/uv4.log
index 03df30f..0b26db1 100644
--- a/MDK-ARM/.vscode/uv4.log
+++ b/MDK-ARM/.vscode/uv4.log
@@ -1,8 +1,8 @@
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil\ARM\ARMCC\Bin'
Build target 'R1-shooter'
-compiling ball.cpp...
+compiling usart.c...
linking...
-Program Size: Code=30584 RO-data=2144 RW-data=276 ZI-data=24012
+Program Size: Code=30588 RO-data=2144 RW-data=276 ZI-data=24012
FromELF: creating hex file...
"R1-shooter\R1-shooter.axf" - 0 Error(s), 0 Warning(s).
-Build Time Elapsed: 00:00:03
+Build Time Elapsed: 00:00:05
diff --git a/MDK-ARM/.vscode/uv4.log.lock b/MDK-ARM/.vscode/uv4.log.lock
index 83f0a16..ac993ff 100644
--- a/MDK-ARM/.vscode/uv4.log.lock
+++ b/MDK-ARM/.vscode/uv4.log.lock
@@ -1 +1 @@
-2025/5/28 19:17:30
\ No newline at end of file
+2025/5/31 16:57:56
\ No newline at end of file
diff --git a/MDK-ARM/R1-shooter.uvoptx b/MDK-ARM/R1-shooter.uvoptx
index a8fdc74..82bb2d9 100644
--- a/MDK-ARM/R1-shooter.uvoptx
+++ b/MDK-ARM/R1-shooter.uvoptx
@@ -218,85 +218,55 @@
12
1
- ball_state,0x0A
+ shoot,0x0A
13
1
- flag,0x0A
+ speedm,0x0A
14
1
- shoot,0x0A
+ shoot_flag,0x0A
15
1
- speedm,0x0A
+ angle1,0x0A
16
1
- a1,0x0A
+ motor_5065
17
1
- a2,0x0A
+ test_distance
18
1
- shoot_flag,0x0A
+ xxx
19
1
- angle1,0x0A
+ test_speed,0x0A
20
1
- rx_header
+ speedm,0x0A
21
1
- rx_data
-
-
- 22
- 1
- motor_5065
-
-
- 23
- 1
- test_distance
-
-
- 24
- 1
- xxx
-
-
- 25
- 1
- test_speed,0x0A
-
-
- 26
- 1
- speedm,0x0A
-
-
- 27
- 1
Torque,0x0A
- 28
+ 22
1
triggerspeed,0x0A
diff --git a/User/device/GO_M8010_6_Driver.c b/User/device/GO_M8010_6_Driver.c
index 394a410..bbfc3df 100644
--- a/User/device/GO_M8010_6_Driver.c
+++ b/User/device/GO_M8010_6_Driver.c
@@ -32,7 +32,7 @@ void GO_M8010_init (){
}
// HAL_UART_RegisterCallback(&huart1, HAL_UART_TX_COMPLETE_CB_ID, uartTxCB);
- HAL_UART_RegisterCallback(&huart6, HAL_UART_TX_COMPLETE_CB_ID, uartTxCB);
+ // HAL_UART_RegisterCallback(&huart6, HAL_UART_TX_COMPLETE_CB_ID, uartTxCB);
}
diff --git a/User/device/nuc.c b/User/device/nuc.c
index cc5dba2..00db11a 100644
--- a/User/device/nuc.c
+++ b/User/device/nuc.c
@@ -77,19 +77,12 @@ int8_t NUC_RawParse(NUC_t *n) {
} instance; // 方便在浮点数和字符数组之间进行数据转换
// 校验数据包头
- if (nucbuf[0] != HEAD) {
- return DEVICE_ERR;
- }
- // 提取数据包中的 CRC 值(假设 CRC 值在数据包的最后两个字节)
- uint16_t received_crc = (nucbuf[16] << 8) | nucbuf[17]; // 假设 CRC 在第 16 和 17 字节
- uint16_t calculated_crc = do_crc_table(nucbuf, 16); // 计算前 16 字节的 CRC
- // 校验 CRC
- if (received_crc == calculated_crc) {
-
+ if(nucbuf[0]!=HEAD) goto error; //发送ID不是底盘
+ else
+ {
n->status_fromnuc = nucbuf[1];
- n->ctrl_status = nucbuf[2];
-
- switch (n->status_fromnuc) {
+ n->ctrl_status = nucbuf[2];
+ switch (n->status_fromnuc) {
case VISION:
/* 协议格式
0xFF HEAD
@@ -100,42 +93,103 @@ int8_t NUC_RawParse(NUC_t *n) {
z fp32
0xFE TAIL
*/
- if (nucbuf[15] != TAIL) goto error;
+ if (nucbuf[15] != TAIL) goto error;
- instance.data[3] = nucbuf[3];
- instance.data[2] = nucbuf[4];
- instance.data[1] = nucbuf[5];
- instance.data[0] = nucbuf[6];
- n->vision.x = instance.x[0];
+ instance.data[3] = nucbuf[3];
+ instance.data[2] = nucbuf[4];
+ instance.data[1] = nucbuf[5];
+ instance.data[0] = nucbuf[6];
+ n->vision.x = instance.x[0];
- instance.data[7] = nucbuf[7];
- instance.data[6] = nucbuf[8];
- instance.data[5] = nucbuf[9];
- instance.data[4] = nucbuf[10];
- n->vision.y = instance.x[1];
+ instance.data[7] = nucbuf[7];
+ instance.data[6] = nucbuf[8];
+ instance.data[5] = nucbuf[9];
+ instance.data[4] = nucbuf[10];
+ 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];
+ 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;
- }
- else
- {
- return DEVICE_ERR;
-
+ return DEVICE_OK;
}
+
error:
return DEVICE_ERR;
}
+// 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) {
+// return DEVICE_ERR;
+// }
+// // 提取数据包中的 CRC 值(假设 CRC 值在数据包的最后两个字节)
+// uint16_t received_crc = (nucbuf[16] << 8) | nucbuf[17]; // 假设 CRC 在第 16 和 17 字节
+// uint16_t calculated_crc = do_crc_table(nucbuf, 16); // 计算前 16 字节的 CRC
+// // 校验 CRC
+// if (received_crc == calculated_crc) {
+
+// n->status_fromnuc = nucbuf[1];
+// n->ctrl_status = nucbuf[2];
+
+// switch (n->status_fromnuc) {
+// case VISION:
+// /* 协议格式
+// 0xFF HEAD
+// 0x02 控制帧
+// 0x01 相机帧
+// x fp32
+// y fp32
+// z fp32
+// 0xFE TAIL
+// */
+// if (nucbuf[15] != TAIL) goto error;
+
+// instance.data[3] = nucbuf[3];
+// instance.data[2] = nucbuf[4];
+// instance.data[1] = nucbuf[5];
+// instance.data[0] = nucbuf[6];
+// n->vision.x = instance.x[0];
+
+// instance.data[7] = nucbuf[7];
+// instance.data[6] = nucbuf[8];
+// instance.data[5] = nucbuf[9];
+// instance.data[4] = nucbuf[10];
+// 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;
+// }
+// else
+// {
+// return DEVICE_ERR;
+
+// }
+
+// error:
+// return DEVICE_ERR;
+// }
+
+
int8_t NUC_HandleOffline(NUC_t *cmd)
{
if(cmd == NULL) return DEVICE_ERR_NULL;
diff --git a/User/module/shoot.cpp b/User/module/shoot.cpp
index 0b24d5f..6e475bc 100644
--- a/User/module/shoot.cpp
+++ b/User/module/shoot.cpp
@@ -16,8 +16,8 @@ float vofa[8];
#define Error 50
int triggerspeed = -5000; // 扳机速度
-int test_speed =34700;
-float test_distance =3.6;
+int test_speed =35200;
+float test_distance =1;
float xxx;
#define STOP 0
@@ -78,7 +78,7 @@ void Shoot::errorControl()
void Shoot :: distanceGet(const NUC_t &nuc_v)
{
- test_distance=nuc_v.vision.z;
+ test_distance=nuc_v.vision.x; // 获取自瞄数据
}
@@ -115,8 +115,8 @@ void Shoot::shootStateMachine() {
case SHOOT_READY:
{
// 发射状态,控制电机发射
- speed_5065 = test_speed;
- // speed_5065 =polynomial(distance);
+ //speed_5065 = test_speed;
+ speed_5065 =polynomial(distance);
if(motor_5065[0]->rotor_speed>=speed_5065-Error && motor_5065[0]->rotor_speed<=speed_5065+Error &&
motor_5065[1]->rotor_speed>=speed_5065-Error && motor_5065[1]->rotor_speed<=speed_5065+Error)
{
@@ -178,24 +178,10 @@ void Shoot::shootStateMachine() {
//MATLAB拟合函数
float polynomial(float x) {
- return 1185.3918f * powf(x, 5.0f)
- + -45876.846f * powf(x, 4.0f)
- + 517061.22f * powf(x, 3.0f)
- + -2567947.4f * powf(x, 2.0f)
- + 5954537.4f * x
- + -5258769.0f;
+ return 6348.2377f * powf(x, 5.0f)
+ + -128275.8296f * powf(x, 4.0f)
+ + 1030651.0231f * powf(x, 3.0f)
+ + -4115199.9362f * powf(x, 2.0f)
+ + 8167973.1254f * x
+ + -6420648.3555f;
}
-
-
-float polynomial2(float x) {
- return 49162.7402f * powf(x, 5.0f)
- + -917344.6015f * powf(x, 4.0f)
- + 6840516.5228f * powf(x, 3.0f)
- + -25479457.6038f * powf(x, 2.0f)
- + 47406744.9129f * x
- + -35217628.5565f;
-}
-
-// float polynomial(float x) {
-// return 1185.3918*pow(x,5) + -45876.846*pow(x,4) + 517061.22*pow(x,3) + -2567947.4*pow(x,2) + 5954537.4*x + -5258769;
-// }
diff --git a/User/task/nucTask.cpp b/User/task/nucTask.cpp
index 901a127..8a0bb97 100644
--- a/User/task/nucTask.cpp
+++ b/User/task/nucTask.cpp
@@ -22,7 +22,6 @@ void Function_nuc(void *argument)
NUC_Init(&cmd_fromnuc);
-
uint32_t tick = osKernelGetTickCount();
while(1)
diff --git a/User/task/shootTask.cpp b/User/task/shootTask.cpp
index 7e79eab..f9469dc 100644
--- a/User/task/shootTask.cpp
+++ b/User/task/shootTask.cpp
@@ -45,7 +45,7 @@ while(1)
if (osMessageQueueGet(task_struct.msgq.nuc, &nucData, NULL, 0) == osOK)
{
- //shoot.distanceGet(nucData);
+ shoot.distanceGet(nucData);
}