2024-01-16 20:03:21 +08:00
|
|
|
|
#include "jj_motion.h"
|
2024-05-05 19:15:51 +08:00
|
|
|
|
#include <math.h>
|
2024-03-22 11:35:15 +08:00
|
|
|
|
#include "zf_common_headfile.h"
|
|
|
|
|
|
#include "pid.h"
|
2024-06-27 02:28:12 +08:00
|
|
|
|
#include "jj_voltage.h"
|
2024-03-22 11:35:15 +08:00
|
|
|
|
#include "jj_blueteeth.h"
|
2024-01-16 20:03:21 +08:00
|
|
|
|
#include "by_fan_control.h"
|
|
|
|
|
|
#include "by_imu.h"
|
2024-07-05 14:25:08 +08:00
|
|
|
|
#include "by_frame.h"
|
2024-03-02 16:05:24 +08:00
|
|
|
|
|
|
|
|
|
|
PID_TypeDef far_angle_pid;
|
2024-07-02 20:32:08 +08:00
|
|
|
|
PID_TypeDef pos_pid;
|
2024-03-02 16:05:24 +08:00
|
|
|
|
PID_TypeDef far_gyro_pid;
|
|
|
|
|
|
PID_TypeDef speed_pid;
|
2024-06-23 13:11:56 +08:00
|
|
|
|
PID_TypeDef cir_pos_pid;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
///////////////////////////////////////////
|
2024-06-07 21:55:55 +08:00
|
|
|
|
// 直道后面风扇角度环
|
2024-07-17 10:51:06 +08:00
|
|
|
|
float an_Kp1 = 46.0f;
|
2024-05-23 15:53:21 +08:00
|
|
|
|
float an_Ki1 = 0.0f;
|
|
|
|
|
|
float an_Kd1 = 0.0f;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
// 直道角速度环
|
2024-07-17 10:51:06 +08:00
|
|
|
|
float gy_Kp1 = 1.530f;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
float gy_Ki1 = 0.0f;
|
|
|
|
|
|
float gy_Kd1 = 0.0f;
|
|
|
|
|
|
// 直道侧面风扇角度环
|
2024-07-17 10:51:06 +08:00
|
|
|
|
float po_Kp1 = 2.10f;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
float po_Ki1 = 0.0f;
|
|
|
|
|
|
float po_Kd1 = 0.0f;
|
|
|
|
|
|
////////////////////////////////////
|
|
|
|
|
|
// 弯道后面风扇角度环
|
2024-07-17 10:51:06 +08:00
|
|
|
|
float an_Kp0 = 53.0f;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
float an_Ki0 = 0.0f;
|
|
|
|
|
|
float an_Kd0 = 0.0f;
|
|
|
|
|
|
|
|
|
|
|
|
// 弯道角速度环
|
2024-07-17 10:51:06 +08:00
|
|
|
|
float gy_Kp0 = 2.2180f;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
float gy_Ki0 = 0.0f;
|
|
|
|
|
|
float gy_Kd0 = 0.0f;
|
|
|
|
|
|
|
|
|
|
|
|
// 弯道侧面风扇角度环
|
2024-07-17 10:51:06 +08:00
|
|
|
|
float cn_Kp1 = 7.0f;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
float cn_Ki1 = 0.f;
|
|
|
|
|
|
float cn_Kd1 = 0.0f;
|
|
|
|
|
|
////////////////////////////////////////
|
2024-07-13 19:11:12 +08:00
|
|
|
|
// 避障后面角度环
|
2024-07-17 10:51:06 +08:00
|
|
|
|
float za_Kp = 55.f;
|
2024-07-13 19:11:12 +08:00
|
|
|
|
float za_Ki = 0;
|
|
|
|
|
|
float za_Kd = 0;
|
2024-07-02 20:32:08 +08:00
|
|
|
|
|
2024-07-17 10:51:06 +08:00
|
|
|
|
float zg_Kp = 2.f;
|
2024-07-13 19:11:12 +08:00
|
|
|
|
float zg_Ki = 0;
|
|
|
|
|
|
float zg_Kd = 0;
|
|
|
|
|
|
|
2024-07-17 10:51:06 +08:00
|
|
|
|
float zp_Kp = 6.f;
|
2024-07-13 19:11:12 +08:00
|
|
|
|
float zp_Ki = 0;
|
|
|
|
|
|
float zp_Kd = 0;
|
|
|
|
|
|
///////////////////////////////////////
|
2024-06-07 21:55:55 +08:00
|
|
|
|
// 圆环后面风扇角度环
|
2024-07-17 10:51:06 +08:00
|
|
|
|
float yu_Kp0 = 58.0f;
|
2024-06-07 21:55:55 +08:00
|
|
|
|
float yu_Ki0 = 0.0f;
|
|
|
|
|
|
float yu_Kd0 = 0.0f;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
// 圆环角速度环
|
2024-07-17 10:51:06 +08:00
|
|
|
|
float ygy_Kp0 = 2.20f;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
float ygy_Ki0 = 0.0f;
|
|
|
|
|
|
float ygy_Kd0 = 0.0f;
|
2024-07-13 19:11:12 +08:00
|
|
|
|
// 圆环侧面角度环
|
2024-08-09 17:00:24 +08:00
|
|
|
|
float yuc_Kp = 4.4f;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
// 速度环
|
2024-07-17 10:51:06 +08:00
|
|
|
|
float sp_Kp = 3.40f;
|
|
|
|
|
|
float sp_Ki = 3.6f;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
float sp_Kd = 0.0f;
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
// 当前和输入量
|
|
|
|
|
|
float in_gyro;
|
|
|
|
|
|
float out_gyro;
|
2024-06-07 21:55:55 +08:00
|
|
|
|
// 期望和当前量
|
2024-03-02 16:05:24 +08:00
|
|
|
|
float in_angle;
|
|
|
|
|
|
float set_angle = 0.0f;
|
|
|
|
|
|
float out_angle;
|
2024-06-07 21:55:55 +08:00
|
|
|
|
float in_pos;
|
|
|
|
|
|
float out_pos;
|
|
|
|
|
|
float set_pos = 0.0f;
|
2024-03-03 19:23:21 +08:00
|
|
|
|
// float set_gyro = 0.0f;
|
2024-08-09 17:00:24 +08:00
|
|
|
|
float rate_K = 0;
|
2024-03-02 16:05:24 +08:00
|
|
|
|
float in_speed;
|
|
|
|
|
|
float out_speed;
|
2024-07-09 19:32:36 +08:00
|
|
|
|
float last_angle;
|
2024-06-07 21:55:55 +08:00
|
|
|
|
float set_speed;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
float set_speed0 = 657.0f;
|
|
|
|
|
|
float set_speed1 = 1111.0f;
|
|
|
|
|
|
float set_speed2 = 815.f;
|
|
|
|
|
|
float set_speed3 = 666.f;
|
|
|
|
|
|
float set_speed4 = 720.f;
|
2024-07-05 03:29:56 +08:00
|
|
|
|
int cnt1 = 0;
|
|
|
|
|
|
int cnt2 = 0;
|
|
|
|
|
|
int cnt3 = 0;
|
|
|
|
|
|
int cnt4 = 0;
|
|
|
|
|
|
int cnt5 = 0;
|
|
|
|
|
|
int cnt6 = 0;
|
|
|
|
|
|
int cnt7 = 0;
|
|
|
|
|
|
int cnt8 = 0;
|
2024-07-09 19:32:36 +08:00
|
|
|
|
int cnt9 = 0;
|
2024-08-09 17:00:24 +08:00
|
|
|
|
int cnt10 = 0;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
int if_start = 0;
|
2024-07-08 21:02:14 +08:00
|
|
|
|
float shock_stop = 0;
|
2024-05-05 19:15:51 +08:00
|
|
|
|
uint8_t in_state = 0;
|
|
|
|
|
|
uint8_t in_stop = 0;
|
|
|
|
|
|
uint8_t last_state = 0;
|
2024-06-07 21:55:55 +08:00
|
|
|
|
uint8_t stop_flag = 0;
|
2024-06-16 20:49:57 +08:00
|
|
|
|
int32_t pwm_duty_ls;
|
|
|
|
|
|
int32_t pwm_duty_rs;
|
|
|
|
|
|
int32_t pwm_duty_lb;
|
|
|
|
|
|
int32_t pwm_duty_rb;
|
2024-08-09 17:00:24 +08:00
|
|
|
|
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;
|
2024-06-23 13:11:56 +08:00
|
|
|
|
/*
|
|
|
|
|
|
0:无状态
|
|
|
|
|
|
1:弯道
|
|
|
|
|
|
2:直道
|
|
|
|
|
|
3:入环
|
|
|
|
|
|
4:环内
|
|
|
|
|
|
5:障碍
|
|
|
|
|
|
*/
|
2024-03-24 18:24:32 +08:00
|
|
|
|
static float myclip_f(float x, float low, float up)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (x > up ? up : x < low ? low
|
|
|
|
|
|
: x);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-05 19:38:31 +08:00
|
|
|
|
float sport_get_speed(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
#define ALPHA (0.97f)
|
|
|
|
|
|
static float speed_now = 0;
|
|
|
|
|
|
static float speed_last = 0;
|
|
|
|
|
|
|
2024-04-16 10:54:44 +08:00
|
|
|
|
speed_now = ALPHA * (float)encoder_get_count(TIM3_ENCOEDER) + (1.0f - ALPHA) * speed_last;
|
2024-03-05 19:38:31 +08:00
|
|
|
|
speed_last = speed_now;
|
2024-04-16 10:54:44 +08:00
|
|
|
|
encoder_clear_count(TIM3_ENCOEDER);
|
2024-03-05 19:38:31 +08:00
|
|
|
|
|
|
|
|
|
|
return speed_now;
|
|
|
|
|
|
|
|
|
|
|
|
#undef ALPHA
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-07 21:55:55 +08:00
|
|
|
|
void sport_motion()
|
2024-01-16 20:03:21 +08:00
|
|
|
|
{
|
2024-05-23 15:53:21 +08:00
|
|
|
|
imu660ra_get_gyro();
|
2024-06-07 21:55:55 +08:00
|
|
|
|
imu660ra_get_acc();
|
2024-06-27 02:28:12 +08:00
|
|
|
|
get_vol();
|
2024-05-23 15:53:21 +08:00
|
|
|
|
in_gyro = imu660ra_gyro_z;
|
2024-07-09 19:32:36 +08:00
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////停车任务///////////////////////////////////////////////
|
|
|
|
|
|
// 抖动停车
|
2024-07-02 20:32:08 +08:00
|
|
|
|
if (imu660ra_acc_z <= 800) {
|
2024-07-05 03:29:56 +08:00
|
|
|
|
cnt7++;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
cnt7 = 0;
|
|
|
|
|
|
}
|
2024-08-09 17:00:24 +08:00
|
|
|
|
if (cnt7 >= 50 && ((uint32_t)shock_stop == 1 || (uint32_t)shock_stop == 2)) {
|
2024-07-02 20:32:08 +08:00
|
|
|
|
bt_fly_flag = bt_run_flag = 0;
|
2024-07-09 19:32:36 +08:00
|
|
|
|
bt_printf("up");
|
|
|
|
|
|
}
|
|
|
|
|
|
// 異常值停车
|
2024-08-09 17:00:24 +08:00
|
|
|
|
if (fabs(in_angle - last_angle) > 45.f && ((uint32_t)shock_stop == 1 || (uint32_t)shock_stop == 3)) {
|
2024-07-09 19:32:36 +08:00
|
|
|
|
bt_fly_flag = bt_run_flag = 0;
|
|
|
|
|
|
bt_printf("bug");
|
2024-07-02 20:32:08 +08:00
|
|
|
|
}
|
2024-07-07 23:08:49 +08:00
|
|
|
|
// 斑马线停车,摄像头识别
|
|
|
|
|
|
if (1 == in_stop && if_start == 1) {
|
2024-06-07 21:55:55 +08:00
|
|
|
|
stop_flag = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (stop_flag == 1) {
|
2024-07-09 19:32:36 +08:00
|
|
|
|
bt_printf("finish");
|
|
|
|
|
|
bt_fly_flag = bt_run_flag = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 出界停车
|
|
|
|
|
|
if (2 == in_stop) {
|
2024-08-09 17:00:24 +08:00
|
|
|
|
stop_cnt++;
|
|
|
|
|
|
if (stop_cnt >= 5) {
|
|
|
|
|
|
bt_printf("out");
|
|
|
|
|
|
stop_cnt = 0;
|
|
|
|
|
|
bt_fly_flag = bt_run_flag = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
stop_cnt = 0;
|
2024-06-07 21:55:55 +08:00
|
|
|
|
}
|
2024-07-13 19:11:12 +08:00
|
|
|
|
//////////////////////////////////////////////// 动力风扇设置 */////////////////////////////////////////////////////////
|
2024-03-24 18:24:32 +08:00
|
|
|
|
if (1 == bt_run_flag) {
|
|
|
|
|
|
cnt1++;
|
|
|
|
|
|
cnt2++;
|
2024-06-12 18:13:18 +08:00
|
|
|
|
cnt5++;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
if (if_start == 0) {
|
|
|
|
|
|
cnt8++;
|
2024-08-09 17:00:24 +08:00
|
|
|
|
if (cnt8 >= 5000) {
|
2024-07-07 23:08:49 +08:00
|
|
|
|
if_start = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-23 15:53:21 +08:00
|
|
|
|
// pid参数切换
|
|
|
|
|
|
if ((last_state != in_state) && (in_state == 0 || in_state == 2)) { // 直道
|
2024-07-07 23:08:49 +08:00
|
|
|
|
|
2024-06-05 20:17:45 +08:00
|
|
|
|
bt_printf("to 直道");
|
2024-05-23 15:53:21 +08:00
|
|
|
|
set_speed = set_speed1;
|
2024-08-09 17:00:24 +08:00
|
|
|
|
|
2024-05-23 15:53:21 +08:00
|
|
|
|
PID_SetTunings(&far_angle_pid, an_Kp1, an_Ki1, an_Kd1);
|
|
|
|
|
|
PID_SetTunings(&far_gyro_pid, gy_Kp1, gy_Ki1, gy_Kd1);
|
2024-07-02 20:32:08 +08:00
|
|
|
|
PID_SetTunings(&pos_pid, po_Kp1, po_Ki1, po_Kd1);
|
2024-08-09 17:00:24 +08:00
|
|
|
|
} else if ((last_state != in_state) && in_state == 1) { // 弯道
|
2024-06-05 20:17:45 +08:00
|
|
|
|
bt_printf("to 入弯");
|
2024-08-09 17:00:24 +08:00
|
|
|
|
set_speed = set_speed0 - fabs(rate_K * myclip_f(in_pos, -50.f, 50.f));
|
2024-07-07 23:08:49 +08:00
|
|
|
|
|
2024-05-23 15:53:21 +08:00
|
|
|
|
PID_SetTunings(&far_angle_pid, an_Kp0, an_Ki0, an_Kd0);
|
|
|
|
|
|
PID_SetTunings(&far_gyro_pid, gy_Kp0, gy_Ki0, gy_Kd0);
|
2024-07-02 20:32:08 +08:00
|
|
|
|
PID_SetTunings(&pos_pid, cn_Kp1, cn_Ki1, cn_Kd1);
|
2024-08-09 17:00:24 +08:00
|
|
|
|
} else if ((last_state != in_state) && (in_state == 3 || in_state == 4)) { // 圆环
|
2024-06-05 20:17:45 +08:00
|
|
|
|
bt_printf("to 圆环");
|
2024-07-05 03:29:56 +08:00
|
|
|
|
if (in_state == 3)
|
|
|
|
|
|
set_speed = set_speed2;
|
|
|
|
|
|
else
|
|
|
|
|
|
set_speed = set_speed3;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
|
2024-06-12 18:13:18 +08:00
|
|
|
|
PID_SetTunings(&far_angle_pid, yu_Kp0, yu_Ki0, yu_Kd0);
|
|
|
|
|
|
PID_SetTunings(&far_gyro_pid, ygy_Kp0, ygy_Ki0, ygy_Kd0);
|
2024-07-13 19:11:12 +08:00
|
|
|
|
PID_SetTunings(&pos_pid, yuc_Kp, cn_Ki1, cn_Kd1);
|
2024-08-09 17:00:24 +08:00
|
|
|
|
} else if ((last_state != in_state) && in_state == 5) { //
|
2024-07-02 20:32:08 +08:00
|
|
|
|
bt_printf("to 障碍");
|
|
|
|
|
|
set_speed = set_speed4;
|
2024-07-07 23:08:49 +08:00
|
|
|
|
|
2024-07-02 20:32:08 +08:00
|
|
|
|
PID_SetTunings(&far_angle_pid, za_Kp, za_Ki, za_Kd);
|
|
|
|
|
|
PID_SetTunings(&far_gyro_pid, zg_Kp, zg_Ki, zg_Kd);
|
|
|
|
|
|
PID_SetTunings(&pos_pid, zp_Kp, zp_Ki, zp_Kd);
|
2024-06-05 20:17:45 +08:00
|
|
|
|
}
|
2024-08-09 17:00:24 +08:00
|
|
|
|
|
|
|
|
|
|
if (in_state == 1) {
|
|
|
|
|
|
set_speed = set_speed0 - fabs(rate_K * myclip_f(in_pos, -50.f, 50.f));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-23 15:53:21 +08:00
|
|
|
|
last_state = in_state;
|
2024-06-16 20:49:57 +08:00
|
|
|
|
// pid计算
|
2024-06-05 20:17:45 +08:00
|
|
|
|
if (cnt1 >= 2) {
|
|
|
|
|
|
PID_Compute(&far_gyro_pid);
|
2024-03-24 18:24:32 +08:00
|
|
|
|
cnt1 = 0;
|
|
|
|
|
|
}
|
2024-06-05 20:17:45 +08:00
|
|
|
|
if (cnt2 >= 10) {
|
|
|
|
|
|
in_speed = sport_get_speed();
|
2024-07-02 20:32:08 +08:00
|
|
|
|
cnt2 = 0;
|
2024-08-09 17:00:24 +08:00
|
|
|
|
PID_Compute(&far_angle_pid);
|
2024-06-19 20:55:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (cnt5 >= 20) {
|
2024-06-27 02:28:12 +08:00
|
|
|
|
|
2024-07-02 20:32:08 +08:00
|
|
|
|
PID_Compute(&pos_pid);
|
2024-06-27 02:28:12 +08:00
|
|
|
|
PID_Compute(&speed_pid);
|
2024-06-12 18:13:18 +08:00
|
|
|
|
cnt5 = 0;
|
2024-05-23 15:53:21 +08:00
|
|
|
|
}
|
2024-07-05 03:29:56 +08:00
|
|
|
|
// 并级pid,限幅
|
2024-08-09 17:00:24 +08:00
|
|
|
|
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);
|
2024-07-13 19:11:12 +08:00
|
|
|
|
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) {
|
|
|
|
|
|
pwm_duty_lb = (pwm_duty_lb + last_lb) / 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (pwm_duty_rb - last_rb > 1000) {
|
|
|
|
|
|
pwm_duty_rb = (pwm_duty_rb + last_rb) / 2;
|
|
|
|
|
|
}
|
2024-07-02 20:32:08 +08:00
|
|
|
|
|
2024-07-13 19:11:12 +08:00
|
|
|
|
last_rb = pwm_duty_rb;
|
|
|
|
|
|
last_lb = pwm_duty_lb;
|
2024-06-30 14:44:35 +08:00
|
|
|
|
|
2024-07-13 19:11:12 +08:00
|
|
|
|
by_pwm_power_duty(500 + pwm_duty_ls, 500 + pwm_duty_rs, 3000 + pwm_duty_lb, 3000 + pwm_duty_rb);
|
2024-01-16 20:03:21 +08:00
|
|
|
|
} else {
|
2024-03-24 18:24:32 +08:00
|
|
|
|
by_pwm_power_duty(0, 0, 0, 0);
|
2024-01-16 20:03:21 +08:00
|
|
|
|
}
|
2024-07-13 19:11:12 +08:00
|
|
|
|
///////////////////////////////////////////////////* 升力风扇设置 */ /////////////////////////////////////////////////////////////////////////////////////////////////
|
2024-03-02 16:05:24 +08:00
|
|
|
|
if (bt_fly_flag == 0) {
|
2024-07-05 03:29:56 +08:00
|
|
|
|
by_pwm_update_duty(500, 500);
|
2024-03-05 21:28:08 +08:00
|
|
|
|
} else {
|
2024-07-13 19:11:12 +08:00
|
|
|
|
by_pwm_update_duty(bt_fly + 500, bt_fly + 500);
|
|
|
|
|
|
// 防止起步拉满
|
2024-08-09 17:00:24 +08:00
|
|
|
|
if (bt_run_flag == 0) {
|
|
|
|
|
|
|
|
|
|
|
|
by_pwm_power_duty(680, 680, 4000, 4000);
|
|
|
|
|
|
}
|
2024-03-02 16:05:24 +08:00
|
|
|
|
}
|
2024-01-16 20:03:21 +08:00
|
|
|
|
}
|
2024-03-05 19:38:31 +08:00
|
|
|
|
|
2024-01-16 20:03:21 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 结构体初始化
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
void sport_pid_init()
|
|
|
|
|
|
{
|
2024-03-22 11:35:15 +08:00
|
|
|
|
/* 角度控制 */
|
2024-05-23 15:53:21 +08:00
|
|
|
|
PID(&far_angle_pid, &in_angle, &out_angle, &set_angle, an_Kp1, an_Ki1, an_Kd1, _PID_P_ON_E, _PID_CD_REVERSE);
|
2024-03-22 11:35:15 +08:00
|
|
|
|
PID_SetMode(&far_angle_pid, _PID_MODE_AUTOMATIC);
|
2024-08-09 17:00:24 +08:00
|
|
|
|
PID_SetSampleTime(&far_angle_pid, 10);
|
|
|
|
|
|
PID_SetOutputLimits(&far_angle_pid, -6000.0f, 6000.0f);
|
2024-07-02 20:32:08 +08:00
|
|
|
|
// 侧面位置环
|
|
|
|
|
|
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);
|
2024-08-09 17:00:24 +08:00
|
|
|
|
PID_SetOutputLimits(&pos_pid, -320.0f, 320.0f);
|
2024-07-02 20:32:08 +08:00
|
|
|
|
|
2024-03-22 11:35:15 +08:00
|
|
|
|
/* 角速度控制 */
|
2024-05-23 15:53:21 +08:00
|
|
|
|
PID(&far_gyro_pid, &in_gyro, &out_gyro, &out_angle, gy_Kp1, gy_Ki1, gy_Kd1, _PID_P_ON_E, _PID_CD_REVERSE); // m是增量
|
2024-03-22 11:35:15 +08:00
|
|
|
|
PID_SetMode(&far_gyro_pid, _PID_MODE_AUTOMATIC);
|
2024-06-19 20:55:36 +08:00
|
|
|
|
PID_SetSampleTime(&far_gyro_pid, 20);
|
2024-08-09 17:00:24 +08:00
|
|
|
|
PID_SetOutputLimits(&far_gyro_pid, -2100.0f, 2100.0f);
|
2024-03-22 11:35:15 +08:00
|
|
|
|
|
|
|
|
|
|
/* 速度控制 */
|
2024-05-23 15:53:21 +08:00
|
|
|
|
PID(&speed_pid, &in_speed, &out_speed, &set_speed, sp_Kp, sp_Ki, sp_Kd, _PID_P_ON_M, _PID_CD_DIRECT);
|
2024-03-22 11:35:15 +08:00
|
|
|
|
PID_SetMode(&speed_pid, _PID_MODE_AUTOMATIC);
|
2024-06-19 20:55:36 +08:00
|
|
|
|
PID_SetSampleTime(&speed_pid, 20);
|
2024-08-09 17:00:24 +08:00
|
|
|
|
PID_SetOutputLimits(&speed_pid, -0.0f, 2500.0f);
|
2024-01-16 20:03:21 +08:00
|
|
|
|
}
|