存了一下最新的pid参数
This commit is contained in:
@@ -9,8 +9,8 @@
|
||||
#define FAN_LB_PWM_A_PIN TIM10_PWM_MAP3_CH2_D3 // 左侧动力风扇
|
||||
#define FAN_LB_PWM_B_PIN TIM10_PWM_MAP3_CH4_D7 // 左侧动力风扇
|
||||
// M1
|
||||
#define FAN_RB_PWM_A_PIN TIM4_PWM_MAP1_CH3_D14 // 右侧动力风扇
|
||||
#define FAN_RB_PWM_B_PIN TIM4_PWM_MAP1_CH1_D12 // 右侧动力风扇
|
||||
#define FAN_RB_PWM_A_PIN TIM4_PWM_MAP1_CH1_D12 // 右侧动力风扇
|
||||
#define FAN_RB_PWM_B_PIN TIM4_PWM_MAP1_CH3_D14 // 右侧动力风扇
|
||||
// M3
|
||||
#define FAN_LS_PWM_A_PIN TIM10_PWM_MAP3_CH1_D1 // 左后动力风扇
|
||||
#define FAN_LS_PWM_B_PIN TIM10_PWM_MAP3_CH3_D5 // 左后动力风扇
|
||||
@@ -83,8 +83,7 @@ void by_pwm_init(void)
|
||||
pwm_init(FAN_LB_PWM_B_PIN, 12000, 0);
|
||||
pwm_init(FAN_RB_PWM_A_PIN, 12000, 0);
|
||||
pwm_init(FAN_RB_PWM_B_PIN, 12000, 0);
|
||||
// while (1)
|
||||
// ;
|
||||
// while (1);
|
||||
// system_delay_ms(3000);
|
||||
// // pwm_init(FAN_LS_PWM_PIN, 50, 1000); // 动力风扇左 1
|
||||
// // pwm_init(FAN_RS_PWM_PIN, 50, 1000); // 动力风扇右 1
|
||||
@@ -135,8 +134,7 @@ void by_pwm_power_duty(int32_t bpwm_duty_ls, int32_t bpwm_duty_rs, int32_t bpwm_
|
||||
if (bpwm_duty_ls >= 0) {
|
||||
pwm_set_duty(FAN_LS_PWM_A_PIN, bpwm_duty_ls);
|
||||
pwm_set_duty(FAN_LS_PWM_B_PIN, 0);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pwm_set_duty(FAN_LS_PWM_A_PIN, 0);
|
||||
pwm_set_duty(FAN_LS_PWM_B_PIN, -1 * pwm_duty_ls);
|
||||
}
|
||||
@@ -144,8 +142,7 @@ void by_pwm_power_duty(int32_t bpwm_duty_ls, int32_t bpwm_duty_rs, int32_t bpwm_
|
||||
if (bpwm_duty_rs >= 0) {
|
||||
pwm_set_duty(FAN_RS_PWM_A_PIN, bpwm_duty_rs);
|
||||
pwm_set_duty(FAN_RS_PWM_B_PIN, 0);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pwm_set_duty(FAN_RS_PWM_A_PIN, 0);
|
||||
pwm_set_duty(FAN_RS_PWM_B_PIN, -1 * pwm_duty_rs);
|
||||
}
|
||||
@@ -153,7 +150,7 @@ void by_pwm_power_duty(int32_t bpwm_duty_ls, int32_t bpwm_duty_rs, int32_t bpwm_
|
||||
if (bpwm_duty_lb >= 0) {
|
||||
pwm_set_duty(FAN_LB_PWM_A_PIN, bpwm_duty_lb);
|
||||
pwm_set_duty(FAN_LB_PWM_B_PIN, 0);
|
||||
} else {
|
||||
} else {
|
||||
pwm_set_duty(FAN_LB_PWM_A_PIN, 0);
|
||||
pwm_set_duty(FAN_LB_PWM_B_PIN, -1 * bpwm_duty_lb);
|
||||
}
|
||||
@@ -161,7 +158,7 @@ void by_pwm_power_duty(int32_t bpwm_duty_ls, int32_t bpwm_duty_rs, int32_t bpwm_
|
||||
if (bpwm_duty_rb >= 0) {
|
||||
pwm_set_duty(FAN_RB_PWM_A_PIN, bpwm_duty_rb);
|
||||
pwm_set_duty(FAN_RB_PWM_B_PIN, 0);
|
||||
} else{
|
||||
} else {
|
||||
pwm_set_duty(FAN_RB_PWM_A_PIN, 0);
|
||||
pwm_set_duty(FAN_RB_PWM_B_PIN, -1 * bpwm_duty_rb);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ PID_TypeDef angle_pid;
|
||||
PID_TypeDef far_gyro_pid;
|
||||
PID_TypeDef speed_pid;
|
||||
// 弯道后面风扇角度环
|
||||
float an_Kp0 = 51.0f;
|
||||
float an_Kp0 = 40.0f;
|
||||
float an_Ki0 = 0.0f;
|
||||
float an_Kd0 = 0.0f;
|
||||
// 直道后面风扇角度环
|
||||
@@ -20,15 +20,15 @@ float an_Kp1 = 42.0f;
|
||||
float an_Ki1 = 0.0f;
|
||||
float an_Kd1 = 0.0f;
|
||||
// 圆环后面风扇角度环
|
||||
float yu_Kp0 = 40.0f;
|
||||
float yu_Kp0 = 60.0f;
|
||||
float yu_Ki0 = 0.0f;
|
||||
float yu_Kd0 = 0.0f;
|
||||
// 弯道侧面风扇角度环
|
||||
float cn_Kp1 = 420.0f;
|
||||
float cn_Kp1 = 300.0f;
|
||||
float cn_Ki1 = 0.f;
|
||||
float cn_Kd1 = 0.0f;
|
||||
// 直道侧面风扇角度环
|
||||
float po_Kp1 = 600.0f;
|
||||
float po_Kp1 = 400.0f;
|
||||
float po_Ki1 = 0.0f;
|
||||
float po_Kd1 = 0.0f;
|
||||
// 期望和当前量
|
||||
@@ -39,15 +39,15 @@ float in_pos;
|
||||
float out_pos;
|
||||
float set_pos = 0.0f;
|
||||
// 弯道角速度环
|
||||
float gy_Kp0 = 2.50f;
|
||||
float gy_Kp0 = 4.50f;
|
||||
float gy_Ki0 = 0.0f;
|
||||
float gy_Kd0 = 0.0f;
|
||||
// 直道角速度环
|
||||
float gy_Kp1 = 4.2f;
|
||||
float gy_Kp1 = 3.2f;
|
||||
float gy_Ki1 = 0.0f;
|
||||
float gy_Kd1 = 0.0f;
|
||||
// 圆环角速度环
|
||||
float ygy_Kp0 = 0.0f;
|
||||
float ygy_Kp0 = 4.0f;
|
||||
float ygy_Ki0 = 0.0f;
|
||||
float ygy_Kd0 = 0.0f;
|
||||
// 当前和输入量
|
||||
@@ -55,21 +55,22 @@ float in_gyro;
|
||||
float out_gyro;
|
||||
// float set_gyro = 0.0f;
|
||||
// 速度环
|
||||
float sp_Kp = 16.0f;
|
||||
float sp_Ki = 42.f;
|
||||
float sp_Kp = 10.0f;
|
||||
float sp_Ki = 100.f;
|
||||
float sp_Kd = 0.0f;
|
||||
|
||||
float in_speed;
|
||||
float out_speed;
|
||||
|
||||
float set_speed;
|
||||
float set_speed0 = 520.0f;
|
||||
float set_speed1 = 900.0f;
|
||||
float set_speed2 = 550.f;
|
||||
float set_speed0 = 800.0f;
|
||||
float set_speed1 = 1100.0f;
|
||||
float set_speed2 = 810.f;
|
||||
int cnt1 = 0;
|
||||
int cnt2 = 0;
|
||||
int cnt3 = 0;
|
||||
int cnt4 = 0;
|
||||
int cnt5 = 0;
|
||||
uint8_t cnt3_flag = 0;
|
||||
uint8_t in_state = 0;
|
||||
uint8_t in_stop = 0;
|
||||
@@ -124,6 +125,7 @@ void sport_motion()
|
||||
if (1 == bt_run_flag) {
|
||||
cnt1++;
|
||||
cnt2++;
|
||||
cnt5++;
|
||||
// pid参数切换
|
||||
if ((last_state != in_state) && (in_state == 0 || in_state == 2)) { // 直道
|
||||
cnt3_flag = 0;
|
||||
@@ -148,19 +150,28 @@ void sport_motion()
|
||||
bt_printf("to 圆环");
|
||||
set_speed = set_speed2;
|
||||
cnt3_flag = 1;
|
||||
PID_SetTunings(&far_angle_pid, an_Kp0, an_Ki0, an_Kd0);
|
||||
PID_SetTunings(&far_angle_pid, an_Kp0, an_Ki0, an_Kd0);
|
||||
PID_SetTunings(&far_angle_pid, yu_Kp0, yu_Ki0, yu_Kd0);
|
||||
PID_SetTunings(&far_gyro_pid, ygy_Kp0, ygy_Ki0, ygy_Kd0);
|
||||
|
||||
PID_SetTunings(&angle_pid, cn_Kp1, cn_Ki1, cn_Kd1);
|
||||
}
|
||||
last_state = in_state;
|
||||
if (cnt3_flag == 1 && (in_state == 1 || in_state == 3)) {
|
||||
cnt3++;
|
||||
if (cnt3 >= 500) // 200ms
|
||||
{
|
||||
bt_printf("to 环内");
|
||||
cnt3_flag = 2;
|
||||
cnt3 = 0;
|
||||
if (in_state == 3) {
|
||||
if (cnt3 >= 1500) // 200ms
|
||||
{
|
||||
bt_printf("to 环内");
|
||||
cnt3_flag = 2;
|
||||
cnt3 = 0;
|
||||
}
|
||||
} else {
|
||||
if (cnt3 >= 500) // 200ms
|
||||
{
|
||||
bt_printf("to 环内");
|
||||
cnt3_flag = 2;
|
||||
cnt3 = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,23 +181,25 @@ void sport_motion()
|
||||
}
|
||||
if (cnt2 >= 10) {
|
||||
in_speed = sport_get_speed();
|
||||
PID_Compute(&speed_pid);
|
||||
|
||||
PID_Compute(&far_angle_pid);
|
||||
PID_Compute(&angle_pid);
|
||||
cnt2 = 0;
|
||||
}
|
||||
if (cnt5 >= 20) {
|
||||
PID_Compute(&speed_pid);
|
||||
PID_Compute(&far_angle_pid);
|
||||
PID_Compute(&angle_pid);
|
||||
cnt5 = 0;
|
||||
}
|
||||
if (in_state == 0 || in_state == 2) {
|
||||
pwm_duty_ls = (int32_t)myclip_f(-out_pos, 0.0f, 6000.f);
|
||||
pwm_duty_rs = (int32_t)myclip_f(out_pos, 0.0f, 6000.f);
|
||||
pwm_duty_lb = (int32_t)myclip_f(out_speed + out_gyro, 0.0f, 6000.f);
|
||||
pwm_duty_rb = (int32_t)myclip_f(out_speed - out_gyro, 0.0f, 6000.f);
|
||||
pwm_duty_ls = (int32_t)myclip_f(-out_pos, 0.0f, 7000.f);
|
||||
pwm_duty_rs = (int32_t)myclip_f(out_pos, 0.0f, 7000.f);
|
||||
pwm_duty_lb = (int32_t)myclip_f(out_speed + out_gyro, 0.0f, 5000.f);
|
||||
pwm_duty_rb = (int32_t)myclip_f(out_speed - out_gyro, 0.0f, 5000.f);
|
||||
} else if (in_state == 1 || in_state == 3) {
|
||||
|
||||
pwm_duty_ls = (int32_t)myclip_f(-out_pos, -6000.0f, 6000.f);
|
||||
pwm_duty_rs = (int32_t)myclip_f(out_pos, -6000.0f, 6000.f);
|
||||
pwm_duty_lb = (int32_t)myclip_f(out_speed + out_gyro, -6000.0f, 6000.f);
|
||||
pwm_duty_rb = (int32_t)myclip_f(out_speed - out_gyro, -6000.0f, 6000.f);
|
||||
pwm_duty_ls = (int32_t)myclip_f(-out_pos, -7000.0f, 7000.f);
|
||||
pwm_duty_rs = (int32_t)myclip_f(out_pos, -7000.0f, 7000.f);
|
||||
pwm_duty_lb = (int32_t)myclip_f(out_speed + out_gyro, 0.0f, 5000.f);
|
||||
pwm_duty_rb = (int32_t)myclip_f(out_speed - out_gyro, 0.0f, 5000.f);
|
||||
}
|
||||
|
||||
by_pwm_power_duty((int32_t)pwm_duty_ls, (int32_t)pwm_duty_rs, (int32_t)pwm_duty_lb, (int32_t)pwm_duty_rb);
|
||||
@@ -197,8 +210,8 @@ void sport_motion()
|
||||
if (bt_fly_flag == 0) {
|
||||
by_pwm_update_duty(0 + 500, 0 + 500);
|
||||
} else {
|
||||
if (in_state == 1 && cnt3_flag == 1) {
|
||||
float tt = 60 * fabs(tanf(myclip_f(in_angle, -60.f, 60.f) / 180 * PI));
|
||||
if ((in_state == 1 || in_state == 3) && cnt3_flag == 1) {
|
||||
float tt =0;//60 * fabs(tanf(myclip_f(in_angle, -60.f, 60.f) / 180 * PI));
|
||||
by_pwm_update_duty(bt_fly + 500 - tt, bt_fly + 500 - tt);
|
||||
|
||||
} else {
|
||||
@@ -216,23 +229,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, 10);
|
||||
PID_SetOutputLimits(&far_angle_pid, -3000.0f, 3000.0f);
|
||||
PID_SetSampleTime(&far_angle_pid, 20);
|
||||
PID_SetOutputLimits(&far_angle_pid, -4000.0f, 4000.0f);
|
||||
|
||||
PID(&angle_pid, &in_angle, &out_pos, &set_pos, po_Kp1, po_Ki1, po_Kd1, _PID_P_ON_E, _PID_CD_REVERSE);
|
||||
PID_SetMode(&angle_pid, _PID_MODE_AUTOMATIC);
|
||||
PID_SetSampleTime(&angle_pid, 10);
|
||||
PID_SetOutputLimits(&angle_pid, -6000.0f, 6000.0f);
|
||||
PID_SetSampleTime(&angle_pid, 20);
|
||||
PID_SetOutputLimits(&angle_pid, -7000.0f, 7000.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, 10);
|
||||
PID_SetSampleTime(&far_gyro_pid, 20);
|
||||
PID_SetOutputLimits(&far_gyro_pid, -5000.0f, 5000.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, 10);
|
||||
PID_SetOutputLimits(&speed_pid, -4000.0f, 5000.0f);
|
||||
PID_SetSampleTime(&speed_pid, 20);
|
||||
PID_SetOutputLimits(&speed_pid, -2000.0f, 4000.0f);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ static void Loop()
|
||||
ips200_show_string(0, 60, "accz");
|
||||
ips200_show_float(80, 60, (float)imu660ra_acc_z, 6, 1);
|
||||
ips200_show_string(0, 80, "accy");
|
||||
ips200_show_float(80, 80, (float)imu660ra_acc_y, 4, 2);
|
||||
ips200_show_float(80, 80, (float)imu660ra_gyro_z, 4, 2);
|
||||
ips200_show_string(0, 100, "speed");
|
||||
ips200_show_float(80, 100, in_speed, 4, 4);
|
||||
ips200_show_string(0, 120, "outang");
|
||||
|
||||
Reference in New Issue
Block a user