华科转速测量和工作台综合测控实验.docx

上传人:b****6 文档编号:4299042 上传时间:2022-11-29 格式:DOCX 页数:36 大小:567KB
下载 相关 举报
华科转速测量和工作台综合测控实验.docx_第1页
第1页 / 共36页
华科转速测量和工作台综合测控实验.docx_第2页
第2页 / 共36页
华科转速测量和工作台综合测控实验.docx_第3页
第3页 / 共36页
华科转速测量和工作台综合测控实验.docx_第4页
第4页 / 共36页
华科转速测量和工作台综合测控实验.docx_第5页
第5页 / 共36页
点击查看更多>>
下载资源
资源描述

华科转速测量和工作台综合测控实验.docx

《华科转速测量和工作台综合测控实验.docx》由会员分享,可在线阅读,更多相关《华科转速测量和工作台综合测控实验.docx(36页珍藏版)》请在冰豆网上搜索。

华科转速测量和工作台综合测控实验.docx

华科转速测量和工作台综合测控实验

转速测量及工作台实验

 

班级:

人员:

实验项目:

工作台实验、转速测量实验

时间:

2012年6月

目录

 

1、工作台实验

1.1实验目的---------------------------------------------------------------------------3

1.2实验原理---------------------------------------------------------------------------3

1.3实验代码解析---------------------------------------------------------------------5

1.4实验结果展示及分析------------------------------------------------------------14

1.5实验小结及感想------------------------------------------------------------------15

 

2、转子实验台——转速测量实验

2.1实验目的----------------------------------------------------------------------------16

2.2实验原理----------------------------------------------------------------------------16

2.3实验内容及设计过程-------------------------------------------------------------16

2.4实验代码解析----------------------------------------------------------------------20

2.5实验结果展示及分析-------------------------------------------------------------28

2.6实验小结及感想-------------------------------------------------------------------31

 

1.1实验目的

实验平台对软件的要求,需要安装Matlab7.0.4version和MicrosoftVisualc++6.0。

MATLAB是目前在国际上被广泛接受和使用的科学与工程计算软件。

虽然CleveMoler教授开发它的初衷是为了更简单、更快捷地解决矩阵运算,但MATLAB现在的发展已经使其成为一种集数值运算、符号运算、数据可视化、图形界面设计、程序设计、仿真等多种功能于一体的集成软件。

通过用matlab对实验工作台进行快进、工进、快退的控制,学习matlab在控制方面的知识。

学习matlab种simulink函数的运用。

2.2实验原理

运用到的主要simulink模块的介绍。

驱动电机运动的运动指令代码都是在VC下面编写的,实验之前已经有了用VC做了一些s-function并生成*.dll文件(使用s-functionexample模板编写好c文件之后再用mex将其编译成dll文件),包括InitOpenIPpos.dll,GetCurPos.dll,SetPara.dll,下面依次对部分s-function作出简要说明。

InitOpenIPpos.dll

初始化运动控制卡,其功能主要是使伺服上电并且设定电机的一些参数,如:

运动模式(速度,位置,模式等),最大速度值,最大加速度值等等。

以上这些都已经在InitOpenIP.c文件里面设定好了,可以打开这个文件查看。

比如,我们根据实际情况设定电机的运动模式为位置模式(zl_set_prfl_pos(0))。

GetCurPos.dll

读取当前轴的位置。

如果某个simulink模块调用了GetCurPos.dll文件后,在设置参数时需要注意,parameters项填写“1”是代表当前读取的是1号轴即电机轴的位置,如果填写的是“3”则是代表立摆的转动轴,此时读出的是倒立摆的摆角位移。

SetPara.dll

设置各种不同运动模式时的运动参数。

 

(1)仅实现手动的快进及快退功能。

要实现快进、工进、快退功能,首先可以从较简单的功能实现开始,因此我们选取了最先实现快进、快退功能来开始试验,下图是实现该功能的原理图:

手动切换开关可实现工作台的快进、快退。

(2)实现快进、工进及手动的快退功能。

执行程序后,工作台开始自动快进,到达预定位置后减速工进,随后手动换开关ManualSwitch,实现快退。

 

 

(3)实现自动地快进、工进和快退。

执行程序后,工作台开始自动快进,到达预定位置后减速工进,工进一段时间后达到预定位置,switch自动换向,实现快退。

1.3实验代码解析

(1)s-functionsetpara代码

#defineS_FUNCTION_NAMESetPara

#defineS_FUNCTION_LEVEL2

/*定义函数*/

#include"simstruc.h"

#include"ZLPCIDrv.h"

#include"ZLPCI400d.h"

#include"PendX.h"

/*添加头文件*/

#pragmacomment(lib,"ZLPCIDrv.lib")

#pragmacomment(lib,"ZLPCI400d.lib")

#pragmawarning(disable:

4761)

#pragmawarning(disable:

4244)

/*预定义的标识符,指定注释的类型,指定库函数*/

//--------------------------------------------------------------------------

/*====================*

*S-functionmethods*

*====================*/

#defineERR_INVALID_PARAM_1\

"Invalidaxisnumber.Thefirstparametermustbe\nanunsignedintegernumberbetween1and4."

#defineERR_INVALID_PARAM_2\

"Invalidnumberofinputports.Thesecondparametermustbe\nanunsignedintegernumberbetween2and5."

#defineAXIS_NUM(ssGetSFcnParam(S,0))

#defineNUM_INPUTS(ssGetSFcnParam(S,1))

/*定义输入值*/

#defineMDL_CHECK_PARAMETERS

staticvoidmdlCheckParameters(SimStruct*S)

{

uint8_Taxis_num;

int_Tinputs;

axis_num=(uint8_T)*(mxGetPr(AXIS_NUM));

if(axis_num<1||axis_num>4){

ssSetErrorStatus(S,ERR_INVALID_PARAM_1);

return;

}

/*AXIS_NUMD的有效范围*/

inputs=(int_T)(*(mxGetPr(NUM_INPUTS)));

if(inputs<2||inputs>5){

ssSetErrorStatus(S,ERR_INVALID_PARAM_2);

return;

}/*NUM_INPUTS的有效范围*/

}

/*Function:

mdlInitializeSizes===============================================

*/

staticvoidmdlInitializeSizes(SimStruct*S)

{

inti;

int_Tinputs;

ssSetNumSFcnParams(S,2);

if(ssGetNumSFcnParams(S)==ssGetSFcnParamsCount(S)){

mdlCheckParameters(S);

if(ssGetErrorStatus(S)!

=NULL){

return;

}

}else{

return;/*Simulinkwillreportaparametermismatcherror*/

}

inputs=(int_T)(*(mxGetPr(NUM_INPUTS)));

if(!

ssSetNumInputPorts(S,inputs))return;

for(i=0;i

ssSetInputPortWidth(S,i,1);

ssSetInputPortDirectFeedThrough(S,i,1);

}

if(!

ssSetNumOutputPorts(S,1))return;

ssSetOutputPortWidth(S,0,1);

ssSetNumSampleTimes(S,1);

/*Takecarewhenspecifyingexceptionfreecode-seesfuntmpl_doc.c*/

ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE);

}

 

/*Function:

mdlInitializeSampleTimes=========================================

*Abstract:

Specifiythatweinheritoursampletimefromthedrivingblock.

*/

staticvoidmdlInitializeSampleTimes(SimStruct*S)

{

ssSetSampleTime(S,0,INHERITED_SAMPLE_TIME);

ssSetOffsetTime(S,0,0.0);

}

//Function:

mdlOutputs=======================================================

staticvoidmdlOutputs(SimStruct*S,int_Ttid)

{

InputRealPtrsTypeuPtrs=ssGetInputPortRealSignalPtrs(S,0);

real_T*y=ssGetOutputPortRealSignal(S,0);

unsignedshortaxis_status,inputs;

unsignedshortaxis_num;

/*setthecurrentaxisnumberasdefinedbyS_functionfirstparameter*/

axis_num=(uint8_T)*(mxGetPr(AXIS_NUM));

inputs=(uint8_T)(*(mxGetPr(NUM_INPUTS)));

if(inputs>=2)

{

zl_set_vel(*uPtrs[0],axis_num-1);

zl_set_acc(*uPtrs[1],axis_num-1);

}

if(inputs>=3)

{

zl_set_pos((long)*uPtrs[2],axis_num-1);

}

if(inputs>=4)

{

zl_set_max_acc(*uPtrs[3],axis_num-1);

}

if(inputs>=5)

{

return;

}

//updatecardparameters

zl_update(axis_num-1);

zl_get_status(&axis_status,axis_num-1);

//axis_status=16&axis_status;

//*y=(axis_status?

1:

0);

*y=axis_status&127;

}

 

/*Function:

mdlTerminate=====================================================

*Abstract:

*Noterminationneeded,butwearerequiredtohavethisroutine.

*/

staticvoidmdlTerminate(SimStruct*S)

{

}

 

#ifdefMATLAB_MEX_FILE/*IsthisfilebeingcompiledasaMEX-file?

*/

#include"simulink.c"/*MEX-fileinterfacemechanism*/

#else

#include"cg_sfun.h"/*Codegenerationregistrationfunction*/

#endif

(2)s-functionGetCurPos代码

#defineS_FUNCTION_NAMEGetCurPos

#defineS_FUNCTION_LEVEL2

/*定义函数*/

#include"simstruc.h"

#include"ZLPCIDrv.h"

#include"ZLPCI400d.h"

#include"PendX.h"

/*添加头文件*/

#pragmacomment(lib,"ZLPCIDrv.lib")

#pragmacomment(lib,"ZLPCI400d.lib")

#pragmawarning(disable:

4761)

#pragmawarning(disable:

4244)

/*预定义的标识符,指定注释的类型,指定库函数*/

 

//--------------------------------------------------------------------------

#defineERR_INVALID_PARAM\

"Invalidaxisnumber.Theparametermustbe\nanunsignedintegernumberbetween1and4."

/*totalnumberofblockparameters*/

enum{PARAM=0,NUM_PARAMS};

#defineAXIS_NUM(ssGetSFcnParam(S,0))

#defineMDL_CHECK_PARAMETERS

staticvoidmdlCheckParameters(SimStruct*S)

{

uint8_Taxis_num;

axis_num=(uint8_T)*(mxGetPr(AXIS_NUM));

if(axis_num<1||axis_num>4){

ssSetErrorStatus(S,ERR_INVALID_PARAM);

return;

}

}

/*Function:

mdlInitializeSizes===============================================

*/

staticvoidmdlInitializeSizes(SimStruct*S)

{

ssSetNumSFcnParams(S,1);

if(ssGetNumSFcnParams(S)==ssGetSFcnParamsCount(S)){

mdlCheckParameters(S);

if(ssGetErrorStatus(S)!

=NULL){

return;

}

}else{

return;/*Simulinkwillreportaparametermismatcherror*/

}

if(!

ssSetNumInputPorts(S,0))return;

if(!

ssSetNumOutputPorts(S,1))return;

ssSetOutputPortWidth(S,0,1);

ssSetNumSampleTimes(S,1);

/*Takecarewhenspecifyingexceptionfreecode-seesfuntmpl_doc.c*/

ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE);

}

 

/*Function:

mdlInitializeSampleTimes=========================================

*Abstract:

Specifiythatweinheritoursampletimefromthedrivingblock.

*/

staticvoidmdlInitializeSampleTimes(SimStruct*S)

{

ssSetSampleTime(S,0,CONTINUOUS_SAMPLE_TIME);

ssSetOffsetTime(S,0,0.0);

}

 

//Function:

mdlOutputs=======================================================

staticvoidmdlOutputs(SimStruct*S,int_Ttid)

{

real_T*y=ssGetOutputPortRealSignal(S,0);

uint8_Taxis_num;

longdata;

/*setthecurrentaxisnumberasdefinedbyS_functionfirstparameter*/

axis_num=(uint8_T)*(mxGetPr(AXIS_NUM));

/*getpositionofaxisthatisdefinedbyS-funcparameter*/

zl_get_actl_pos(&data,axis_num-1);

*y=data;

}

 

/*Function:

mdlTerminate=====================================================

*Abstract:

*Noterminationneeded,butwearerequiredtohavethisroutine.

*/

staticvoidmdlTerminate(SimStruct*S)

{

}

 

#ifdefMATLAB_MEX_FILE/*IsthisfilebeingcompiledasaMEX-file?

*/

#include"simulink.c"/*MEX-fileinterfacemechanism*/

#else

#include"cg_sfun.h"/*Codegenerationregistrationfunction*/

#endif

s-fuction函数InitOpenIPpos

#defineS_FUNCTION_NAMEInitOpenIPpos

#defineS_FUNCTION_LEVEL2

/*定义函数*

#include"simstruc.h"

#include"ZLPCIDrv.h"

#include"ZLPCI400d.h"

#include"PendX.h"

/*添加头文件*/

#pragmacomment(lib,"ZLPCIDrv.lib")

#pragmacomment(lib,"ZLPCI400d.lib")

#pragmawarning(disable:

4761)

#pragmawarning(disable:

4244)

/*预定义的标识符,指定注释的类型,指定库函数*/

/*Function:

mdlInitializeSizes===============================================

*/

staticvoidmdlInitializeSizes(SimStruct*S)

{

ssSetNumSFcnParams(S,0);

if(ssGetNumSFcnParams(S)!

=ssGetSFcnParamsCount(S)){

return;/*ParametermismatchwillbereportedbySimulink*/

}

if(!

ssSetNumInputPorts(S,1))return;

ssSetInputPortWidth(S,0,1);

ssSetInputPortDirectFeedThrough(S,0,1);

if(!

ssSetNumOutputPorts(S,0))return;

ssSetNumSampleTimes(S,1);

/*Takecarewhenspecifyingexceptionfreecode-seesfuntmpl_doc.c*/

ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE);

}

 

/*Function:

mdlInitializeSampleTimes=========================================

*Abstract:

Specifiythatweinheritoursampletimefromthedrivingblock.

*/

staticvoidmdlI

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 交通运输

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1