From 53d06467d646a835f41b5679a8a875a58d467d79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=95=E6=98=8E=E6=B1=9F?= <246462502@qq.com> Date: Fri, 9 Aug 2024 17:00:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E9=99=90=E5=B9=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/by_fan_control.c | 4 +-- app/jj_motion.c | 74 +++++++++++++++++++++++------------------- app/jj_motion.h | 1 + app/jj_param.c | 2 +- app/page/page_dparam.c | 2 ++ 5 files changed, 47 insertions(+), 36 deletions(-) diff --git a/app/by_fan_control.c b/app/by_fan_control.c index d9c9bd6..1734a12 100644 --- a/app/by_fan_control.c +++ b/app/by_fan_control.c @@ -70,8 +70,8 @@ void by_pwm_update_duty(uint32_t update_pwm_duty1, uint32_t update_pwm_duty2) */ void by_pwm_power_duty(int32_t bpwm_duty_ls, int32_t bpwm_duty_rs, int32_t bpwm_duty_lb, int32_t bpwm_duty_rb) { - bpwm_duty_ls = clip_s32(bpwm_duty_ls, 500, 1000); - bpwm_duty_rs = clip_s32(bpwm_duty_rs, 500, 1000); + bpwm_duty_ls = clip_s32(bpwm_duty_ls, 500, 980); + bpwm_duty_rs = clip_s32(bpwm_duty_rs, 500, 980); bpwm_duty_lb = clip_s32(bpwm_duty_lb, 2500, 6000); bpwm_duty_rb = clip_s32(bpwm_duty_rb, 2500, 6000); pwm_set_duty(FAN_LS_PWM_PIN, bpwm_duty_ls); diff --git a/app/jj_motion.c b/app/jj_motion.c index c7a6d71..33c574f 100644 --- a/app/jj_motion.c +++ b/app/jj_motion.c @@ -64,7 +64,7 @@ float ygy_Kp0 = 2.20f; float ygy_Ki0 = 0.0f; float ygy_Kd0 = 0.0f; // 圆环侧面角度环 -float yuc_Kp=4.4f; +float yuc_Kp = 4.4f; // 速度环 float sp_Kp = 3.40f; float sp_Ki = 3.6f; @@ -81,7 +81,7 @@ float in_pos; float out_pos; float set_pos = 0.0f; // float set_gyro = 0.0f; - +float rate_K = 0; float in_speed; float out_speed; float last_angle; @@ -100,6 +100,7 @@ int cnt6 = 0; int cnt7 = 0; int cnt8 = 0; int cnt9 = 0; +int cnt10 = 0; int if_start = 0; float shock_stop = 0; uint8_t in_state = 0; @@ -110,10 +111,11 @@ int32_t pwm_duty_ls; int32_t pwm_duty_rs; int32_t pwm_duty_lb; int32_t pwm_duty_rb; -float qd_down = 0.0f; -float last_gy = 0.0f; -int32_t last_lb = 0; -int32_t last_rb = 0; +float qd_down = 0.0f; +float last_gy = 0.0f; +int32_t stop_cnt = 0; +int32_t last_lb = 0; +int32_t last_rb = 0; /* 0:无状态 1:弯道 @@ -150,11 +152,6 @@ void sport_motion() get_vol(); in_gyro = imu660ra_gyro_z; - if (fabs(out_gyro) < 700) { - PID_SetOutputLimits(&speed_pid, -0.0f, 2500.0f); - } else { - PID_SetOutputLimits(&speed_pid, -0.0f, 1800.0f); - } ////////////////////////////////////////停车任务/////////////////////////////////////////////// // 抖动停车 if (imu660ra_acc_z <= 800) { @@ -162,12 +159,12 @@ void sport_motion() } else { cnt7 = 0; } - if (cnt7 >= 50 && ((uint32_t)shock_stop ==1||(uint32_t)shock_stop == 2)) { + if (cnt7 >= 50 && ((uint32_t)shock_stop == 1 || (uint32_t)shock_stop == 2)) { bt_fly_flag = bt_run_flag = 0; bt_printf("up"); } // 異常值停车 - if (fabs(in_angle - last_angle) > 45.f&&((uint32_t)shock_stop == 1||(uint32_t)shock_stop == 3)) { + if (fabs(in_angle - last_angle) > 45.f && ((uint32_t)shock_stop == 1 || (uint32_t)shock_stop == 3)) { bt_fly_flag = bt_run_flag = 0; bt_printf("bug"); } @@ -181,8 +178,14 @@ void sport_motion() } // 出界停车 if (2 == in_stop) { - bt_printf("out"); - bt_fly_flag = bt_run_flag = 0; + stop_cnt++; + if (stop_cnt >= 5) { + bt_printf("out"); + stop_cnt = 0; + bt_fly_flag = bt_run_flag = 0; + } + } else { + stop_cnt = 0; } //////////////////////////////////////////////// 动力风扇设置 *///////////////////////////////////////////////////////// if (1 == bt_run_flag) { @@ -191,7 +194,7 @@ void sport_motion() cnt5++; if (if_start == 0) { cnt8++; - if (cnt8 >= 10000) { + if (cnt8 >= 5000) { if_start = 1; } } @@ -200,19 +203,18 @@ void sport_motion() bt_printf("to 直道"); set_speed = set_speed1; + PID_SetTunings(&far_angle_pid, an_Kp1, an_Ki1, an_Kd1); PID_SetTunings(&far_gyro_pid, gy_Kp1, gy_Ki1, gy_Kd1); PID_SetTunings(&pos_pid, po_Kp1, po_Ki1, po_Kd1); - } - if ((last_state != in_state) && in_state == 1) { // 弯道 + } else if ((last_state != in_state) && in_state == 1) { // 弯道 bt_printf("to 入弯"); - set_speed = set_speed0; + set_speed = set_speed0 - fabs(rate_K * myclip_f(in_pos, -50.f, 50.f)); PID_SetTunings(&far_angle_pid, an_Kp0, an_Ki0, an_Kd0); PID_SetTunings(&far_gyro_pid, gy_Kp0, gy_Ki0, gy_Kd0); PID_SetTunings(&pos_pid, cn_Kp1, cn_Ki1, cn_Kd1); - } - if ((last_state != in_state) && (in_state == 3 || in_state == 4)) { // 圆环 + } else if ((last_state != in_state) && (in_state == 3 || in_state == 4)) { // 圆环 bt_printf("to 圆环"); if (in_state == 3) set_speed = set_speed2; @@ -222,8 +224,7 @@ void sport_motion() PID_SetTunings(&far_angle_pid, yu_Kp0, yu_Ki0, yu_Kd0); PID_SetTunings(&far_gyro_pid, ygy_Kp0, ygy_Ki0, ygy_Kd0); PID_SetTunings(&pos_pid, yuc_Kp, cn_Ki1, cn_Kd1); - } - if ((last_state != in_state) && in_state == 5) { // + } else if ((last_state != in_state) && in_state == 5) { // bt_printf("to 障碍"); set_speed = set_speed4; @@ -231,6 +232,11 @@ void sport_motion() PID_SetTunings(&far_gyro_pid, zg_Kp, zg_Ki, zg_Kd); PID_SetTunings(&pos_pid, zp_Kp, zp_Ki, zp_Kd); } + + if (in_state == 1) { + set_speed = set_speed0 - fabs(rate_K * myclip_f(in_pos, -50.f, 50.f)); + } + last_state = in_state; // pid计算 if (cnt1 >= 2) { @@ -240,17 +246,17 @@ void sport_motion() if (cnt2 >= 10) { in_speed = sport_get_speed(); cnt2 = 0; + PID_Compute(&far_angle_pid); } if (cnt5 >= 20) { - PID_Compute(&far_angle_pid); PID_Compute(&pos_pid); PID_Compute(&speed_pid); cnt5 = 0; } // 并级pid,限幅 - pwm_duty_ls = (int32_t)myclip_f(320 - out_pos, 140.0f, 500.f); - pwm_duty_rs = (int32_t)myclip_f(320 + out_pos, 140.0f, 500.f); + pwm_duty_ls = (int32_t)myclip_f(180 - out_pos, 100.0f, 500.f); + pwm_duty_rs = (int32_t)myclip_f(180 + out_pos, 100.0f, 500.f); pwm_duty_lb = (int32_t)myclip_f(out_speed + out_gyro, 1000.0f, 3000.f); pwm_duty_rb = (int32_t)myclip_f(out_speed - out_gyro, 1000.0f, 3000.f); if (pwm_duty_lb - last_lb > 1000) { @@ -273,8 +279,10 @@ void sport_motion() } else { by_pwm_update_duty(bt_fly + 500, bt_fly + 500); // 防止起步拉满 - if (bt_run_flag == 0) - by_pwm_power_duty(0, 0, 4000, 4000); + if (bt_run_flag == 0) { + + by_pwm_power_duty(680, 680, 4000, 4000); + } } } @@ -287,23 +295,23 @@ void sport_pid_init() /* 角度控制 */ PID(&far_angle_pid, &in_angle, &out_angle, &set_angle, an_Kp1, an_Ki1, an_Kd1, _PID_P_ON_E, _PID_CD_REVERSE); PID_SetMode(&far_angle_pid, _PID_MODE_AUTOMATIC); - PID_SetSampleTime(&far_angle_pid, 20); - PID_SetOutputLimits(&far_angle_pid, -4000.0f, 4000.0f); + PID_SetSampleTime(&far_angle_pid, 10); + PID_SetOutputLimits(&far_angle_pid, -6000.0f, 6000.0f); // 侧面位置环 PID(&pos_pid, &in_angle, &out_pos, &set_pos, po_Kp1, po_Ki1, po_Kd1, _PID_P_ON_E, _PID_CD_REVERSE); PID_SetMode(&pos_pid, _PID_MODE_AUTOMATIC); PID_SetSampleTime(&pos_pid, 20); - PID_SetOutputLimits(&pos_pid, -180.0f, 180.0f); + PID_SetOutputLimits(&pos_pid, -320.0f, 320.0f); /* 角速度控制 */ PID(&far_gyro_pid, &in_gyro, &out_gyro, &out_angle, gy_Kp1, gy_Ki1, gy_Kd1, _PID_P_ON_E, _PID_CD_REVERSE); // m是增量 PID_SetMode(&far_gyro_pid, _PID_MODE_AUTOMATIC); PID_SetSampleTime(&far_gyro_pid, 20); - PID_SetOutputLimits(&far_gyro_pid, -1500.0f, 1500.0f); + PID_SetOutputLimits(&far_gyro_pid, -2100.0f, 2100.0f); /* 速度控制 */ PID(&speed_pid, &in_speed, &out_speed, &set_speed, sp_Kp, sp_Ki, sp_Kd, _PID_P_ON_M, _PID_CD_DIRECT); PID_SetMode(&speed_pid, _PID_MODE_AUTOMATIC); PID_SetSampleTime(&speed_pid, 20); - PID_SetOutputLimits(&speed_pid, -0.0f, 1800.0f); + PID_SetOutputLimits(&speed_pid, -0.0f, 2500.0f); } diff --git a/app/jj_motion.h b/app/jj_motion.h index b7b69ac..a3bb6bb 100644 --- a/app/jj_motion.h +++ b/app/jj_motion.h @@ -60,6 +60,7 @@ extern float set_speed4; extern float shock_stop; extern float last_angle; extern float yuc_Kp; +extern float rate_K; extern int32_t pwm_duty_ls; extern int32_t pwm_duty_rs; extern int32_t pwm_duty_lb; diff --git a/app/jj_param.c b/app/jj_param.c index 0d1f4e4..746cc67 100644 --- a/app/jj_param.c +++ b/app/jj_param.c @@ -28,7 +28,7 @@ void jj_param_eeprom_init(void) PARAM_REG(can_Kp1, &cn_Kp1, EFLOAT, 1, "cn_P1:"); // 注冊 PARAM_REG(can_Ki1, &yuc_Kp, EFLOAT, 1, "yu_P1:"); // 注冊 - PARAM_REG(can_Kd1, &cn_Kd1, EFLOAT, 1, "cn_D1:"); + PARAM_REG(can_Kd1, &rate_K, EFLOAT, 1, "ra_K:"); PARAM_REG(fly_pwm, &bt_fly, EFLOAT, 1, "fly:"); diff --git a/app/page/page_dparam.c b/app/page/page_dparam.c index 0539a25..d47b182 100644 --- a/app/page/page_dparam.c +++ b/app/page/page_dparam.c @@ -62,6 +62,8 @@ static void Loop() ips200_show_float(80, 160, out_pos, 4, 1); ips200_show_string(0, 180, "vol"); ips200_show_float(80, 180, (float)now_vol, 4,2); + ips200_show_string(0, 200, "setsp"); + ips200_show_float(80, 200, set_speed, 4,2); ips200_show_string(180, 0, "ls"); ips200_show_float(220, 0, pwm_duty_ls, 4, 1);