rm_balance/User/module/config.c
2026-02-12 17:37:15 +08:00

378 lines
13 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 配置相关
*/
/* Includes ----------------------------------------------------------------- */
#include "module/config.h"
#include <stdbool.h>
/* Private typedef ---------------------------------------------------------- */
/* Private define ----------------------------------------------------------- */
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* Exported variables ------------------------------------------------------- */
/**
* @brief 机器人参数配置
* @note 在此配置机器人参数
*/
Config_RobotParam_t robot_config = {
/* USER CODE BEGIN robot_config */
.gimbal_param = {
.pid = {
.yaw_omega = {
.k = 0.25f,
.p = 1.0f,
.i = 0.0f,
.d = 0.0f,
.i_limit = 1.0f,
.out_limit = 1.0f,
.d_cutoff_freq = -1.0f,
.range = -1.0f,
},
.yaw_angle = {
.k = 7.0f,
.p = 3.5f,
.i = 0.0f,
.d = 0.0f,
.i_limit = 0.0f,
.out_limit = 10.0f,
.d_cutoff_freq = -1.0f,
.range = M_2PI,
},
.pit_omega = {
.k = 0.25f,
.p = 1.0f,
.i = 0.0f,
.d = 0.0f,
.i_limit = 1.0f,
.out_limit = 1.0f,
.d_cutoff_freq = -1.0f,
.range = -1.0f,
},
.pit_angle = {
.k = 2.5f,
.p = 5.0f,
.i = 0.2f,
.d = 0.01f,
.i_limit = 0.0f,
.out_limit = 10.0f,
.d_cutoff_freq = -1.0f,
.range = M_2PI,
},
},
.mech_zero = {
.yaw = 0.0f,
.pit = 2.2f,
},
.travel = {
.yaw = -1.0f,
.pit = 0.85f,
},
.low_pass_cutoff_freq = {
.out = -1.0f,
.gyro = 1000.0f,
},
.pit_motor ={
.can = BSP_CAN_1,
.id = 0x206,
.gear = false,
.module = MOTOR_GM6020,
.reverse = true,
},
.yaw_motor = {
.can = BSP_CAN_1,
.can_id = 0x1,
.master_id = 0x11,
.module = MOTOR_DM_J4310,
.reverse = false,
},
.imu = {
.can = BSP_CAN_2,
.accl_id = 0x100, // 加速度计 (十进制256)
.gyro_id = 0x101, // 陀螺仪 (十进制257)
.eulr_id = 0x102, // 欧拉角 (十进制258)
.quat_id = 0x103 // 四元数 (十进制259)
},
},
.shoot_param = {
.trig_step_angle=M_2PI/8,
.shot_delay_time=0.05f,
.shot_burst_num=1,
.fric_motor_param[0] = {
.can = BSP_CAN_1,
.id = 0x201,
.module = MOTOR_M3508,
.reverse = false,
.gear=false,
},
.fric_motor_param[1] = {
.can = BSP_CAN_1,
.id = 0x202,
.module = MOTOR_M3508,
.reverse = true,
.gear=false,
},
.trig_motor_param = {
.can = BSP_CAN_1,
.id = 0x203,
.module = MOTOR_M2006,
.reverse = true,
.gear=true,
},
.fric_follow = {
.k=1.0f,
.p=1.5f,
.i=0.0f,
.d=0.0f,
.i_limit=0.0f,
.out_limit=0.9f,
.d_cutoff_freq=30.0f,
.range=-1.0f,
},
.fric_err = {
.k=1.0f,
.p=4.0f,
.i=0.4f,
.d=0.04f,
.i_limit=0.25f,
.out_limit=0.25f,
.d_cutoff_freq=40.0f,
.range=-1.0f,
},
.trig_omg = {
.k=1.0f,
.p=1.5f,
.i=0.3f,
.d=0.5f,
.i_limit=0.2f,
.out_limit=0.9f,
.d_cutoff_freq=-1.0f,
.range=-1.0f,
},
.trig = {
.k=1.0f,
.p=1.0f,
.i=0.1f,
.d=0.05f,
.i_limit=0.8f,
.out_limit=0.5f,
.d_cutoff_freq=-1.0f,
.range=M_2PI,
},
.filter.fric = {
.in = 30.0f,
.out = 30.0f,
},
.filter.trig = {
.in = 30.0f,
.out = 30.0f,
},
},
.chassis_param = {
.yaw={
.k=1.0f,
.p=1.0f,
.i=0.0f,
.d=0.3f,
.i_limit=0.0f,
.out_limit=1.0f,
.d_cutoff_freq=30.0f,
.range=M_2PI, /* 2*PI用于处理角度循环误差 */
},
.roll={
.k=0.15f,
.p=0.3f, /* 横滚角腿长补偿比例系数 (降低避免抖动) */
.i=0.0f, /* 横滚角腿长补偿积分系数 (关闭避免震荡) */
.d=0.01f, /* 横滚角腿长补偿微分系数 (关闭避免噪声放大) */
.i_limit=0.0f, /* 积分限幅 */
.out_limit=0.03f, /* 输出限幅,腿长差值限制(m) 降低避免过度补偿 */
.d_cutoff_freq=30.0f, /* 微分截止频率 */
.range=-1.0f, /* 不使用循环误差处理 */
},
.roll_force={
.k=5.0f,
.p=10.0f, /* 横滚角力补偿比例系数 (大幅降低避免抖动) */
.i=0.0f, /* 横滚角力补偿积分系数 */
.d=5.0f, /* 横滚角力补偿微分系数 (降低避免高频抖动) */
.i_limit=0.0f, /* 积分限幅 */
.out_limit=20.0f, /* 输出限幅,力补偿限制(N) 降低避免过度补偿 */
.d_cutoff_freq=30.0f, /* 微分截止频率 */
.range=-1.0f, /* 不使用循环误差处理 */
},
.leg_length={
.k = 40.0f,
.p = 30.0f,
.i = 0.0f,
.d = 1.5f,
.i_limit = 0.0f,
.out_limit = 200.0f,
.d_cutoff_freq = -1.0f,
.range = -1.0f,
},
.leg_theta={
.k=5.0f,
.p=2.0f, /* 摆角比例系数 */
.i=0.0f, /* 摆角积分系数 */
.d=0.0f, /* 摆角微分系数 */
.i_limit=0.0f, /* 积分限幅 */
.out_limit=0.05f, /* 输出限幅,腿长差值限制 */
.d_cutoff_freq=30.0f, /* 微分截止频率 */
.range=-1.0f, /* 不使用循环误差处理 */
},
.tp={
.k=4.0f,
.p=3.0f, /* 俯仰角比例系数 */
.i=0.0f, /* 俯仰角积分系数 */
.d=0.0f, /* 俯仰角微分系数 */
.i_limit=0.0f, /* 积分限幅 */
.out_limit=10.0f, /* 输出限幅,腿长差值限制 */
.d_cutoff_freq=30.0f, /* 微分截止频率 */
.range=-1.0f, /* 不使用循环误差处理 */
},
.low_pass_cutoff_freq = {
.in = 30.0f,
.out = 30.0f,
},
.yaw_motor = { // 云台Yaw轴电机
.can = BSP_CAN_1,
.can_id = 0x1,
.master_id = 0x11,
.module = MOTOR_DM_J4310,
.reverse = false,
},
.joint_param = {
{ // 左髋关节
.can = BSP_CAN_3,
.motor_id = 124,
.host_id = 0xFF,
.module = MOTOR_LZ_RSO3,
.reverse = false,
.mode = MOTOR_LZ_MODE_MOTION,
},
{ // 右髋关节
.can = BSP_CAN_3,
.motor_id = 125,
.host_id = 0xFF,
.module = MOTOR_LZ_RSO3,
.reverse = false,
.mode = MOTOR_LZ_MODE_MOTION,
},
{ // 左膝关节
.can = BSP_CAN_3,
.motor_id = 126,
.host_id = 0xFF,
.module = MOTOR_LZ_RSO3,
.reverse = true,
.mode = MOTOR_LZ_MODE_MOTION,
},
{ // 右膝关节
.can = BSP_CAN_3,
.motor_id = 127,
.host_id = 0xFF,
.module = MOTOR_LZ_RSO3,
.reverse = true,
.mode = MOTOR_LZ_MODE_MOTION,
},
},
.wheel_param = {
{ // 左轮电机
.can = BSP_CAN_3,
.id = 0x142,
.module = MOTOR_LK_MF9025,
.reverse = false,
},
{ // 右轮电机
.can = BSP_CAN_3,
.id = 0x141,
.module = MOTOR_LK_MF9025,
.reverse = true,
},
},
.mech_zero_yaw = 1.78040409f, /* 机械零点 */
.joint_zero = {0.0f, 0.0f, 0.0f, 0.0f}, /* 关节电机零点偏移位置 */
.hip_width = 0.423f, /* 髋宽,即两腿间距 (m)用于Roll几何补偿 */
.vmc_param = {
{ // 左腿
.leg_1 = 0.215f, // 后髋连杆长度 (L1) (m)
.leg_2 = 0.258f, // 后膝连杆长度 (L2) (m)
.leg_3 = 0.258f, // 前膝连杆长度 (L3) (m)
.leg_4 = 0.215f, // 前髋连杆长度 (L4) (m)
.hip_length = 0.0f // 髋宽 (L5) (m)
},
{ // 右腿
.leg_1 = 0.215f, // 后髋连杆长度 (L1) (m)
.leg_2 = 0.258f, // 后膝连杆长度 (L2) (m)
.leg_3 = 0.258f, // 前膝连杆长度 (L3) (m)
.leg_4 = 0.215f, // 前髋连杆长度 (L4) (m)
.hip_length = 0.0f // 髋宽 (L5) (m)
}
},
.lqr_gains = {
.k11_coeff = { -1.997928012118380e+02f, 2.358970856133577e+02f, -1.221432656066952e+02f, -3.660884265594530e+00f }, // theta
.k12_coeff = { 1.144642140244768e+00f, -6.781143989723293e-01f, -8.286867905694857e+00f, -3.233743818654922e-01f }, // d_theta
.k13_coeff = { -2.920908857554099e+01f, 3.294053235814564e+01f, -1.331127106026891e+01f, -2.036633181450379e+00f }, // x
.k14_coeff = { -2.202395151966686e+01f, 2.624258394298977e+01f, -1.238392622003398e+01f, -2.516594294742349e+00f }, // d_x
.k15_coeff = { -5.531234648285231e+01f, 7.666196018790744e+01f, -4.254301644877548e+01f, 1.191958597928930e+01f }, // phi
.k16_coeff = { -8.603393557876432e+00f, 1.181868681749069e+01f, -6.519358011847959e+00f, 2.002836931783026e+00f }, // d_phi
.k21_coeff = { 3.121841964126664e+02f, -2.644789946321499e+02f, 5.653973783920610e+01f, 1.306067415926613e+01f }, // theta
.k22_coeff = { 9.751578045310433e+00f, -8.174866581419979e+00f, 1.060040492386880e+00f, 1.945460420856203e+00f }, // d_theta
.k23_coeff = { -1.589159892148102e+01f, 3.771040781828523e+01f, -2.789168930865428e+01f, 8.354369470743295e+00f }, // x
.k24_coeff = { -3.304075197263637e+01f, 5.411818719230526e+01f, -3.342861600971858e+01f, 9.256855471266778e+00f }, // d_x
.k25_coeff = { 2.574491871362636e+02f, -2.771545105998671e+02f, 1.074894289176479e+02f, 3.130550754680395e+00f }, // phi
.k26_coeff = { 4.162978395880715e+01f, -4.533986766238992e+01f, 1.794589550749570e+01f, 2.032213740678163e-01f }, // d_phi
},
.jump_params = {
.crouch_time_ms = 100,
.launch_time_ms = 120,
.retract_time_ms = 80,
.land_time_ms = 300,
.crouch_leg_length = 0.1f,
.launch_force = 200.0f,
.retract_leg_length = 0.1f, /* 收腿目标更短 */
.retract_force = -120.0f, /* 收腿前馈力加大 */
},
.theta = 0.0f,
.x = 0.0f,
.phi = 0.0f,
},
.ai_param = {
.can = BSP_FDCAN_2,
.vision_id = 0x104,
},
/* USER CODE END robot_config */
};
/* Private function prototypes ---------------------------------------------- */
/* Exported functions ------------------------------------------------------- */
/**
* @brief 获取机器人配置参数
* @return 机器人配置参数指针
*/
Config_RobotParam_t* Config_GetRobotParam(void) {
return &robot_config;
}