PID算法的極好學(xué)習(xí)資料,匿名四軸資料
0.png (35.3 KB, 下載次數(shù): 53)
下載附件
2017-8-12 00:02 上傳
0.png (16.47 KB, 下載次數(shù): 53)
下載附件
2017-8-12 00:02 上傳
0.png (72.7 KB, 下載次數(shù): 51)
下載附件
2017-8-12 00:04 上傳
stm32單片機(jī)風(fēng)力擺源程序如下:
- #include "sys.h"
- #include "delay.h"
- #include "usart.h"
- #include "led.h"
- #include "key.h"
- #include "mpu6050.h"
- #include "pwmset.h"
- #include "niming.h"
- #include "pid.h"
- #include "usmart.h"
- #include "inv_mpu.h"
- #include "inv_mpu_dmp_motion_driver.h"
- volatile float pitch,roll,yaw; //歐拉角
- volatile u8 mode = 1; //當(dāng)前工作方式
- volatile float step = 0;
- int main(void)
- {
- Stm32_Clock_Init(9); //系統(tǒng)時鐘設(shè)置
- uart_init(72,500000); //串口初始化為500000
- delay_init(72); //延時初始化
- usmart_dev.init(72); //初始化USMART
- LED_Init(); //初始化與LED連接的硬件接口
- KEY_Init(); //初始化按鍵
- MPU_Init(); //初始化MPU6050
- TIM3_PWM_Init(999,8); //初始化脈寬波輸出
- TIM2_Int_Init(4999,71); //初始化定時器2,每5ms產(chǎn)生一次中斷
- while(mpu_dmp_init())
- {
- delay_ms(20);
- }
-
- while(1)
- {
- key=KEY_Scan(0);
- if(key==KEY2_PRES) //測試發(fā)送pid數(shù)據(jù)給上位機(jī)
- {
- pid_send_data(rol_p,rol_i,rol_d,pit_p,pit_i,pit_d);
- }
-
- if(key==KEY0_PRES) //開啟或關(guān)閉下位機(jī)數(shù)據(jù)發(fā)送開關(guān)
- {
- report=!report;
- }
- if(key==KEY1_PRES) //開啟或關(guān)閉下位機(jī)數(shù)據(jù)發(fā)送開關(guān)
- {
- Rol_SumError = 0;
- }
- if(key == KEY8_PRES) //PE8按下
- {
- rol_p += 1;
- LED0 = ~LED0;
- }
- if(key == KEY9_PRES)
- {
- rol_i += 0.1;
- LED0 = ~LED0;
- }
- if(key == KEY10_PRES)
- {
- R += 0.05;
- LED0 = ~LED0;
- }
- if(key == KEY11_PRES) //模式切換
- {
- mode++;
- LED0 = ~LED0;
- }
- if(key == KEY12_PRES)
- {
- rol_p -= 1;
- LED0 = ~LED0;
- }
- if(key == KEY13_PRES)
- {
- rol_i -= 0.1;
- LED0 = ~LED0;
- }
- if(key == KEY14_PRES)
- {
- R -= 0.05;
- LED0 = ~LED0;
- }
- if(key == KEY15_PRES)
- {
- mode--; //模式切換
- LED0 = ~LED0;
- }
-
- if(USART_RX_STA == 1) //檢測是否接收到了數(shù)據(jù)。
- {
- USART_RX_STA = 0; //清除接收標(biāo)志,防止多次判斷。
- LED1 = ~LED1;
- rol_p = (USART_RX_BUF[4]<<8)|USART_RX_BUF[5];
- rol_i = (USART_RX_BUF[6]<<8)|USART_RX_BUF[7];
- rol_d = (USART_RX_BUF[8]<<8)|USART_RX_BUF[9];
- pit_p = (USART_RX_BUF[10]<<8)|USART_RX_BUF[11];
- pit_i = (USART_RX_BUF[12]<<8)|USART_RX_BUF[13];
- pit_d = (USART_RX_BUF[14]<<8)|USART_RX_BUF[15];
- }
-
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
15電賽風(fēng)力擺源碼及上位機(jī).rar
(3.81 MB, 下載次數(shù): 144)
2017-8-12 00:06 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|