日常更新

This commit is contained in:
2024-06-05 20:17:45 +08:00
parent 55cc6b31f3
commit 5dd6ddd802
6 changed files with 57 additions and 42 deletions

View File

@@ -153,7 +153,7 @@ void by_pwm_power_duty(int32_t bpwm_duty_ls, int32_t bpwm_duty_rs, int32_t bpwm_
if (bpwm_duty_lb >= 0) { if (bpwm_duty_lb >= 0) {
pwm_set_duty(FAN_LB_PWM_A_PIN, bpwm_duty_lb); pwm_set_duty(FAN_LB_PWM_A_PIN, bpwm_duty_lb);
pwm_set_duty(FAN_LB_PWM_B_PIN, 0); pwm_set_duty(FAN_LB_PWM_B_PIN, 0);
} else if (bpwm_duty_lb < -1000 && out_speed < -2000.0f) { } else {
pwm_set_duty(FAN_LB_PWM_A_PIN, 0); pwm_set_duty(FAN_LB_PWM_A_PIN, 0);
pwm_set_duty(FAN_LB_PWM_B_PIN, -1 * bpwm_duty_lb); pwm_set_duty(FAN_LB_PWM_B_PIN, -1 * bpwm_duty_lb);
} }
@@ -161,7 +161,7 @@ void by_pwm_power_duty(int32_t bpwm_duty_ls, int32_t bpwm_duty_rs, int32_t bpwm_
if (bpwm_duty_rb >= 0) { if (bpwm_duty_rb >= 0) {
pwm_set_duty(FAN_RB_PWM_A_PIN, bpwm_duty_rb); pwm_set_duty(FAN_RB_PWM_A_PIN, bpwm_duty_rb);
pwm_set_duty(FAN_RB_PWM_B_PIN, 0); pwm_set_duty(FAN_RB_PWM_B_PIN, 0);
} else if (bpwm_duty_rb < -1000 && out_speed < -2000.0f) { } else{
pwm_set_duty(FAN_RB_PWM_A_PIN, 0); pwm_set_duty(FAN_RB_PWM_A_PIN, 0);
pwm_set_duty(FAN_RB_PWM_B_PIN, -1 * bpwm_duty_rb); pwm_set_duty(FAN_RB_PWM_B_PIN, -1 * bpwm_duty_rb);
} }

View File

@@ -6,7 +6,7 @@ uint8_t bt_buffer; // 接收字符存入
uint8_t bt_run_flag = 0; uint8_t bt_run_flag = 0;
uint8_t bt_fly_flag = 0; uint8_t bt_fly_flag = 0;
uint32_t bt_run = 0; uint32_t bt_run = 0;
uint32_t bt_fly = 300; uint32_t bt_fly = 250;
enum bt_order { enum bt_order {
Fly_ctrl = 0x01, // 起飞转换 Fly_ctrl = 0x01, // 起飞转换
Fly_up = 0x02, // 起飞程度增加 Fly_up = 0x02, // 起飞程度增加

View File

@@ -23,7 +23,6 @@ float an_Kd1 = 0.0f;
float in_angle; float in_angle;
float set_angle = 0.0f; float set_angle = 0.0f;
float out_angle; float out_angle;
float cn_Kp1 = 45.0f; float cn_Kp1 = 45.0f;
float cn_Ki1 = 0.f; float cn_Ki1 = 0.f;
float cn_Kd1 = 0.0f; float cn_Kd1 = 0.0f;
@@ -62,9 +61,11 @@ float temp_data = 0;
float set_speed = 100.0f; float set_speed = 100.0f;
float set_speed0 = 200.0f; float set_speed0 = 200.0f;
float set_speed1 = 300.0f; float set_speed1 = 300.0f;
float set_speed2 = 500.f;
int cnt1 = 0; int cnt1 = 0;
int cnt2 = 0; int cnt2 = 0;
int cnt3 = 0; int cnt3 = 0;
int cnt4 = 0;
uint8_t cnt3_flag = 0; uint8_t cnt3_flag = 0;
uint8_t in_state = 0; uint8_t in_state = 0;
uint8_t in_stop = 0; uint8_t in_stop = 0;
@@ -109,69 +110,83 @@ void sport_motion(void)
if (1 == bt_run_flag) { if (1 == bt_run_flag) {
cnt1++; cnt1++;
cnt2++; cnt2++;
cnt4++;
// pid参数切换 // pid参数切换
if ((last_state != in_state) && (in_state == 0 || in_state == 2)) { // 直道 if ((last_state != in_state) && (in_state == 0 || in_state == 2)) { // 直道
cnt3_flag = 0; cnt3_flag = 0;
cnt3 = 0; cnt3 = 0;
bt_printf("to 0"); bt_printf("to 直道");
set_speed = set_speed1; set_speed = set_speed1;
PID_SetTunings(&far_angle_pid, an_Kp1, an_Ki1, an_Kd1); PID_SetTunings(&far_angle_pid, an_Kp1, an_Ki1, an_Kd1);
PID_SetTunings(&far_gyro_pid, gy_Kp1, gy_Ki1, gy_Kd1); PID_SetTunings(&far_gyro_pid, gy_Kp1, gy_Ki1, gy_Kd1);
} }
if ((last_state != in_state) && (in_state == 1 || in_state == 3)) { // 弯道 if ((last_state != in_state) && in_state == 1) { // 弯道
bt_printf("to 1"); bt_printf("to 入弯");
set_speed = set_speed0; set_speed = set_speed0;
cnt3_flag = 1; 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_gyro_pid, gy_Kp0, gy_Ki0, gy_Kd0); PID_SetTunings(&far_gyro_pid, gy_Kp0, gy_Ki0, gy_Kd0);
} }
if ((last_state != in_state) && in_state == 3) { // 弯道
bt_printf("to 圆环");
set_speed = set_speed2;
cnt3_flag = 1;
PID_SetTunings(&far_angle_pid, an_Kp0, an_Ki0, an_Kd0);
PID_SetTunings(&far_gyro_pid, gy_Kp0, gy_Ki0, gy_Kd0);
}
last_state = in_state; last_state = in_state;
if (cnt3_flag == 1 && in_state == 1) { if (cnt3_flag == 1 && (in_state == 1 || in_state == 3)) {
cnt3++; cnt3++;
if (cnt3 >= 500) // 200ms if (cnt3 >= 500) // 200ms
{ {
bt_printf("to 2"); bt_printf("to 环内");
cnt3_flag = 2; cnt3_flag = 2;
cnt3 = 0; cnt3 = 0;
} }
} }
if (cnt1 >= 2) {
PID_Compute(&far_gyro_pid); PID_Compute(&far_gyro_pid);
PID_Compute(&near_pos_pid);
if (cnt1 >= 10) {
in_speed = sport_get_speed();
PID_Compute(&speed_pid);
cnt1 = 0; cnt1 = 0;
} }
if (cnt2 >= 20) { if (cnt2 >= 10) {
cnt2 = 0; cnt2 = 0;
PID_Compute(&near_pos_pid);
}
if (cnt4 >= 10) {
in_speed = sport_get_speed();
PID_Compute(&speed_pid);
PID_Compute(&far_angle_pid); PID_Compute(&far_angle_pid);
PID_Compute(&angle_pid); PID_Compute(&angle_pid);
cnt4 = 0;
} }
if (in_state == 0 || in_state == 2) { if (in_state == 0 || in_state == 2) {
pwm_duty_ls = (int32_t)myclip_f(-out_pos, 0.0f, 7000.f); pwm_duty_ls = (int32_t)myclip_f(-out_pos, 0.0f, 6000.f);
pwm_duty_rs = (int32_t)myclip_f(out_pos, 0.0f, 7000.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_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_rb = (int32_t)myclip_f(out_speed - out_gyro, 0.0f, 6000.f);
} else if (in_state == 1) { } else if (in_state == 1||in_state == 3) {
pwm_duty_ls = (int32_t)myclip_f(-out_cangle, -7000.0f, 7000.f); pwm_duty_ls = (int32_t)myclip_f(-out_cangle, -6000.0f, 6000.f);
pwm_duty_rs = (int32_t)myclip_f(out_cangle, -7000.0f, 7000.f); pwm_duty_rs = (int32_t)myclip_f(out_cangle, -6000.0f, 6000.f);
pwm_duty_lb = (int32_t)myclip_f(out_speed + out_gyro, 0.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, 0.0f, 6000.f); pwm_duty_rb = (int32_t)myclip_f(out_speed - out_gyro, -6000.0f, 6000.f);
} else if (in_state == 3) {
if (out_gyro > 0) {
pwm_duty_ls = (int32_t)myclip_f(-out_cangle, -7000.0f, 7000.f);
pwm_duty_rs = (int32_t)myclip_f(out_cangle, -7000.0f, 7000.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, 0.0f, 6000.f);
} else {
pwm_duty_ls = (int32_t)myclip_f(-out_cangle, -7000.0f, 7000.f);
pwm_duty_rs = (int32_t)myclip_f(out_cangle, -7000.0f, 7000.f);
pwm_duty_lb = (int32_t)myclip_f(out_speed, 0.0f, 6000.f);
pwm_duty_rb = (int32_t)myclip_f(out_speed - out_gyro, 0.0f, 6000.f);
}
} }
// else if (in_state == 3) {
// if (out_gyro > 0) {
// pwm_duty_ls = (int32_t)myclip_f(-out_cangle, -6000.0f, 6000.f);
// pwm_duty_rs = (int32_t)myclip_f(out_cangle, -6000.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, 0.0f, 6000.f);
// } else {
// pwm_duty_ls = (int32_t)myclip_f(-out_cangle, -6000.0f, 6000.f);
// pwm_duty_rs = (int32_t)myclip_f(out_cangle, -6000.0f, 6000.f);
// pwm_duty_lb = (int32_t)myclip_f(out_speed, 0.0f, 6000.f);
// pwm_duty_rb = (int32_t)myclip_f(out_speed - out_gyro, 0.0f, 6000.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); by_pwm_power_duty((int32_t)pwm_duty_ls, (int32_t)pwm_duty_rs, (int32_t)pwm_duty_lb, (int32_t)pwm_duty_rb);
} else { } else {
@@ -182,8 +197,8 @@ void sport_motion(void)
by_pwm_update_duty(0 + 500, 0 + 500); by_pwm_update_duty(0 + 500, 0 + 500);
} else { } else {
if (in_state == 1 && cnt3_flag == 1) { if (in_state == 1 && cnt3_flag == 1) {
float tt = 150 * fabs(tanf(myclip_f(in_angle, -45.f, 45.f) / 180 * PI)); float tt = 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); by_pwm_update_duty(bt_fly + 500 - tt, bt_fly + 500 - tt);
} else { } else {
by_pwm_update_duty(bt_fly + 500, bt_fly + 500); by_pwm_update_duty(bt_fly + 500, bt_fly + 500);
@@ -212,7 +227,7 @@ void sport_pid_init()
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(&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_SetMode(&far_gyro_pid, _PID_MODE_AUTOMATIC);
PID_SetSampleTime(&far_gyro_pid, 10); PID_SetSampleTime(&far_gyro_pid, 10);
PID_SetOutputLimits(&far_gyro_pid, -4000.0f, 4000.0f); PID_SetOutputLimits(&far_gyro_pid, -5000.0f, 5000.0f);
/* 近点控制 */ /* 近点控制 */
PID(&near_pos_pid, &in_angle, &out_pos, &set_pos, po_Kp1, po_Ki1, po_Kd1, _PID_P_ON_E, _PID_CD_REVERSE); PID(&near_pos_pid, &in_angle, &out_pos, &set_pos, po_Kp1, po_Ki1, po_Kd1, _PID_P_ON_E, _PID_CD_REVERSE);
@@ -225,6 +240,6 @@ void sport_pid_init()
PID(&speed_pid, &in_speed, &out_speed, &set_speed, sp_Kp, sp_Ki, sp_Kd, _PID_P_ON_M, _PID_CD_DIRECT); 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_SetMode(&speed_pid, _PID_MODE_AUTOMATIC);
PID_SetSampleTime(&speed_pid, 10); PID_SetSampleTime(&speed_pid, 10);
PID_SetOutputLimits(&speed_pid, -4000.0f, 6000.0f); PID_SetOutputLimits(&speed_pid, -4000.0f, 5000.0f);
// PID_Init(&speed_pid); // PID_Init(&speed_pid);
} }

View File

@@ -24,7 +24,7 @@ extern float gy_Kd0;
extern float in_gyro; extern float in_gyro;
extern float out_gyro; extern float out_gyro;
extern float set_gyro; extern float set_gyro;
extern float out_cangle;
extern float po_Kp1; extern float po_Kp1;
extern float po_Ki1; extern float po_Ki1;
extern float po_Kd1; extern float po_Kd1;

View File

@@ -44,8 +44,8 @@ static void Loop()
{ {
ips200_show_string(0, 0, "sta:"); ips200_show_string(0, 0, "sta:");
ips200_show_float(80, 0, in_state, 4, 1); ips200_show_float(80, 0, in_state, 4, 1);
ips200_show_string(0, 20, "sto:"); ips200_show_string(0, 20, "outca:");
ips200_show_float(80, 20, in_stop, 4, 1); ips200_show_float(80, 20, out_cangle, 4, 1);
ips200_show_string(0, 40, "angle"); ips200_show_string(0, 40, "angle");
ips200_show_float(80, 40, in_angle, 4, 1); ips200_show_float(80, 40, in_angle, 4, 1);
ips200_show_string(0, 60, "near"); ips200_show_string(0, 60, "near");

View File

@@ -12,7 +12,7 @@ static char Text[] = "Menu";
static int8_t Curser = LINE_HEAD; // 定义光标位置 static int8_t Curser = LINE_HEAD; // 定义光标位置
static int8_t Curser_Last = LINE_HEAD; // 定义光标位置 static int8_t Curser_Last = LINE_HEAD; // 定义光标位置
uint32_t cnt = 0; uint32_t cnt = 0;
uint32_t reset[1]; uint32_t reset[3];
static void Print_Menu_p(void); static void Print_Menu_p(void);
/*************************************************************************************** /***************************************************************************************
* *