日常更新

This commit is contained in:
2024-03-04 22:33:43 +08:00
parent 4cc3fd8864
commit 8c21e784d8
6 changed files with 32 additions and 28 deletions

View File

@@ -45,10 +45,10 @@ void by_buzzer_init(void)
by_buzzer_add(1250); by_buzzer_add(1250);
by_buzzer_add(1500); by_buzzer_add(1500);
by_buzzer_add(1750); by_buzzer_add(1700);
by_buzzer_add(1500); by_buzzer_add(1500);
by_buzzer_add(1200); by_buzzer_add(1200);
by_buzzer_add(900); by_buzzer_add(1500);
} }
void by_buzzer_add(uint16_t tone) void by_buzzer_add(uint16_t tone)

View File

@@ -37,8 +37,8 @@ void by_pwm_init(void)
void by_pwm_update_duty(uint32_t update_pwm_duty1, uint32_t 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, 900); update_pwm_duty1=myclip(update_pwm_duty1, 500, 1000);
update_pwm_duty2=myclip(update_pwm_duty2, 500, 900); update_pwm_duty2=myclip(update_pwm_duty2, 500, 1000);
pwm_set_duty(Fan_pwm_up1, update_pwm_duty1); pwm_set_duty(Fan_pwm_up1, update_pwm_duty1);
pwm_set_duty(Fan_pwm_up2, update_pwm_duty2); pwm_set_duty(Fan_pwm_up2, update_pwm_duty2);
} }

View File

@@ -96,8 +96,6 @@ void USART1_IRQHandler(void)
void USART2_IRQHandler(void) void USART2_IRQHandler(void)
{ {
if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) { if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) {
uart_query_byte(UART_2, &bt_buffer);
bt_rx_flag = true;
USART_ClearITPendingBit(USART2, USART_IT_RXNE); USART_ClearITPendingBit(USART2, USART_IT_RXNE);
} }
} }
@@ -140,7 +138,8 @@ void UART7_IRQHandler(void)
void UART8_IRQHandler(void) void UART8_IRQHandler(void)
{ {
if (USART_GetITStatus(UART8, USART_IT_RXNE) != RESET) { if (USART_GetITStatus(UART8, USART_IT_RXNE) != RESET) {
gps_uart_callback(); uart_query_byte(UART_8, &bt_buffer);
bt_rx_flag = true;
USART_ClearITPendingBit(UART8, USART_IT_RXNE); USART_ClearITPendingBit(UART8, USART_IT_RXNE);
} }
} }
@@ -315,7 +314,6 @@ void TIM6_IRQHandler(void)
{ {
if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET) { if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET) {
// ICM_getEulerianAngles(); // ICM_getEulerianAngles();
imu660ra_get_gyro();
TIM_ClearITPendingBit(TIM6, TIM_IT_Update); TIM_ClearITPendingBit(TIM6, TIM_IT_Update);
} }
} }

View File

@@ -21,9 +21,9 @@ enum bt_order {
*/ */
void jj_bt_init() void jj_bt_init()
{ {
uart_init(UART_2, 115200, UART2_MAP1_TX_D5, UART2_MAP1_RX_D6); uart_init(UART_8, 115200, UART8_MAP0_TX_C4, UART8_MAP0_RX_C5);
// uart_tx_interrupt(UART_2, 1); // uart_tx_interrupt(UART_2, 1);
uart_rx_interrupt(UART_2, ENABLE); uart_rx_interrupt(UART_8, ENABLE);
} }
/** /**
*@brief 蓝牙中断回调函数 *@brief 蓝牙中断回调函数
@@ -39,16 +39,16 @@ void jj_bt_run()
bt_run_flag = !bt_run_flag; bt_run_flag = !bt_run_flag;
break; break;
case Fly_up: case Fly_up:
bt_fly += 10; bt_fly += 50;
break; break;
case Fly_dowm: case Fly_dowm:
bt_fly -= 10; bt_fly -= 50;
break; break;
case Speed_up: case Speed_up:
bt_run += 10; bt_run += 50;
break; break;
case Speed_down: case Speed_down:
bt_run -= 10; bt_run -= 50;
break; break;
default: default:
break; break;
@@ -66,8 +66,8 @@ void bt_printf(const char *format, ...)
va_end(args); va_end(args);
for (uint16_t i = 0; i < strlen(sbuf); i++) { for (uint16_t i = 0; i < strlen(sbuf); i++) {
while (USART_GetFlagStatus((USART_TypeDef *)uart_index[UART_2], USART_FLAG_TC) == RESET) while (USART_GetFlagStatus((USART_TypeDef *)uart_index[UART_8], USART_FLAG_TC) == RESET)
; ;
USART_SendData((USART_TypeDef *)uart_index[UART_2], sbuf[i]); USART_SendData((USART_TypeDef *)uart_index[UART_8], sbuf[i]);
} }
} }

View File

@@ -44,6 +44,7 @@ void sport_motion(void)
{ {
cnt1++; cnt1++;
imu660ra_get_gyro();
in_gyro = imu660ra_gyro_z; // 陀螺仪输入 in_gyro = imu660ra_gyro_z; // 陀螺仪输入
// in_angle = 0; // 图像远端输入 // in_angle = 0; // 图像远端输入
// in_pos = 0; // 图像近端输入 // in_pos = 0; // 图像近端输入
@@ -53,15 +54,14 @@ void sport_motion(void)
if (cnt1 >= 10) { if (cnt1 >= 10) {
PID_Compute(&far_angle_pid); PID_Compute(&far_angle_pid);
PID_Compute(&speed_pid); PID_Compute(&speed_pid);
in_speed = encoder_get_count(TIM5_ENCOEDER); // 速度输入m/s in_speed = -encoder_get_count(TIM5_ENCOEDER); // 速度输入m/s
// printf("rate:%d\r\n", (int16)in_speed); // printf("rate:%d\r\n", (int16)in_speed);
encoder_clear_count(TIM5_ENCOEDER); encoder_clear_count(TIM5_ENCOEDER);
PID_Compute(&near_pos_pid);
cnt1 = 0; cnt1 = 0;
} }
PID_Compute(&near_pos_pid); if (bt_run_flag == 1) {
if (bt_run_flag == 1) {
by_pwm_power_duty((int32_t)(500 + out_pos + out_gyro), by_pwm_power_duty((int32_t)(500 + out_pos + out_gyro),
(int32_t)(500 - out_pos - out_gyro), (int32_t)(500 - out_pos - out_gyro),
(int32_t)(500 + out_speed + out_gyro), (int32_t)(500 + out_speed + out_gyro),
@@ -72,7 +72,6 @@ void sport_motion(void)
if (bt_fly_flag == 0) { if (bt_fly_flag == 0) {
bt_fly = 0; bt_fly = 0;
} }
by_pwm_update_duty(bt_fly + 500, bt_fly + 500); by_pwm_update_duty(bt_fly + 500, bt_fly + 500);
} }
/** /**
@@ -82,7 +81,7 @@ void sport_motion(void)
void sport_pid_init() void sport_pid_init()
{ {
PID(&far_angle_pid, &in_angle, &out_angle, &set_angle, an_Kp, an_Ki, an_Kd, 0, 0); PID(&far_angle_pid, &in_angle, &out_angle, &set_angle, an_Kp, an_Ki, an_Kd, 0, 1);
PID(&far_gyro_pid, &in_gyro, &out_gyro, &out_angle, gy_Kp, gy_Ki, gy_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_angle_pid);
PID_Init(&far_gyro_pid); PID_Init(&far_gyro_pid);
@@ -94,7 +93,7 @@ void sport_pid_init()
PID_SetMode(&far_angle_pid, 1); PID_SetMode(&far_angle_pid, 1);
PID(&near_pos_pid, &in_pos, &out_pos, &set_pos, po_Kp, po_Ki, po_Kd, 0, 0); PID(&near_pos_pid, &in_pos, &out_pos, &set_pos, po_Kp, po_Ki, po_Kd, 0, 0);
PID(&speed_pid, &in_speed, &out_speed, &out_speed, sp_Kp, sp_Ki, sp_Kd, 1, 1); PID(&speed_pid, &in_speed, &out_speed, &set_speed, sp_Kp, sp_Ki, sp_Kd, 1, 0);
PID_Init(&near_pos_pid); PID_Init(&near_pos_pid);
PID_Init(&speed_pid); PID_Init(&speed_pid);

View File

@@ -50,22 +50,29 @@ int main(void)
jj_bt_init(); jj_bt_init();
by_rb_init(); by_rb_init();
by_pwm_init(); by_pwm_init();
// by_buzzer_init(); by_buzzer_init();
by_frame_init(); by_frame_init();
Page_Init(); Page_Init();
sport_pid_init(); sport_pid_init();
pit_ms_init(TIM6_PIT, 10); // 陀螺仪
pit_ms_init(TIM1_PIT, 1); // 运动解算bianmaqi pit_ms_init(TIM1_PIT, 1); // 运动解算bianmaqi
printf("ok\r\n"); printf("ok\r\n");
while (1) { while (1) {
Page_Run(); Page_Run();
by_frame_parse(2, &test_data[1].u32); by_frame_parse(2, &test_data[0].u32);
// uart_write_byte(UART_8, 0x1F);
by_buzzer_run(); by_buzzer_run();
jj_bt_run(); jj_bt_run();
in_pos=test_data[1].f32;
in_angle=test_data[0].f32;
ips200_show_float(40, 40, test_data[0].f32, 4, 1);
ips200_show_float(40, 60, test_data[1].f32, 4, 1);
ips200_show_float(40, 80, in_gyro, 4, 2);
ips200_show_float(40, 100, in_speed, 4, 4);
ips200_show_string(0,120,"outang"); ips200_show_float(80,120,out_angle,4,1);
ips200_show_string(0,140,"outgyr"); ips200_show_float(80,140,out_gyro,4,1);
} }
} }