Merge branch 'master' of http://git.brisky.space:441/btl143/firmware_zinnia
This commit is contained in:
@@ -39,7 +39,7 @@ float out_speed;
|
||||
float set_speed = 0.0f;
|
||||
|
||||
int cnt1 = 0;
|
||||
|
||||
int cnt2 = 0;
|
||||
float sport_get_speed(void)
|
||||
{
|
||||
#define ALPHA (0.97f)
|
||||
@@ -60,6 +60,7 @@ void sport_motion(void)
|
||||
{
|
||||
|
||||
cnt1++;
|
||||
cnt2++;
|
||||
imu660ra_get_gyro();
|
||||
in_gyro = imu660ra_gyro_z; // 陀螺仪输入
|
||||
// in_angle = 0; // 图像远端输入
|
||||
@@ -68,27 +69,40 @@ void sport_motion(void)
|
||||
PID_Compute(&far_gyro_pid);
|
||||
|
||||
if (cnt1 >= 10) {
|
||||
PID_Compute(&far_angle_pid);
|
||||
|
||||
PID_Compute(&speed_pid);
|
||||
// in_speed = -encoder_get_count(TIM5_ENCOEDER); // 速度输入,m/s
|
||||
in_speed = sport_get_speed();
|
||||
in_speed = -sport_get_speed();
|
||||
// printf("rate:%d\r\n", (int16_t)in_speed);
|
||||
PID_Compute(&near_pos_pid);
|
||||
cnt1 = 0;
|
||||
}
|
||||
|
||||
if (cnt2 >= 20) {
|
||||
cnt2 = 0;
|
||||
PID_Compute(&far_angle_pid);
|
||||
}
|
||||
if (bt_run_flag == 1) {
|
||||
by_pwm_power_duty((int32_t)(500 + out_pos + out_gyro),
|
||||
(int32_t)(500 - out_pos - out_gyro),
|
||||
(int32_t)(500 + out_speed + out_gyro),
|
||||
(int32_t)(500 + out_speed - out_gyro));
|
||||
if (out_gyro > 0) {
|
||||
by_pwm_power_duty((int32_t)(500 - 1 * out_pos + 0 * out_gyro),
|
||||
(int32_t)(500 + 1 * out_pos - 0 * out_gyro),
|
||||
(int32_t)(500 + out_speed + out_gyro),
|
||||
(int32_t)(500 + out_speed - out_gyro));
|
||||
|
||||
} else if (out_gyro <= 0) {
|
||||
by_pwm_power_duty((int32_t)(500 - 1 * out_pos + 0 * out_gyro),
|
||||
(int32_t)(500 + 1 * out_pos - 0 * out_gyro),
|
||||
(int32_t)(500 + out_speed + out_gyro),
|
||||
(int32_t)(500 + out_speed - out_gyro));
|
||||
}
|
||||
|
||||
// by_pwm_power_duty(500+out_gyro, 500-out_gyro, 500+out_gyro , 500-out_gyro);
|
||||
} else {
|
||||
by_pwm_power_duty(500, 500, 500, 500);
|
||||
}
|
||||
if (bt_fly_flag == 0) {
|
||||
bt_fly = 0;
|
||||
by_pwm_update_duty(0 + 500, 0 + 500);
|
||||
} else {
|
||||
by_pwm_update_duty(bt_fly + 500, bt_fly + 500);
|
||||
}
|
||||
by_pwm_update_duty(bt_fly + 500, bt_fly + 500);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +112,7 @@ void sport_motion(void)
|
||||
void sport_pid_init()
|
||||
{
|
||||
|
||||
PID(&far_angle_pid, &in_angle, &out_angle, &set_angle, an_Kp, an_Ki, an_Kd, 0, 1);
|
||||
PID(&far_angle_pid, &in_angle, &out_angle, &set_angle, an_Kp, an_Ki, an_Kd, 1, 1);
|
||||
PID(&far_gyro_pid, &in_gyro, &out_gyro, &out_angle, gy_Kp, gy_Ki, gy_Kd, 1, 1);
|
||||
PID_Init(&far_angle_pid);
|
||||
PID_Init(&far_gyro_pid);
|
||||
@@ -109,13 +123,13 @@ void sport_pid_init()
|
||||
PID_SetMode(&far_gyro_pid, 1);
|
||||
PID_SetMode(&far_angle_pid, 1);
|
||||
|
||||
PID(&near_pos_pid, &in_pos, &out_pos, &set_pos, po_Kp, po_Ki, po_Kd, 0, 0);
|
||||
PID(&near_pos_pid, &in_pos, &out_pos, &set_pos, po_Kp, po_Ki, po_Kd, 1, 0);
|
||||
PID(&speed_pid, &in_speed, &out_speed, &set_speed, sp_Kp, sp_Ki, sp_Kd, 1, 0);
|
||||
PID_Init(&near_pos_pid);
|
||||
PID_Init(&speed_pid);
|
||||
|
||||
PID_SetOutputLimits(&near_pos_pid, -500.0f, 500.0f);
|
||||
PID_SetOutputLimits(&speed_pid, -400.0f, 400.0f);
|
||||
PID_SetOutputLimits(&speed_pid, 0.0f, 400.0f);
|
||||
|
||||
PID_SetMode(&near_pos_pid, 1);
|
||||
PID_SetMode(&speed_pid, 1);
|
||||
|
||||
Reference in New Issue
Block a user