mirror of
https://gitee.com/dlmu-cone/bf_original_balance_chassis
synced 2026-07-23 19:25:09 +08:00
修复电机反转bug,添加部分注释
This commit is contained in:
@@ -22,49 +22,54 @@ static float del_t;
|
||||
|
||||
/* 底盘拥有的模块实例 */
|
||||
static attitude_t *imu_data;
|
||||
static RC_ctrl_t *rc_data; // 调试用
|
||||
static RC_ctrl_t *rc_data; // 底盘单独调试用
|
||||
static Referee_Interactive_info_t my_ui;
|
||||
static referee_info_t *referee_data;
|
||||
static Chassis_Ctrl_Cmd_s chassis_cmd_recv; // syh
|
||||
static Chassis_Ctrl_Cmd_s chassis_cmd_recv;
|
||||
static Chassis_Upload_Data_s chassis_feed;
|
||||
static CANCommInstance *ci;
|
||||
static SuperCapInstance *cap; // syh
|
||||
static SuperCapInstance *cap;
|
||||
|
||||
// 四个关节电机和两个驱动轮电机
|
||||
static HTMotorInstance *lf, *lb, *rf, *rb, *joint[4]; // 指针数组方便传参和调试
|
||||
static LKMotorInstance *l_driven, *r_driven, *driven[2];
|
||||
|
||||
// 两个腿的参数,0为左腿,1为右腿
|
||||
static LinkNPodParam l_side, r_side; // syh phi5
|
||||
static LinkNPodParam l_side, r_side;
|
||||
static ChassisParam chassis;
|
||||
|
||||
// 综合运动补偿的PID控制器
|
||||
static PIDInstance steer_p_pid, steer_v_pid; // 转向PID,有转向指令时使用IMU的加速度反馈积分以获取速度和位置状态量
|
||||
static PIDInstance anti_crash_pid, phi5_pid; // 抗劈叉,将输出以相反的方向叠加到左右腿的上
|
||||
static PIDInstance leglen_pid_l, leglen_pid_r; // 用PD模拟弹簧,不要积分(弹簧是无积分二阶系统),增益不可过大否则抗外界冲击响应时太"硬"
|
||||
static PIDInstance legdot_pid_l, legdot_pid_r;
|
||||
static PIDInstance roll_compensate_pid, rolldot_pid; // roll轴补偿,用于保持机体水平
|
||||
|
||||
static Robot_Status_e chassis_status;
|
||||
|
||||
void BalanceInit()
|
||||
{
|
||||
referee_data = UITaskInit(&huart6, &my_ui);
|
||||
rc_data = RemoteControlInit(&huart3);
|
||||
imu_data = INS_Init();
|
||||
|
||||
// 双板通信
|
||||
CANComm_Init_Config_s commconf = {
|
||||
.can_config = {
|
||||
.can_handle = &hcan1,
|
||||
.can_handle = &hcan2,
|
||||
.tx_id = 0x40,
|
||||
.rx_id = 0x41},
|
||||
.recv_data_len = sizeof(Chassis_Ctrl_Cmd_s),
|
||||
.send_data_len = sizeof(Chassis_Upload_Data_s)};
|
||||
ci = CANCommInit(&commconf);
|
||||
imu_data = INS_Init();
|
||||
|
||||
// 超级电容
|
||||
SuperCap_Init_Config_s cap_conf = {
|
||||
.can_config = {
|
||||
.can_handle = &hcan1,
|
||||
.can_handle = &hcan2,
|
||||
.tx_id = 0x302, // todo 电容id
|
||||
.rx_id = 0x301}};
|
||||
cap = SuperCapInit(&cap_conf);
|
||||
|
||||
// 关节电机
|
||||
Motor_Init_Config_s joint_conf = {
|
||||
// 写一个,剩下的修改方向和id即可
|
||||
.can_init_config = {
|
||||
@@ -101,6 +106,7 @@ void BalanceInit()
|
||||
joint_conf.can_init_config.rx_id = 11;
|
||||
joint[RB] = rb = HTMotorInit(&joint_conf);
|
||||
|
||||
// 驱动轮电机
|
||||
Motor_Init_Config_s driven_conf = {
|
||||
// 写一个,剩下的修改方向和id即可
|
||||
.can_init_config.can_handle = &hcan2,
|
||||
@@ -118,6 +124,7 @@ void BalanceInit()
|
||||
driven_conf.can_init_config.tx_id = 2;
|
||||
driven[RD] = r_driven = LKMotorInit(&driven_conf);
|
||||
|
||||
// 转向PID
|
||||
PID_Init_Config_s steer_p_pid_conf = {
|
||||
.Kp = 2,
|
||||
.Kd = 1,
|
||||
@@ -140,6 +147,7 @@ void BalanceInit()
|
||||
};
|
||||
PIDInit(&steer_v_pid, &steer_v_pid_conf);
|
||||
|
||||
// 抗劈叉
|
||||
PID_Init_Config_s anti_crash_pid_conf = {
|
||||
.Kp = 8,
|
||||
.Kd = 2.5,
|
||||
@@ -154,6 +162,7 @@ void BalanceInit()
|
||||
};
|
||||
PIDInit(&anti_crash_pid, &anti_crash_pid_conf);
|
||||
|
||||
// 腿长控制
|
||||
PID_Init_Config_s leg_length_pid_conf = {
|
||||
.Kp = 450,
|
||||
.Kd = 150,
|
||||
@@ -168,6 +177,7 @@ void BalanceInit()
|
||||
PIDInit(&leglen_pid_l, &leg_length_pid_conf);
|
||||
PIDInit(&leglen_pid_r, &leg_length_pid_conf);
|
||||
|
||||
// 横滚角补偿
|
||||
PID_Init_Config_s roll_compensate_pid_conf = {
|
||||
.Kp = 0.0008f,
|
||||
.Kd = 0.00065f,
|
||||
@@ -179,7 +189,7 @@ void BalanceInit()
|
||||
};
|
||||
PIDInit(&roll_compensate_pid, &roll_compensate_pid_conf);
|
||||
|
||||
l_side.target_len = r_side.target_len = 0.23;
|
||||
l_side.target_len = r_side.target_len = 0.23; // 初始腿长
|
||||
chassis.vel_cov = 1000; // 初始化速度协方差
|
||||
chassis_status = ROBOT_READY;
|
||||
DWT_GetDeltaT(&balance_dwt_cnt);
|
||||
@@ -195,7 +205,8 @@ static void EnableAllMotor() /* 打开所有电机 */
|
||||
|
||||
/* 切换底盘遥控器控制和云台双板控制 */
|
||||
static void ControlSwitch()
|
||||
{ // 右侧拨杆向下,进入遥控器底盘控制,此时不响应云台控制指令
|
||||
{
|
||||
// 右侧拨杆向下,进入遥控器底盘控制,此时不响应云台控制指令
|
||||
if (switch_is_down(rc_data->rc.switch_right) && RemoteControlIsOnline())
|
||||
{
|
||||
if (rc_data->rc.rocker_l1 < -600)
|
||||
@@ -220,6 +231,9 @@ static void ControlSwitch()
|
||||
|
||||
void BalanceTask()
|
||||
{
|
||||
|
||||
del_t = DWT_GetDeltaT(&balance_dwt_cnt);
|
||||
|
||||
// 切换遥控器控制or云台板控制
|
||||
ControlSwitch();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user