feat: 增加上下位机通信接口 (底盘速度和位置控制)

This commit is contained in:
bmy
2024-04-24 23:22:21 +08:00
parent 7123fb2f25
commit 1c3131e9c7
14 changed files with 560 additions and 294 deletions

74
app/by_messy.c Normal file
View File

@@ -0,0 +1,74 @@
#include "by_messy.h"
#include "lwprintf.h"
#include "by_frame.h"
#include "by_motion.h"
void by_messy_init(void)
{
by_frame_init();
}
void by_messy_loop(void)
{
uint8_t cmd = 0;
uint32_t buff[BY_FRAME_DATA_NUM] = {0};
if (!by_frame_parse(&cmd, buff)) {
lwprintf("get cmd: %X\r\n", cmd);
switch (cmd) {
case 0x31: // 设置速度 x
memcpy(&motion_speed_struct.v_x, buff, sizeof(motion_speed_struct.v_x));
by_motion_set_mode(0);
break;
case 0x32: // 设置速度 y
memcpy(&motion_speed_struct.v_y, buff, sizeof(motion_speed_struct.v_y));
by_motion_set_mode(0);
break;
case 0x33: // 设置速度 omega
memcpy(&motion_speed_struct.v_w, buff, sizeof(motion_speed_struct.v_w));
by_motion_set_mode(0);
break;
case 0x34: // 设置移动距离 x
by_frame_send(cmd, buff); // 正确接收后直接返回原文
memcpy(&motion_speed_struct.v_x, buff, sizeof(motion_speed_struct.v_x));
by_motion_set_mode(1);
motion_time_struct.t_x += buff[1];
break;
case 0x35: // 设置移动距离 y
by_frame_send(cmd, buff); // 正确接收后直接返回原文
memcpy(&motion_speed_struct.v_y, buff, sizeof(motion_speed_struct.v_y));
by_motion_set_mode(1);
motion_time_struct.t_y += buff[1];
break;
case 0x36: // 设置旋转角度 omega
by_frame_send(cmd, buff); // 正确接收后直接返回原文
memcpy(&motion_speed_struct.v_w, buff, sizeof(motion_speed_struct.v_w));
by_motion_set_mode(1);
motion_time_struct.t_w += buff[1];
break;
case 0x41: // 设置转台 x 轴复位
by_frame_send(cmd, buff); // 正确接收后直接返回原文
break;
case 0x42: // 设置转台 z 轴复位
by_frame_send(cmd, buff); // 正确接收后直接返回原文
break;
case 0x43: // 设置转台末端执行器复位
by_frame_send(cmd, buff); // 正确接收后直接返回原文
break;
default:
break;
}
}
}