2021-11-18 15:18:24 索煒達電子 1154
項目編號:L71
文件大小:32M
源碼說明:帶中文注釋
開發(fā)環(huán)境:LabVIEW
簡要概述:
基于LabVIEW的直流有刷電機PID調(diào)試及控制助手設(shè)計:使用LabVIEW開發(fā)環(huán)境和VISA串口、單片機電機控制系統(tǒng)
實現(xiàn)
(1)上位機對下位機PID控制器PID參數(shù)的調(diào)整
(2)下位機系統(tǒng)被控量波形的顯示
(3)上位機對下位機電機的轉(zhuǎn)速和位置的控制。
目 錄
1 緒論 1
1.1 研究的目的與意義 1
1.2 PID控制算法介紹 1
1.3 直流有刷電機調(diào)速原理 3
1.4 系統(tǒng)指標 3
2 下位機設(shè)計 4
2.1 總體方案 4
2.2 下位機硬件設(shè)計 4
2.2.1 STM32最小系統(tǒng)的設(shè)計 4
2.2.2 L298N電機驅(qū)動模塊 5
2.2.3 電機及編碼器 6
2.2.4 各模塊間的連接 6
2.3 下位機軟件設(shè)計 7
2.3.1 電機驅(qū)動 8
2.3.2 編碼器驅(qū)動 9
2.3.3 PID算法 11
2.3.4 兩種PID控制算法間的切換 12
3 通信協(xié)議設(shè)計 14
3.1 指令包格式 14
3.2 指令匯總 14
3.3 指令詳解 15
3.3 下位機通信協(xié)議程序?qū)崿F(xiàn) 17
4 上位機設(shè)計 22
4.1 整體方案設(shè)計 22
4.2 前面板設(shè)計 22
4.3 后面板程序設(shè)計 24
4.3.1 主VI的設(shè)計 24
4.3.2 獲取指令字節(jié)子VI 28
4.3.3 獲取實際值子VI 28
4.3.4 獲取PID參數(shù)子VI 29
4.3.5 數(shù)據(jù)打包子VI 30
5 系統(tǒng)調(diào)試 32
5.1 硬件調(diào)試 32
5.1.1 硬件連接 32
5.1.2 程序編譯下載 32
5.2 聯(lián)合調(diào)試 32
6 結(jié)論與展望 35
7 參考文獻 36
8 附錄 37
設(shè)計報告:
系統(tǒng)調(diào)試
硬件連接
將單片機最小系統(tǒng)、L298N電機驅(qū)動模塊、電機及電源按第二章2.2節(jié)下位機硬件設(shè)計中的各模塊連接表用線連接起來,連接后如圖
程序編譯下載
用Keil軟件編寫下位機STM32程序,編譯沒有錯誤后用串口下載軟件將編譯生成的.hex文件下載到STM32單片機。
聯(lián)合調(diào)試
通過USB數(shù)據(jù)線將STM32最小系統(tǒng)板與電腦相連,打開LabVIEW主VI并運行,端口選擇COM5、波特率選擇115200、奇偶校驗選擇無、數(shù)據(jù)為選8位、停止位1位。點擊打開串口按鈕即可同下位機通信。經(jīng)過測試上下位機之間的通信均正常,上位機可以完整的解析下位機發(fā)送來的數(shù)據(jù),下位機也可正確的執(zhí)行上位機發(fā)送來的控制指令,整個系統(tǒng)可正常運行。如圖5-2所示。系統(tǒng)設(shè)置為位置控制模式,目標值設(shè)置為5000,發(fā)送目標值后,電機開始轉(zhuǎn)動最終實際值達到4997電機停止。
改變PID參數(shù)點擊發(fā)送PID,重新設(shè)置目標值點擊發(fā)送目標值。結(jié)果
目錄│文件列表:
└ LabVIEW
│ PID轉(zhuǎn)換.vi
│ 發(fā)送數(shù)據(jù)打包-八位校驗和.vi
│ 控件 2.ctl
│ 電機控制.vi
│ 電機控制調(diào)試.aliases
│ 電機控制調(diào)試.lvlps
│ 電機控制調(diào)試.lvproj
│ 編碼盤.ctl
│ 獲取PID參數(shù).vi
│ 獲取實際值.vi
│ 獲取指令字節(jié).vi
│ 轉(zhuǎn)盤.ctl
│ 通訊協(xié)議解析.vi
│ 通訊格式.txt
│ 通訊格式.txt.bak
├ exe
│ │ 電機調(diào)試控制.aliases
│ │ 電機調(diào)試控制.exe
│ └ 電機調(diào)試控制.ini
├ 下位機
│ ├ Doc
│ │ └ readme.txt
│ ├ Libraries
│ │ ├ CMSIS
│ │ │ │ ARM.CMSIS.pdsc
│ │ │ ├ Device
│ │ │ │ └ ST
│ │ │ │ └ STM32F1xx
│ │ │ │ ├ Include
│ │ │ │ │ │ stm32f103x6.h
│ │ │ │ │ │ stm32f103xb.h
│ │ │ │ │ │ stm32f103xe.h
│ │ │ │ │ │ stm32f103xg.h
│ │ │ │ │ │ stm32f1xx.h
│ │ │ │ │ └ system_stm32f1xx.h
│ │ │ │ └ Source
│ │ │ │ └ Templates
│ │ │ │ │ system_stm32f1xx.c
│ │ │ │ └ arm
│ │ │ │ │ startup_stm32f103xb.s
│ │ │ │ └ startup_stm32f103xe.s
│ │ │ └ Include
│ │ │ │ cmsis_armcc.h
│ │ │ │ cmsis_armclang.h
│ │ │ │ cmsis_compiler.h
│ │ │ │ cmsis_gcc.h
│ │ │ │ cmsis_iccarm.h
│ │ │ │ cmsis_version.h
│ │ │ │ core_armv8mbl.h
│ │ │ │ core_armv8mml.h
│ │ │ │ core_cm0.h
│ │ │ │ core_cm0plus.h
│ │ │ │ core_cm1.h
│ │ │ │ core_cm23.h
│ │ │ │ core_cm3.h
│ │ │ │ core_cm33.h
│ │ │ │ core_cm4.h
│ │ │ │ core_cm7.h
│ │ │ │ core_sc000.h
│ │ │ │ core_sc300.h
│ │ │ │ mpu_armv7.h
│ │ │ │ mpu_armv8.h
│ │ │ └ tz_context.h
│ │ └ STM32F1xx_HAL_Driver
│ │ ├ Inc
│ │ │ │ stm32f1xx_hal.h
│ │ │ │ stm32f1xx_hal_adc.h
│ │ │ │ stm32f1xx_hal_adc_ex.h
│ │ │ │ stm32f1xx_hal_can.h
│ │ │ │ stm32f1xx_hal_cec.h
│ │ │ │ stm32f1xx_hal_conf_template.h
│ │ │ │ stm32f1xx_hal_cortex.h
│ │ │ │ stm32f1xx_hal_crc.h
│ │ │ │ stm32f1xx_hal_dac.h
│ │ │ │ stm32f1xx_hal_dac_ex.h
│ │ │ │ stm32f1xx_hal_def.h
│ │ │ │ stm32f1xx_hal_dma.h
│ │ │ │ stm32f1xx_hal_dma_ex.h
│ │ │ │ stm32f1xx_hal_eth.h
│ │ │ │ stm32f1xx_hal_exti.h
│ │ │ │ stm32f1xx_hal_flash.h
│ │ │ │ stm32f1xx_hal_flash_ex.h
│ │ │ │ stm32f1xx_hal_gpio.h
│ │ │ │ stm32f1xx_hal_gpio_ex.h
│ │ │ │ stm32f1xx_hal_hcd.h
│ │ │ │ stm32f1xx_hal_i2c.h
│ │ │ │ stm32f1xx_hal_i2s.h
│ │ │ │ stm32f1xx_hal_irda.h
│ │ │ │ stm32f1xx_hal_iwdg.h
│ │ │ │ stm32f1xx_hal_mmc.h
│ │ │ │ stm32f1xx_hal_nand.h
│ │ │ │ stm32f1xx_hal_nor.h
│ │ │ │ stm32f1xx_hal_pccard.h
│ │ │ │ stm32f1xx_hal_pcd.h
│ │ │ │ stm32f1xx_hal_pcd_ex.h
│ │ │ │ stm32f1xx_hal_pwr.h
│ │ │ │ stm32f1xx_hal_rcc.h
│ │ │ │ stm32f1xx_hal_rcc_ex.h
│ │ │ │ stm32f1xx_hal_rtc.h
│ │ │ │ stm32f1xx_hal_rtc_ex.h
│ │ │ │ stm32f1xx_hal_sd.h
│ │ │ │ stm32f1xx_hal_smartcard.h
│ │ │ │ stm32f1xx_hal_spi.h
│ │ │ │ stm32f1xx_hal_sram.h
│ │ │ │ stm32f1xx_hal_tim.h
│ │ │ │ stm32f1xx_hal_tim_ex.h
│ │ │ │ stm32f1xx_hal_uart.h
│ │ │ │ stm32f1xx_hal_usart.h
│ │ │ │ stm32f1xx_hal_wwdg.h
│ │ │ │ stm32f1xx_ll_adc.h
│ │ │ │ stm32f1xx_ll_bus.h
│ │ │ │ stm32f1xx_ll_cortex.h
│ │ │ │ stm32f1xx_ll_crc.h
│ │ │ │ stm32f1xx_ll_dac.h
│ │ │ │ stm32f1xx_ll_dma.h
│ │ │ │ stm32f1xx_ll_exti.h
│ │ │ │ stm32f1xx_ll_fsmc.h
│ │ │ │ stm32f1xx_ll_gpio.h
│ │ │ │ stm32f1xx_ll_i2c.h
│ │ │ │ stm32f1xx_ll_iwdg.h
│ │ │ │ stm32f1xx_ll_pwr.h
│ │ │ │ stm32f1xx_ll_rcc.h
│ │ │ │ stm32f1xx_ll_rtc.h
│ │ │ │ stm32f1xx_ll_sdmmc.h
│ │ │ │ stm32f1xx_ll_spi.h
│ │ │ │ stm32f1xx_ll_system.h
│ │ │ │ stm32f1xx_ll_tim.h
└ 演示文稿1.pptx