feat: 初步完成有刷适配

This commit is contained in:
bmy
2024-03-22 11:35:15 +08:00
parent 0a943fd849
commit 756e8ce029
6 changed files with 91 additions and 70 deletions

View File

@@ -1,9 +1,11 @@
#include "jj_motion.h"
#include "zf_common_headfile.h"
#include "pid.h"
#include "jj_blueteeth.h"
#include "by_fan_control.h"
#include "by_imu.h"
#include "jj_blueteeth.h"
#include "../3rd-lib/PID-Library/pid.h"
#include "zf_driver_encoder.h"
PID_TypeDef far_angle_pid;
PID_TypeDef far_gyro_pid;
@@ -70,18 +72,21 @@ void sport_motion(void)
PID_Compute(&far_gyro_pid);
if (cnt1 >= 10) {
in_speed = -1 * sport_get_speed();
PID_Compute(&speed_pid);
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) {
/* 动力风扇设置 */
if (1 == bt_run_flag) {
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),
@@ -99,6 +104,8 @@ void sport_motion(void)
} else {
by_pwm_power_duty(500, 500, 500, 500);
}
/* 升力风扇设置 */
if (bt_fly_flag == 0) {
by_pwm_update_duty(0 + 500, 0 + 500);
} else {
@@ -112,26 +119,31 @@ void sport_motion(void)
*/
void sport_pid_init()
{
/* 角度控制 */
PID(&far_angle_pid, &in_angle, &out_angle, &set_angle, an_Kp, an_Ki, an_Kd, _PID_P_ON_E, _PID_CD_REVERSE);
PID_SetMode(&far_angle_pid, _PID_MODE_AUTOMATIC);
PID_SetSampleTime(&far_angle_pid, 20);
PID_SetOutputLimits(&far_angle_pid, -3000.0f, 3000.0f);
// PID_Init(&far_angle_pid);
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);
/* 角速度控制 */
PID(&far_gyro_pid, &in_gyro, &out_gyro, &out_angle, gy_Kp, gy_Ki, gy_Kd, _PID_P_ON_E, _PID_CD_REVERSE);
PID_SetMode(&far_gyro_pid, _PID_MODE_AUTOMATIC);
PID_SetSampleTime(&far_gyro_pid, 1);
PID_SetOutputLimits(&far_gyro_pid, -3000.0f, 3000.0f);
// PID_Init(&far_gyro_pid);
PID_SetOutputLimits(&far_angle_pid, -500.0f, 500.0f);
PID_SetOutputLimits(&far_gyro_pid, -500.0f, 500.0f);
/* 近点控制 */
PID(&near_pos_pid, &in_pos, &out_pos, &set_pos, po_Kp, po_Ki, po_Kd, _PID_P_ON_E, _PID_CD_DIRECT);
PID_SetMode(&near_pos_pid, _PID_MODE_AUTOMATIC);
PID_SetSampleTime(&near_pos_pid, 10);
PID_SetOutputLimits(&near_pos_pid, -3000.0f, 3000.0f);
// PID_Init(&near_pos_pid);
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, 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, 0.0f, 400.0f);
PID_SetMode(&near_pos_pid, 1);
PID_SetMode(&speed_pid, 1);
/* 速度控制 */
PID(&speed_pid, &in_speed, &out_speed, &set_speed, sp_Kp, sp_Ki, sp_Kd, _PID_P_ON_E, _PID_CD_DIRECT);
PID_SetMode(&speed_pid, _PID_MODE_AUTOMATIC);
PID_SetSampleTime(&speed_pid, 10);
PID_SetOutputLimits(&speed_pid, 0.0f, 2500.0f);
// PID_Init(&speed_pid);
}