本文介紹如何用C語言實現電機控制模擬,目的是方便移植到 DSP 中執行(或阻止 Simulink 繼續「禍害」廣大人民群眾)。

前言

呃,先在這裡跟大家說聲抱歉,迫於時間壓力,儘管是粗製濫造的視頻教程仍然還是先上傳了——畢竟爛片子總比沒有片子好吧。為了保證清晰度,知乎這裡就不上傳視頻了,嗶哩嗶哩傳送門走你(記得用至少1.25倍速度觀看哦。。。):

https://www.bilibili.com/video/av51496015/?

www.bilibili.com

視頻暫時只介紹了如何實現感應電機的VVVF控制,但實際上有了這個框架以後,你要做反饋控制和觀測都很方便了,後續會不會及時更新要隨緣了哈。

下面的「正文」是按 markdown 的格式寫的,建議複製粘貼到 Visual Studio Code 中,按下 ctrl+shift+v (Windows 系統)後閱讀。


正文(請配合視頻食用)

# ACMSimC: AC Machine Simulation Tool in C Language

免責聲明:做好將來你的擁有100台dSpace的合作者問你要Simuliink模擬結果你卻沒有的心理準備,然後我們開始吧。## 1. Prerequisite* Compiler - MinGW (gcc) - Anaconda3 (python) ``` D:UsershorycAnaconda3pkgsopenssl-1.1.1b-he774522_1Libraryin D:UsershorycAnaconda3Lib D:UsershorycAnaconda3Libraryin

D:UsershorycAnaconda3Scripts

D:UsershorycAnaconda3 ```2. Editor - Sublime Text 3: the **shell command** is as follows: ```json { "working_dir": "$file_path", "cmd": "gcc -Wall $file_name -o $file_base_name", "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",

"selector": "source.c",

"variants": [ { "name": "Run", "shell_cmd": "gcc $file controller.c observer.c -o $file_base_name && start cmd /c "${file_path}/${file_base_name}"" } ] } ```

3. Utility

* AutoHotkey (to close all figures at once) ``` #NoEnv #Warn SendMode Input SetWorkingDir %A_ScriptDir% SetTitleMatchMode 2 #q:: closePythonPlot() closePythonPlot()

{

isExist = 1 while isExist { PostMessage, 0x112, 0xF060,,, Figure IfWinNotExist, Figure { isExist = 0 } }

}

``` * MS Visual Studio Code (to properly read this readme.md file) * Hyper (good-looking terminal) * Windows Subsystem for Linux, a.k.a. WSL (for being cool?) * Git in WSL or in DOS Cmd (for version control)## 2. Machine Models### 2.1. Model of Induction Machine<!-- [egin{array}{l}{L_sigma }p{i_s} = {u_s} - left( {{r_s} + {r_{req}}}
ight){i_s} + left( {alpha I - omega J}
ight){psi _mu }\

p{psi _mu } = {r_{req}}{i_s} - left( {aI - omega J}
ight){psi _mu }

end{array}] -->![eq:IM](eq_IM.png)### 2.2. Model of Permanent Magnet Synchronous Machine<!-- [egin{array}{l}{L_d}p{i_d} = - r{i_d} + omega {L_q}{i_q} + {u_d}\{L_q}p{i_q} = - r{i_q} - omega {L_d}{i_d} + {u_q} - omega {psi _{{
m{PM}}}}end{array}] -->![eq:PMSM](eq_PMSM.png)### 2.3. Model of Bearingless Induction Machine*

## 3. Block Diagram for the Codes

Simulation procedure is as follows: for loop begins{ time machine_simulation(); // machine_dynamics, numeric_integration measurement(); // speed, current observation(); // observer control(); // speed_control, current_control inverter_model(); // }

## Future Topics (Brainstorming)

* C語言電機模擬架構 / framework in C language (done)* 永磁電機的模擬* 電機設計的電路參數擬合* 電機參數自整定* 電流環係數設計* 轉速環係數設計* 轉動慣量辯識* 自抗擾控制* 基於帶寬指標的自抗擾控制係數設計* 全局穩定轉速自適應觀測器設計* 逆變器非線性建模 / inverter nonlinearity* SPWM建模* SVPWM建模* 飽和建模 / modeling of saturation* 非理想電流測量環節建模* 母線電容建模和無軸承電機的彷彿有UPS控制* 無軸承感應電機建模* 基於擴展反電勢模型的無感測器控制* 基於 Active Flux 模型的無感測器控制* 三維模型的繪製技巧
推薦閱讀:
相关文章