优化龙头模式

This commit is contained in:
myperworld committed 2025-12-06 15:22:37 +08:00
1 parent 0b8a6cf00e
commit d78c65dc8e
3 files changed
+31 -19

No files matched your search

+8 -3
View File
@@ -31,13 +31,18 @@ void parseSingleParam(char* cmd) {
// 匹配参数名并赋值(访问全局对象,已在 SerialParser.h 中声明) // 匹配参数名并赋值(访问全局对象,已在 SerialParser.h 中声明)
if (strcmp(param_name, "kp") == 0) { if (strcmp(param_name, "kp") == 0) {
pid_super_balance.P = param_val; pid_speed.P = param_val;
} else if (strcmp(param_name, "ki") == 0) { } else if (strcmp(param_name, "ki") == 0) {
pid_super_balance.I = param_val; pid_speed.I = param_val;
} else if (strcmp(param_name, "kd") == 0) { } else if (strcmp(param_name, "kd") == 0) {
pid_super_balance.D = param_val; pid_speed.D = param_val;
} else if (strcmp(param_name, "zaccel_threshold") == 0) { } else if (strcmp(param_name, "zaccel_threshold") == 0) {
zaccel_threshold = param_val; zaccel_threshold = param_val;
} else if (strcmp(param_name, "dragon_joyx_factor") == 0) {
dragon_joyx_factor = param_val;
// } else if (strcmp(param_name, "go_shrink_v") == 0) { // } else if (strcmp(param_name, "go_shrink_v") == 0) {
// go_shrink_v = param_val; // go_shrink_v = param_val;
// } else if (strcmp(param_name, "servo_up_height") == 0) { // } else if (strcmp(param_name, "servo_up_height") == 0) {
+1
View File
@@ -10,6 +10,7 @@
extern PIDController pid_super_balance; extern PIDController pid_super_balance;
extern PIDController pid_speed; extern PIDController pid_speed;
extern float zaccel_threshold; extern float zaccel_threshold;
extern float dragon_joyx_factor;
// extern float obstacle_pitch; // extern float obstacle_pitch;
+22 -16
View File
@@ -253,7 +253,11 @@ RobotAction* currentAction = NULL;
// 龙头模式 // 龙头模式
bool dragon_head_mode = false; // 龙头模式标志 bool dragon_head_mode = false; // 龙头模式标志
float dragon_joyx_factor = 1.0f;
int convertedJ1PotX;
int convertedJ2PotX;
int last_convertedJ1PotX;
int last_convertedJ2PotX;
typedef struct typedef struct
{ {
@@ -585,7 +589,7 @@ void lqr_balance_loop()
} }
// 超级平衡模式 误差=实际角度 - 默认零点 // 超级平衡模式 误差=实际角度 - 默认零点
if (super_balance_mode && !is_falling && robot_enabled && !sitting_down && !jump_flag && !dragon_head_mode) { if (super_balance_mode && !is_falling && robot_enabled && !sitting_down && !jump_flag ) {
float balance_joyy = pid_super_balance(LQR_angle -pitch_zeropoint); float balance_joyy = pid_super_balance(LQR_angle -pitch_zeropoint);
balance_joyy = constrain(balance_joyy, -100.0f, 100.0f); balance_joyy = constrain(balance_joyy, -100.0f, 100.0f);
wrobot.joyy = balance_joyy; wrobot.joyy = balance_joyy;
@@ -667,9 +671,10 @@ void lqr_balance_loop()
pid_lqr_u.error_prev = 0; // 输出积分清零 pid_lqr_u.error_prev = 0; // 输出积分清零
} }
if(jump_flag){
if (wrobot.height < 50){ pid_speed.P = 0.5;
pid_speed.P = 0.7; } if (wrobot.height < 50){
pid_speed.P = 0.8;
}else if (wrobot.height < 64){ }else if (wrobot.height < 64){
pid_speed.P = 0.6; pid_speed.P = 0.6;
}else{ }else{
@@ -1056,36 +1061,37 @@ void processControllerData(const XboxControllerNotificationParser& remoteData) {
} }
// 左右转向 左摇杆X轴:先映射到-100~100,再按比例放大到-100~100 // 左右转向 左摇杆X轴:先映射到-100~100,再按比例放大到-100~100
if(!dragon_head_mode){ // 龙头模式 if(!dragon_head_mode){ // 双手控制模式
int convertedJ1PotX = constrain( convertedJ1PotX = constrain(
map(remoteData.joyLHori, 0, 65535, -100, 100), map(remoteData.joyLHori, 0, 65535, -100, 100),
-100, 100 -100, 100
); );
if(abs(convertedJ1PotX) > deadZone if(abs(convertedJ1PotX) > deadZone
&& ( (last_joyLHori > 0 && ( remoteData.joyLHori- last_joyLHori)> 0 ) && ( (last_convertedJ1PotX > 0 && convertedJ1PotX >= last_convertedJ1PotX )
|| (last_joyLHori <0 && ( remoteData.joyLHori- last_joyLHori)< 0 ) || (last_convertedJ1PotX < 0 && convertedJ1PotX <= last_convertedJ1PotX)
)) { // 左右运动 -100 到 100 )) { // 左右运动 -100 到 100
wrobot.joyx = convertedJ1PotX; wrobot.joyx = convertedJ1PotX;
} else { } else {
wrobot.joyx = 0; wrobot.joyx = 0;
} }
}else{ }else{ // 龙头模式
int convertedJ2PotX = constrain( convertedJ2PotX = constrain(
map(remoteData.joyRHori, 0, 65535, -100, 100), map(remoteData.joyRHori, 0, 65535, -100, 100),
-100, 100 -100, 100
); );
if(abs(convertedJ2PotX) > deadZone if(abs(convertedJ2PotX) > deadZone
&& ( (last_joyRHori > 0 && ( remoteData.joyRHori- last_joyRHori)> 0 ) && ( (last_convertedJ2PotX > 0 && convertedJ2PotX >= last_convertedJ2PotX )
|| (last_joyRHori <0 && ( remoteData.joyRHori- last_joyRHori)< 0 ) || (last_convertedJ2PotX <0 && convertedJ2PotX <= last_convertedJ2PotX )
)) { // 左右运动 -100 到 100 )) { // 左右运动 -100 到 100
wrobot.joyx = convertedJ2PotX * 0.3; wrobot.joyx = convertedJ2PotX * dragon_joyx_factor;
} else { } else {
wrobot.joyx = 0; wrobot.joyx = 0;
} }
} }
last_joyRHori = remoteData.joyRHori;
last_joyLHori = remoteData.joyLHori; last_convertedJ1PotX = convertedJ1PotX;
last_convertedJ2PotX = convertedJ2PotX;
// 智能计算wrobot.height ,根据前后速度, // 智能计算wrobot.height ,根据前后速度,