本期带来基于Matlab与LabVIEW联合开发的电机测试平台,LabVIEW是一款图形化开环设计软件,可以实现VXI、串口、GPIBPXI等总线的通信,具有良好的通用性能,可以极大的缩短系统的研发时间,提高工作效率。本系统能实时采集电机在不同工况运行下的各种参数,对电机的电压、电流、功率等进行监测,实现对电机性能的检测。LabVIEW通过SIT工具包调用来实现Matlab对电机启动的电流等信号进行分析与处理。
1、系统构成
系统基于虚拟仪器为核心的测试平台,其数据采集卡选用的是美国NI公司产品,并配以外围电机驱动电路如直流电机的供电电源控制、起动大电路等部分,由程序来控制外围驱动电路以实现对电机的起动和制动控制。整个过程充分发挥了计算机在数据处理、显示和存储上的强大功能,使得整个测试系统的高效性得到了保证,极大提高了系统的灵活性。编程环境选择LabVIEW编程语言,并结合Matlab对电机信号处理分析,充分利用二者的混合编程技术,提高电机测试平台的效率。
2、硬件系统设计
电机测试系统硬件主要包括为电机提供能量及驱动的电机控制柜,用于测量电机功率信息的功率分析仪,两电机间用于测量扭矩、电机转速的扭矩传感器,为系统降温的水冷系统和用于测量水冷系统水温的温度采集卡,读取系统数字信号及模拟信号的数据釆集卡。
3、软件系统设计
利用LabVIEW良好的人机交互特性,将所需调用的参数和仿真信息全部显示在界面上,以便实时观测电机各参数检测结果。
4、Matlab实时通讯
LabVIEW通过仿真接口工具包(SIT)可调用MATLAB/Simulink程序并能够实现同步通讯。安装MATLAB、LabVIEW和仿真接口工具包SIT后打开MATLAB,运行edit MATLABrc,在打开的MATLABrc 文件末尾添加:
addpath(‘C:Simulation InterfaceToolkit’); % 将SimilinkInterface Toolkit添加到Path中
NISIT_Add Paths;
NISITServer;
MATLAB,在命令窗口上会出现以下信息:
>Starting the SIT Server on Port 6011
>SIT Server started
打开Simulink可以在Libraries找到NISIT Blocks 模块。建立MATLAB与LabVIEW实时通讯主要分为两个步骤,即指定模型路径和控件与模型建立连接。
(1)指定MATLAB仿真路径
打开前面建立的LabVIEW控制界面,选择工具下的SITConnection Manager, 进入配置页面。首先选择Modeland Host选项卡,在Current Model中,指定Sinulink路径
(2)控件与模块建立连接
选择Mappings选项卡,指定LabVIEW前面板中输入控件、波形图表与永磁同步电机矢量控制系统MATLAB/Simulink仿真模型模型的参数一一对应。
%%%%%%%%%总体改变%%%%%%%
%%%% n 行波波数
%%%% u 定转子动摩擦系数
%%%% ke 摩擦材料的等效刚度
%%%% R 转子等效半径
%%%% Dz 轴向阻尼系数
%%%% Dr 转子光电总阻尼
%%%% Fn 预压力
%%%%电机工作频率
%%%%行波波长
%%%%%%%%%%总体改变%%%%%%%%
%%%%%%%%%%%%%%%%参数值
J17=9;
J18=0.2;
J19=2.6E+09;
J21=3.10E-03;
J25=9300;
J26=10;
J27=70000;
J29=0.00014;
J30=0.0005;
J20=1.5E-03;
J22=0.00000066675;
J23=0.000000142;
J24=0.0005;
J28=2*3.1415926*J27;
%%%%%%%%%%%%%%%%%参数值
gain0=J17/J21;
gain1=1/gain0;
gain2=gain0;
gain3=gain1;
gain4=2*J18*J19*J22;
gain5=2;
gain6=J17*J21;
gain7=1/J23;
gain8=J21/gain0/J28;
gain9=gain1;
gain10=60/3.1415926/2;
gain11=2*J17*J19;
gain12=J25;
gain13=1/J24;
gain14=1;
gain15=gain1;
%%%%%%%%%%%%%转换为set_para可以用的字符串类型,并且不丢失精度
temp=sym(gain0);
gain0=char(vpa(temp,15));
temp=sym(gain1);
gain1=char(vpa(temp,15));
temp=sym(gain2);
gain2=char(vpa(temp,15));
temp=sym(gain3);
gain3=char(vpa(temp,15));
temp=sym(gain4);
gain4=char(vpa(temp,15));
temp=sym(gain5);
gain5=char(vpa(temp,15));
temp=sym(gain6);
gain6=char(vpa(temp,15));
temp=sym(gain7);
gain7=char(vpa(temp,15));
temp=sym(gain8);
gain8=char(vpa(temp,15));
temp=sym(gain9);
gain9=char(vpa(temp,15));
temp=sym(gain10);
gain10=char(vpa(temp,15));
temp=sym(gain11);
gain11=char(vpa(temp,15));
temp=sym(gain12);
gain12=char(vpa(temp,15));
temp=sym(gain13);
gain13=char(vpa(temp,15));
temp=sym(gain14);
gain14=char(vpa(temp,15));
temp=sym(gain15);
gain15=char(vpa(temp,15));
%%%将三个simulink模型参数调整
open ModerForJ.slx
set_param('ModerForJ/Gain0','Gain',gain0);
set_param('ModerForJ/Gain1','Gain',gain1);
set_param('ModerForJ/Gain2','Gain',gain2);
set_param('ModerForJ/Gain3','Gain',gain3);
set_param('ModerForJ/Gain4','Gain',gain4);
set_param('ModerForJ/Gain5','Gain',gain5);
set_param('ModerForJ/Gain6','Gain',gain6);
set_param('ModerForJ/Gain7','Gain',gain7);
set_param('ModerForJ/Gain8','Gain',gain8);
set_param('ModerForJ/Gain9','Gain',gain9);
set_param('ModerForJ/Gain10','Gain',gain10);
set_param('ModerForJ/Gain11','Gain',gain11);
set_param('ModerForJ/Gain12','Gain',gain12);
set_param('ModerForJ/Gain13','Gain',gain13);
set_param('ModerForJ/Gain14','Gain',gain14);
set_param('ModerForJ/Gain15','Gain',gain15);
save_system;
close_system
open ModerForT.slx
set_param('ModerForT/Gain0','Gain',gain0);
set_param('ModerForT/Gain1','Gain',gain1);
set_param('ModerForT/Gain2','Gain',gain2);
set_param('ModerForT/Gain3','Gain',gain3);
set_param('ModerForT/Gain4','Gain',gain4);
set_param('ModerForT/Gain5','Gain',gain5);
set_param('ModerForT/Gain6','Gain',gain6);
set_param('ModerForT/Gain7','Gain',gain7);
set_param('ModerForT/Gain8','Gain',gain8);
set_param('ModerForT/Gain9','Gain',gain9);
set_param('ModerForT/Gain10','Gain',gain10);
set_param('ModerForT/Gain11','Gain',gain11);
set_param('ModerForT/Gain12','Gain',gain12);
set_param('ModerForT/Gain13','Gain',gain13);
set_param('ModerForT/Gain14','Gain',gain14);
set_param('ModerForT/Gain15','Gain',gain15);
save_system;
close_system
open ModerForV.slx
set_param('ModerForV/Gain0','Gain',gain0);
set_param('ModerForV/Gain1','Gain',gain1);
set_param('ModerForV/Gain2','Gain',gain2);
set_param('ModerForV/Gain3','Gain',gain3);
set_param('ModerForV/Gain4','Gain',gain4);
set_param('ModerForV/Gain5','Gain',gain5);
set_param('ModerForV/Gain6','Gain',gain6);
set_param('ModerForV/Gain7','Gain',gain7);
set_param('ModerForV/Gain8','Gain',gain8);
set_param('ModerForV/Gain9','Gain',gain9);
set_param('ModerForV/Gain10','Gain',gain10);
set_param('ModerForV/Gain11','Gain',gain11);
set_param('ModerForV/Gain12','Gain',gain12);
set_param('ModerForV/Gain13','Gain',gain13);
set_param('ModerForV/Gain14','Gain',gain14);
set_param('ModerForV/Gain15','Gain',gain15);
save_system;
close_system
或者,通过LabVIEW的MATLABScript节点实现LabVIEW与Matlab的混合编程。MatlabScript节点属于数学的公式节点选板中。使用Math Script有两种方法:使用LabviewMath Script窗口;或者在图形程序中使用MathScript节点。和Matlab比较两者编程语法结构完全相同,并支持从Matlab编译环境的程序导入LabVIEWMath Script,方便开发人员进行程序的移植,缩短开发周期。
5、测试分析
6、小结
基于LabVIEW开发平台,采用模块化设计方法,完成各个硬件模块以及数据显示、存储模块的程序开发。实现了测试系统中工控机与各个硬件设备之间的数据通信、被测电机和负载的精确控制、测试数据的处理、显示与存储功能。
考虑到篇幅有限,再加上电机测试系统需要功率分析仪、扭矩传感器、水冷系统、数据采集卡等硬件设备,这里主要提供上位机软件部分,供大家参考学习。代码自取:
链接:https://pan.baidu.com/s/1mW0mXQGJIUD_n9s5LFV09A
提取码:shm3
原文始发于微信公众号(新能源汽车仿真团队):电机仿真系列-基于LabVIEW+Matlab的电机测试系统