- #include "led.h"
- #include "delay.h"
- #include "usart.h"
- #include "key.h"
- #include "sys.h"
- #include "oled.h"
- #include "menu.h"
- #include "encoder.h"
- #include "timer.h"
- #include "motor.h"
- #include "pid.h"
- /************************************************
- 功能加上串口通讯
- x,下舵机(1750->1950)从右往左
- y,上舵机(1750->1950)从上往下
- ************************************************/
- int x_pwm = 1850,y_pwm = 1825;
- // 初始化目标值和小球的中心位置
- int x_face = 320, y_face = 240;
- int if_face=0;
- int x_face_store = 320, y_face_store = 240;
- int face_store=0;
- int x_target = 320, y_target = 240;
- // 上下舵机PID参数
- float x_KP = -0.00060,x_KI = 0.0007, x_KD = 0.002;
- float y_KP = -0.00060, y_KI = 0.0007, y_KD =0.002;
- // 储存OPENCV发送来的数据
- u16 Res;
- int main(void)
- {
- /*延时函数初始化*/
- delay_init();
-
- /* 设置中断优先级分组2*/
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
-
- /*串口初始化为115200*/
- uart_init(115200);
-
- /*LED初始化*/
- LED_Init();
-
- /*KEY初始化*/
- KEY_Init();
-
- /*OLED初始化*/
- OLED_Init();
-
- /*100hz的计数频率,每10ms进入一次定时器中断,更新当前电机速度*/
- TIM6_Int_Init(99,7199);
-
- /*初始化编码器 */
- Encoder_Init_TIM2();
-
- /*舵机定时器初始化 50HZ范围1750-1950*/
- TIM3_PWM_Init(1999,719);
-
- /*初始化TIM1 PWM 10KHZ,用于驱动电机 */
- TIM4_PWM_Init(7199,0);
-
- /*200hz的计数频率,每5ms进入一次定时器中断:中断PID赋值*/
- TIM7_Int_Init(49,7199);
-
- AIN2=1;
- AIN1=0;//初始将电机不转
- PWMA=0;
- TIM_SetCompare1 (TIM3,1850); //初始将舵机云台位置设置在中间
- TIM_SetCompare2 (TIM3,1825);
-
-
- OLED_Fill(0, 0, 128, 63, 0);
- Display_OLEDMenu();
- while (1)
- {
- MenuReflash();
- }
- }
复制代码
Keil代码下载:
单片机程序V1.2.7z
(217.74 KB, 下载次数: 40)
|