加了视觉

This commit is contained in:
ws 2025-05-31 19:52:56 +08:00
parent a235d14661
commit f9b87f8f39
10 changed files with 120 additions and 109 deletions

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -1 +1 @@
2025/5/28 19:17:30
2025/5/31 16:57:56

View File

@ -218,85 +218,55 @@
<Ww>
<count>12</count>
<WinNumber>1</WinNumber>
<ItemText>ball_state,0x0A</ItemText>
<ItemText>shoot,0x0A</ItemText>
</Ww>
<Ww>
<count>13</count>
<WinNumber>1</WinNumber>
<ItemText>flag,0x0A</ItemText>
<ItemText>speedm,0x0A</ItemText>
</Ww>
<Ww>
<count>14</count>
<WinNumber>1</WinNumber>
<ItemText>shoot,0x0A</ItemText>
<ItemText>shoot_flag,0x0A</ItemText>
</Ww>
<Ww>
<count>15</count>
<WinNumber>1</WinNumber>
<ItemText>speedm,0x0A</ItemText>
<ItemText>angle1,0x0A</ItemText>
</Ww>
<Ww>
<count>16</count>
<WinNumber>1</WinNumber>
<ItemText>a1,0x0A</ItemText>
<ItemText>motor_5065</ItemText>
</Ww>
<Ww>
<count>17</count>
<WinNumber>1</WinNumber>
<ItemText>a2,0x0A</ItemText>
<ItemText>test_distance</ItemText>
</Ww>
<Ww>
<count>18</count>
<WinNumber>1</WinNumber>
<ItemText>shoot_flag,0x0A</ItemText>
<ItemText>xxx</ItemText>
</Ww>
<Ww>
<count>19</count>
<WinNumber>1</WinNumber>
<ItemText>angle1,0x0A</ItemText>
<ItemText>test_speed,0x0A</ItemText>
</Ww>
<Ww>
<count>20</count>
<WinNumber>1</WinNumber>
<ItemText>rx_header</ItemText>
<ItemText>speedm,0x0A</ItemText>
</Ww>
<Ww>
<count>21</count>
<WinNumber>1</WinNumber>
<ItemText>rx_data</ItemText>
</Ww>
<Ww>
<count>22</count>
<WinNumber>1</WinNumber>
<ItemText>motor_5065</ItemText>
</Ww>
<Ww>
<count>23</count>
<WinNumber>1</WinNumber>
<ItemText>test_distance</ItemText>
</Ww>
<Ww>
<count>24</count>
<WinNumber>1</WinNumber>
<ItemText>xxx</ItemText>
</Ww>
<Ww>
<count>25</count>
<WinNumber>1</WinNumber>
<ItemText>test_speed,0x0A</ItemText>
</Ww>
<Ww>
<count>26</count>
<WinNumber>1</WinNumber>
<ItemText>speedm,0x0A</ItemText>
</Ww>
<Ww>
<count>27</count>
<WinNumber>1</WinNumber>
<ItemText>Torque,0x0A</ItemText>
</Ww>
<Ww>
<count>28</count>
<count>22</count>
<WinNumber>1</WinNumber>
<ItemText>triggerspeed,0x0A</ItemText>
</Ww>

View File

@ -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);
}

View File

@ -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;

View File

@ -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;
// }

View File

@ -22,7 +22,6 @@ void Function_nuc(void *argument)
NUC_Init(&cmd_fromnuc);
uint32_t tick = osKernelGetTickCount();
while(1)

View File

@ -45,7 +45,7 @@ while(1)
if (osMessageQueueGet(task_struct.msgq.nuc, &nucData, NULL, 0) == osOK)
{
//shoot.distanceGet(nucData);
shoot.distanceGet(nucData);
}