【正文】
ar modes。在 RealTime Windows Target 也提供了參數(shù)設(shè)定的功能,這個(gè)功能13 的應(yīng)用與廠商提供的軟件有相同的靈活性。 Simulink 外部模式下實(shí)現(xiàn)參數(shù)傳遞的機(jī)制,在外部模式下 Simutink 不再對(duì)框圖表示的系統(tǒng)模型進(jìn)行仿真,而是把當(dāng)前的參數(shù)值下 載到目標(biāo)系統(tǒng)。在初始下載完成后, Simulink 保持在等待狀態(tài),只有在框圖中的參數(shù)發(fā)生改變或者接收到來自目標(biāo)機(jī)的參數(shù)才開始動(dòng)作。 當(dāng)框圖的參數(shù)發(fā)生改變, Simulink 調(diào)用一個(gè)外部接口 Mex 文件,把新的參數(shù)值和其他一些信號(hào)傳遞給外部 Mex 文件。外部接口 Mex 文件執(zhí)行Inter Process Communication (IPC)通道一端的代碼,這個(gè)通道把 Simulink 過程 (Mex 文件執(zhí)行的過程 )和外部可執(zhí)行性程序的過程連接在一起。 Mex 文件通過這個(gè)通道,把新的參數(shù)傳遞給外部程序。通道的另 一端在外部程序中執(zhí)行,這一端把新的參數(shù)值寫到目標(biāo)參數(shù)結(jié)構(gòu)中。 Simulink 通過發(fā)送一個(gè)含有參數(shù)信息的訊息初始化下載操作。在 C/S 結(jié)構(gòu)中, Simulink 作為客戶端,外部程序?yàn)榉?wù)端。兩個(gè)過程可以是遠(yuǎn)程的,也可以是當(dāng)?shù)氐摹.?dāng)客戶端和服務(wù)端是遠(yuǎn)程的時(shí)候,通過 TCP/IP 方式傳遞數(shù)據(jù),當(dāng)客戶端與服務(wù)端是當(dāng)?shù)氐臅r(shí)候,采用共享內(nèi)存的方式傳送數(shù)據(jù),在本系統(tǒng)中采用的就是后一種方式 。 過程控制算法的實(shí)現(xiàn)方法, 一個(gè)通用的仿真平臺(tái),必須能夠方便的讓用戶加入自己的控制算法或控制系統(tǒng)設(shè)計(jì)方案,此過程控制混合仿真平臺(tái)提供 了以下三種控制算法的嵌入方法: 應(yīng)用 Simulink 提供的模塊搭建控制器模型, Simulink 提供了各種各樣的模塊集合,在 Simulink 提供的圖形用戶界面上,只要進(jìn)行簡(jiǎn)單拖拉操作,就可利用這些模塊集合構(gòu)造出復(fù)雜的控制器模型。此外 Simulink 還提供了諸如模糊邏輯工具箱與神經(jīng)網(wǎng)絡(luò)工具箱之類的高級(jí)算法控制工具箱,利用這些工具箱,結(jié)合其他模塊,可搭建出各種與之相關(guān)的控制算法模型,如模糊 PID、神經(jīng)網(wǎng)絡(luò) PID 等,如以模糊 PID 控制器模型。利用工具箱的圖形用戶界面編輯控制器,可方便地設(shè)計(jì)智能控制器的直 觀圖式系統(tǒng)。 利用 Simulink 模塊搭建控制器模型靈活方便,它外表以方塊圖形式呈現(xiàn),且采用分層結(jié)構(gòu)。應(yīng)用 Simulink 模型作為控制器的可視化界面,不僅能讓用戶知道控制器具體環(huán)節(jié)的動(dòng)態(tài)細(xì)節(jié),而且能讓用戶清晰地了解控制器中各器件、各子系統(tǒng)的信息交換,掌握各部分間的交互影響,為進(jìn)一步分析改善控制器提供了便利條件。 編寫 C 語言的 S函數(shù)實(shí)現(xiàn)控制算法,在實(shí)際應(yīng)用中,通常會(huì)發(fā)現(xiàn)有些算14 法用普通的 Simulink 模塊不容易搭建,對(duì)此可以使用 Simulink 支持的 S函數(shù)格式, S函數(shù)作為 Simulink 的擴(kuò) 展工具有固定的程序格式,可采用MATLAB、 C/C++、 Fortran 等語言編寫。但由于在實(shí)時(shí)仿真過程中需要將Simulink 模型轉(zhuǎn)化為 C 代碼并生成獨(dú)立文件,只有 C/C++語言編寫的 S函數(shù)支持這一功能,因此在算法擴(kuò)展中必須采用 C/C++語言編寫的 S函數(shù)。 S函數(shù)的工作原理和 Simulink 的仿真原理基本類似,每一個(gè) Simulink模塊都具有輸入 u、輸出 y、狀態(tài) x三個(gè)向量和其他一些對(duì)應(yīng)仿真各階段的方法。 Simulink 通過循環(huán)調(diào)用模型中的各模塊的特定方法來完成諸如計(jì)算輸出值、更新離散狀態(tài)值、計(jì)算連 續(xù)狀態(tài)微分等任務(wù)。在 S函數(shù)中提供了與Simulink 仿真不同階段相對(duì)應(yīng)的回調(diào)函數(shù)。初始化階段包括mdlInitializeSizes , mdlInitializeSampleTimes 和 mdlInitializeCondi 模塊它們分別起初始化系統(tǒng)輸入維數(shù)輸出維數(shù)、狀態(tài)變量個(gè)數(shù),定義仿真采樣時(shí)間和初始化狀態(tài)變量的作用。輸出階段 mdlOutputs 模塊計(jì)算系統(tǒng)輸出。循環(huán)仿真階段 mdlUpdate 模塊計(jì)算更新系統(tǒng)當(dāng)前狀態(tài)變量的值。 C 語言 S函數(shù)不僅可以將具有 C 語言描述功能的代碼嵌入 Simulink 模塊,以便 于在 Simulink中仿真,而且可以很容易的將 C語言 S函數(shù)模塊功能代碼轉(zhuǎn)換成純 C代碼 。 15 MATALAB hybrid simulation platform control algorithm overview MATLAB Hybrid simulation platform, that is, the hardware put into the simulation loop in the loop simulation system for process control of the development and testing. Platform embedded controller provides three methods, in particular, can use MATLAB language has greatly enhanced the flexibility of the platform. In order to build simulation system for process control systems must be addressed as a virtual controller PC, the environment and in the Windows operating system to achieve realtime control to achieve these two problems. We first elaborate simulation system for process control system principle, and finally introduced the embedded platform control algorithm method and the experiment results verify the effectiveness of the platform. Hybrid simulation platform process control theory: (1) numerical calculation, based on more than 600 MATLAB provides some monly used mathematical and engineering functions. The numerical putation of these functions are optimized for matrix operations, you can use it to replace the underlying programming language. Maintain the same performance in the case, the programming effort is very small, value calculated using the LAPACK and BLAS, FFTW other excellent math library, so the calculation efficiency is further improved. MATLAB contains the main mathematical functions are linear algebra and matrix operations, Fourier transform and statistical analysis, solving differential equations, sparse matrix operations, and trigonometric and other elementary mathematics, etc. In addition, use of MATLAB applications with continuous expanded to add a function for a number of specific areas. (2) Algorithm development, puting power, easy to use programming language and 16 rich mathematical functions to the most suitable for MATLAB for algorithm development. Typical applications include: data analysis, signal processing, image processing, system modeling and advanced algorithm research. Whether the user is using the existing algorithms or developing their own, based on MATLAB provides a mon platform. MATLAB for algorithm development using the mathematical expression of the same writing as usual Userbased algorithms developed in MATLAB integration to external systems running. Once the user39。s algorithms and simulation through the writing and debugging, MATLAB piler and the C / C + + Math Library MATLAB application will be automatically converted to portable 231。 and C + + code tool. For signal processing, control system design and other applications, MATLAB toolbox providing a range of advanced technology. Toolbox far beyond the scope of provision of some basic algorithms: they provide a learning, research, innovation and cuttinged