2022-11-27 18:54:27 +08:00
|
|
|
#include "shoot.h"
|
2022-12-02 22:17:10 +08:00
|
|
|
#include "robot_def.h"
|
|
|
|
#include "dji_motor.h"
|
2022-12-03 15:20:17 +08:00
|
|
|
#include "message_center.h"
|
2022-12-04 20:26:15 +08:00
|
|
|
#include "bsp_dwt.h"
|
2022-12-02 22:17:10 +08:00
|
|
|
|
2022-12-04 20:26:15 +08:00
|
|
|
#define ONE_BULLET_DELTA_ANGLE 0 // 发射一发弹丸拨盘转动的距离,由机械设计图纸给出
|
|
|
|
#define REDUCTION_RATIO 49.0f // 拨盘电机的减速比,英雄需要修改为3508的19.0f
|
|
|
|
#define NUM_PER_CIRCLE 1 // 拨盘一圈的装载量
|
|
|
|
|
|
|
|
/* 对于双发射机构的机器人,将下面的数据封装成结构体即可,生成两份shoot应用实例 */
|
2022-12-03 15:20:17 +08:00
|
|
|
static dji_motor_instance *friction_l; // 左摩擦轮
|
|
|
|
static dji_motor_instance *friction_r; // 右摩擦轮
|
|
|
|
static dji_motor_instance *loader; // 拨盘电机
|
2022-12-04 20:26:15 +08:00
|
|
|
// static servo_instance *lid; 需要增加弹舱盖
|
2022-12-03 15:20:17 +08:00
|
|
|
|
|
|
|
static Publisher_t *shoot_pub;
|
|
|
|
static Shoot_Ctrl_Cmd_s shoot_cmd_recv; // 来自gimbal_cmd的发射控制信息
|
|
|
|
static Subscriber_t *shoot_sub;
|
|
|
|
static Shoot_Upload_Data_s shoot_feedback_data; // 来自gimbal_cmd的发射控制信息
|
2022-11-27 18:54:27 +08:00
|
|
|
|
2022-12-04 20:26:15 +08:00
|
|
|
// 定时,计算冷却用
|
|
|
|
static uint32_t INS_DWT_Count = 0;
|
|
|
|
static float dt = 0, t = 0;
|
|
|
|
|
2022-11-27 18:54:27 +08:00
|
|
|
void ShootInit()
|
|
|
|
{
|
2022-12-03 15:20:17 +08:00
|
|
|
// 左摩擦轮
|
|
|
|
Motor_Init_Config_s left_friction_config = {
|
|
|
|
.can_init_config = {
|
|
|
|
.can_handle = &hcan1,
|
|
|
|
.tx_id = 1,
|
|
|
|
},
|
|
|
|
.controller_param_init_config = {
|
|
|
|
.angle_PID = {
|
|
|
|
.Kd = 10,
|
|
|
|
.Ki = 1,
|
|
|
|
.Kd = 2,
|
|
|
|
},
|
|
|
|
.speed_PID = {
|
|
|
|
|
|
|
|
},
|
|
|
|
.current_PID = {
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.controller_setting_init_config = {
|
|
|
|
.angle_feedback_source = MOTOR_FEED,
|
|
|
|
.speed_feedback_source = MOTOR_FEED,
|
2022-12-04 20:26:15 +08:00
|
|
|
|
|
|
|
.outer_loop_type = SPEED_LOOP,
|
2022-12-03 15:20:17 +08:00
|
|
|
.close_loop_type = SPEED_LOOP | CURRENT_LOOP,
|
|
|
|
.reverse_flag = MOTOR_DIRECTION_REVERSE,
|
|
|
|
},
|
|
|
|
.motor_type = M3508};
|
|
|
|
// 右摩擦轮
|
|
|
|
Motor_Init_Config_s right_friction_config = {
|
|
|
|
.can_init_config = {
|
|
|
|
.can_handle = &hcan1,
|
|
|
|
.tx_id = 2,
|
|
|
|
},
|
|
|
|
.controller_param_init_config = {
|
|
|
|
.angle_PID = {
|
|
|
|
.Kd = 10,
|
|
|
|
.Ki = 1,
|
|
|
|
.Kd = 2,
|
|
|
|
},
|
|
|
|
.speed_PID = {
|
|
|
|
|
|
|
|
},
|
|
|
|
.current_PID = {
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.controller_setting_init_config = {
|
|
|
|
.angle_feedback_source = MOTOR_FEED,
|
|
|
|
.speed_feedback_source = MOTOR_FEED,
|
2022-12-04 20:26:15 +08:00
|
|
|
.outer_loop_type = SPEED_LOOP,
|
2022-12-03 15:20:17 +08:00
|
|
|
.close_loop_type = SPEED_LOOP | CURRENT_LOOP,
|
|
|
|
.reverse_flag = MOTOR_DIRECTION_REVERSE,
|
|
|
|
},
|
|
|
|
.motor_type = M3508};
|
2022-12-04 20:26:15 +08:00
|
|
|
// 拨盘电机
|
2022-12-03 15:20:17 +08:00
|
|
|
Motor_Init_Config_s loader_config = {
|
|
|
|
.can_init_config = {
|
|
|
|
.can_handle = &hcan1,
|
|
|
|
.tx_id = 3,
|
|
|
|
},
|
|
|
|
.controller_param_init_config = {
|
|
|
|
.angle_PID = {
|
2022-12-04 20:26:15 +08:00
|
|
|
// 如果启用位置环来控制发弹,需要较大的I值保证输出力矩的线性度否则出现接近拨出的力矩大幅下降
|
2022-12-03 15:20:17 +08:00
|
|
|
.Kd = 10,
|
|
|
|
.Ki = 1,
|
|
|
|
.Kd = 2,
|
2022-12-04 20:26:15 +08:00
|
|
|
},
|
|
|
|
.angle_PID = {
|
|
|
|
|
2022-12-03 15:20:17 +08:00
|
|
|
},
|
|
|
|
.speed_PID = {
|
|
|
|
|
|
|
|
},
|
|
|
|
.current_PID = {
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.controller_setting_init_config = {
|
2022-12-04 20:26:15 +08:00
|
|
|
.angle_feedback_source = MOTOR_FEED, .speed_feedback_source = MOTOR_FEED,
|
|
|
|
.outer_loop_type = SPEED_LOOP, // 初始化成SPEED_LOOP,让拨盘停在原地,防止拨盘上电时乱转
|
|
|
|
.close_loop_type = ANGLE_LOOP | SPEED_LOOP | CURRENT_LOOP,
|
|
|
|
.reverse_flag = MOTOR_DIRECTION_REVERSE, // 注意方向设置为拨盘的拨出的击发方向
|
2022-12-03 15:20:17 +08:00
|
|
|
},
|
2022-12-04 20:26:15 +08:00
|
|
|
.motor_type = M2006 // 英雄使用m3508
|
|
|
|
};
|
2022-12-03 15:20:17 +08:00
|
|
|
|
|
|
|
friction_l = DJIMotorInit(&left_friction_config);
|
|
|
|
friction_r = DJIMotorInit(&right_friction_config);
|
|
|
|
loader = DJIMotorInit(&loader_config);
|
|
|
|
|
|
|
|
shoot_pub = PubRegister("shoot_feed", sizeof(Shoot_Upload_Data_s));
|
|
|
|
shoot_sub = SubRegister("shoot_cmd", sizeof(Shoot_Ctrl_Cmd_s));
|
2022-11-27 18:54:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShootTask()
|
|
|
|
{
|
2022-12-04 20:26:15 +08:00
|
|
|
// 从cmd获取控制数据
|
|
|
|
SubGetMessage(shoot_sub, &shoot_cmd_recv);
|
|
|
|
|
|
|
|
// 根据控制模式进行电机参考值设定和模式切换
|
|
|
|
switch (shoot_cmd_recv.load_mode)
|
|
|
|
{
|
|
|
|
// 停止三个电机
|
|
|
|
case SHOOT_STOP:
|
|
|
|
DJIMotorStop(friction_l);
|
|
|
|
DJIMotorStop(friction_r);
|
|
|
|
DJIMotorStop(loader);
|
|
|
|
break;
|
|
|
|
// 停止拨盘
|
|
|
|
case LOAD_STOP:
|
|
|
|
DJIMotorOuterLoop(loader, SPEED_LOOP);
|
|
|
|
DJIMotorSetRef(loader, 0);
|
|
|
|
break;
|
|
|
|
// 单发模式,根据鼠标按下的时间,触发一次之后需要进入不响应输入的状态(否则按下的时间内可能多次进入)
|
|
|
|
// 激活能量机关/干扰对方用,英雄用.
|
|
|
|
case LOAD_1_BULLET:
|
|
|
|
DJIMotorOuterLoop(loader, ANGLE_LOOP);
|
|
|
|
DJIMotorSetRef(loader, loader->motor_measure.total_angle + ONE_BULLET_DELTA_ANGLE); // 增加一发弹丸
|
|
|
|
break;
|
|
|
|
// 三连发,如果不需要后续可能删除
|
|
|
|
case LOAD_3_BULLET:
|
|
|
|
DJIMotorOuterLoop(loader, ANGLE_LOOP);
|
|
|
|
DJIMotorSetRef(loader, loader->motor_measure.total_angle + 3 * ONE_BULLET_DELTA_ANGLE); // 增加3发
|
|
|
|
break;
|
|
|
|
// 连发模式,对速度闭环,射频后续修改为可变
|
|
|
|
case LOAD_BURSTFIRE:
|
|
|
|
DJIMotorOuterLoop(loader, SPEED_LOOP);
|
|
|
|
DJIMotorSetRef(loader, shoot_cmd_recv.shoot_rate * 360 * REDUCTION_RATIO / NUM_PER_CIRCLE);
|
|
|
|
// x颗/秒换算成速度: 已知一圈的载弹量,由此计算出1s需要转的角度,注意换算角速度
|
|
|
|
break;
|
|
|
|
// 拨盘反转,对速度闭环,后续增加卡弹检测(通过裁判系统剩余热量反馈)
|
|
|
|
// 可能需要从switch-case中独立出来
|
|
|
|
case LOAD_REVERSE:
|
|
|
|
DJIMotorOuterLoop(loader, SPEED_LOOP);
|
|
|
|
// ...
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 根据收到的弹速设置设定摩擦轮参考值,需实测后填入
|
|
|
|
switch (shoot_cmd_recv.bullet_speed)
|
|
|
|
{
|
|
|
|
case SMALL_AMU_15:
|
|
|
|
DJIMotorSetRef(friction_l, 0);
|
|
|
|
DJIMotorSetRef(friction_l, 0);
|
|
|
|
break;
|
|
|
|
case SMALL_AMU_18:
|
|
|
|
DJIMotorSetRef(friction_l, 0);
|
|
|
|
DJIMotorSetRef(friction_l, 0);
|
|
|
|
break;
|
|
|
|
case SMALL_AMU_30:
|
|
|
|
DJIMotorSetRef(friction_l, 0);
|
|
|
|
DJIMotorSetRef(friction_l, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 开关弹舱盖
|
|
|
|
if (shoot_cmd_recv.lid_mode == LID_CLOSE)
|
|
|
|
{
|
|
|
|
//...
|
|
|
|
}
|
|
|
|
else if (shoot_cmd_recv.lid_mode == LID_OPEN)
|
|
|
|
{
|
|
|
|
//...
|
|
|
|
}
|
2022-11-27 18:54:27 +08:00
|
|
|
}
|