增加发车状态上发
This commit is contained in:
@@ -78,10 +78,10 @@ void by_pwm_init(void)
|
|||||||
// pwm_init(FAN_LS_PWM_B_PIN, 40000, 0);
|
// pwm_init(FAN_LS_PWM_B_PIN, 40000, 0);
|
||||||
// pwm_init(FAN_RS_PWM_A_PIN, 40000, 0);
|
// pwm_init(FAN_RS_PWM_A_PIN, 40000, 0);
|
||||||
// pwm_init(FAN_RS_PWM_B_PIN, 40000, 0);
|
// pwm_init(FAN_RS_PWM_B_PIN, 40000, 0);
|
||||||
pwm_init(FAN_LB_PWM_A_PIN, 30000, 0);
|
pwm_init(FAN_LB_PWM_A_PIN, 50000, 0);
|
||||||
pwm_init(FAN_LB_PWM_B_PIN, 30000, 0);
|
pwm_init(FAN_LB_PWM_B_PIN, 50000, 0);
|
||||||
pwm_init(FAN_RB_PWM_A_PIN, 30000, 0);
|
pwm_init(FAN_RB_PWM_A_PIN, 50000, 0);
|
||||||
pwm_init(FAN_RB_PWM_B_PIN, 30000, 0);
|
pwm_init(FAN_RB_PWM_B_PIN, 50000, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ void by_frame_init(void)
|
|||||||
void by_frame_send(uint32_t* data_array)
|
void by_frame_send(uint32_t* data_array)
|
||||||
{
|
{
|
||||||
uint16_t crc_cal = 0;
|
uint16_t crc_cal = 0;
|
||||||
const uint8_t data_byte_num = BY_FRAME_DATA_NUM * sizeof(uint32_t);
|
const uint8_t data_byte_num = 1 * sizeof(uint32_t);
|
||||||
|
|
||||||
frame_buffer_send[0] = BY_FRAME_HEAD_1;
|
frame_buffer_send[0] = BY_FRAME_HEAD_1;
|
||||||
frame_buffer_send[1] = BY_FRAME_HEAD_2;
|
frame_buffer_send[1] = BY_FRAME_HEAD_2;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#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"
|
||||||
|
#include "by_frame.h"
|
||||||
|
|
||||||
PID_TypeDef far_angle_pid;
|
PID_TypeDef far_angle_pid;
|
||||||
PID_TypeDef pos_pid;
|
PID_TypeDef pos_pid;
|
||||||
@@ -103,9 +104,9 @@ 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;
|
||||||
int stop_have = 0;
|
uint32_t stop_have = 0;
|
||||||
float qd_down = 0.0f;
|
float qd_down = 0.0f;
|
||||||
float last_gy = 0.0f;
|
float last_gy = 0.0f;
|
||||||
/*
|
/*
|
||||||
0:无状态
|
0:无状态
|
||||||
1:弯道
|
1:弯道
|
||||||
@@ -146,16 +147,15 @@ void sport_motion()
|
|||||||
|
|
||||||
if (imu660ra_acc_z <= 800) {
|
if (imu660ra_acc_z <= 800) {
|
||||||
cnt7++;
|
cnt7++;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
cnt7 = 0;
|
cnt7 = 0;
|
||||||
}
|
}
|
||||||
if (cnt7 >= 50) {
|
if (cnt7 >= 100) {
|
||||||
bt_fly_flag = bt_run_flag = 0;
|
bt_fly_flag = bt_run_flag = 0;
|
||||||
bt_printf("ting");
|
bt_printf("ting");
|
||||||
}
|
}
|
||||||
// 斑马线停车
|
// 斑马线停车
|
||||||
if (1 == in_stop && stop_have == 1) {
|
if (1 == in_stop) {
|
||||||
stop_flag = 1;
|
stop_flag = 1;
|
||||||
}
|
}
|
||||||
if (stop_flag == 1) {
|
if (stop_flag == 1) {
|
||||||
@@ -169,10 +169,10 @@ void sport_motion()
|
|||||||
cnt1++;
|
cnt1++;
|
||||||
cnt2++;
|
cnt2++;
|
||||||
cnt5++;
|
cnt5++;
|
||||||
cnt8++;
|
// 屏蔽斑马线
|
||||||
if (cnt8 >= 10000) {
|
if (stop_have == 0) {
|
||||||
stop_have = 1;
|
stop_have = 1;
|
||||||
cnt8=0;
|
by_frame_send(&stop_have);
|
||||||
}
|
}
|
||||||
// pid参数切换
|
// pid参数切换
|
||||||
if ((last_state != in_state) && (in_state == 0 || in_state == 2)) { // 直道
|
if ((last_state != in_state) && (in_state == 0 || in_state == 2)) { // 直道
|
||||||
@@ -231,8 +231,8 @@ void sport_motion()
|
|||||||
// 并级pid,限幅
|
// 并级pid,限幅
|
||||||
pwm_duty_ls = (int32_t)myclip_f(300 - out_pos, 100.0f, 500.f);
|
pwm_duty_ls = (int32_t)myclip_f(300 - out_pos, 100.0f, 500.f);
|
||||||
pwm_duty_rs = (int32_t)myclip_f(300 + out_pos, 100.0f, 500.f);
|
pwm_duty_rs = (int32_t)myclip_f(300 + out_pos, 100.0f, 500.f);
|
||||||
pwm_duty_lb = (int32_t)myclip_f(out_speed + out_gyro, 0.0f, 5000.f);
|
pwm_duty_lb = (int32_t)myclip_f(out_speed + out_gyro, 0.0f, 6000.f);
|
||||||
pwm_duty_rb = (int32_t)myclip_f(out_speed - out_gyro, 0.0f, 5000.f);
|
pwm_duty_rb = (int32_t)myclip_f(out_speed - out_gyro, 0.0f, 6000.f);
|
||||||
|
|
||||||
by_pwm_power_duty(500 + pwm_duty_ls, 500 + pwm_duty_rs, pwm_duty_lb, pwm_duty_rb);
|
by_pwm_power_duty(500 + pwm_duty_ls, 500 + pwm_duty_rs, pwm_duty_lb, pwm_duty_rb);
|
||||||
|
|
||||||
@@ -248,14 +248,14 @@ void sport_motion()
|
|||||||
cnt3++;
|
cnt3++;
|
||||||
|
|
||||||
if (in_state == 3) {
|
if (in_state == 3) {
|
||||||
if (cnt3 >= 100) // 200ms
|
if (cnt3 >= 1000) // 200ms
|
||||||
{
|
{
|
||||||
bt_printf("to 环内");
|
bt_printf("to 环内");
|
||||||
cnt3_flag = 2;
|
cnt3_flag = 2;
|
||||||
cnt3 = 0;
|
cnt3 = 0;
|
||||||
}
|
}
|
||||||
if (in_speed > set_speed) {
|
if (in_speed > set_speed) {
|
||||||
qd_down = 50;
|
qd_down = 50;
|
||||||
} else if (in_speed > set_speed - 100) {
|
} else if (in_speed > set_speed - 100) {
|
||||||
qd_down = 20;
|
qd_down = 20;
|
||||||
} else {
|
} else {
|
||||||
@@ -293,12 +293,12 @@ void sport_motion()
|
|||||||
|
|
||||||
by_pwm_update_duty(bt_fly + 500 - qd_down, bt_fly + 500 - qd_down);
|
by_pwm_update_duty(bt_fly + 500 - qd_down, bt_fly + 500 - qd_down);
|
||||||
} else {
|
} else {
|
||||||
if (in_state == 1 ) {
|
if (in_state == 1) {
|
||||||
qd_down = 40;
|
qd_down = 50;
|
||||||
} else if(in_state == 3){
|
} else if (in_state == 3) {
|
||||||
qd_down = 70;
|
qd_down = 10;
|
||||||
}else{
|
} else {
|
||||||
qd_down=0;
|
qd_down = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
by_pwm_update_duty(bt_fly + 500 - qd_down, bt_fly + 500 - qd_down);
|
by_pwm_update_duty(bt_fly + 500 - qd_down, bt_fly + 500 - qd_down);
|
||||||
@@ -327,11 +327,11 @@ 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, -5000.0f, 5000.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);
|
||||||
PID_SetMode(&speed_pid, _PID_MODE_AUTOMATIC);
|
PID_SetMode(&speed_pid, _PID_MODE_AUTOMATIC);
|
||||||
PID_SetSampleTime(&speed_pid, 20);
|
PID_SetSampleTime(&speed_pid, 20);
|
||||||
PID_SetOutputLimits(&speed_pid, -0.0f, 4500.0f);
|
PID_SetOutputLimits(&speed_pid, -0.0f, 6000.0f);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ int main(void)
|
|||||||
bt_printf("ok\r\n");
|
bt_printf("ok\r\n");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
// printf("pwm:%lu,%lu,%lu,%lu\r\n", pwm_duty_ls_g, pwm_duty_rs_g, pwm_duty_lb_g, pwm_duty_rb_g);
|
// printf("pwm:%lu,%lu,%lu,%lu\r\n", pwm_duty_ls_g, pwm_duty_rs_g, pwm_duty_lb_g, pwm_duty_rb_g);
|
||||||
Page_Run();
|
Page_Run();
|
||||||
by_frame_parse(&test_data[0].u32);
|
by_frame_parse(&test_data[0].u32);
|
||||||
|
|||||||
Reference in New Issue
Block a user