日常更新
This commit is contained in:
@@ -48,7 +48,7 @@ void by_pwm_init(void)
|
||||
pwm_init(FAN_LL_PWM_PIN, 50, 500);
|
||||
pwm_init(FAN_RL_PWM_PIN, 50, 500);
|
||||
|
||||
#if FIX_DRIVE==1
|
||||
#if FIX_DRIVE == 1
|
||||
pwm_init(FAN_LS_PWM_A_PIN, 12000, 1000);
|
||||
pwm_init(FAN_LS_PWM_B_PIN, 12000, 1000);
|
||||
pwm_init(FAN_RS_PWM_A_PIN, 12000, 1000);
|
||||
@@ -58,16 +58,25 @@ void by_pwm_init(void)
|
||||
pwm_init(FAN_RB_PWM_A_PIN, 12000, 1000);
|
||||
pwm_init(FAN_RB_PWM_B_PIN, 12000, 1000);
|
||||
while (1);
|
||||
#endif
|
||||
pwm_init(FAN_LS_PWM_A_PIN, 12000, 0);
|
||||
#elif FIX_DRIVE == 2
|
||||
pwm_init(FAN_LS_PWM_A_PIN, 12000, 1000);
|
||||
pwm_init(FAN_LS_PWM_B_PIN, 12000, 0);
|
||||
pwm_init(FAN_RS_PWM_A_PIN, 12000, 0);
|
||||
pwm_init(FAN_RS_PWM_A_PIN, 12000, 1000);
|
||||
pwm_init(FAN_RS_PWM_B_PIN, 12000, 0);
|
||||
pwm_init(FAN_LB_PWM_A_PIN, 12000, 0);
|
||||
pwm_init(FAN_LB_PWM_A_PIN, 12000, 1000);
|
||||
pwm_init(FAN_LB_PWM_B_PIN, 12000, 0);
|
||||
pwm_init(FAN_RB_PWM_A_PIN, 12000, 0);
|
||||
pwm_init(FAN_RB_PWM_A_PIN, 12000, 1000);
|
||||
pwm_init(FAN_RB_PWM_B_PIN, 12000, 0);
|
||||
|
||||
while(1);
|
||||
#endif
|
||||
pwm_init(FAN_LS_PWM_A_PIN, 14000, 0);
|
||||
pwm_init(FAN_LS_PWM_B_PIN, 14000, 0);
|
||||
pwm_init(FAN_RS_PWM_A_PIN, 14000, 0);
|
||||
pwm_init(FAN_RS_PWM_B_PIN, 14000, 0);
|
||||
pwm_init(FAN_LB_PWM_A_PIN, 14000, 0);
|
||||
pwm_init(FAN_LB_PWM_B_PIN, 14000, 0);
|
||||
pwm_init(FAN_RB_PWM_A_PIN, 14000, 0);
|
||||
pwm_init(FAN_RB_PWM_B_PIN, 14000, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -164,28 +164,28 @@ void sport_motion()
|
||||
}
|
||||
if (cnt2 >= 10) {
|
||||
in_speed = sport_get_speed();
|
||||
|
||||
cnt2 = 0;
|
||||
}
|
||||
if (cnt5 >= 20) {
|
||||
PID_Compute(&speed_pid);
|
||||
PID_Compute(&far_angle_pid);
|
||||
PID_Compute(&str_angle_pid);
|
||||
PID_Compute(&tur_cal_pid);
|
||||
cnt2 = 0;
|
||||
}
|
||||
if (cnt5 >= 50) {
|
||||
|
||||
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_ls = (int32_t)myclip_f(-out_pos, 0.0f, 6500.f);
|
||||
pwm_duty_rs = (int32_t)myclip_f(out_pos, 0.0f, 6500.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);
|
||||
} else if (in_state == 1 || in_state == 3) {
|
||||
|
||||
pwm_duty_ls = (int32_t)myclip_f(-out_cal, -5000.0f, 6000.f);
|
||||
pwm_duty_rs = (int32_t)myclip_f(out_cal, -5000.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_cal, 0.0f, 8000.f);
|
||||
pwm_duty_rs = (int32_t)myclip_f(out_cal, 0.0f, 8000.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);
|
||||
}
|
||||
|
||||
by_pwm_power_duty(pwm_duty_ls, pwm_duty_rs, pwm_duty_lb, pwm_duty_rb);
|
||||
@@ -197,7 +197,7 @@ void sport_motion()
|
||||
by_pwm_update_duty(0 + 500, 0 + 500);
|
||||
} else {
|
||||
if ((in_state == 1 || in_state == 3) && cnt3_flag == 1) {
|
||||
float tt = 3 * fabs(in_pos);
|
||||
float tt = 3 * fabs(in_pos);
|
||||
by_pwm_update_duty(bt_fly + 500 - tt, bt_fly + 500 - tt);
|
||||
cnt3++;
|
||||
if (in_state == 3) {
|
||||
@@ -230,27 +230,27 @@ 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_SetSampleTime(&far_angle_pid, 20);
|
||||
PID_SetOutputLimits(&far_angle_pid, -4000.0f, 4000.0f);
|
||||
// 直道侧面位置环
|
||||
PID(&str_angle_pid, &in_angle, &out_pos, &set_pos, po_Kp1, po_Ki1, po_Kd1, _PID_P_ON_E, _PID_CD_REVERSE);
|
||||
PID_SetMode(&str_angle_pid, _PID_MODE_AUTOMATIC);
|
||||
PID_SetSampleTime(&str_angle_pid, 10);
|
||||
PID_SetSampleTime(&str_angle_pid, 20);
|
||||
PID_SetOutputLimits(&str_angle_pid, -6000.0f, 6000.0f);
|
||||
// 弯道侧面曲率环
|
||||
PID(&tur_cal_pid, &in_pos, &out_cal, &set_pos, cn_Kp1, cn_Ki1, cn_Kd1, _PID_P_ON_E, _PID_CD_DIRECT);
|
||||
PID(&tur_cal_pid, &in_angle, &out_cal, &set_pos, cn_Kp1, cn_Ki1, cn_Kd1, _PID_P_ON_E, _PID_CD_REVERSE);
|
||||
PID_SetMode(&tur_cal_pid, _PID_MODE_AUTOMATIC);
|
||||
PID_SetSampleTime(&tur_cal_pid, 10);
|
||||
PID_SetOutputLimits(&tur_cal_pid, -6000.0f, 6000.0f);
|
||||
PID_SetSampleTime(&tur_cal_pid, 20);
|
||||
PID_SetOutputLimits(&tur_cal_pid, -8000.0f, 8000.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, -6000.0f, 6000.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_SetSampleTime(&speed_pid, 20);
|
||||
PID_SetOutputLimits(&speed_pid, -2000.0f, 5000.0f);
|
||||
}
|
||||
|
||||
@@ -35,11 +35,7 @@
|
||||
#include "by_frame.h"
|
||||
#include "by_rt_button.h"
|
||||
#include "by_fan_control.h"
|
||||
static float myclip_f(float x, float low, float up)
|
||||
{
|
||||
return (x > up ? up : x < low ? low
|
||||
: x);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TYPE_UNION test_data[BY_FRAME_DATA_NUM];
|
||||
@@ -70,7 +66,7 @@ int main(void)
|
||||
Page_Run();
|
||||
by_frame_parse(&test_data[0].u32);
|
||||
jj_bt_run();
|
||||
in_pos = myclip_f(1000.f* test_data[1].f32,-50.f,50.f);
|
||||
in_pos =1000.f* test_data[1].f32;
|
||||
in_angle = test_data[0].f32;
|
||||
in_state = test_data[2].u8[0];
|
||||
in_stop = test_data[2].u8[1];
|
||||
|
||||
@@ -63,14 +63,14 @@ static void Loop()
|
||||
ips200_show_string(0, 180, "outcal");
|
||||
ips200_show_float(80, 180, out_cal, 4, 1);
|
||||
|
||||
ips200_show_string(100, 0, "ls");
|
||||
ips200_show_float(180, 0, pwm_duty_ls, 4, 1);
|
||||
ips200_show_string(100, 20, "rs");
|
||||
ips200_show_float(180, 20, pwm_duty_rs, 4, 1);
|
||||
ips200_show_string(100, 40, "lb");
|
||||
ips200_show_float(180, 40, pwm_duty_lb, 4, 1);
|
||||
ips200_show_string(100, 60, "rb");
|
||||
ips200_show_float(180, 60, pwm_duty_rb, 4, 1);
|
||||
ips200_show_string(180, 0, "ls");
|
||||
ips200_show_float(220, 0, pwm_duty_ls, 4, 1);
|
||||
ips200_show_string(180, 20, "rs");
|
||||
ips200_show_float(220, 20, pwm_duty_rs, 4, 1);
|
||||
ips200_show_string(180, 40, "lb");
|
||||
ips200_show_float(220, 40, pwm_duty_lb, 4, 1);
|
||||
ips200_show_string(180, 60, "rb");
|
||||
ips200_show_float(220, 60, pwm_duty_rb, 4, 1);
|
||||
}
|
||||
/**
|
||||
* @brief 页面事件
|
||||
|
||||
Reference in New Issue
Block a user