S函数LABVIEW
- 格式:docx
- 大小:100.41 KB
- 文档页数:10
LabVIEWLabVIEW is a highly productive graphical programming language for building data acquisition an instrumentation systems.With LabVIEW, you quickly create user interfaces that give you interactive control of your software system. To specify your system functionality,you simply assemble block diagrams - a natural design notation for scientists and engineers. Tis tight integration with measurement hardware facilitates rapid development of data acquisition ,analysis,and presentation bVIEW contains powerful built -in measurement analysis and a graphical compiler for optimum performance. LabVIEW is available for Windows 2000/NT/Me/9x, Mac OS, Linux, Sun Solaris, and HP-UX, and comes in three different development system options.Faster DevelopmentLabVIEW accelerates development over traditional programming by 4 to 10 times! With the modularity and hierarchical structure of LabVIEW, you can prototype ,design, and modify systems in a short amount of time. You can also reuse LabVIEW code easily and quickly in other applications.Better InvestmentUsing a Lab VIEW system, each user has access to a complete instrumentation laboratory at less than the cost of a single commercial instrument. In addition, user configurable LabVIEW systems are flexible enough to adapt to technology changes, resulting in a better bong-term investment.Optimal PerformanceAll LabVIEW applications execute at compiled speed for optimal performance. With the LabVIEW Professional Development System or Application Builder, you can build stand-alone executables or DLLs for secure distribution of your code. You can even create shared libraries or DLLs to call LabVIEW code from other programming languages.Open Development EnvironmentWith the open development environment of LabVIEW, you can connect to other applications through ActiveX, the Web, DLLs, shared libraries, SQL(for databases), DataSocket, TCP/IP,and numerous other e LabVIEW to quickly create networked measurement and automation systems that integrate the latest technologies in Web publishing and remote data sharing. LabVIEW also has driver libraries available for plug-in data acquisition, signal conditioning , GPIB,VXI,PXI, computer-based instruments,serial protocols, image acquisition, and motion control. In addition to the LabVIEW development systems, National Instruments offers a variety of add-on modules and tool sets that extend the functionality of LabVIEW .This enables you to quickly build customizable, robust measurement and automation systems.LabVIEW Datalogging and Supervisory Control ModuleFor high channel count and distributed applications, the LabVIEW Datelogging and Supervisory Control Module provides a complete solution. This module delivers I/O management, event logging and alarm management, distributed logging, historical and real-time trending, built-in security, configurable networking features, OPC device connectivity, and over 3,300 built-in graphics.LabVIEW Real-TimeFor applications that require real-time performance, National Instruments offers LabVIEWReal-Time. LabVIEW Real-Time downloads standard LabVIEW code to a dedicated hardware target running a real-time operating system independent from Windows.LabVIEW Vision Development ModuleThe LabVIEW Vision Development Module is for scientists, automation engineers,and technicians who are developing LabVIEW machine vision and scientific imaging applications. The LabVIEW Vision Development Module includes IMAQ Vision, a library of vision functions, and IMAQ Vision Builder, an interactive environment for vision applications. Unlike any other vision products, IMAQ Vision Builder and IMAQ Vision work together to simplify vision software development so that you can apply vision to your measurement and automation applications.Countless ApplicationsLabVIEW applications are implemented in many industries worldwide including automotive, telecommunications, aerospace, semiconductor, electronic design and production, process control, biomedical, and many others, Applications cover all phases of product development from research to design to production and to service. By leveraging LabVIEW throughout your organization you can save time and money by sharing information and software.Test and MeasurementLabVIEW has become an industry-standard development tool for test and measurement applications. With Test Stand, LabVIEW-based test programs, and the industry's largest instrument driver library, you have a single, consistent development and execution environment for your entire system.Process Control and Factory AutomationLabVIEW is used in numerous process control and factory automation applications.Many scientists and engineers look to LabVIEW for the high speed, high channel count measurement and control that graphical programming offers.For large, complex industrial automation and control applications, the LabVIEW Data logging and Supervisory Control Module provides the same graphical programming as LabVIEW, but is designed specifically for monitoring large numbers of I/O points, communicating with industrial controllers and networks, and providing PC-based control.Machine Monitoring and ControlLabVIEW is ideal for machine monitoring and predictive maintenance applications that need deterministic control, vibration analysis, vision and image processing, and motion control. With the LabVIEW platform of products including LabVIEW Real-Time for real-time deterministic control and the LabVIEW Data logging and Supervisory Control Module, scientists and engineers can create powerful machine monitoring and control applications quickly and accurately.Research and AnalysisThe integrated LabVIEW measurement analysis library provides everything you need in an analysis package. Scientists and researchers have used LabVIEW to analyse and compute real results for biomedical, aerospace, and energy research applications, and in numerous other industries. The available signal generation and processing, digital filtering, windowing, curve-fitting, For specialized analysis, such as joint time-frequency analysis, wavelet,and model-based spectral analysis, LabVIEW offers the specially designed Signal Processing Toolset.The Sound and Vibration Toolset offers octave analysis, averaged and nonaveraged frequency analysis, transient analysis, weighted filtering, and sound-level measurement, and more.Draw Your Own SolutionWith LabVIEW, you build graphical programs called virtual instruments (VIs) instead of writing text-based programs. You quickly create front panel user interfaces that give you the interactive control of your system. To add functionality to the user interface, you intuitively assemble block diagrams- a natural design notation for engineers and scientists.Create the Front PanelOn the front panel of your VI, you place the controls and data displays for your system by selecting ob jects from the Controls palette, such as numeric displays, meters, gauges, thermometers, LEDs, charts,and graphs.When you complete and run your VI,you use the front panel to control your system whether you move a slide, zoom in on a graph, or enter a value with the keyboard.Construct the Graphical Block DiagramTo program the VI, you construct the block diagram without worrying about the syntactical details of text-based programming languages. You do this by selecting objects (icons) from the Functions palette and connecting them together with wires to transfer data among block diagram objects. These objects include simple arithmetic functions, advanced acquisition and analysis routines, network and file I/O operations, and more.Dataflow ProgrammingLabVIEW uses a patented dataflow programming model that frees you from the linear architecture of text-based programming languages. Because the execution order in LabVIEW is determined by the flow of data between nodes,and not by sequential lines of text,you can create block diagrams that execute multiple operations in parallel. Consequently, LabVIEW is a multitasking system capable of running multiple execution threads and multiple VIs in parallel.Modularity and HierarchyLabVIEW VIs are modular in design, so any VI can run by itself or as part of another VI. You can even create icons for your own VIs, so you can design a hierarchy of VIs that serve as application building blocks. You can modify, interchange, and combine them with other VIs to meet your changing application needs.Graphical CompilerIn many applications, execution speed is critical. LabVIEW is the only graphical programming system with a compiler that generates optimized code with execution speeds comparable to compiled C programs. You can even use the LabVIEW profiler to analyse and optimize time-critical operations. Consequently, you increase your productivity with graphical programming without sacrificing execution speed.Measurements and MathematicsLabVIEW includes a variety of other measurement analysis tools. Examples include curve fitting, signal generation, peak detection, and probability and statistics. Measurement analysis functions can determine signal characteristics such as DC/RMS levels, total harmonic distortion (THD),impulse response, frequency response, and cross-power spectrum. LabVIEW users can also deploy numerical tools for solving differential equations, optimization, root finding, and other mathematical problems.In addition, you can extend these built-in capabilities by entering MATLAB or HIQ scripts directly in your LabVIEW programs. For charting and graphing, you can rely on the built-in LabVIEW 2D and 3D visualization tools. 2D tools include features such as autoscaling X and Y ranges, reconfigurable attributes (point/line styles, colors, and more)andcursors, Microsoft Windows users can employ OpenGL-based 3D graphs and then dynamically rotate, zoom, and pan these graphs with the mouse.Development SystemThe LabVIEW Professional Development System facilitates the development of high-end, sophisticated instrumentation systems for developers working in teams, users developing large suites of VIs, or programmers needing to adhere to stringent quality standards.Built on the Full Development System, the Professional Development System also includes the LabVIEW Application Builder for building stand-alone executables and shared libraries (DLLs)and creating distribution kits. In addition, the development system furnishes source code control tools and offers utilities for quantitatively measuring the complexity of your applications. With graphical differencing, you can quickly identify both cosmetic and functional differences between two LabVIEW applications.We include programming standards and style guides that provide direction for consistent LabVIEW programming methodology. The system also contains quality standards documents that discuss the steps LabVIEW users must follow to meet internal regulations or FDA approval. The Professional Development System operates on Windows 2000/NT/Me/9x,Mac OS, HP-UX, and Linux.LabVIEW Full Development SystemThe LabVIEW Full Development System equips you with all of the tools you need to develop instrumentation systems. It includes GPIB, VISA, VXI, RS-232, DAQ, and instrument driver libraries for data acquisition and instrument control. The measurement analysis add DC/RMS measurements, single tone analysis, harmonic distortion analysis, SINAD analysis, limit testing, signal generation capabilities, signal processing, digital filtering, windowing, curve fitting, statistics, and a myriad of linear algebra and mathematical functions. The development system also provides functions for direct access to DLLs, ActiveX, and other external code. Other features of the system include Web publishing tools, advanced report generation tools, the ability to call MATLAB and HiQ scripts, 3D surface, line, and contour graphs, and custom graphics and animation. The Full Development System operates on Windows 2000/NT/Me/9x, Mac OS, HP-UX, and Linux.LabVIEW Base PackageUse the LabVIEW Base Package, the minimum LabVIEW configuration, for developing data acquisition and analysis, instrument control, and basic data presentation. The Base Package operates on Windows 2000/NT/Me/9x.Debug License for LabVIEWIf you deploy LabVIEW applications, including LabVIEW tests for use with Test Stand, the debug license allows you to install the LabVIEW development system on the target machines so you can step into your test code for complete test debugging. This license is not intended for program development.虚拟仪器(LabVIEW)虚拟仪器是一种高效用于构建数据采集与监测系统图形化编程语言。
实验一软件无线电基础一、实验目的熟悉软件无线电实验平台,了解软件无线电平台的软硬件处理通信任务的过程,学会软件无线电的基本设计方法和开发工具软件使用方法。
二、实验内容用软件无线电实验平台和LabVIEW软件创建一个调频无线接收器;创建一个自定义LabVIEW用户界面,配置USRP,用LabVIEW设计无线通信系统原型。
三、实验仪器1 USRP实验平台一台2计算机一台四、实验原理1软件无线电平台原理无线通信测试创新论坛对软件无线电(SDR)的定义:〃无线电的一些或全部的物理层功能由软件定义。
〃软件无线电参考了这样一个技术:在通用硬件平台上运行软件模块,用于实现无线通信功能。
结合USRP通用软件无线电硬件和模块化软件的优势,提供了满足多功能需求且灵活性强的快速通信原型平台,适用于物理层设计、算法验证、多标准无线系统、无线信号录制与回放、通信情报等应用。
图1.软件无线电平台构架2软件无线电实现的数字通信系统2.1 典型的数字通信系统一个典型的数字通信系统包括:发射机、接收机和通信信道。
图3展示了一个数字 通信系统的通用组件。
放在第一行是发射机,包含信源编码、信道编码、调制、上变频 模块。
第二行是接收机由下变频、匹配滤波器、均衡器、解调、信道译码和信源译码模 块组成。
数字处理.I合成船1 __________________控制软件接收器控制器□ RF/IF □混含信号 口数亭部分 敬宇处理骐劭器1 放大可配置 H 接收器T N 口D/A可配置 发射端BEF E图2数字通信系统框图酬三P8 -KU-PCI3 Zu 」ncl6-SUUE J=Jj_n r BitsKEP£a白Bu」LTLT日均u.EH-np岂=O_£^CQWCSQQ2.2NI USRP无线通信实验系统图3 NI-USRP无线实验系统硬件、软件平台1) NI USRP硬件平台图4 NI-USRP硬件平台前面板射频信号输入到SMA连接器,USRP硬件平台通过直接变频接收机中的混频操作,产生同相正交(I/Q)基带信号,再经过一个2通道,速率为100 MS/s的14位模数转换器 依口0采样。
2020年5月25日第4卷第10期现代信息科技Modern Information Technology May.2020Vol.4 No.10收稿日期:2020-03-29基于LabVIEW的高精度时序控制程序设计郑本昌,任金磊(中国运载火箭技术研究院 研究发展部 ,北京 100076)摘 要:针对在原子钟测试测量实验过程中对仪器设备模拟电压信号进行高精度时序控制的需求,提出了一种基于LabVIEW 和NI 高速模拟输出卡的时序控制程序设计方法。
以板载高精度采样时钟为基准,设计了可以精确控制模拟电压输出时间的LabVIEW 控制方案,通过将时间控制转换为数据数量控制,实现了支持非线性变化的可定制化时序模拟电压输出,可实现在实验周期内同时对多路输出电压信号时间的任意控制,达到μs 级的输出时间控制精度。
关键词:LabVIEW ;高精度;时序控制;可扩展性中图分类号:TP274 文献标识码:A 文章编号:2096-4706(2020)10-0041-04Programming Approach of High Precision Sequential ControllingBased on LabVIEWZHENG Benchang ,REN Jinlei(Department of Research and Development ,China Academy of Launch Vehicle Technology ,Beijing 100076,China )Abstract :In order to meet the demand of high precision timing control for analog voltage signal of instrument and equipment in the process of atomic clock test and measurement experiment ,a timing control program design method based on LabVIEW and NI high speed analog output card is proposed. Based on the high-precision sampling clock on board , a LabVIEW control scheme which can precisely control the output time of analog voltage is designed. By converting the time control into the data quantity control ,the customized sequential analog voltage output supporting nonlinear change is realized. The time of multi-output voltage signal can be controlled arbitrarily in the experimental period ,reaching the output time of μs level The accuracy of control.Keywords :LabVIEW ; high precision ;sequential control ;scalability0 引 言原子钟作为导航系统测距的星上时间基准,是卫星导航系统的核心部分,其性能直接决定用户的导航定位精度[1],冷原子钟可以在空间轨道上实现高精度的时间频率基准,从而实现更高精度的全球导航定位与时间同步,已经成为未来星载原子钟的首选[2,3]。
基于LabVIEW-VISA方式的串口通信研究魏义虎;陈雷【摘要】针对使用LabVIEW的VISA函数编写串口通信程序出现数据丢失问题,本文在介绍串口通信的基础上,详细说明了LabVIEW使用VISA方式实现串口通信的一般编程方法、以及需要注意的问题,特别对丢失数据现象进行了原因分析,采用设置延时和设置流控制方式加以解决。
实际应用表明,该方法简单有效,满足串口通信要求。
%Aiming at data losing in writing serial port communication programme by using VISA in LabVIEW,On the base of introduction of serial port communication, illustrates the basic way to program via using VISA, as well as the points needed to be noted, analyses the phenomenon of data losing,takes steps of seting time delay and seting flow control to resolve the problem. The application show that this method is simple and effective, achieves the requirement of serial port communication.【期刊名称】《电子设计工程》【年(卷),期】2015(000)024【总页数】3页(P129-131)【关键词】LabVIEW;VISA;串口通信;数据丢失【作者】魏义虎;陈雷【作者单位】军械工程学院弹药工程系,河北石家庄 050003;军械工程学院弹药工程系,河北石家庄 050003【正文语种】中文【中图分类】TN0串口通信作为串行通信的一种实现方式,其历史可追溯到1969 年。
3. Front Panel Style3.前面板风格The LabVIEW front panel is named to emphasize its capability to emulate the panels of traditional self-contained instruments. Indeed, when LabVIEW was first released in 1986, its primary purpose was to control laboratory instruments via GPIB and serial interface. Oh, how times have changed! Today LabVIEW is applied to many different types of applications, industries, and instrumentation. The complexity of applications has dramatically increased. The evolution of front panels is no exception. 3D controls, tab controls, tree controls, containers, Property Nodes, VI Server, Event structures, and subpanels are modern innovations that facilitate powerful LabVIEW applications.LabVIEW前面板命名着重于仿效传统的自成一体的仪器的前面板,其实,当LabVIEW在1986年首次发布时,它主要目的是通过GPIB和串行接口控制实验室仪器,随着时间的推移,今天LabVIEW适用于许多不同类型的应用领域,包括工业和测量仪器。
基于MATLAB控制系统
的S函数
姓 名:
学 号:
院 (系):
班 级:
基于MATLAB控制系统的S函数
The S function control system
based on MATLAB
概述
Abstract
S函数是System Function的简称。用它来写自己的simulink
模块,可以用matlab、C、C++、Fortran、Ada等语言来写。s函数可
以利用MATLAB的丰富资源,而用c或c++等语言写的s函数还可以
实现对硬件端口的操作,还可以操作windows API等。
The S function is the abbreviation of System Function.Use it
to describe their own modules,by matlab、C、C++、Fortran、Ada and
so on.The S Function not only can use the rich resources of
MATLAB,but slao can be realized on hardware port operation using
the S Function of the C or C++ language to write.
关键字:S函数(System Function)、MATLAB
一、 实验原理
1、 函数模板编辑环境进入:
在MATLAB主界面中直接输入:edit sfuntmpl
即可弹出S函数模板编辑的M文件环境,修改即可。
在MATLAB主界面中直接输入:sfundemos,即可调出S
函数的许多编程例子。
2、 S函数模板的相关基础:
1) M文件S函数的引导语句为:
,...)2,1,,,,(],,0,[ppflaguxtftsstrxsysFunction
S函数默认的四个输入参数:t ,x ,u ,flag
S函数默认的四个输出函数:sys ,x0 ,str ,ts
各个参数的含义如下:
T :代表当前的仿真时间,该输入决定了下一个采样时间;
X :表示状态向量,行向量,引用格式:X(1),X(2)
U :表示输入向量;
Flag :控制在每一个仿真阶段调用哪一个子函数的参数,由
SIMULINK在调用时自动取值;
Sys :通用的返回变量,返回的数值决定Flag值,mdlUpdates
里:列向量,引用格式:Sys(1,1),Sys(2,1);mdlOutputs里:行向
量,引用格式:Sys =x.
X0 :初始的状态值;列向量,引用格式:X0=[ 0;0;0 ]
Str :空矩阵,无具体含义;
Ts :包含模块采样时间和偏差的矩阵。[period, offset]
当Ts为-1时,表示与输入信号同采样周期。
2) S函数工作方式:
Flag = 0时,调用mdlInitializeSizes函数,定义S函数的基
本特性,包括采样时间,连续或者离散状态的初始条件
和Sizes数组;
Flag = 1时,调用mdlDerivatives函数,计算连续状态变量
的微分方程;求所给表达式的等号左边状态变量的积分值
的过程。
Flag = 2时,调用mdlUpdate函数,用于更新离散状态,采
样时间和主时间步的要求;
Flag = 3时,调用mdlOutputs函数,计算S函数的输出;
Flag = 4时,调用mdlGetTimeOfNextVarHit函数,计算下一
个采样点的绝对时间,这个方法仅仅是使用户在
mdlInitializeSize 里说明一个可变的离散采样时间;
Flag = 9时,调用mdlTerminate函数,实现仿真任务的结束。
3)S函数仿真过程:
① 初始化:mdlInitializeSizes,初始化S函数
初始化SimStruct,包含了S函数的所有信息;
设置输入、输出端口数;
设置采样时间;
分配存储空间。
② 数值积分:mdlDerivatives
用于连续状态的求解和非采样过零点;
如果存在连续状态,调用mdlDerivatives和
mdlOutput两个子函数;
如果存在非采样过零点,调用mdlOutput和
mdlZeroCrossings子函数,以定位过零点。
③ 更新离散状态:mdlUpdate
④ 计算输出:mdlOutputs,计算所有输出端口的输出值。
⑤ 计算下一个采样时间点:mdlGetTimeOfNextVarHit
⑥ 仿真结束:mdlTerminate,在仿真结束时调用。
3、 S函数的编写:
1) 参数初始设定:初始化sizes结构,再调用simsizes函数;
Sizes结构体:
NumContStates:连续状态的个数
NumDiscStates:离散状态的个数
NumOutputs:输出变量的个数
NumInputs:输入变量的个数
DirFeedthrough:有无直接馈入,值为1时表示输入直
接传到输出口
NumSampleTimes:采样时间的个数,值为1时表示只
有一个采样周期
Simsizes函数的调用:sys = simsizes (sizes) ,即将sizes结构体
中的信息传递给sys。
2)状态的动态更新:
连续模块的状态更新由mdlDerivatives函数来进行;
离散模块的状态更新由mdlUpdate函数来进行;
3)输出信号的计算:
计算出模块的输出信号,系统的输出仍然由sys变量返回。
4、 M文件S函数的模块化:
在动态系统仿真设计,分析中,用户可以使用S-Function
模块来调用S-函数。
1) S-Function模块是一个单输入单输出的模块,如果有多个
输入与输出信号,可以使用Mux模块与Demux模块对信号进
行组合和分离操作;
2) 在S-Function模块的参数设置对话框中,包含了调用的S
函数名和用户输入的参数列表。
3) S-Function模块是以图形的方式提供给用户一个调用S函
数的接口,S函数中的源文件必须由用户自行编写;
4) S-Function模块中的S-函数名和参数值列表必须与用户填
写的S函数源文件的名称和参数列表完全一致,包括参数的
顺序。
二、 实验过程及分析
1)S函数Simulink仿真模型
图1
2)S函数
function [sys,x0,str,ts] = spacemodel(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);
case {2,4,9}
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 2;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 3;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % At least one sample time is needed
sys = simsizes(sizes);
x0 = [0;0];
str = [];
ts = [0 0];
function sys=mdlDerivatives(t,x,u) %Time-varying model
kp=10;
ki=2;
kd=1;
ut=kp*u(1)+ki*u(2)+kd*u(3);
J=20+10*sin(6*pi*t);
K=400+300*sin(2*pi*t);
sys(1)=x(2);
sys(2)=-J*x(2)+K*ut;
function sys=mdlOutputs(t,x,u)
sys(1)=x(1);
3)响应曲线
图2
实验分析
该S函数主要利用C++的swtich语句来产生一组正弦波。