改底盘1

This commit is contained in:
guoxy06
2026-04-12 17:07:22 +08:00
parent 8bc4c0bb1f
commit eaacf449c5

View File

@@ -57,15 +57,15 @@ static referee_info_t* referee_data; // 用于获取裁判系统的数据
static Referee_Interactive_info_t ui_data; // UI数据,将底盘中的数据传入此结构体的对应变量中,UI会自动检测是否变化,对应显示UI
static SuperCapInstance *cap; // 超级电容
static LKMotorInstance *motor_lf,*motor_rb; // 轮电机9015
static DJIMotorInstance *motor_steering_lf,*motor_steering_rb; // 舵电机6020
static LKMotorInstance *motor_rf,*motor_lb; // 轮电机9015
static DJIMotorInstance *motor_steering_rf,*motor_steering_lb; // 舵电机6020
/* 用于自旋变速策略的时间变量 */
// static float t;
/* 私有函数计算的中介变量,设为静态避免参数传递的开销 */
static float chassis_vx, chassis_vy; // 将云台系的速度投影到底盘
static float vt_lf, vt_rb; // 底盘速度解算后的临时输出,待进行限幅
static float at_lf, at_rb; // 底盘的角度解算后的临时输出,待进行限幅
static float vt_rf, vt_lb; // 底盘速度解算后的临时输出,待进行限幅
static float at_rf, at_lb; // 底盘的角度解算后的临时输出,待进行限幅
static PIDInstance chassis_follow_pid; // 底盘跟随云台的PID
void ChassisInit()
@@ -75,7 +75,7 @@ void ChassisInit()
.can_init_config.can_handle = &hcan1,
.controller_param_init_config = {
.speed_PID = {
.Kp = 80, // 4.5
.Kp = 95, // 4.5
.Ki = 0, // 0
.Kd = 0, // 0
.IntegralLimit = 8000,
@@ -83,7 +83,7 @@ void ChassisInit()
.MaxOut = 12000,
},
.current_PID = {
.Kp = 1, // 0.4
.Kp = 0.4, // 0.4
.Ki = 0, // 0
.Kd = 0,
.IntegralLimit = 10500,
@@ -103,11 +103,11 @@ void ChassisInit()
chassis_motor_config.can_init_config.tx_id = 1;
// chassis_motor_config.controller_setting_init_config.motor_reverse_flag = MOTOR_DIRECTION_REVERSE;
motor_rb = LKMotorInit(&chassis_motor_config);
motor_rf = LKMotorInit(&chassis_motor_config);
chassis_motor_config.can_init_config.tx_id = 2;
// chassis_motor_config.controller_setting_init_config.motor_reverse_flag = MOTOR_DIRECTION_REVERSE;
motor_lf = LKMotorInit(&chassis_motor_config);
motor_lb = LKMotorInit(&chassis_motor_config);
// 舵电机6020初始化
Motor_Init_Config_s chassis_motor_steering_config = {
@@ -146,15 +146,15 @@ void ChassisInit()
};
chassis_motor_steering_config.can_init_config.tx_id = 1;
motor_steering_rb = DJIMotorInit(&chassis_motor_steering_config);
motor_steering_rf = DJIMotorInit(&chassis_motor_steering_config);
chassis_motor_steering_config.can_init_config.tx_id = 2;
motor_steering_lf = DJIMotorInit(&chassis_motor_steering_config);
motor_steering_lb = DJIMotorInit(&chassis_motor_steering_config);
PID_Init_Config_s chassis_follow_pid_conf = {
.Kp = 12, // 6
.Ki = 3.0f,
.Kd = 0.015f, // 0.5
.Kp = 1.2, // 6
.Ki = 0,
.Kd = 0.1f, // 0.5
.DeadBand = 0.5,
.CoefA = 0.2,
.CoefB = 0.3,
@@ -241,44 +241,53 @@ static void MinmizeRotation(float *angle, const float *last_angle, float *speed)
*/
static void SteeringWheelCalculate()
{
float offset_lf, offset_rb; // 用于计算舵轮的角度
float at_lf_last, at_rb_last; // 上次的角度
at_lf_last = motor_steering_lf->measure.total_angle;
at_rb_last = motor_steering_rb->measure.total_angle;
float offset_rf, offset_lb; // 用于计算舵轮的角度
float at_rf_last, at_lb_last; // 上次的角度
at_rf_last = motor_steering_rf->measure.total_angle;
at_lb_last = motor_steering_lb->measure.total_angle;
if (chassis_vx == 0 && chassis_vy == 0 && chassis_cmd_recv.wz == 0) {
// at_lf = at_lf_last;
// at_rf = at_rf_last;
// at_lb = at_lb_last;
// at_rb = at_rb_last;
vt_lf = 0, vt_rb = 0;
vt_rf = 0, vt_lb = 0;
} else {
// 生成预计算变量,减少计算量,空间换时间
float w = chassis_cmd_recv.wz * CHASSIS_WHEEL_OFFSET * SQRT2;
float temp_x = chassis_vx - w, temp_y = chassis_vy - w;
arm_sqrt_f32(temp_x * temp_x + temp_y * temp_y, &vt_lf); // lf:y- , x-
temp_y = chassis_vy + w; // 重复利用变量,temp_x = chassis_vy - w;与上次相同因此注释
// arm_sqrt_f32(temp_x * temp_x + temp_y * temp_y, &vt_lb); // lb: y+ , x-
// temp_x = chassis_vx + w; // temp_y = chassis_vx + w;与上次相同因此注释
arm_sqrt_f32(temp_x * temp_x + temp_y * temp_y, &vt_rb); // rb: y+ , x+
temp_y = chassis_vy - w; // temp_x = chassis_vy + w;与上次相同因此注释
// arm_sqrt_f32(temp_x * temp_x + temp_y * temp_y, &vt_rf); // rf: y- , x+
// float temp_x = chassis_vx - w, temp_y = chassis_vy - w;
// arm_sqrt_f32(temp_x * temp_x + temp_y * temp_y, &vt_lf); // lf:y- , x-
// temp_y = chassis_vy + w; // 重复利用变量,temp_x = chassis_vy - w;与上次相同因此注释
// // arm_sqrt_f32(temp_x * temp_x + temp_y * temp_y, &vt_lb); // lb: y+ , x-
// // temp_x = chassis_vx + w; // temp_y = chassis_vx + w;与上次相同因此注释
// arm_sqrt_f32(temp_x * temp_x + temp_y * temp_y, &vt_rb); // rb: y+ , x+
// temp_y = chassis_vy - w; // temp_x = chassis_vy + w;与上次相同因此注释
// // arm_sqrt_f32(temp_x * temp_x + temp_y * temp_y, &vt_rf); // rf: y- , x+
float temp_x = chassis_vx - w, temp_y = chassis_vy + w;
arm_sqrt_f32(temp_x * temp_x + temp_y * temp_y, &vt_lb); // lb: y+ , x-
temp_x = chassis_vx + w;
temp_y = chassis_vy - w;
arm_sqrt_f32(temp_x * temp_x + temp_y * temp_y, &vt_rf); // rf: y- , x+
// 计算角度偏移
offset_lf = atan2f(chassis_vy - w, chassis_vx - w) * RAD_2_DEGREE; // lf: y- , x-
offset_rb = atan2f(chassis_vy + w, chassis_vx + w) * RAD_2_DEGREE; // rb: y+ , x+
// offset_lf = atan2f(chassis_vy - w, chassis_vx - w) * RAD_2_DEGREE; // lf: y- , x-
// offset_rb = atan2f(chassis_vy + w, chassis_vx + w) * RAD_2_DEGREE; // rb: y+ , x+
offset_lb = atan2f(chassis_vy + w, chassis_vx - w) * RAD_2_DEGREE; // lb: y+ , x-
offset_rf = atan2f(chassis_vy - w, chassis_vx + w) * RAD_2_DEGREE; // rf: y- , x+
at_lf = STEERING_CHASSIS_ALIGN_ANGLE_RF + offset_lf; // 此处似乎不需要加上真实角度,因为我们需要的是绝对角度而不是相对角度
at_rb = STEERING_CHASSIS_ALIGN_ANGLE_LB + offset_rb;
at_rf = STEERING_CHASSIS_ALIGN_ANGLE_RF + offset_rf; // 此处似乎不需要加上真实角度,因为我们需要的是绝对角度而不是相对角度
at_lb = STEERING_CHASSIS_ALIGN_ANGLE_LB + offset_lb;
ANGLE_LIMIT_360_TO_180_ABS(at_lf);
ANGLE_LIMIT_360_TO_180_ABS(at_rb);
ANGLE_LIMIT_360_TO_180_ABS(at_rf);
ANGLE_LIMIT_360_TO_180_ABS(at_lb);
MinmizeRotation(&at_lf, &at_lf_last, &vt_lf);
MinmizeRotation(&at_rb, &at_rb_last, &vt_rb);
// MinmizeRotation(&at_lf, &at_lf_last, &vt_lf);
// MinmizeRotation(&at_rb, &at_rb_last, &vt_rb);
MinmizeRotation(&at_lb, &at_lb_last, &vt_lb);
MinmizeRotation(&at_rf, &at_rf_last, &vt_rf);
}
DJIMotorSetRef(motor_steering_lf, at_lf);
DJIMotorSetRef(motor_steering_rb, at_rb);
DJIMotorSetRef(motor_steering_rf, at_rf);
DJIMotorSetRef(motor_steering_lb, at_lb);
}
/**
@@ -308,8 +317,8 @@ static void LimitChassisOutput()
// LKMotorSetRef( motor_lf , vt_lf );
// LKMotorSetRef( motor_rb , vt_rb );
LKMotorSetRef( motor_lf , vt_lf );
LKMotorSetRef( motor_rb , vt_rb );
LKMotorSetRef( motor_rf , vt_rf );
LKMotorSetRef( motor_lb , vt_lb );
}
/**
@@ -337,18 +346,18 @@ void ChassisTask() {
if (chassis_cmd_recv.chassis_mode == CHASSIS_ZERO_FORCE)
{ // 如果出现重要模块离线或遥控器设置为急停,让电机停止
LKMotorStop(motor_lf);
LKMotorStop(motor_rb);
DJIMotorStop(motor_steering_lf);
DJIMotorStop(motor_steering_rb);
LKMotorStop(motor_rf);
LKMotorStop(motor_lb);
DJIMotorStop(motor_steering_rf);
DJIMotorStop(motor_steering_lb);
}
else
{
// 正常工作
LKMotorEnable(motor_lf);
LKMotorEnable(motor_rb);
DJIMotorEnable(motor_steering_lf);
DJIMotorEnable(motor_steering_rb);
LKMotorEnable(motor_rf);
LKMotorEnable(motor_lb);
DJIMotorEnable(motor_steering_rf);
DJIMotorEnable(motor_steering_lb);
}
// 根据控制模式设定旋转速度
@@ -361,7 +370,7 @@ void ChassisTask() {
chassis_cmd_recv.wz = PIDCalculate(&chassis_follow_pid, chassis_cmd_recv.offset_angle, 0);
break;
case CHASSIS_ROTATE: // 自旋,同时保持全向机动;当前wz维持定值,后续增加不规则的变速策略
chassis_cmd_recv.wz = 4000;
chassis_cmd_recv.wz = 0.75;
break;
default:
break;