改视觉备用

This commit is contained in:
ZHAISHUI04 2025-06-03 23:16:33 +08:00
parent bcfaac985f
commit 9567222df6
9 changed files with 85 additions and 74 deletions

View File

@ -80,6 +80,7 @@ int main(void)
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */

View File

@ -345,6 +345,11 @@
<WinNumber>1</WinNumber>
<ItemText>NUC_send</ItemText>
</Ww>
<Ww>
<count>38</count>
<WinNumber>1</WinNumber>
<ItemText>cmd_fromnuc</ItemText>
</Ww>
</WatchWindow1>
<Tracepoint>
<THDelay>0</THDelay>

Binary file not shown.

View File

@ -124,7 +124,7 @@ int8_t Chassis_Control(Chassis_t *c, CMD_t *ctrl, CAN_Output_t *out) {
case AUTO: // 自动模式
switch (c->chassis_ctrl.mode) {
case AUTO_NAVI: // 自动雷达
case AUTO_MID360: // 自动雷达
// 全向轮方向, 注意xy方向
c->move_vec.Vw = ctrl->cmd_MID360.posw * 1000;
c->move_vec.Vy = -ctrl->cmd_MID360.posy * 1000;
@ -137,14 +137,14 @@ int8_t Chassis_Control(Chassis_t *c, CMD_t *ctrl, CAN_Output_t *out) {
c->NUC_send .send [0]=0;
break;
case AUTO_NAVI_Pitch:
case AUTO_MID360_Pitch:
c->move_vec.Vw = 0;
c->move_vec.Vy = 0;
c->move_vec.Vx = 0;
c->NUC_send .send [0]=0;
break;
case AUTO_NAVI_Adjust:
case AUTO_MID360_Adjust:
c->move_vec.Vw = ctrl->Vw * 6000;
c->move_vec.Vx = ctrl->Vy * 6000;
c->move_vec.Vy = ctrl->Vx * 6000;

View File

@ -335,7 +335,7 @@ int8_t UP_control(UP_t *u,CAN_Output_t *out,CMD_t *c)
case AUTO:
switch(c-> CMD_mode)
{
case AUTO_NAVI_Pitch:
case AUTO_MID360_Pitch:
u->PitchContext .PitchConfig .go1_Receive_ball=LowPassFilter2p_Apply(&u->filled[0],c->pos);
if (u->PitchContext .PitchState ==PITCH_PREPARE)
@ -348,7 +348,7 @@ int8_t UP_control(UP_t *u,CAN_Output_t *out,CMD_t *c)
Pitch_Process(u,out);
break ;
case AUTO_NAVI:
case AUTO_MID360:
u->motor_target .Shoot_M2006_angle =u->PitchContext .PitchConfig .m2006_init_angle ;
u->PitchContext .PitchState = PITCH_PREPARE;
@ -432,6 +432,8 @@ return 0;
int8_t Dribble_Process(UP_t *u, CAN_Output_t *out)
{
static int common_speed_flag=0;//是否共速
static int common_speed_reverse_flag=0;//是否共速
switch (u->DribbleContext.DribbleState) {
@ -467,6 +469,7 @@ int8_t Dribble_Process(UP_t *u, CAN_Output_t *out)
u->motor_target.Dribble_M3508_speed[2]=u->DribbleContext .DribbleConfig.m3508_dribble_Reverse_speed;
u->DribbleContext .DribbleState=DRIBBLE_PROCESS_UP;
}
}
@ -474,20 +477,24 @@ int8_t Dribble_Process(UP_t *u, CAN_Output_t *out)
break;
case DRIBBLE_PROCESS_UP:
common_speed_flag =0;
common_speed_flag =0;
if((u->motorfeedback .DJmotor_feedback [0].rpm<-2000)&&
(u->motorfeedback .DJmotor_feedback [1].rpm>-2000)&&
(u->motorfeedback .DJmotor_feedback [2].rpm>-2000)
if((u->motorfeedback .DJmotor_feedback [0].rpm<-500)&&
(u->motorfeedback .DJmotor_feedback [1].rpm<-500)&&
(u->motorfeedback .DJmotor_feedback [2].rpm<-500)
){
if(u->DribbleContext .DribbleConfig .light_ball_flag == 1){
common_speed_reverse_flag=1;
}
if(common_speed_reverse_flag){
if(u->DribbleContext .DribbleConfig .light_ball_flag == 1){
u->DribbleContext .DribbleState=DRIBBLE_DONE;
RELAY1_TOGGLE(0); //关闭气缸
}
}
}
}
break ;
case DRIBBLE_DONE:
common_speed_reverse_flag=0;
for(int i=0;i<3;i++){
u->motor_target.Dribble_M3508_speed[i]=u->DribbleContext .DribbleConfig.m3508_dribble_init_speed ;//三摩擦速度归0
}

View File

@ -99,17 +99,17 @@ int8_t CMD_ParseNuc(CMD_t *cmd,CMD_NUC_t *n){
switch(cmd->cmd_status){
case MID:
cmd->cmd_MID360.posx = n->navi.vx;
cmd->cmd_MID360.posy = n->navi.vy;
cmd->cmd_MID360.posw = n->navi.wz;
cmd->cmd_MID360.posx = n->MID360.vx;
cmd->cmd_MID360.posy = n->MID360.vy;
cmd->cmd_MID360.posw = n->MID360.wz;
cmd->pos =n->navi .pos ;
cmd->pos =n->MID360 .pos ;
break;
case PICK :
cmd ->cmd_pick .posx =n->pick .posx ;
cmd ->cmd_pick .posy =n->pick .posy ;
cmd ->cmd_pick .posw =n->pick .posw ;
case VISION :
cmd ->cmd_pick .posx =n->camera.data1 ;
cmd ->cmd_pick .posy =n->camera.data2 ;
cmd ->cmd_pick .posw =n->camera.data3 ;
break;
@ -153,11 +153,11 @@ int8_t CMD_DR16(CMD_t *cmd,const CMD_RC_t *rc) {
{
cmd ->CMD_CtrlType =AUTO;
if(rc->dr16.sw_r ==CMD_SW_UP) cmd ->CMD_mode =AUTO_NAVI; //左中,右中,雷达
if(rc->dr16.sw_r ==CMD_SW_UP) cmd ->CMD_mode =AUTO_MID360; //左中,右中,雷达
if(rc->dr16.sw_r ==CMD_SW_MID) cmd ->CMD_mode =Normal; //左中,右中,无模式
if(rc->dr16.sw_r ==CMD_SW_DOWN) cmd ->CMD_mode =AUTO_NAVI_Pitch; //左中,右下,视觉
if(rc->dr16.sw_r ==CMD_SW_DOWN) cmd ->CMD_mode =AUTO_MID360_Pitch; //左中,右下,视觉
}
else if(rc->dr16.sw_l==CMD_SW_DOWN)
@ -191,12 +191,12 @@ int8_t CMD_LD(CMD_t *cmd,const CMD_RC_t *rc){
if(cmd ->CMD_CtrlType ==AUTO){
/*自动下的*/
if (rc->LD.key_C ==CMD_SW_UP) cmd ->CMD_mode =AUTO_NAVI_Adjust;
if (rc->LD.key_C ==CMD_SW_UP) cmd ->CMD_mode =AUTO_MID360_Adjust;
else {
if(rc->LD.key_E ==CMD_SW_DOWN ) cmd ->CMD_mode =Normal;
else if(rc->LD.key_E ==CMD_SW_UP) cmd ->CMD_mode =AUTO_NAVI_Pitch;
else if(rc->LD .key_E ==CMD_SW_MID ) cmd ->CMD_mode =AUTO_NAVI;
else if(rc->LD.key_E ==CMD_SW_UP) cmd ->CMD_mode =AUTO_MID360_Pitch;
else if(rc->LD .key_E ==CMD_SW_MID ) cmd ->CMD_mode =AUTO_MID360;
else cmd ->CMD_mode =Normal ;
}
}
@ -208,3 +208,4 @@ int8_t CMD_LD(CMD_t *cmd,const CMD_RC_t *rc){
else cmd ->CMD_mode =Normal;
}
}

View File

@ -8,7 +8,7 @@
#include <string.h>
#define MID (0x09)
#define PICK (0x06)
#define VISION (0x02)
#define NUC (0x08)
typedef enum{
@ -23,9 +23,9 @@ typedef enum{
Normal, //无模式
AUTO_NAVI,
AUTO_NAVI_Pitch,
AUTO_NAVI_Adjust,//雷达调整
AUTO_MID360,
AUTO_MID360_Pitch,
AUTO_MID360_Adjust,//雷达调整
UP_Adjust,//上层调整
@ -48,18 +48,13 @@ typedef struct {
fp32 angle;
char flag;
}navi;
}MID360;
struct
{
fp32 posx;
fp32 posy;
fp32 posw;
}pick;
struct
{
fp32 angle;
}sick_cali;
fp32 data1;
fp32 data2;
fp32 data3;
}camera;//相机
} CMD_NUC_t;
/* 拨杆位置 */

View File

@ -32,6 +32,7 @@ int8_t NUC_StartReceiving() {
int8_t NUC_StartSending(fp32 *data) {
union
{
float x[4];
@ -81,33 +82,34 @@ int8_t NUC_RawParse(CMD_NUC_t *n){
n->ctrl_status =nucbuf[2];
switch (n->status_fromnuc)
{
// case MID://控制帧0x09
// /* 协议格式
// 0xFF HEAD
// 0x09 控制帧
// 0x01 相机帧
// vx fp32
// vy fp32
// wz fp32
// 0xFE TAIL
// */
//// if(nucbuf[15]!=TAIL)goto error;
// instance.data[3] = nucbuf[6];
// instance.data[2] = nucbuf[5];
// instance.data[1] = nucbuf[4];
// instance.data[0] = nucbuf[3];
// n->navi.vx = instance.x[0]; //
// instance.data[7] = nucbuf[10];
// instance.data[6] = nucbuf[9];
// instance.data[5] = nucbuf[8];
// instance.data[4] = nucbuf[7];
// n->navi.vy = instance.x[1];//
// instance.data[11] = nucbuf[14];
// instance.data[10] = nucbuf[13];
// instance.data[9] = nucbuf[12];
// instance.data[8] = nucbuf[11];
// n->navi.wz = instance.x[2];//
// break;
case VISION://控制帧0x02
/* 协议格式
0xFF HEAD
0x02
0x01
vx fp32
vy fp32
wz fp32
0xFE TAIL
*/
instance.data[3] = nucbuf[3];
instance.data[2] = nucbuf[4];
instance.data[1] = nucbuf[5];
instance.data[0] = nucbuf[6];
n->camera .data1 = instance.x[0]; //
instance.data[7] = nucbuf[7];
instance.data[6] = nucbuf[8];
instance.data[5] = nucbuf[9];
instance.data[4] = nucbuf[10];
n->camera .data2 = instance.x[1];//
instance.data[11] = nucbuf[11];
instance.data[10] = nucbuf[12];
instance.data[9] = nucbuf[13];
instance.data[8] = nucbuf[14];
n->camera .data3 = instance.x[2];//
break;
case MID ://控制帧0x08
/* 协议格式
0xFF HEAD
@ -123,29 +125,29 @@ int8_t NUC_RawParse(CMD_NUC_t *n){
instance.data[2] = nucbuf[5];
instance.data[1] = nucbuf[4];
instance.data[0] = nucbuf[3];
n->navi.vx = instance.x[0]; //
n->MID360.vx = instance.x[0]; //
instance.data[7] = nucbuf[10];
instance.data[6] = nucbuf[9];
instance.data[5] = nucbuf[8];
instance.data[4] = nucbuf[7];
n->navi.vy = instance.x[1];//
n->MID360.vy = instance.x[1];//
instance.data[11] = nucbuf[14];
instance.data[10] = nucbuf[13];
instance.data[9] = nucbuf[12];
instance.data[8] = nucbuf[11];
n->navi.wz = instance.x[2];//
n->MID360.wz = instance.x[2];//
instance.data[15] = nucbuf[18];
instance.data[14] = nucbuf[17];
instance.data[13] = nucbuf[16];
instance.data[12] = nucbuf[15];
n->navi.pos = instance.x[3];//
n->MID360.pos = instance.x[3];//
instance.data[19] = nucbuf[22];
instance.data[18] = nucbuf[21];
instance.data[17] = nucbuf[20];
instance.data[16] = nucbuf[19];
n->navi.angle = instance.x[4];//
n->MID360.angle = instance.x[4];//
n->navi.flag = nucbuf[23];//
n->MID360.flag = nucbuf[23];//
break;

View File

@ -31,7 +31,7 @@ void Task_nuc(void *argument){
task_runtime.stack_water_mark.nuc= osThreadGetStackSpace(osThreadGetId());
#endif
NUC_StartReceiving();
NUC_StartSending(NUC_send.send);
// NUC_StartSending(NUC_send.send);
if (NUC_WaitDmaCplt()){
NUC_RawParse(&cmd_fromnuc);
}