feat: 初步完成有刷适配
This commit is contained in:
@@ -62,7 +62,8 @@
|
||||
"app/page",
|
||||
"app/tiny_frame",
|
||||
"3rd-lib/crc16",
|
||||
"3rd-lib/lwrb/inc"
|
||||
"3rd-lib/lwrb/inc",
|
||||
"3rd-lib/PID-Library"
|
||||
],
|
||||
"libList": [
|
||||
"libraries/zf_device"
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "zf_common_headfile.h"
|
||||
// #include "zf_common_headfile.h"
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Defines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
|
||||
/* ------------------------ Library ------------------------ */
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "by_fan_control.h"
|
||||
#include "zf_common_headfile.h"
|
||||
#define Fan_pwm_up1 TIM8_PWM_MAP0_CH1_C6
|
||||
#define Fan_pwm_up2 TIM8_PWM_MAP0_CH2_C7
|
||||
#define Fan_pwm_power1 TIM4_PWM_MAP1_CH3_D14
|
||||
#define Fan_pwm_power2 TIM4_PWM_MAP1_CH4_D15
|
||||
#define Fan_pwm_power3 TIM4_PWM_MAP1_CH2_D13
|
||||
#define Fan_pwm_power4 TIM4_PWM_MAP1_CH1_D12
|
||||
|
||||
#define FAN_LL_PWM_PIN TIM8_PWM_MAP0_CH1_C6 // 左升力风扇
|
||||
#define FAN_RL_PWM_PIN TIM8_PWM_MAP0_CH2_C7 // 右升力风扇
|
||||
#define FAN_LS_PWM_PIN TIM4_PWM_MAP1_CH4_D15 // 左侧动力风扇
|
||||
#define FAN_RS_PWM_PIN TIM4_PWM_MAP1_CH3_D14 // 右侧动力风扇
|
||||
#define FAN_LB_PWM_PIN TIM4_PWM_MAP1_CH2_D13 // 左后动力风扇
|
||||
#define FAN_RB_PWM_PIN TIM4_PWM_MAP1_CH1_D12 // 右后动力风扇
|
||||
|
||||
uint32_t myclip(uint32_t x, uint32_t low, uint32_t up)
|
||||
{
|
||||
@@ -15,51 +16,58 @@ uint32_t myclip(uint32_t x, uint32_t low, uint32_t up)
|
||||
|
||||
void by_pwm_init(void)
|
||||
{
|
||||
pwm_init(Fan_pwm_up1, 50, 500); // 浮力风扇左
|
||||
pwm_init(Fan_pwm_up2, 50, 500); // 浮力风扇右
|
||||
pwm_init(FAN_LL_PWM_PIN, 50, 500);
|
||||
pwm_init(FAN_RL_PWM_PIN, 50, 500);
|
||||
|
||||
pwm_init(Fan_pwm_power1, 50, 500); // 动力风扇左 1
|
||||
pwm_init(Fan_pwm_power2, 50, 500); // 动力风扇右 1
|
||||
pwm_init(Fan_pwm_power3, 50, 500); // 动力风扇左 2
|
||||
pwm_init(Fan_pwm_power4, 50, 500); // 动力风扇右 2
|
||||
pwm_init(FAN_LS_PWM_PIN, 4000, 500);
|
||||
pwm_init(FAN_RS_PWM_PIN, 4000, 500);
|
||||
pwm_init(FAN_LB_PWM_PIN, 4000, 500);
|
||||
pwm_init(FAN_RB_PWM_PIN, 4000, 500);
|
||||
// system_delay_ms(3000);
|
||||
// // pwm_init(Fan_pwm_power1, 50, 1000); // 动力风扇左 1
|
||||
// // pwm_init(Fan_pwm_power2, 50, 1000); // 动力风扇右 1
|
||||
// // pwm_init(Fan_pwm_power3, 50, 1000); // 动力风扇左 2
|
||||
// // pwm_init(Fan_pwm_power4, 50, 1000); // 动力风扇右 2
|
||||
// // pwm_init(FAN_LS_PWM_PIN, 50, 1000); // 动力风扇左 1
|
||||
// // pwm_init(FAN_RS_PWM_PIN, 50, 1000); // 动力风扇右 1
|
||||
// // pwm_init(FAN_LB_PWM_PIN, 50, 1000); // 动力风扇左 2
|
||||
// // pwm_init(FAN_RB_PWM_PIN, 50, 1000); // 动力风扇右 2
|
||||
// // system_delay_ms(5000);
|
||||
// pwm_set_duty(Fan_pwm_power1, 600);
|
||||
// pwm_set_duty(Fan_pwm_power2, 600);
|
||||
// pwm_set_duty(Fan_pwm_power3, 600);
|
||||
// pwm_set_duty(Fan_pwm_power4, 600);
|
||||
// pwm_set_duty(FAN_LS_PWM_PIN, 600);
|
||||
// pwm_set_duty(FAN_RS_PWM_PIN, 600);
|
||||
// pwm_set_duty(FAN_LB_PWM_PIN, 600);
|
||||
// pwm_set_duty(FAN_RB_PWM_PIN, 600);
|
||||
// while(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 更新升力风扇占空比
|
||||
*
|
||||
* @param update_pwm_duty1
|
||||
* @param update_pwm_duty2
|
||||
*/
|
||||
void by_pwm_update_duty(uint32_t update_pwm_duty1, uint32_t update_pwm_duty2)
|
||||
{
|
||||
update_pwm_duty1 = myclip(update_pwm_duty1, 500, 1000);
|
||||
update_pwm_duty2 = myclip(update_pwm_duty2, 500, 1000);
|
||||
pwm_set_duty(Fan_pwm_up1, update_pwm_duty1);
|
||||
pwm_set_duty(Fan_pwm_up2, update_pwm_duty2);
|
||||
pwm_set_duty(FAN_LL_PWM_PIN, update_pwm_duty1);
|
||||
pwm_set_duty(FAN_RL_PWM_PIN, update_pwm_duty2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @brief 更新动力风扇占空比
|
||||
*
|
||||
* @param power_pwm_duty_l1 左转向风扇
|
||||
* @param power_pwm_duty_r1 右转向风扇
|
||||
* @param power_pwm_duty_l2 左驱动风扇
|
||||
* @param power_pwm_duty_r2 右驱动风扇
|
||||
* @param pwm_duty_ls
|
||||
* @param pwm_duty_rs
|
||||
* @param pwm_duty_lb
|
||||
* @param pwm_duty_rb
|
||||
*/
|
||||
void by_pwm_power_duty(uint32_t power_pwm_duty_l1, uint32_t power_pwm_duty_r1, uint32_t power_pwm_duty_l2, uint32_t power_pwm_duty_r2)
|
||||
void by_pwm_power_duty(uint32_t pwm_duty_ls, uint32_t pwm_duty_rs, uint32_t pwm_duty_lb, uint32_t pwm_duty_rb)
|
||||
{
|
||||
|
||||
power_pwm_duty_l1=myclip(power_pwm_duty_l1, 500, 900);
|
||||
power_pwm_duty_r1=myclip(power_pwm_duty_r1, 500, 900);
|
||||
power_pwm_duty_l2=myclip(power_pwm_duty_l2, 500, 900);
|
||||
power_pwm_duty_r2=myclip(power_pwm_duty_r2, 500, 900);
|
||||
pwm_duty_ls = myclip(pwm_duty_ls, 500, 3000);
|
||||
pwm_duty_rs = myclip(pwm_duty_rs, 500, 3000);
|
||||
pwm_duty_lb = myclip(pwm_duty_lb, 500, 3000);
|
||||
pwm_duty_rb = myclip(pwm_duty_rb, 500, 3000);
|
||||
|
||||
pwm_set_duty(Fan_pwm_power1, power_pwm_duty_l1);
|
||||
pwm_set_duty(Fan_pwm_power2, power_pwm_duty_r1);
|
||||
pwm_set_duty(Fan_pwm_power3, power_pwm_duty_l2);
|
||||
pwm_set_duty(Fan_pwm_power4, power_pwm_duty_r2);
|
||||
pwm_set_duty(FAN_LS_PWM_PIN, pwm_duty_ls);
|
||||
pwm_set_duty(FAN_RS_PWM_PIN, pwm_duty_rs);
|
||||
pwm_set_duty(FAN_LB_PWM_PIN, pwm_duty_lb);
|
||||
pwm_set_duty(FAN_RB_PWM_PIN, pwm_duty_rb);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ int main(void)
|
||||
while (1) {
|
||||
debug_array[0] = in_pos;
|
||||
debug_array[1] = out_pos;
|
||||
by_vofa_send(&vofa_test); // 发送数据
|
||||
// by_vofa_send(&vofa_test); // 发送数据
|
||||
Page_Run();
|
||||
by_frame_parse(2, &test_data[0].u32);
|
||||
by_buzzer_run();
|
||||
|
||||
@@ -42,11 +42,11 @@ static void Exit()
|
||||
*/
|
||||
static void Loop()
|
||||
{
|
||||
ips200_show_string(0, 40, "far");
|
||||
ips200_show_string(0, 40, "angle");
|
||||
ips200_show_float(80, 40, in_angle, 4, 1);
|
||||
ips200_show_string(0, 60, "near");
|
||||
ips200_show_float(80, 60, in_pos, 4, 1);
|
||||
ips200_show_string(0, 80, "gyrz");
|
||||
ips200_show_string(0, 80, "gyroz");
|
||||
ips200_show_float(80, 80, in_gyro, 4, 2);
|
||||
ips200_show_string(0, 100, "speed");
|
||||
ips200_show_float(80, 100, in_speed, 4, 4);
|
||||
|
||||
Reference in New Issue
Block a user