完赛的一个版本
This commit is contained in:
@@ -12,11 +12,11 @@
|
|||||||
#define FAN_RB_PWM_A_PIN TIM4_PWM_MAP1_CH1_D12 // 右后
|
#define FAN_RB_PWM_A_PIN TIM4_PWM_MAP1_CH1_D12 // 右后
|
||||||
#define FAN_RB_PWM_B_PIN TIM4_PWM_MAP1_CH3_D14 // 右后
|
#define FAN_RB_PWM_B_PIN TIM4_PWM_MAP1_CH3_D14 // 右后
|
||||||
// M3
|
// M3
|
||||||
#define FAN_LS_PWM_A_PIN TIM10_PWM_MAP3_CH3_D5 // 左侧
|
#define FAN_LS_PWM_B_PIN TIM10_PWM_MAP3_CH3_D5 // 左侧
|
||||||
#define FAN_LS_PWM_B_PIN TIM10_PWM_MAP3_CH1_D1 // 左侧
|
#define FAN_LS_PWM_A_PIN TIM10_PWM_MAP3_CH1_D1 // 左侧
|
||||||
// M2
|
// M2
|
||||||
#define FAN_RS_PWM_A_PIN TIM4_PWM_MAP1_CH4_D15 // 右侧
|
#define FAN_RS_PWM_B_PIN TIM4_PWM_MAP1_CH4_D15 // 右侧
|
||||||
#define FAN_RS_PWM_B_PIN TIM4_PWM_MAP1_CH2_D13 // 右侧
|
#define FAN_RS_PWM_A_PIN TIM4_PWM_MAP1_CH2_D13 // 右侧
|
||||||
|
|
||||||
int32_t pwm_duty_ls_g;
|
int32_t pwm_duty_ls_g;
|
||||||
int32_t pwm_duty_rs_g;
|
int32_t pwm_duty_rs_g;
|
||||||
@@ -49,24 +49,24 @@ void by_pwm_init(void)
|
|||||||
pwm_init(FAN_RL_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, 30000, 1000);
|
pwm_init(FAN_LS_PWM_A_PIN, 20000, 7000);
|
||||||
pwm_init(FAN_LS_PWM_B_PIN, 30000, 1000);
|
pwm_init(FAN_LS_PWM_B_PIN, 20000, 7000);
|
||||||
pwm_init(FAN_RS_PWM_A_PIN, 12000, 1000);
|
pwm_init(FAN_RS_PWM_A_PIN, 20000, 7000);
|
||||||
pwm_init(FAN_RS_PWM_B_PIN, 12000, 1000);
|
pwm_init(FAN_RS_PWM_B_PIN, 20000, 7000);
|
||||||
pwm_init(FAN_LB_PWM_A_PIN, 12000, 1000);
|
pwm_init(FAN_LB_PWM_A_PIN, 20000, 7000);
|
||||||
pwm_init(FAN_LB_PWM_B_PIN, 12000, 1000);
|
pwm_init(FAN_LB_PWM_B_PIN, 20000, 7000);
|
||||||
pwm_init(FAN_RB_PWM_A_PIN, 30000, 1000);
|
pwm_init(FAN_RB_PWM_A_PIN, 20000, 7000);
|
||||||
pwm_init(FAN_RB_PWM_B_PIN, 30000, 1000);
|
pwm_init(FAN_RB_PWM_B_PIN, 20000, 7000);
|
||||||
while (1);
|
while (1);
|
||||||
#elif FIX_DRIVE == 2
|
#elif FIX_DRIVE == 2
|
||||||
pwm_init(FAN_LS_PWM_A_PIN, 12000, 1000);
|
pwm_init(FAN_LS_PWM_A_PIN, 20000, 7000);
|
||||||
pwm_init(FAN_LS_PWM_B_PIN, 12000, 0);
|
pwm_init(FAN_LS_PWM_B_PIN, 20000, 0);
|
||||||
pwm_init(FAN_RS_PWM_A_PIN, 12000, 1000);
|
pwm_init(FAN_RS_PWM_A_PIN, 20000, 7000);
|
||||||
pwm_init(FAN_RS_PWM_B_PIN, 12000, 0);
|
pwm_init(FAN_RS_PWM_B_PIN, 20000, 0);
|
||||||
pwm_init(FAN_LB_PWM_A_PIN, 12000, 1000);
|
pwm_init(FAN_LB_PWM_A_PIN, 20000, 7000);
|
||||||
pwm_init(FAN_LB_PWM_B_PIN, 12000, 0);
|
pwm_init(FAN_LB_PWM_B_PIN, 20000, 0);
|
||||||
pwm_init(FAN_RB_PWM_A_PIN, 12000, 1000);
|
pwm_init(FAN_RB_PWM_A_PIN, 20000, 7000);
|
||||||
pwm_init(FAN_RB_PWM_B_PIN, 12000, 0);
|
pwm_init(FAN_RB_PWM_B_PIN, 20000, 0);
|
||||||
while (1);
|
while (1);
|
||||||
#endif
|
#endif
|
||||||
pwm_init(FAN_LS_PWM_A_PIN, 20000, 0);
|
pwm_init(FAN_LS_PWM_A_PIN, 20000, 0);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "zf_common_headfile.h"
|
#include "zf_common_headfile.h"
|
||||||
#include "pid.h"
|
#include "pid.h"
|
||||||
|
#include "jj_voltage.h"
|
||||||
#include "jj_blueteeth.h"
|
#include "jj_blueteeth.h"
|
||||||
#include "by_fan_control.h"
|
#include "by_fan_control.h"
|
||||||
#include "by_imu.h"
|
#include "by_imu.h"
|
||||||
@@ -88,6 +88,7 @@ int32_t pwm_duty_ls;
|
|||||||
int32_t pwm_duty_rs;
|
int32_t pwm_duty_rs;
|
||||||
int32_t pwm_duty_lb;
|
int32_t pwm_duty_lb;
|
||||||
int32_t pwm_duty_rb;
|
int32_t pwm_duty_rb;
|
||||||
|
float qd_down = 0.0f;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
0:无状态
|
0:无状态
|
||||||
@@ -123,6 +124,7 @@ void sport_motion()
|
|||||||
|
|
||||||
imu660ra_get_gyro();
|
imu660ra_get_gyro();
|
||||||
imu660ra_get_acc();
|
imu660ra_get_acc();
|
||||||
|
get_vol();
|
||||||
in_gyro = imu660ra_gyro_z;
|
in_gyro = imu660ra_gyro_z;
|
||||||
// 抖动停车
|
// 抖动停车
|
||||||
if (imu660ra_acc_z <= 600) {
|
if (imu660ra_acc_z <= 600) {
|
||||||
@@ -149,6 +151,7 @@ void sport_motion()
|
|||||||
if ((last_state != in_state) && (in_state == 0 || in_state == 2)) { // 直道
|
if ((last_state != in_state) && (in_state == 0 || in_state == 2)) { // 直道
|
||||||
cnt3_flag = 1;
|
cnt3_flag = 1;
|
||||||
cnt3 = 0;
|
cnt3 = 0;
|
||||||
|
|
||||||
bt_printf("to 直道");
|
bt_printf("to 直道");
|
||||||
set_speed = set_speed1;
|
set_speed = set_speed1;
|
||||||
PID_SetTunings(&far_angle_pid, an_Kp1, an_Ki1, an_Kd1);
|
PID_SetTunings(&far_angle_pid, an_Kp1, an_Ki1, an_Kd1);
|
||||||
@@ -165,6 +168,7 @@ void sport_motion()
|
|||||||
if ((last_state != in_state) && in_state == 3) { // 圆环
|
if ((last_state != in_state) && in_state == 3) { // 圆环
|
||||||
bt_printf("to 圆环");
|
bt_printf("to 圆环");
|
||||||
set_speed = set_speed2;
|
set_speed = set_speed2;
|
||||||
|
|
||||||
cnt3_flag = 1;
|
cnt3_flag = 1;
|
||||||
PID_SetTunings(&far_angle_pid, yu_Kp0, yu_Ki0, yu_Kd0);
|
PID_SetTunings(&far_angle_pid, yu_Kp0, yu_Ki0, yu_Kd0);
|
||||||
PID_SetTunings(&far_gyro_pid, ygy_Kp0, ygy_Ki0, ygy_Kd0);
|
PID_SetTunings(&far_gyro_pid, ygy_Kp0, ygy_Ki0, ygy_Kd0);
|
||||||
@@ -181,10 +185,11 @@ void sport_motion()
|
|||||||
cnt2 = 0;
|
cnt2 = 0;
|
||||||
}
|
}
|
||||||
if (cnt5 >= 20) {
|
if (cnt5 >= 20) {
|
||||||
PID_Compute(&speed_pid);
|
|
||||||
PID_Compute(&far_angle_pid);
|
PID_Compute(&far_angle_pid);
|
||||||
PID_Compute(&str_angle_pid);
|
PID_Compute(&str_angle_pid);
|
||||||
PID_Compute(&tur_cal_pid);
|
PID_Compute(&tur_cal_pid);
|
||||||
|
PID_Compute(&speed_pid);
|
||||||
cnt5 = 0;
|
cnt5 = 0;
|
||||||
}
|
}
|
||||||
// 输出限幅
|
// 输出限幅
|
||||||
@@ -234,8 +239,12 @@ void sport_motion()
|
|||||||
cnt3 = 0;
|
cnt3 = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float tt = 6 * fabs(in_pos);
|
if (in_speed > set_speed - 100) {
|
||||||
by_pwm_update_duty(bt_fly + 500 - tt, bt_fly + 500 - tt);
|
qd_down = 6 * fabs(in_pos);
|
||||||
|
} else {
|
||||||
|
qd_down = 0;
|
||||||
|
}
|
||||||
|
by_pwm_update_duty(bt_fly + 500 - qd_down, bt_fly + 500 - qd_down);
|
||||||
} else {
|
} else {
|
||||||
if (in_state == 4) {
|
if (in_state == 4) {
|
||||||
by_pwm_update_duty(bt_fly + 515, bt_fly + 515);
|
by_pwm_update_duty(bt_fly + 515, bt_fly + 515);
|
||||||
@@ -277,7 +286,7 @@ void sport_pid_init()
|
|||||||
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(&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_SetMode(&far_gyro_pid, _PID_MODE_AUTOMATIC);
|
||||||
PID_SetSampleTime(&far_gyro_pid, 20);
|
PID_SetSampleTime(&far_gyro_pid, 20);
|
||||||
PID_SetOutputLimits(&far_gyro_pid, -5500.0f, 5500.0f);
|
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(&speed_pid, &in_speed, &out_speed, &set_speed, sp_Kp, sp_Ki, sp_Kd, _PID_P_ON_M, _PID_CD_DIRECT);
|
||||||
|
|||||||
@@ -1 +1,13 @@
|
|||||||
#include "jj_voltage.h"
|
#include "jj_voltage.h"
|
||||||
|
#include "zf_driver_adc.h"
|
||||||
|
|
||||||
|
#define GET_VOL_PIN ADC2_IN5_A5
|
||||||
|
float now_vol;
|
||||||
|
void vol_init(void)
|
||||||
|
{
|
||||||
|
adc_init(GET_VOL_PIN,ADC_12BIT);
|
||||||
|
}
|
||||||
|
void get_vol()
|
||||||
|
{
|
||||||
|
now_vol=0.003377f*adc_convert(GET_VOL_PIN)+0.16f;
|
||||||
|
}
|
||||||
@@ -3,5 +3,7 @@
|
|||||||
|
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "zf_driver_uart.h"
|
#include "zf_driver_uart.h"
|
||||||
|
extern float now_vol;
|
||||||
|
void vol_init();
|
||||||
|
void get_vol();
|
||||||
#endif
|
#endif
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "jj_param.h"
|
#include "jj_param.h"
|
||||||
#include "jj_motion.h"
|
#include "jj_motion.h"
|
||||||
#include "jj_blueteeth.h"
|
#include "jj_blueteeth.h"
|
||||||
|
#include "jj_voltage.h"
|
||||||
|
|
||||||
#include "by_imu.h"
|
#include "by_imu.h"
|
||||||
#include "by_vofa.h"
|
#include "by_vofa.h"
|
||||||
@@ -49,6 +50,7 @@ int main(void)
|
|||||||
;
|
;
|
||||||
jj_param_eeprom_init();
|
jj_param_eeprom_init();
|
||||||
jj_bt_init();
|
jj_bt_init();
|
||||||
|
vol_init();
|
||||||
by_rb_init();
|
by_rb_init();
|
||||||
by_pwm_init();
|
by_pwm_init();
|
||||||
by_buzzer_init();
|
by_buzzer_init();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "page_ui_widget.h"
|
#include "page_ui_widget.h"
|
||||||
#include "jj_motion.h"
|
#include "jj_motion.h"
|
||||||
#include "page.h"
|
#include "page.h"
|
||||||
|
#include"jj_voltage.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#define LINE_HEAD 0
|
#define LINE_HEAD 0
|
||||||
@@ -62,6 +62,8 @@ static void Loop()
|
|||||||
ips200_show_float(80, 160, out_pos, 4, 1);
|
ips200_show_float(80, 160, out_pos, 4, 1);
|
||||||
ips200_show_string(0, 180, "outcal");
|
ips200_show_string(0, 180, "outcal");
|
||||||
ips200_show_float(80, 180, out_cal, 4, 1);
|
ips200_show_float(80, 180, out_cal, 4, 1);
|
||||||
|
ips200_show_string(0, 200, "vol");
|
||||||
|
ips200_show_float(80, 200, (float)now_vol, 4,2);
|
||||||
|
|
||||||
ips200_show_string(180, 0, "ls");
|
ips200_show_string(180, 0, "ls");
|
||||||
ips200_show_float(220, 0, pwm_duty_ls, 4, 1);
|
ips200_show_float(220, 0, pwm_duty_ls, 4, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user