Compare commits

...

3 Commits

Author SHA1 Message Date
0ef286e5f2 更新 2025-04-14 21:11:43 +08:00
37dc1ac1e9 目的,无线串口发送需要数据 2025-04-13 14:55:49 +08:00
3d6cb3d799 最终了,不大改了,改改参数就这样了 2025-04-07 19:58:25 +08:00
11 changed files with 264 additions and 180 deletions

View File

@ -103,7 +103,7 @@
<bEvRecOn>1</bEvRecOn> <bEvRecOn>1</bEvRecOn>
<bSchkAxf>0</bSchkAxf> <bSchkAxf>0</bSchkAxf>
<bTchkAxf>0</bTchkAxf> <bTchkAxf>0</bTchkAxf>
<nTsel>6</nTsel> <nTsel>3</nTsel>
<sDll></sDll> <sDll></sDll>
<sDllPa></sDllPa> <sDllPa></sDllPa>
<sDlgDll></sDlgDll> <sDlgDll></sDlgDll>
@ -114,7 +114,7 @@
<tDlgDll></tDlgDll> <tDlgDll></tDlgDll>
<tDlgPa></tDlgPa> <tDlgPa></tDlgPa>
<tIfile></tIfile> <tIfile></tIfile>
<pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon> <pMon>BIN\CMSIS_AGDI.dll</pMon>
</DebugOpt> </DebugOpt>
<TargetDriverDllRegistry> <TargetDriverDllRegistry>
<SetRegEntry> <SetRegEntry>
@ -145,7 +145,7 @@
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>DLGUARM</Key> <Key>DLGUARM</Key>
<Name>(105=-1,-1,-1,-1,0)</Name> <Name></Name>
</SetRegEntry> </SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
@ -158,82 +158,32 @@
<Ww> <Ww>
<count>0</count> <count>0</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>raw,0x0A</ItemText> <ItemText>UP,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>1</count> <count>1</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>UP,0x0A</ItemText> <ItemText>GO_motor_info</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>2</count> <count>2</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>can,0x0A</ItemText> <ItemText>dr16,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>3</count> <count>3</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>can_out,0x0A</ItemText> <ItemText>cmd,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>4</count> <count>4</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>bbb,0x0A</ItemText> <ItemText>rc_ctrl,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>5</count> <count>5</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>aaa,0x0A</ItemText> <ItemText>aaa</ItemText>
</Ww>
<Ww>
<count>6</count>
<WinNumber>1</WinNumber>
<ItemText>CCC</ItemText>
</Ww>
<Ww>
<count>7</count>
<WinNumber>1</WinNumber>
<ItemText>GO_motor_info</ItemText>
</Ww>
<Ww>
<count>8</count>
<WinNumber>1</WinNumber>
<ItemText>cbuf[36]</ItemText>
</Ww>
<Ww>
<count>9</count>
<WinNumber>1</WinNumber>
<ItemText>dr16,0x0A</ItemText>
</Ww>
<Ww>
<count>10</count>
<WinNumber>1</WinNumber>
<ItemText>cmd,0x0A</ItemText>
</Ww>
<Ww>
<count>11</count>
<WinNumber>1</WinNumber>
<ItemText>rc_ctrl,0x0A</ItemText>
</Ww>
<Ww>
<count>12</count>
<WinNumber>1</WinNumber>
<ItemText>up_cmd,0x0A</ItemText>
</Ww>
<Ww>
<count>13</count>
<WinNumber>1</WinNumber>
<ItemText>angle</ItemText>
</Ww>
<Ww>
<count>14</count>
<WinNumber>1</WinNumber>
<ItemText>can_ZZ</ItemText>
</Ww>
<Ww>
<count>15</count>
<WinNumber>1</WinNumber>
<ItemText>flaggg,0x0A</ItemText>
</Ww> </Ww>
</WatchWindow1> </WatchWindow1>
<WatchWindow2> <WatchWindow2>

Binary file not shown.

View File

@ -214,6 +214,14 @@ void abs_limit_fp(fp32 *num, fp32 Limit)
} }
} }
void limit(double *a, double b, double c) {
if (*a < b) {
*a = b; // 如果 a 小于下限 b将 a 设置为 b
} else if (*a > c) {
*a = c; // 如果 a 大于上限 c将 a 设置为 c
}
// 如果 a 在范围 [b, c] 内,不做任何修改
}
/* 移动向量 */ /* 移动向量 */
MoveVector_t *mv; MoveVector_t *mv;

View File

@ -159,5 +159,6 @@ PolarCoordinate_t addPolarVectors(PolarCoordinate_t v1, PolarCoordinate_t v2);
uint8_t average(uint8_t arr[], uint8_t n); uint8_t average(uint8_t arr[], uint8_t n);
/*判断是否在误差内*/ /*判断是否在误差内*/
bool is_arrived(float target, float current, float mistake) ; bool is_arrived(float target, float current, float mistake) ;
void limit(double *a, double b, double c) ;
#endif #endif

View File

@ -38,14 +38,14 @@ static const ConfigParam_t param_chassis ={
}, },
.M3508_angle_param = { .M3508_angle_param = {
.p = 10.0f, .p = 10.0f,
.i = 0.0f, .i = 0.5f,
.d = 1.5f, .d = 0.0f,
.i_limit = 1000.0f, .i_limit = 1000.0f,
.out_limit = 3000.0f, .out_limit = 3000.0f,
}, },
.M3508_speed_param={ .M3508_speed_param={
.p = 5.1f, .p = 6.0f,
.i = 0.02f, .i = 0.0f,
.d = 3.2f, .d = 3.2f,
.i_limit = 200.0f, .i_limit = 200.0f,
.out_limit =6000.0f, .out_limit =6000.0f,
@ -68,34 +68,44 @@ static const ConfigParam_t param_chassis ={
.go_param[0]={ .go_param[0]={
.rev = 0, .rev = 0,
.T=0.1, .T=0.79,
.W=0.1, .W=0.1,
.K_P=0.1, .K_P=0.2,
.K_W=0.1, .K_W=0.1,
}, },
.go_param[1]={ .go_param[1]={
.rev = 0, .rev = 0,
.T=0.1, .T=0,
.W=0.1, .W=0,
.K_P=0.10f, .K_P=1.0f,
.K_W=0.1, .K_W=0.1,
},
.go1_position_param={
.p =0.1f,
.i =0.1f,
.d =0.0f,
.i_limit = 2.0f,
.out_limit = 10.0f
}, },
/*上层其他参数*/ /*上层其他参数*/
/*运球*/ /*运球*/
.DribbleConfig_Config = { .DribbleConfig_Config = {
.m3508_init_angle = 0, .m3508_init_angle = 50,
.m3508_high_angle = 900, .m3508_high_angle = 1200,
.go2_init_angle = 35, .go2_init_angle = 0,
.go2_flip_angle = -130, .go2_flip_angle = -250,
.flip_timing = 200, .flip_timing = 200,
.release_threshold = -1.2f, .go2_release_threshold = -550.0f,
}, },
/*投球*/ /*投球*/
.PitchConfig_Config = { .PitchConfig_Config = {
.m2006_init_angle =-140, .m2006_init_angle =-150,
.m2006_trigger_angle =0, .m2006_trigger_angle =0,
.go1_init_position = 0, .go1_init_position = -500,
.go1_release_threshold =-2050, .go1_release_threshold =-1900,
.m2006_Screw_init=0
}, },

View File

@ -34,10 +34,10 @@ int8_t up_init(UP_t *u,const UP_Param_t *param,float target_freq)
PID_init (&u->pid .GM6020_speed,PID_POSITION ,&(u->param ->UP_GM6020_speed_param )); PID_init (&u->pid .GM6020_speed,PID_POSITION ,&(u->param ->UP_GM6020_speed_param ));
PID_init (&u->pid .GM6020_angle,PID_POSITION ,&(u->param ->UP_GM6020_angle_param )); PID_init (&u->pid .GM6020_angle,PID_POSITION ,&(u->param ->UP_GM6020_angle_param ));
PID_init (&u->pid .GO1_position ,PID_POSITION,&(u->param->go1_position_param ));
for(int i=0;i<2;i++){ //go初始位置设置为0 // for(int i=0;i<2;i++){ //go初始位置设置为0
GO_M8010_send_data(BSP_UART_GetHandle(BSP_UART_RS485), i,u->param->go_param[i] .rev ,u->param->go_param[i] .T ,u->param->go_param[i] .W ,0,u->param->go_param [i].K_P ,u->param->go_param[i] .K_W ); // GO_M8010_send_data(BSP_UART_GetHandle(BSP_UART_RS485), i,u->param->go_param[i] .rev ,u->param->go_param[i] .T ,u->param->go_param[i] .W ,0,u->param->go_param [i].K_P ,u->param->go_param[i] .K_W );
} // }
// 初始化上层状态机 // 初始化上层状态机
@ -45,15 +45,13 @@ int8_t up_init(UP_t *u,const UP_Param_t *param,float target_freq)
u->DribbleContext .DribbleConfig = u->param ->DribbleConfig_Config ;//赋值 u->DribbleContext .DribbleConfig = u->param ->DribbleConfig_Config ;//赋值
u->DribbleContext .DribbleState = Dribble_PREPARE; u->DribbleContext .DribbleState = Dribble_PREPARE;
u->DribbleContext .is_initialized = 1; u->DribbleContext .is_initialized = 1;
u->DribbleContext .Dribble_run_num =0;//记录运行次数
} }
if (!u->PitchContext .is_initialized) { if (!u->PitchContext .is_initialized) {
u->PitchContext .PitchConfig = u->param ->PitchConfig_Config ;//赋值 u->PitchContext .PitchConfig = u->param ->PitchConfig_Config ;//赋值
u->PitchContext .PitchState = PITCH_PREPARE; //状态更新,开始夹球 u->PitchContext .PitchState = PITCH_PREPARE; //状态更新,开始夹球
u->PitchContext .is_initialized = 1; u->PitchContext .is_initialized = 1;
u->PitchContext .Pitch_run_num =0;//记录运行次数
} }
@ -199,8 +197,10 @@ int8_t GM6020_control(UP_t *u,fp32 angle)
/*go电机控制*/ /*go电机控制*/
int8_t GO_SendData(UP_t *u,int id,float pos) int8_t GO_SendData(UP_t *u,int id,float pos)
{ {
fp32 deal_pos;
GO_M8010_send_data(BSP_UART_GetHandle(BSP_UART_RS485), id,u->param->go_param[id] .rev ,u->param->go_param[id] .T ,u->param->go_param[id] .W ,AngleChange(RADIAN,pos),u->param->go_param [id].K_P ,u->param->go_param[id] .K_W ); // deal_pos = PID_calc (&u->pid .GO1_position ,u->motorfeedback .GO_motor_info [0]->Pos ,pos);
GO_M8010_send_data(BSP_UART_GetHandle(BSP_UART_RS485), id,u->param->go_param[id] .rev ,u->param->go_param[id].T ,u->param->go_param[id] .W ,pos,u->param->go_param [id].K_P ,u->param->go_param[id] .K_W );
return 0; return 0;
} }
@ -217,7 +217,6 @@ int8_t ALL_Motor_Control(UP_t *u,CAN_Output_t *out)
GO_SendData(u,0 ,u->motor_target .go_shoot ); GO_SendData(u,0 ,u->motor_target .go_shoot );
GO_SendData(u,1 ,u->motor_target .go_spin);
for(int i=0;i<4;i++){ for(int i=0;i<4;i++){
@ -241,7 +240,7 @@ int8_t UP_control(UP_t *u,CAN_Output_t *out,CMD_t *c)
{ {
if(u ==NULL) return 0; if(u ==NULL) return 0;
static int is_pitch=1;
switch (c->CMD_CtrlType ) switch (c->CMD_CtrlType )
{ {
case UP_RCcontrol: //在手动模式下 case UP_RCcontrol: //在手动模式下
@ -251,42 +250,50 @@ int8_t UP_control(UP_t *u,CAN_Output_t *out,CMD_t *c)
case Normal : case Normal :
/*投篮*/ /*投篮*/
if(is_pitch){
u->motor_target .go_shoot =u->PitchContext .PitchConfig .go1_init_position ; u->motor_target .go_shoot =u->PitchContext .PitchConfig .go1_init_position ;
is_pitch=0;
}
u->motor_target .M2006_angle =u->PitchContext .PitchConfig .m2006_init_angle ; u->motor_target .M2006_angle =u->PitchContext .PitchConfig .m2006_init_angle ;
/*运球*/ u->PitchContext .PitchState = PITCH_PREPARE; //状态更新,开始夹球
u->motor_target .go_spin = u->DribbleContext.DribbleConfig .go2_init_angle ;
u->motor_target .M3508_angle =u->DribbleContext .DribbleConfig .m3508_init_angle ; // /*运球*/
// u->motor_target .go_spin = u->DribbleContext.DribbleConfig .go2_init_angle ;
// u->motor_target .M3508_angle =u->DribbleContext .DribbleConfig .m3508_init_angle ;
// u->DribbleContext .DribbleState = Dribble_PREPARE; //重置最初状态
RELAY1_TOGGLE (1);//接球1开0关 // RELAY1_TOGGLE (1);//夹球0夹1开
RELAY2_TOGGLE (1);//夹球0关1开 // RELAY2_TOGGLE (0);//球0接1收
//
break; break;
case Pitch : case Pitch :
Pitch_Process(u,out); if (u->PitchContext .PitchState ==PITCH_PREPARE) //首次启动
{
u->PitchContext .PitchState=PITCH_START;//置标志位用于启动投篮 u->PitchContext .PitchState=PITCH_START;//置标志位用于启动投篮
}
Pitch_Process(u,out,c);
break ; break ;
case Dribble: case Dribble:
{ {
/*夹球 -> 3508 升起 同时go2翻转 -> 到位置后继电器开放球同时3508降go2翻回->接球,收 */ /*夹球 -> 3508 升起 同时go2翻转 -> 到位置后继电器开放球同时3508降go2翻回->接球,收 */
if(u->DribbleContext.DribbleState== Dribble_PREPARE){
u->DribbleContext .DribbleState =STATE_GRAB_BALL;
}
Dribble_Process(u,out); Dribble_Process(u,out);
u->DribbleContext .DribbleState =STATE_GRAB_BALL;//置标志位用于启动运球
}break ; }break ;
case Dribbl_transfer:
case PICK_Pitch_START : Dribbl_transfer_a(u,out);
Pitch_Process(u,out);
u->PitchContext .PitchState=PITCH_START;//置标志位用于启动视觉辅助投篮
break;
} }
break; break;
@ -302,43 +309,58 @@ return 0;
} }
int8_t Pitch_Process(UP_t *u, CAN_Output_t *out)
{
int8_t Pitch_Process(UP_t *u, CAN_Output_t *out,CMD_t *c)
{
static fp32 go1_position,M2006_Screw_position ;
static int is_initialize=1;
if(is_initialize)
{
go1_position=u->PitchContext .PitchConfig .go1_init_position ;
M2006_Screw_position=u->PitchContext .PitchConfig .m2006_Screw_init;
is_initialize=0;
}
switch(u->PitchContext .PitchState){ switch(u->PitchContext .PitchState){
case PITCH_START: case PITCH_START:
u->motor_target .go_shoot = u->PitchContext .PitchConfig .go1_release_threshold; u->motor_target .go_shoot = u->PitchContext .PitchConfig .go1_release_threshold;
if(u->motorfeedback .GO_motor_info[0]->Pos < -35.0) //检测go位置到达最上面这里的检测条件可以更改 if(u->motorfeedback .GO_motor_info[0]->Pos < -32.40){ //检测go位置到达最上面这里的检测条件可以更改
u->motor_target .M2006_angle = u->PitchContext .PitchConfig .m2006_trigger_angle ;//设置2006角度0 u->motor_target .M2006_angle = u->PitchContext .PitchConfig .m2006_trigger_angle ;//设置2006角度0
u->PitchContext .PitchState =PITCH_PULL_TRIGGER; //更改标志位
u->PitchContext .PitchState=PITCH_PULL_TRIGGER;
}//更改标志位
break ; break ;
case PITCH_PULL_TRIGGER: case PITCH_PULL_TRIGGER:
if(u->motorfeedback .M2006 .total_angle <5) //当2006的总角度小于5可以认为已经勾上
if(u->motorfeedback .M2006 .total_angle >-1) //当2006的总角度小于1可以认为已经勾上,误差为1
{ {
u->motor_target .go_shoot =u->PitchContext.PitchConfig .go1_init_position;//go下拉 u->motor_target .go_shoot = go1_position;//go下拉
u->PitchContext.PitchState =PITCH_LAUNCHING;//转移标志位 u->motor_target .M3508_angle = M2006_Screw_position;//丝杠上的2006
go1_position = go1_position + c->Vx ;
M2006_Screw_position=M2006_Screw_position+ c->Vy;
} }
break ; break ;
case PITCH_LAUNCHING:
if(u->motorfeedback .GO_motor_info [0]->Pos <2.0f)
{
u->motor_target .M2006_angle =u->PitchContext .PitchConfig .m2006_init_angle ;//给-140角度发射
u->PitchContext .PitchState =PITCH_COMPLETE;
}
break ;
case PITCH_COMPLETE://完成运行动作后恢复2006-140度gopos0位置
u->motor_target .M2006_angle =u->PitchContext .PitchConfig .m2006_init_angle ;//给-140角度
u->motor_target .go_shoot = u->PitchContext .PitchConfig .go1_init_position;
u->PitchContext .Pitch_run_num ++;//运行次数+1
break ;
} }
@ -352,23 +374,46 @@ return 0;
int8_t Dribble_Process(UP_t *u, CAN_Output_t *out) int8_t Dribble_Process(UP_t *u, CAN_Output_t *out)
{ {
switch (u->DribbleContext.DribbleState) { switch (u->DribbleContext.DribbleState) {
case STATE_GRAB_BALL://开始 case STATE_GRAB_BALL://开始
RELAY2_TOGGLE (0);//夹球 RELAY1_TOGGLE (0);//夹球
u->motor_target.M3508_angle =u->DribbleContext .DribbleConfig .m3508_high_angle;//3508升起 u->motor_target.M3508_angle =u->DribbleContext .DribbleConfig .m3508_high_angle;//3508升起
u->motor_target.go_spin =u->DribbleContext .DribbleConfig .go2_flip_angle; u->motor_target.go_spin =u->DribbleContext .DribbleConfig .go2_flip_angle;
if((u->motorfeedback .M3508 .total_angle >400)) { if((u->motorfeedback .M3508 .total_angle >400)) {
RELAY1_TOGGLE (0); RELAY2_TOGGLE (1);
if((u->motorfeedback.GO_motor_info[1]->angle) <-53){ if(((u->motorfeedback.GO_motor_info[1]->Pos ) <-1.1)&&(u->motorfeedback.M3508 .total_angle >1190)){
u->DribbleContext .DribbleState = STATE_RELEASE_BALL; //当go2到标准位置标志位改变 u->DribbleContext .DribbleState = STATE_RELEASE_BALL; //当go2到标准位置标志位改变
} }
@ -378,13 +423,13 @@ int8_t Dribble_Process(UP_t *u, CAN_Output_t *out)
case STATE_RELEASE_BALL: case STATE_RELEASE_BALL:
RELAY2_TOGGLE (1);//松球 RELAY1_TOGGLE (1);//松球
if((u->motorfeedback.GO_motor_info[1]->angle) <-60){ if((u->motorfeedback.GO_motor_info[1]->Pos ) <-1.3){
u->motor_target.go_spin =u->DribbleContext .DribbleConfig .go2_init_angle ; //恢复go2位置 u->motor_target.go_spin =-40; //恢复go2位置
u->DribbleContext .DribbleState = STATE_CATCH_PREP; //当go2到标准位置标志位改变 u->DribbleContext .DribbleState = STATE_CATCH_PREP; //当go2到标准位置标志位改变
} }
@ -392,23 +437,26 @@ int8_t Dribble_Process(UP_t *u, CAN_Output_t *out)
break; break;
case STATE_CATCH_PREP: case STATE_CATCH_PREP:
if((u->motorfeedback.GO_motor_info[1]->angle) > -0){ if((u->motorfeedback.GO_motor_info[1]->Pos )> -0.4){
u->motor_target.M3508_angle =u->DribbleContext .DribbleConfig .m3508_init_angle ; //当go2到初始位置3508降 u->motor_target.M3508_angle =0 ; //当go2到初始位置3508降
RELAY1_TOGGLE (1);//接球 RELAY2_TOGGLE (0);//接球
} }
if(u->motorfeedback .M3508 .total_angle <5){ if(u->motorfeedback .M3508 .total_angle <51.0f){
u->DribbleContext .DribbleState = STATE_CATCH_DONE; RELAY1_TOGGLE (0);//夹球0夹1开
u->DribbleContext .DribbleState = STATE_TRANSFER;
} }
break; break;
case STATE_CATCH_DONE:
RELAY2_TOGGLE (1);//松球
RELAY1_TOGGLE (0);
u->DribbleContext .Dribble_run_num ++;//运行次数增加
break ; break ;
default: default:
break; break;
} }
@ -416,3 +464,42 @@ int8_t Dribble_Process(UP_t *u, CAN_Output_t *out)
return 0; return 0;
} }
void Dribbl_transfer_a(UP_t *u, CAN_Output_t *out)
{
switch (u->DribbleContext.DribbleState) {
case STATE_TRANSFER:
if((u->motorfeedback.M3508 .total_angle <52.0f )) //满足这个状态时认为go和3508到达初始位置再夹上球
{
u->motor_target .go_spin =u->DribbleContext .DribbleConfig .go2_release_threshold ;
}
if(u->motorfeedback .GO_motor_info [1]->Pos < -4.9)
{
RELAY1_TOGGLE (1);//夹球0夹1开
if(u->motorfeedback .GO_motor_info [1]->Pos > -4.8)
{
u->DribbleContext .DribbleState = STATE_CATCH_DONE; //当go2到标准位置标志位改变
}
}
break ;
case STATE_CATCH_DONE:
RELAY1_TOGGLE (1);//夹球0夹1开
RELAY2_TOGGLE (0);//夹球0接1收
u->motor_target.go_spin=u->DribbleContext .DribbleConfig.go2_init_angle ;
break;
break;
}
}

View File

@ -44,7 +44,7 @@
typedef enum { typedef enum {
PITCH_PREPARE, // 准备阶段 PITCH_PREPARE, // 准备阶段
PITCH_START, //启动,拉扳机 PITCH_START, //启动,拉扳机
PITCH_PULL_TRIGGER, // 扳机拉动 PITCH_PULL_TRIGGER,
PITCH_LAUNCHING, // 发射中 PITCH_LAUNCHING, // 发射中
PITCH_COMPLETE // 完成 PITCH_COMPLETE // 完成
} PitchState_t; } PitchState_t;
@ -55,6 +55,7 @@ typedef struct {
fp32 m2006_trigger_angle; // M2006触发角度0,用来合并扳机 fp32 m2006_trigger_angle; // M2006触发角度0,用来合并扳机
fp32 go1_init_position; // GO电机触发位置,0,初始位置 fp32 go1_init_position; // GO电机触发位置,0,初始位置
fp32 go1_release_threshold; // go上升去合并扳机扳机位置 fp32 go1_release_threshold; // go上升去合并扳机扳机位置
fp32 m2006_Screw_init;
} PitchConfig_t; } PitchConfig_t;
/* 投球控制上下文 */ /* 投球控制上下文 */
@ -63,7 +64,6 @@ typedef struct {
PitchConfig_t PitchConfig; PitchConfig_t PitchConfig;
uint8_t is_initialized ; uint8_t is_initialized ;
uint8_t Pitch_run_num;
} PitchContext_t; } PitchContext_t;
@ -80,6 +80,7 @@ typedef enum {
STATE_RELEASE_BALL, // 释放球体 STATE_RELEASE_BALL, // 释放球体
STATE_CATCH_PREP, // 接球准备 STATE_CATCH_PREP, // 接球准备
STATE_CATCH_BALL, // 接球动作 STATE_CATCH_BALL, // 接球动作
STATE_TRANSFER, //转移球
STATE_CATCH_DONE //完成 STATE_CATCH_DONE //完成
} DribbleState_t; } DribbleState_t;
@ -90,7 +91,8 @@ typedef struct {
fp32 go2_init_angle; // GO2初始角度 fp32 go2_init_angle; // GO2初始角度
fp32 go2_flip_angle; // GO2翻转角度 fp32 go2_flip_angle; // GO2翻转角度
fp32 flip_timing; // 翻转触发时机 fp32 flip_timing; // 翻转触发时机
fp32 release_threshold; // 释放球 // fp32
fp32 go2_release_threshold; // 释放球
} DribbleConfig_t; } DribbleConfig_t;
/* 状态机上下文 */ /* 状态机上下文 */
@ -99,7 +101,6 @@ typedef struct {
DribbleConfig_t DribbleConfig; DribbleConfig_t DribbleConfig;
uint8_t is_initialized; uint8_t is_initialized;
uint8_t Dribble_run_num;
} DribbleContext_t; } DribbleContext_t;
@ -154,6 +155,7 @@ typedef struct
pid_param_t M3508_angle_param; pid_param_t M3508_angle_param;
GO_param_t go_param[2]; GO_param_t go_param[2];
pid_param_t go1_position_param;
DribbleConfig_t DribbleConfig_Config; DribbleConfig_t DribbleConfig_Config;
PitchConfig_t PitchConfig_Config; PitchConfig_t PitchConfig_Config;
@ -243,6 +245,8 @@ typedef struct{
pid_type_def M3508_angle; pid_type_def M3508_angle;
pid_type_def M3508_speed; pid_type_def M3508_speed;
pid_type_def GO1_position;
}pid; }pid;
@ -278,9 +282,10 @@ int8_t UP_control(UP_t *u,CAN_Output_t *out,CMD_t *c);
int8_t ALL_Motor_Control(UP_t *u,CAN_Output_t *out); int8_t ALL_Motor_Control(UP_t *u,CAN_Output_t *out);
int8_t UP_M2006_angle(UP_t *u,fp32 target_angle); int8_t UP_M2006_angle(UP_t *u,fp32 target_angle);
int8_t UP_M3508_speed(UP_t *u,fp32 speed); int8_t UP_M3508_speed(UP_t *u,fp32 speed);
int8_t Pitch_Process(UP_t *u, CAN_Output_t *out); int8_t Pitch_Process(UP_t *u, CAN_Output_t *out,CMD_t *c);
int8_t Dribble_Process(UP_t *u, CAN_Output_t *out); int8_t Dribble_Process(UP_t *u, CAN_Output_t *out);
void Dribbl_transfer_a(UP_t *u, CAN_Output_t *out);
#endif #endif

View File

@ -18,7 +18,7 @@ void GO_M8010_init (void){
for (uint8_t id= 0; id <GO_NUM ;id++) for (uint8_t id= 0; id <GO_NUM ;id++)
{ {
GO_motor_info[id].id = id; GO_motor_info[id].id = id;
GO_motor_info[id].mode = 1; //位置模式 GO_motor_info[id].mode = 1; //foc闭环
GO_motor_info[id].correct = 1; GO_motor_info[id].correct = 1;
GO_motor_info[id].MError = 0; GO_motor_info[id].MError = 0;
GO_motor_info[id].Temp = 0; GO_motor_info[id].Temp = 0;
@ -158,14 +158,16 @@ void GO_M8010_recv_data(uint8_t* Temp_buffer)
int16_t W = Temp_buffer[6]<<8 | Temp_buffer[5]; int16_t W = Temp_buffer[6]<<8 | Temp_buffer[5];
motor->W = W; motor->W = W;
motor->W = (motor->W * 6.28319f )/(256*6.33f); motor->W = (motor->W * 6.28319f )/(256*6.33f);
int32_t Pos = Temp_buffer[10]<<24 | Temp_buffer[9]<<16 | Temp_buffer[8]<<8 | Temp_buffer[7]; int32_t Pos = (Temp_buffer[7] << 0) |
motor->Pos = Pos; (Temp_buffer[8] << 8) |
motor->Pos = (motor->Pos * 6.28319f )/(32768*6.33f); (Temp_buffer[9] << 16) |
(Temp_buffer[10] << 24);
if(Pos > 0x7FFFFFFF) Pos -= 0xFFFFFFFF; // 溢出修正
motor->Pos = ((float)Pos / 32768.0f) * (6.28319f / 6.33f);
int8_t Temp = Temp_buffer[11] & 0xFF; int8_t Temp = Temp_buffer[11] & 0xFF;
motor->Temp = Temp; motor->Temp = Temp;
motor->MError = Temp_buffer[12] & 0x7; motor->MError = Temp_buffer[12] & 0x7;
motor ->angle = AngleChange(DEGREE,motor ->Pos);
} }
//力位混合控制 //力位混合控制

View File

@ -44,7 +44,19 @@ int8_t CMD_ParseNuc(CMD_t *cmd,CMD_NUC_t *n){
/*遥控器上下层通用按键控制统一到cmd*/ /*遥控器上下层通用按键控制统一到cmd*/
int8_t CMD_ParseRC(CMD_t *cmd,const CMD_RC_t *rc) { int8_t CMD_ParseRC(CMD_t *cmd,const CMD_RC_t *rc) {
if(cmd == NULL) return -1; if(cmd == NULL) return -1;
const CMD_CtrlType_t prev_CtrlType = cmd->CMD_CtrlType ;
const CMD_UP_mode_t prev_mode = cmd->CMD_UP_mode ;//保存旧状态
cmd->Vx = rc->ch_r_x;
cmd->Vy = rc->ch_r_y;
cmd->Vw = rc->ch_l_x;
cmd->poscamear = rc->ch_l_y;
cmd->key_ctrl_l = rc->sw_l;
cmd->key_ctrl_r = rc->sw_r ;
if ((rc->sw_l == CMD_SW_ERR) || (rc->sw_r == CMD_SW_ERR)) { if ((rc->sw_l == CMD_SW_ERR) || (rc->sw_r == CMD_SW_ERR)) {
cmd->CMD_CtrlType =RELAXED; cmd->CMD_CtrlType =RELAXED;
@ -52,9 +64,9 @@ int8_t CMD_ParseRC(CMD_t *cmd,const CMD_RC_t *rc) {
else if(rc->sw_l==CMD_SW_UP) else if(rc->sw_l==CMD_SW_UP)
{ {
cmd ->CMD_CtrlType =UP_RCcontrol; cmd ->CMD_CtrlType =UP_RCcontrol;
if(rc->sw_r ==CMD_SW_UP) cmd ->CMD_UP_mode =Pitch; //左上,右上,投篮 if(rc->sw_r ==CMD_SW_UP) cmd ->CMD_UP_mode =Pitch; //左上,右上,投篮,设置好的
if(rc->sw_r ==CMD_SW_MID) cmd ->CMD_UP_mode =Normal; //左上,右中,无模式 if(rc->sw_r ==CMD_SW_MID) cmd ->CMD_UP_mode =Normal; //左上,右中,无模式
if(rc->sw_r ==CMD_SW_DOWN) cmd ->CMD_UP_mode =Dribble; //左上,右上,运球 if(rc->sw_r ==CMD_SW_DOWN) cmd ->CMD_UP_mode =Pitch_HAND; //左上,右上,手动调整
} }
else if(rc->sw_l==CMD_SW_MID) else if(rc->sw_l==CMD_SW_MID)
@ -74,14 +86,19 @@ int8_t CMD_ParseRC(CMD_t *cmd,const CMD_RC_t *rc) {
} }
else if(rc->sw_l==CMD_SW_DOWN) else if(rc->sw_l==CMD_SW_DOWN)
{ {
cmd ->CMD_CtrlType =PICK_t; cmd ->CMD_CtrlType =UP_RCcontrol;
if(rc->sw_r ==CMD_SW_UP) cmd ->CMD_UP_mode =PICK_Pitch_Normal; //左下,右上,投篮 if(rc->sw_r ==CMD_SW_UP) cmd ->CMD_UP_mode =Normal; //左下,右上,投篮
if(rc->sw_r ==CMD_SW_MID) cmd ->CMD_UP_mode =Normal; //左下,右中,无模式 if(rc->sw_r ==CMD_SW_MID) cmd ->CMD_UP_mode =Normal; //左下,右中,无模式
if(rc->sw_r ==CMD_SW_DOWN) cmd ->CMD_UP_mode =PICK_Pitch_START; //左下,右上,投篮 if(rc->sw_r ==CMD_SW_DOWN) cmd ->CMD_UP_mode =Normal; //左下,右上,无模式
} }
if (prev_CtrlType!= cmd->CMD_CtrlType ) cmd ->last_CMD_CtrlType = prev_CtrlType;
if (prev_mode!=cmd->CMD_UP_mode ) cmd ->last_CMD_UP_mode =prev_mode;
return 0; return 0;
} }

View File

@ -25,9 +25,9 @@ typedef enum{
Pitch, //投篮 Pitch, //投篮
/*视觉辅助下的投篮*/ /*视觉辅助下的投篮*/
PICK_Pitch_Normal, Pitch_HAND,
PICK_Pitch_START
Dribbl_transfer
}CMD_UP_mode_t; }CMD_UP_mode_t;
typedef struct { typedef struct {
uint8_t status_fromnuc; uint8_t status_fromnuc;
@ -81,6 +81,10 @@ typedef struct {
fp32 key_ctrl_l; fp32 key_ctrl_l;
fp32 key_ctrl_r; fp32 key_ctrl_r;
fp32 Vx;
fp32 Vy;
fp32 Vw;
fp32 poscamear;
/*视觉*/ /*视觉*/
struct { struct {
@ -99,7 +103,8 @@ typedef struct {
CMD_UP_mode_t CMD_UP_mode; CMD_UP_mode_t CMD_UP_mode;
CMD_CtrlType_t CMD_CtrlType; CMD_CtrlType_t CMD_CtrlType;
CMD_CtrlType_t last_CMD_CtrlType;
CMD_UP_mode_t last_CMD_UP_mode;
} CMD_t; } CMD_t;
@ -109,5 +114,7 @@ int8_t CMD_ParseNuc(CMD_t *cmd,CMD_NUC_t *n);
int8_t CMD_ParseRC(CMD_t *cmd,const CMD_RC_t *rc) ; int8_t CMD_ParseRC(CMD_t *cmd,const CMD_RC_t *rc) ;
static void CMD_RcLogic(const CMD_RC_t *rc, CMD_t *cmd) ;
#endif #endif

View File

@ -67,19 +67,16 @@ void Task_up(void *argument)
// //
// GO_SendData(&UP, 1,CCC);
// GO_SendData(&UP, 0,aaa);
UP_control(&UP,&UP_CAN_out,&up_cmd);
// UP.motor_target .go_shoot =aaa;
// UP.motor_target .M2006_angle =bbb ;
// UP_control(&UP,&UP_CAN_out,&up_cmd); // UP_control(&UP,&UP_CAN_out,&up_cmd);
UP.motor_target .go_shoot =aaa;
// UP.motor_target .M2006_angle =bbb ;
// UP.motor_target .M3508_angle =CCC; // UP.motor_target .M3508_angle =CCC;
// UP.motor_target .go_shoot =aaa; // UP.motor_target .go_shoot =aaa;
// UP.motor_target .M2006_angle =bbb; // UP.motor_target .M2006_angle =bbb;
// UP.motor_target .go_spin =ddd; // UP.motor_target .go_spin =ddd;
//
ALL_Motor_Control(&UP,&UP_CAN_out); ALL_Motor_Control(&UP,&UP_CAN_out);
osDelay(1); osDelay(1);