reset again pro plus

This commit is contained in:
fcl
2026-03-08 16:22:50 +08:00
parent a99307cd04
commit cffaa9db09
3 changed files with 35 additions and 31 deletions

View File

@@ -153,7 +153,7 @@ void ChassisInit()
PID_Init_Config_s chassis_follow_pid_conf = {
.Kp = 6, // 6
.Ki = 0,
.Kd = 0.495, // 0.5
.Kd = 0.495, // 0.495
.DeadBand = 0.5f,// 启用死区,值为0.5度
//.CoefA = 0.2,
//.CoefB = 0.3,

View File

@@ -15,7 +15,7 @@
// 私有宏,自动将编码器转换成角度值
#define YAW_ALIGN_ANGLE (YAW_CHASSIS_ALIGN_ECD * ECD_ANGLE_COEF_DJI) // 对齐时的角度,0-360
#define PTICH_HORIZON_ANGLE (PITCH_HORIZON_ECD * ECD_ANGLE_COEF_DJI) // pitch水平时电机的角度,0-360
uint16_t around=0;
/* cmd应用包含的模块实例指针和交互信息存储*/
#ifdef GIMBAL_BOARD // 对双板的兼容,条件编译
#include "can_comm.h"
@@ -80,23 +80,23 @@ void RobotCMDInit()
* @brief 根据gimbal app传回的当前电机角度计算和零位的误差
* 单圈绝对角度的范围是0~360,说明文档中有图示
*
*/static float base_total_angle = 0.0f; // 用于计算偏移的基准角度
*///static float base_total_angle = 0.0f; // 用于计算偏移的基准角度
static void CalcOffsetAngle()
{
static float last_offset_angle = 0;
const float smooth_factor = 0.3f; // 平滑因子,0~1之间,值越大平滑效果越明显
const float smooth_factor = 0.4f; // 平滑因子,0~1之间,值越大平滑效果越明显
//const float deadband = 0.5f; // 死区值
const float deadband = 3.0f; // 死区值
// 新增:跟踪模式变化,用于重置基准角度
static chassis_mode_e last_chassis_mode = CHASSIS_NO_FOLLOW;//
// 当从旋转模式切换到跟随模式时,重置基准角度
if (last_chassis_mode == CHASSIS_ROTATE && chassis_cmd_send.chassis_mode == CHASSIS_FOLLOW_GIMBAL_YAW)
{
base_total_angle = gimbal_fetch_data.yaw_motor_total_angle;
last_offset_angle = 0.0f; // 同时重置历史偏移值
}
// static chassis_mode_e last_chassis_mode = CHASSIS_NO_FOLLOW;//
//
//
// // 当从旋转模式切换到跟随模式时,重置基准角度
// if (last_chassis_mode == CHASSIS_ROTATE && chassis_cmd_send.chassis_mode == CHASSIS_FOLLOW_GIMBAL_YAW)
// {
// base_total_angle = gimbal_fetch_data.yaw_motor_total_angle;
// last_offset_angle = 0.0f; // 同时重置历史偏移值
// }
float new_offset = gimbal_fetch_data.yaw_motor_total_angle - YAW_ALIGN_ANGLE;
#if YAW_ECD_GREATER_THAN_4096
@@ -109,22 +109,22 @@ static void CalcOffsetAngle()
new_offset += 360.0f;
/////
// 应用死区
//if (fabs(new_offset) < deadband) {
// new_offset = 0.0f;
// } else if (new_offset > 0) {
// new_offset -= deadband;
//} else {
// new_offset += deadband;
//}//////
if (fabs(new_offset) < deadband) {
new_offset = 0.0f;
} else if (new_offset > 0) {
new_offset -= deadband;
} else {
new_offset += deadband;
}//////
chassis_cmd_send.offset_angle = last_offset_angle *(1.0f - smooth_factor) + new_offset * smooth_factor;
last_offset_angle = chassis_cmd_send.offset_angle;
// 更新模式状态
last_chassis_mode = chassis_cmd_send.chassis_mode;
// 当处于旋转模式时,更新基准角度以防止累积过大误差
if (chassis_cmd_send.chassis_mode == CHASSIS_ROTATE)
{
base_total_angle = gimbal_fetch_data.yaw_motor_total_angle;
}
// // 更新模式状态
// last_chassis_mode = chassis_cmd_send.chassis_mode;
// // 当处于旋转模式时,更新基准角度以防止累积过大误差
// if (chassis_cmd_send.chassis_mode == CHASSIS_ROTATE)
// {
// base_total_angle = gimbal_fetch_data.yaw_motor_total_angle;
// }
// static float angle;
// static float last_diff = 0.0f; // 用于在±180°附近保持上次符号,避免来回跳变
@@ -181,11 +181,15 @@ static void RemoteControlSet()
// 控制底盘和云台运行模式,云台待添加,云台是否始终使用IMU数据?
if (switch_is_up(rc_data[TEMP].rc.switch_right)) // 右侧开关状态[下],底盘跟随云台
{
// around = 0;
chassis_cmd_send.chassis_mode = CHASSIS_ROTATE;
gimbal_cmd_send.gimbal_mode = GIMBAL_GYRO_MODE;
around= chassis_cmd_send.offset_angle/360;
}
else if (switch_is_mid(rc_data[TEMP].rc.switch_right)) // 右侧开关状态[中],底盘和云台分离,底盘保持不转动
{
//gimbal_fetch_data.yaw_motor_total_angle = gimbal_fetch_data.yaw_motor_total_angle-around*360;
chassis_cmd_send.offset_angle = chassis_cmd_send.offset_angle - 360*around;
chassis_cmd_send.chassis_mode = CHASSIS_FOLLOW_GIMBAL_YAW;
gimbal_cmd_send.gimbal_mode = GIMBAL_GYRO_MODE;
}

View File

@@ -27,7 +27,7 @@ void GimbalInit()
.controller_param_init_config = {
.angle_PID = {
//.Kp = 0.685, // 8
.Kp = 0.6, // 8
.Kp = 0.685, // 8
//.Ki = 0.315,
.Ki = 0.25,
.Kd = 0.022,