From 8c21e784d8eb4cd093454cf2fb578ce115644dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=95=E6=98=8E=E6=B1=9F?= <246462502@qq.com> Date: Mon, 4 Mar 2024 22:33:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=B8=B8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/by_buzzer.c | 4 ++-- app/by_fan_control.c | 4 ++-- app/isr.c | 6 ++---- app/jj_blueteeth.c | 16 ++++++++-------- app/jj_motion.c | 15 +++++++-------- app/main.c | 15 +++++++++++---- 6 files changed, 32 insertions(+), 28 deletions(-) diff --git a/app/by_buzzer.c b/app/by_buzzer.c index d674999..59ef66f 100644 --- a/app/by_buzzer.c +++ b/app/by_buzzer.c @@ -45,10 +45,10 @@ void by_buzzer_init(void) by_buzzer_add(1250); by_buzzer_add(1500); - by_buzzer_add(1750); + by_buzzer_add(1700); by_buzzer_add(1500); by_buzzer_add(1200); - by_buzzer_add(900); + by_buzzer_add(1500); } void by_buzzer_add(uint16_t tone) diff --git a/app/by_fan_control.c b/app/by_fan_control.c index e497d58..6122dd3 100644 --- a/app/by_fan_control.c +++ b/app/by_fan_control.c @@ -37,8 +37,8 @@ void by_pwm_init(void) 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_duty2=myclip(update_pwm_duty2, 500, 900); + 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); } diff --git a/app/isr.c b/app/isr.c index f919409..fb8cd3b 100644 --- a/app/isr.c +++ b/app/isr.c @@ -96,8 +96,6 @@ void USART1_IRQHandler(void) void USART2_IRQHandler(void) { 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); } } @@ -140,7 +138,8 @@ void UART7_IRQHandler(void) void UART8_IRQHandler(void) { 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); } } @@ -315,7 +314,6 @@ void TIM6_IRQHandler(void) { if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET) { // ICM_getEulerianAngles(); - imu660ra_get_gyro(); TIM_ClearITPendingBit(TIM6, TIM_IT_Update); } } diff --git a/app/jj_blueteeth.c b/app/jj_blueteeth.c index dae432e..6b6b44d 100644 --- a/app/jj_blueteeth.c +++ b/app/jj_blueteeth.c @@ -21,9 +21,9 @@ enum bt_order { */ 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_rx_interrupt(UART_2, ENABLE); + uart_rx_interrupt(UART_8, ENABLE); } /** *@brief 蓝牙中断回调函数 @@ -39,16 +39,16 @@ void jj_bt_run() bt_run_flag = !bt_run_flag; break; case Fly_up: - bt_fly += 10; + bt_fly += 50; break; case Fly_dowm: - bt_fly -= 10; + bt_fly -= 50; break; case Speed_up: - bt_run += 10; + bt_run += 50; break; case Speed_down: - bt_run -= 10; + bt_run -= 50; break; default: break; @@ -66,8 +66,8 @@ void bt_printf(const char *format, ...) va_end(args); 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]); } } \ No newline at end of file diff --git a/app/jj_motion.c b/app/jj_motion.c index dc40c84..c890957 100644 --- a/app/jj_motion.c +++ b/app/jj_motion.c @@ -44,6 +44,7 @@ void sport_motion(void) { cnt1++; + imu660ra_get_gyro(); in_gyro = imu660ra_gyro_z; // 陀螺仪输入 // in_angle = 0; // 图像远端输入 // in_pos = 0; // 图像近端输入 @@ -53,15 +54,14 @@ void sport_motion(void) if (cnt1 >= 10) { PID_Compute(&far_angle_pid); PID_Compute(&speed_pid); - in_speed = encoder_get_count(TIM5_ENCOEDER); // 速度输入,m/s - // printf("rate:%d\r\n", (int16)in_speed); + in_speed = -encoder_get_count(TIM5_ENCOEDER); // 速度输入,m/s + // printf("rate:%d\r\n", (int16)in_speed); encoder_clear_count(TIM5_ENCOEDER); + PID_Compute(&near_pos_pid); 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), (int32_t)(500 - out_pos - out_gyro), (int32_t)(500 + out_speed + out_gyro), @@ -72,7 +72,6 @@ void sport_motion(void) if (bt_fly_flag == 0) { bt_fly = 0; } - by_pwm_update_duty(bt_fly + 500, bt_fly + 500); } /** @@ -82,7 +81,7 @@ void sport_motion(void) 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_Init(&far_angle_pid); PID_Init(&far_gyro_pid); @@ -94,7 +93,7 @@ void sport_pid_init() 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(&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(&speed_pid); diff --git a/app/main.c b/app/main.c index 1d0ab48..1eeb461 100644 --- a/app/main.c +++ b/app/main.c @@ -50,22 +50,29 @@ int main(void) jj_bt_init(); by_rb_init(); by_pwm_init(); - // by_buzzer_init(); + by_buzzer_init(); by_frame_init(); Page_Init(); sport_pid_init(); - pit_ms_init(TIM6_PIT, 10); // 陀螺仪 pit_ms_init(TIM1_PIT, 1); // 运动解算,bianmaqi printf("ok\r\n"); while (1) { 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(); 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); } }