特定电解液结晶点测试实验报告

时间:2024.5.2

特定电解液结晶点实验报告

实验目的:测定特定电解液结晶点。

实验仪器及试剂:高低温试验箱、手套箱、250ml锥形瓶、电子天平,磁力搅拌

器,EC,DEC,VC,PS,LiPF6

实验过程:1、配制特定电解液:按配方比例配置三合液(EC:DEC=1:1)。

2、将三合液降温至-9℃ ,此过程中EC不断结晶析出。

3、待温度降低至-9℃时缓慢加锂盐125g,此过程中部分EC会溶解。

4、加完锂盐后在-9℃条件下用磁力搅拌器搅拌30min,仍有大量EC

未溶解。然后停止冷冻,持续搅拌至EC全部溶解。

5、EC全部溶解后按配方比例加入添加剂(VC:1%,PS:3%,添加剂

A)

6、取适量电解液于一次性杯子中放入高低温试验箱中,以2℃为温

度梯度,在每个温度下保持2h,从0℃降温至-20℃都没有出现结

晶。但是常温放置一夜后会出现少许晶体,和絮状不溶物。

7、取适量电解液于锥形瓶中,置于高低温试验箱中,在-40℃保持

3h,开始出现结晶。常温放置一夜后未出现晶体和不溶物。然后

倒入一次性杯子中,常温放置一天后出现晶体和不溶物。

8、将出现晶体和不溶物的电解液,加入适量DMC搅拌,晶体溶解而

絮状不溶物依然不容。

结论:1、此电解液结晶点在-40℃左右。

2、实验过程中出现的结晶和絮状不溶物可能和DEC的挥发有关系。


第二篇:工程测试实验报告



目录:

实验一:测试实验

噪声测量及声频分析界面设计

1. 实验目的-----------------------------------------------3

2. 实验原理-----------------------------------------------3

3. 实验内容及设计过程-------------------------------------3

4. M代码及其注释------------------------------------------3

5. Simulink模型-------------------------------------------6

6. C语言代码及注释----------------------------------------7

7. 实验结果----------------------------------------------14

实验二:球杆定位控制系统实验

1. 机械建模分析------------------------------------------16

2. 实验步骤----------------------------------------------16

3. 实验内容及结果----------------------------------------17

总结:

1. 收获与心得体会----------------------------------------31

2. 分工--------------------------------------------------32

实验一  测试部分

1.       实验目的:

a.       掌握用matlab编程,绘制采样数据所得图形,并进行图形分析。

b.       自学matlab编程语言,提升自主学习能力,感受研究生工作。

2.       实验原理:

a.       通过噪声采集卡采集到噪声信号,将噪声信号传送到我们所编好的界面上显示出来,并进行噪声信号频率处理,由幅值—时间坐标系转变为幅值—频率坐标系,得到频率图后通过低通滤波得到有效信号再次转换为幅值—时间信号显示在界面上。

b.       通过上述步骤得到的处理后的信号,我们可以通过计算得到噪声信号的关于频率、幅值、有效值等信息并显示在界面上提供给使用者。

3.       实验内容及设计过程:

a.       通过自学matlab基本操作和调试掌握指令窗运行入门、控制指令窗的指令和操作、数值数组及其运算、matlab控制流、M文件入门、调试器应用示例。

b.       根据噪声测量及声频分析界面特点初步进行数据的可视化和界面设计,依次进行绘图命令、二维曲线绘图的基本操作、句柄图形和界面、属性查询和设置、控制制作以及静态文本框、滑动键、检录框等一系列操作。

c.       参考实验指导书并根据噪声测量及声频分析界面特点,我们确定噪声信号以及噪声频域分析两个框图大小及位置,设置采集、停止和滤波三个按键。按下采集键时噪声采集卡开始采集数据并将数据传送到介面中显示出来;按下停止键,噪声采集卡停止采集噪声信号,噪声信号框图中的噪声波形固定,噪声频域分析框图显示出进行频域转换后的噪声信号并按照合适的波形大小显示在图框中;按下滤波键,将得到的噪声频域分析图进行滤波处理得到除去高频噪声后的声音信号,并将声音信号重新转换为幅值—时域信号显示在弹出的另一个框图中。

d.       学习simulink动态仿真,掌握simulink模块的数学描述及仿真过程、创建简单模型、进行simulink基本操作、得到simulink子系统创建及封装、构造微分方程求解模型以及多速率离散时间系统。

e.       进行噪声数据采集程序设计,在了解s-function的回调方法及几个主要子函数的基础上编写c语言的s函数---利用s-function模板创建DLL。编写输入输出设置及采集编程将采集到的噪声信号传送到框图中输出。

4.       M代码及其注释:

M代码主程序:

clf reset%清楚图形窗口

set(gcf,'menubar','none'); %除去图形窗口菜单栏

set(gcf,'unit','normalized','position',[0.28,0.15,0.70,0.68]); %设置图形界面的位置和大小

set(gcf,'defaultuicontrolhorizontal','left'); %设置用户缺省控件单位位置属性

set(gcf,'defaultuicontrolunits','normalized');%设置用户缺省控件单位属性值

set(gcf,'defaultuicontrolfontsize',14); %设置用户缺省控件字体大小

set(gcf,'defaultuicontrolfontname','隶书');%设置用户缺省控件字体属性

str='噪声测量与声频分析'; %界面标题

set(gcf,'name',str,'numbertitle','off');%书写图形窗名

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

h_axes1=axes('position',[0.05,0.59,0.52,0.32]);%创建“噪声信号”坐标轴

htitle1=title('噪声信号');%坐标轴命名

h_axes2=axes('position',[0.05,0.16,0.52,0.32]);%创建“噪声噪声频域”坐标轴

htitle2=title('噪声频域分析');%坐标轴命名

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ht1=uicontrol(gcf,'style','toggle','string','Grid',...%制作“栅格”双位按键

    'position',[0.65,0.78,0.07,0.12],'fontsize',15,'backgroundcolor',[0.70,0.78,1]);%设置坐标“分格”双位按键属性

set(ht1,'callback','t1_Callback(h_axes1,h_axes2)');%按钮引起回调

ht2=uicontrol(gcf,'style','toggle','string','Box',...%制作双位按键

    'position',[0.65,0.66,0.07,0.12],'fontsize',15,'backgroundcolor',[0.70,0.78,1]);%设置双位按键属性

set(ht2,'callback','t2_Callback(h_axes1,h_axes2)');%按钮引起回调

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

h_push1=uicontrol(gcf,'style','push',...

    'position',[0.72,0.78,0.19,0.12],'string','采集',...%制作“采集”按钮

    'backgroundcolor',[0.75,0.86,0.77],'foregroundcolor',[0.1,0.6,0.5],'fontsize',24);%设置停止“开始”按钮属性

set(h_push1,'callback',[... %让我们前建立的mylove1.mdl文件运行

    'set_param(''mylove1'',''SimulationCommand'',''start''),',...

    't=timer(''TimerFcn'',''getdata'',''Period'',0.5,''ExecutionMode'',''fixedSpacing'',''TasksToExecute'',inf),',...%设置定时器,运行getdata文件

    'pause(2);start(t);',...%暂停2秒并启动定时器

    ]);%按键引起的回调

h_push2=uicontrol(gcf,'style','push',...

'position',[0.72,0.66,0.19,0.12],'string','停止',...%制作“停止”按钮

'backgroundcolor',[0.72,0.73,0.95],'foregroundcolor',[1,0,0]','fontsize',24);%设置“停止”按钮属性

set(h_push2,'callback','stop(t);set_param(''mylove1'',''simulationcommand'',''stop'');');%mylove.mdl文件停止运行

h_push3=uicontrol(gcf,'style','push',...

    'position',[0.65,0.38,0.26,0.10],'string','滤波',...%制作“滤波”按钮

    'backgroundcolor',[0.50,0.68,0.88],'foregroundcolor',[0,1,1],'fontsize',24);%设置“滤波”按钮属性

set(h_push3,'callback','push3_Callback()');%按钮引起回调

Getdata.m

set_param('mylove1','SimulationCommand','stop');%mdl文件运行

y1=evalin('base','ydata.signals.values');

axes(h_axes1);

plot(y1(1:500)),htitle1=title('噪声信号');%在第一个波形中绘制波形1

set_param('mylove1','SimulationCommand','start');%mdl文件运行

%以下是频谱分析

N=1024;

P=fft(y1,N);%快速傅里叶变换

Pyy=2*sqrt(P.*conj(P))/N;%求频谱幅值

axes(h_axes2); %在图形窗口中第二坐标中绘图

Fs=5000; %设置频率

f=linspace(0,Fs/2,N/2); %求频谱频率

plot(f,Pyy(1:N/2)),htitle2=title('噪声频域分析');%在第二个波形图中绘制频谱波形

t1_Callback.m  %坐标“栅格”子程序
function t1_Callback(h_axes1,h_axes2)')
  axes(h_axes1); %调用坐标系1
  Grid     %坐标系1画“栅格”    
  axes(h_axes2); %调用坐标系2
  Grid     %坐标系2画“栅格”
end%子程序结束

t2_Callback.m  %坐标轴“分格”子程序
function t2_Callback(h_axes1,h_axes2)')
  axes(h_axes1); %调用坐标系1
   Box    %坐标系1画“分格”
  axes(h_axes2); %调用坐标系2
  Box      %坐标系2画“分格”
end%子程序结束

push3_Callback.m

function push3_Callback()

y1=evalin('base','ydata.signals.values');%获取信号

Ft=8000;%设置滤波器参数

Fp=800;%设置滤波器参数

Fs=5000;%设置滤波器参数

wp=2*pi*Fp/Ft;%设置滤波器参数

ws=2*pi*Fs/Ft;%设置滤波器参数

[n11,wn11]=buttord(wp,ws,1,50,'s'); %求低通滤波器的阶数和截止频率

[b11,a11]=butter(n11,wn11,'s');    %求S域的频率响应的参数

[num11,den11]=bilinear(b11,a11,0.5); %利用双线性变换实现频率响应S域到Z域的变换

z11=filter(num11,den11,y1);

N=1024;

P=fft(z11,N);%求滤波后的信号快速傅里叶变换

m11=12*sqrt(P.*conj(P))/N; %求滤波后频谱

f=linspace(0,Fs/2,N/2); %求频谱频率

figure(2); %新建图框

str='滤波后图像'; %界面标题

set(gcf,'name',str,'numbertitle','off');%书写图形窗名

subplot(2,1,1);plot(z11);title('滤波后的信号波形');%绘制波形图

subplot(2,1,2);plot(f,m11(1:N/2),'r');title('滤波后信号的频谱');%绘制频谱

end%子程序结束

5.       simulink模型

6.       c语言代码及注释

mylove.cpp

/*

 * sfuntmpl_basic.c: Basic 'C' template for a level 2 S-function.

 *

 *  -------------------------------------------------------------------------

 *  | See matlabroot/simulink/src/sfuntmpl_doc.c for a more detailed template |

 *  -------------------------------------------------------------------------

 *

 * Copyright 1990-2002 The MathWorks, Inc.

 * $Revision: 1.27 $

 */

/*

 * You must specify the S_FUNCTION_NAME as the name of your S-function

 * (i.e. replace sfuntmpl_basic with the name of your S-function).

 */

#define S_FUNCTION_NAME  Mylove

#define S_FUNCTION_LEVEL 2

/*

 * Need to include simstruc.h for the definition of the SimStruct and

 * its associated macro definitions.

 */

#include "simstruc.h"

#include "abc.h"       /*添加头文件*/

double buffer[5000];   /*定义全局变量*/

double buffer1[5000];

int pnum;

char ch[8];

/* Error handling

 * --------------

 *

 * You should use the following technique to report errors encountered within

 * an S-function:

 *

 *       ssSetErrorStatus(S,"Error encountered due to ...");

 *       return;

 *

 * Note that the 2nd argument to ssSetErrorStatus must be persistent memory.

 * It cannot be a local variable. For example the following will cause

 * unpredictable errors:

 *

 *      mdlOutputs()

 *      {

 *         char msg[256];         {ILLEGAL: to fix use "static char msg[256];"}

 *         sprintf(msg,"Error due to %s", string);

 *         ssSetErrorStatus(S,msg);

 *         return;

 *      }

 *

 * See matlabroot/simulink/src/sfuntmpl_doc.c for more details.

 */

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

 * S-function methods *

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

/* Function: mdlInitializeSizes ===============================================

 * Abstract:

 *    The sizes information is used by Simulink to determine the S-function

 *    block's characteristics (number of inputs, outputs, states, etc.).

 */

static void mdlInitializeSizes(SimStruct *S)

{

    /* See sfuntmpl_doc.c for more details on the macros below */

    ssSetNumSFcnParams(S, 0);  /* Number of expected parameters */

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

        /* Return if number of expected != number of actual parameters */

        return;

    }

    ssSetNumContStates(S, 0);

    ssSetNumDiscStates(S, 0);

    if (!ssSetNumInputPorts(S, 3)) return;

    ssSetInputPortWidth(S, 0, 1);

    ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/

ssSetInputPortWidth(S, 1, 1);

    ssSetInputPortRequiredContiguous(S, 1, true); /*direct input signal access*/

ssSetInputPortWidth(S, 2, 1);

    ssSetInputPortRequiredContiguous(S, 2, true); /*direct input signal access*/

    /*

     * Set direct feedthrough flag (1=yes, 0=no).

     * A port has direct feedthrough if the input is used in either

     * the mdlOutputs or mdlGetTimeOfNextVarHit functions.

     * See matlabroot/simulink/src/sfuntmpl_directfeed.txt.

     */

    ssSetInputPortDirectFeedThrough(S, 0, 1);

ssSetInputPortDirectFeedThrough(S, 1, 1);

ssSetInputPortDirectFeedThrough(S, 2, 1);

    if (!ssSetNumOutputPorts(S, 1)) return;

    ssSetOutputPortWidth(S, 0, 1);

    ssSetNumSampleTimes(S, 1);

    ssSetNumRWork(S, 0);

    ssSetNumIWork(S, 0);

    ssSetNumPWork(S, 0);

    ssSetNumModes(S, 0);

    ssSetNumNonsampledZCs(S, 0);

    ssSetOptions(S, 0);

}

/* Function: mdlInitializeSampleTimes =========================================

 * Abstract:

 *    This function is used to specify the sample time(s) for your

 *    S-function. You must register the same number of sample times as

 *    specified in ssSetNumSampleTimes.

 */

static void mdlInitializeSampleTimes(SimStruct *S)

{

    ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);

    ssSetOffsetTime(S, 0, 0.0);

}

#define MDL_INITIALIZE_CONDITIONS   /* Change to #undef to remove function */

#if defined(MDL_INITIALIZE_CONDITIONS)

  /* Function: mdlInitializeConditions ========================================

   * Abstract:

   *    In this function, you should initialize the continuous and discrete

   *    states for your S-function block.  The initial states are placed

   *    in the state vector, ssGetContStates(S) or ssGetRealDiscStates(S).

   *    You can also perform any other initialization activities that your

   *    S-function may require. Note, this routine will be called at the

   *    start of simulation and if it is present in an enabled subsystem

   *    configured to reset states, it will be call when the enabled subsystem

   *    restarts execution to reset the states.

   */

  static void mdlInitializeConditions(SimStruct *S)

  {

  }

#endif /* MDL_INITIALIZE_CONDITIONS */

#define MDL_START  /* Change to #undef to remove function */

#if defined(MDL_START)

  /* Function: mdlStart =======================================================

   * Abstract:

   *    This function is called once at start of model execution. If you

   *    have states that should be initialized once, this is the place

   *    to do it.

   */

  static void mdlStart(SimStruct *S)    /*添加采集卡初始化及开启采集任务*/

  {

  if(ADCardInit()!=1)

  {

             ssSetErrorStatus(S,"Can't find the DAQCard!");

  }

  DAQ1(0x10,5000,1024*4,buffer);    /*开启采集*/

  pnum=0;                        /*初始化buf指针位置*/

  }

#endif /*  MDL_START */

/* Function: mdlOutputs =======================================================

 * Abstract:

 *    In this function, you compute the outputs of your S-function

 *    block. Generally outputs are placed in the output vector, ssGetY(S).

 */

static void mdlOutputs(SimStruct *S, int_T tid)

{

    int Length=1024*4;               /*读取的buffer长度*/

ReadDaq(5,Length,buffer);            /*从采集卡读取buffer*/

    real_T  *y = ssGetOutputPortRealSignal(S,0);/*获取输出指针*/

    if (pnum>=Length) pnum=0;         /*判断指针是否已满*/

*y=buffer[pnum];                     /*输出第pnum个点的值*/

pnum++;                            /*指针加1*/

}

#define MDL_UPDATE  /* Change to #undef to remove function */

#if defined(MDL_UPDATE)

  /* Function: mdlUpdate ======================================================

   * Abstract:

   *    This function is called once for every major integration time step.

   *    Discrete states are typically updated here, but this function is useful

   *    for performing any tasks that should only take place once per

   *    integration step.

   */

  static void mdlUpdate(SimStruct *S, int_T tid)

  {

  }

#endif /* MDL_UPDATE */

#define MDL_DERIVATIVES  /* Change to #undef to remove function */

#if defined(MDL_DERIVATIVES)

  /* Function: mdlDerivatives =================================================

   * Abstract:

   *    In this function, you compute the S-function block's derivatives.

   *    The derivatives are placed in the derivative vector, ssGetdX(S).

   */

  static void mdlDerivatives(SimStruct *S)

  {

  }

#endif /* MDL_DERIVATIVES */

/* Function: mdlTerminate =====================================================

 * Abstract:

 *    In this function, you should perform any actions that are necessary

 *    at the termination of a simulation.  For example, if memory was

 *    allocated in mdlStart, this is the place to free it.

 */

static void mdlTerminate(SimStruct *S)

{

ADCardQuit();

}                      /*退出采集卡*/

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

 * See sfuntmpl_doc.c for the optional S-function methods *

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

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

 * Required S-function trailer *

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

#ifdef  MATLAB_MEX_FILE    /* Is this file being compiled as a MEX-file? */

#include "simulink.c"      /* MEX-file interface mechanism */

#else

#include "cg_sfun.h"       /* Code generation registration function */

#endif

abc.cpp

#define CHANNEL1 0x01

#define CHANNEL2 0x02

#define CHANNEL3 0x04

#define CHANNEL4 0x08

#define CHANNEL5 0x10

#define CHANNEL6 0x20

#define CHANNEL7 0x40

#define CHANNEL8 0x80

#pragma comment(lib, "DRVIAPI.lib")

extern "C" _declspec(dllimport) int Add(int a,int b);

extern  "C" _declspec(dllimport) int ADCardInit(void);

extern "C" _declspec(dllimport) int Daq(unsigned char Channel,                                                  //???ù?¨??

            unsigned int Frequency,                                    

            unsigned short Length,                                     

            int Num,                                                                                   

            double* wave0 = NULL,                                     

            double* wave1 = NULL,

            double* wave2 = NULL,

            double* wave3 = NULL,

            double* wave4 = NULL,

            double* wave5 = NULL,

            double* wave6 = NULL,

            double* wave7 = NULL);

extern "C" __declspec(dllimport)

int ReadDaq(int Channel, int Length, double *buffer);

extern "C" __declspec(dllimport)

int DAQ1(unsigned char Channel, unsigned int Frequency, unsigned short Length, double *wave);

extern "C" __declspec(dllimport)

int DAQ2(unsigned char Channel, unsigned int Frequency, unsigned short Length, double *wave0, double *wave1);

extern "C" __declspec(dllimport)

int DAQ3(unsigned char Channel, unsigned int Frequency, unsigned short Length, double *wave0, double *wave1, double *wave2);

extern "C" __declspec(dllimport)

int DAQ4(unsigned char Channel, unsigned int Frequency, unsigned short Length, double *wave0, double *wave1, double *wave2, double *wave3);

extern "C" __declspec(dllimport)

int DAQ5(unsigned char Channel, unsigned int Frequency, unsigned short Length, double *wave0, double *wave1, double *wave2, double *wave3, double *wave4);

extern "C" __declspec(dllimport)

int DAQ6(unsigned char Channel, unsigned int Frequency, unsigned short Length, double *wave0, double *wave1, double *wave2, double *wave3, double *wave4, double *wave5);

extern "C" __declspec(dllimport)

int DAQ7(unsigned char Channel, unsigned int Frequency, unsigned short Length, double *wave0, double *wave1, double *wave2, double *wave3, double *wave4, double *wave5, double *wave6);

extern "C" __declspec(dllimport)

int DAQ8(unsigned char Channel, unsigned int Frequency, unsigned short Length, double *wave0, double *wave1, double *wave2, double *wave3, double *wave4, double *wave5, double *wave6, double *wave7);

extern "C" __declspec(dllimport) int ADCardQuit(void);

7.       实验结果

A1.采集信号显示并进行频谱分析

A2.进行滤波处理

B1.再次采集另一不同噪声信号

  

B2.滤波分析

实验二:球杆定位控制系统实验

1.       机械建模分析:

球杆定位系统是一个经典的控制理论数学模型,它具有物理模型简单,概念清晰,便于用控制理论算法进行控制的特点,系统给出一个相对简单的模型。

钢球在滑道加速滚动的力是小球的重力在同滑道平行方向上的分力与摩擦力的合力。钢球滚动的动力学方程,钢球在滑道上滚动加速度:

a=μgcosα-  gsinα

其中为钢球与轨道之间的摩擦系数,而为滑道与水平面之间的夹角。

为了简化系统模型,考虑到摩擦系数比较小,摩擦力可以忽略不记,因此,其基本的数学模型转换成如下公式:

                            ..  

M x  =mgsinα

<<1时,线性化处理后,得到传递函数如下:

                         X(s)    g

                         ---- = -----

                         α(s)   s^2

其中X(s)为钢球在滑道上的位置。

在实际控制的过程中,滑道的仰角是由电动机的转角输出来实现的。影响电动机转角和滑道仰角之间的关系的主要因素就是齿轮的减速比和非线性。因此,我们把该模型进一步简化:

                          (s)=b*(s)

我们可以得到另一个模型:

                         X(s)    c

                         ---- = -----

                         (s)   s^2

期中c是一个包含了b和g的影响的参数。因此球杆系统实际上可以简化为一个二阶系统。

2.       实验步骤:

(1)认真观察球杆定位控制系统,指出系统的各个部分,打开后盖,认知相关的电气控制部分及机械传动部分,并做好记录。

(2)安装好后盖,将电源线,通讯线与电源箱,电脑正常连接。

(3)接通电源,打开测试软件:

1)在matlab下打开QGTEST.MDL进入测试界面

2)点击运行:

3)设置运动位置POS,观察球杆运动情况,

4)切换伺服开关,运动,停止开关,测试硬件响应

5)改变运动速度,加速度及位置,观察运动情况

6)打开各个示波器

7)用手轻拨钢球,让钢球在滑道上缓慢滚动,观察采集到钢球的位置数据

8)停止实时仿真,观察各示波器数据,并保存到相应的文件

3.实验内容及结果:

  a. 搭建球杆控制系统及其子系统

   

b.球杆模型c代码

Get_AD.cpp

#include "Get_AD.h"

#define WIN32

//#ifndef WIN32

//#error "Only WIN32 version is available"

//#endif

#include "windows.h"

#define S_FUNCTION_LEVEL 2

#define S_FUNCTION_NAME  Get_AD

// Need to include simstruc.h for the definition of the SimStruct and

// its associated macro definitions.

#include "simstruc.h"

#include "TML_lib.h"

//#include "TML_lib_compact.h"

#pragma comment(lib, "TML_lib.lib")

#pragma warning( disable: 4761 )

#define IS_PARAM_DOUBLE(pVal) (mxIsNumeric(pVal) && !mxIsLogical(pVal) &&\

!mxIsEmpty(pVal) && !mxIsSparse(pVal) && !mxIsComplex(pVal) && mxIsDouble(pVal))

// Function: mdlInitializeSizes ===============================================

// Abstract:

//    The sizes information is used by Simulink to determine the S-function

//    block's characteristics (number of inputs, outputs, states, etc.).

static void mdlInitializeSizes(SimStruct *S)

{

    // No expected parameters

    ssSetNumSFcnParams(S, 0);

    // Parameter mismatch will be reported by Simulink

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

        return;

    }

    // Specify I/O

    //if (!ssSetNumInputPorts(S, 0)) return;

    if (!ssSetNumInputPorts(S, 1)) return;

    ssSetInputPortWidth(S, 0, DYNAMICALLY_SIZED);

    ssSetInputPortDirectFeedThrough(S, 0, 1);

    if (!ssSetNumOutputPorts(S,1)) return;

    ssSetOutputPortWidth(S, 0, DYNAMICALLY_SIZED);

    ssSetNumSampleTimes(S, 1);

    // Reserve place for C++ object

    ssSetNumPWork(S, 1);

    ssSetOptions(S,

                 SS_OPTION_WORKS_WITH_CODE_REUSE |

                 SS_OPTION_EXCEPTION_FREE_CODE |

                 SS_OPTION_USE_TLC_WITH_ACCELERATOR);

}

// Function: mdlInitializeSampleTimes =========================================

// Abstract:

//   This function is used to specify the sample time(s) for your

//   S-function. You must register the same number of sample times as

//   specified in ssSetNumSampleTimes.

static void mdlInitializeSampleTimes(SimStruct *S)

{

    ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);  //INHERITED_SAMPLE_TIME

    ssSetOffsetTime(S, 0, 0.0);

    ssSetModelReferenceSampleTimeDefaultInheritance(S);

}

// Function: mdlStart =======================================================

// Abstract:

//   This function is called once at start of model execution. If you

//   have states that should be initialized once, this is the place

//   to do it.

#define MDL_START

static void mdlStart(SimStruct *S)

{

    // Store new C++ object in the pointers vector

    DoubleAdder *da  = new DoubleAdder();

 //   InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);

    ssGetPWork(S)[0] = da;

      

}

// Function: mdlOutputs =======================================================

// Abstract:

//   In this function, you compute the outputs of your S-function

//   block. Generally outputs are placed in the output vector, ssGetY(S).

static void mdlOutputs(SimStruct *S, int_T tid)

{

    // Retrieve C++ object from the pointers vector

//    DoubleAdder *da = static_cast<DoubleAdder *>(ssGetPWork(S)[0]);

    // Get data addresses of I/O

    InputRealPtrsType  u = ssGetInputPortRealSignalPtrs(S,0);

    real_T *y = ssGetOutputPortRealSignal(S, 0);

              

//

    // Call AddTo method and return peak value

 //   y[0] = da->AddTo(*u[0]);

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

       short val_ad;

       short AD_No;

       WORD adr_AD;

       AD_No=*u[0];

       adr_AD=0;

    if(AD_No==2) adr_AD = 0x23e;

       if(AD_No==5) adr_AD = 0x241;

       if(adr_AD!=0)

       {

              TS_GetIntVariable(adr_AD,val_ad);  

              *y =400.00*((float)(unsigned short)val_ad/65535.00);

       }

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

}

// Function: mdlTerminate =====================================================

// Abstract:

//   In this function, you should perform any actions that are necessary

//   at the termination of a simulation.  For example, if memory was

//   allocated in mdlStart, this is the place to free it.

static void mdlTerminate(SimStruct *S)

{

    // Retrieve and destroy C++ object

  //  DoubleAdder *da = static_cast<DoubleAdder *>(ssGetPWork(S)[0]);

   // delete da;

}

// Required S-function trailer

#ifdef  MATLAB_MEX_FILE    /* Is this file being compiled as a MEX-file? */

#include "simulink.c"      /* MEX-file interface mechanism */

#else

#include "cg_sfun.h"       /* Code generation registration function */

#endif

InitIPM_RAM.cpp

#include "InitIPM_RAM.h"

#define WIN32

//#ifndef WIN32

//#error "Only WIN32 version is available"

//#endif

#include "windows.h"

#define S_FUNCTION_LEVEL 2

#define S_FUNCTION_NAME  InitIPM_RAM

// Need to include simstruc.h for the definition of the SimStruct and

// its associated macro definitions.

#include "simstruc.h"

#include "TML_lib.h"

//#include "TML_lib_compact.h"

#pragma comment(lib, "TML_lib.lib")

#pragma warning( disable: 4761 )

#define IS_PARAM_DOUBLE(pVal) (mxIsNumeric(pVal) && !mxIsLogical(pVal) &&\

!mxIsEmpty(pVal) && !mxIsSparse(pVal) && !mxIsComplex(pVal) && mxIsDouble(pVal))

// Function: mdlInitializeSizes ===============================================

// Abstract:

//    The sizes information is used by Simulink to determine the S-function

//    block's characteristics (number of inputs, outputs, states, etc.).

static void mdlInitializeSizes(SimStruct *S)

{

    // No expected parameters

    ssSetNumSFcnParams(S, 0);

    // Parameter mismatch will be reported by Simulink

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

        return;

    }

   // Specify I/O

    //if (!ssSetNumInputPorts(S, 0)) return;

    if (!ssSetNumInputPorts(S, 1)) return;

    ssSetInputPortWidth(S, 0, DYNAMICALLY_SIZED);

    ssSetInputPortDirectFeedThrough(S, 0, 1);

    if (!ssSetNumOutputPorts(S,1)) return;

    ssSetOutputPortWidth(S, 0, DYNAMICALLY_SIZED);

    ssSetNumSampleTimes(S, 1);

    // Reserve place for C++ object

    ssSetNumPWork(S, 1);

   

    ssSetOptions(S,

                 SS_OPTION_WORKS_WITH_CODE_REUSE |

                 SS_OPTION_EXCEPTION_FREE_CODE |

                 SS_OPTION_USE_TLC_WITH_ACCELERATOR);

}

// Function: mdlInitializeSampleTimes =========================================

// Abstract:

//   This function is used to specify the sample time(s) for your

//   S-function. You must register the same number of sample times as

//   specified in ssSetNumSampleTimes.

static void mdlInitializeSampleTimes(SimStruct *S)

{

    ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);

    ssSetOffsetTime(S, 0, 0.0);

    ssSetModelReferenceSampleTimeDefaultInheritance(S);

}

// Function: mdlStart =======================================================

// Abstract:

//   This function is called once at start of model execution. If you

//   have states that should be initialized once, this is the place

//   to do it.

#define MDL_START

static void mdlStart(SimStruct *S)

{

    // Store new C++ object in the pointers vector

    //DoubleAdder *da  = new DoubleAdder();

       short rtn;

    InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);

    //ssGetPWork(S)[0] = da;

    //FILE *pfile;

       DWORD nBaud = 115200;

       BYTE nHostID = 255;

       BYTE nRSType=SERIAL_RS232;

       BYTE nPort=1; 

       WORD start_address;

    

       //pfile=fopen("rtn.txt","wt");

    nPort=*uPtrs[0];

       rtn=TS_OpenSerialPort(nRSType, nPort, nHostID, nBaud);

    //fprintf(pfile,"TS_OpenSerialPort:%d\n",rtn);

    rtn=TS_SetupAxis(255,"IPM100.cfg");

    //fprintf(pfile,"TS_SetupAxis:%d\n",rtn);

    rtn=TS_SelectAxis(255);

    //fprintf(pfile,"TS_SelectAxis:%d\n",rtn);

    rtn=TS_Reset();

    Sleep(100);

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

       //工作方式选择_20060917

       // Download the "Ex29RAM.out" file on the drive

       TS_DownloadProgram("mcqg.out", start_address);

       // After the file download, execute the downloaded code

       TS_GOTO(start_address); // go to the start address of the setup program

       // After this, you can start sending on-line commands towards the drive

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

       rtn=TS_Power(POWER_ON);

    //fprintf(pfile,"TS_Power:%d\n",rtn);

    //rtn=TS_MoveVelocity(2,0.64,MOVE_IMMEDIATE,FROM_REFERENCE);

    rtn=TS_MoveAbsolute(4420, 5, 1, UPDATE_IMMEDIATE, FROM_REFERENCE);

    //fprintf(pfile,"TS_MoveVelocity:%d\n",rtn);

    //fclose(pfile);

    Sleep(100);

}

// Function: mdlOutputs =======================================================

// Abstract:

//   In this function, you compute the outputs of your S-function

//   block. Generally outputs are placed in the output vector, ssGetY(S).

static void mdlOutputs(SimStruct *S, int_T tid)

{

    // Retrieve C++ object from the pointers vector

//    DoubleAdder *da = static_cast<DoubleAdder *>(ssGetPWork(S)[0]);

   

    // Get data addresses of I/O

 //   InputRealPtrsType  u = ssGetInputPortRealSignalPtrs(S,0);

      real_T *y = ssGetOutputPortRealSignal(S, 0);

    // Call AddTo method and return peak value

//    y[0] = da->AddTo(*u[0]);

     

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

/*    WORD adr_APOS = 0x228; // address of the APOS TML variable - measured position

    long i_APOS = 0; // variable storing the actual position read from the drive 

    TS_GetLongVariable(adr_APOS, i_APOS); // read the actual position

    if (i_APOS<(4420-10))   *y = 1;//*/

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

    //Sleep(50); 

    *y = 1;

}

// Function: mdlTerminate =====================================================

// Abstract:

//   In this function, you should perform any actions that are necessary

//   at the termination of a simulation.  For example, if memory was

//   allocated in mdlStart, this is the place to free it.

static void mdlTerminate(SimStruct *S)

{

    // Retrieve and destroy C++ object

//    TS_MoveAbsolute(0, 3, 0.1, UPDATE_IMMEDIATE,FROM_REFERENCE ); //FROM_MEASURE

//    Sleep(200);

//    TS_MoveVelocity(0,0.1,MOVE_IMMEDIATE,FROM_REFERENCE);

    TS_Power(POWER_OFF);

       TS_CloseSerialPort();

//    DoubleAdder *da = static_cast<DoubleAdder *>(ssGetPWork(S)[0]);

//    delete da;

}

// Required S-function trailer

#ifdef  MATLAB_MEX_FILE    /* Is this file being compiled as a MEX-file? */

#include "simulink.c"      /* MEX-file interface mechanism */

#else

#include "cg_sfun.h"       /* Code generation registration function */

#endif

Move_AbS.cpp

#include "Move_Abs.h"

#define WIN32

//#ifndef WIN32

//#error "Only WIN32 version is available"

//#endif

#include "windows.h"

#define S_FUNCTION_LEVEL 2

#define S_FUNCTION_NAME  Move_Abs

// Need to include simstruc.h for the definition of the SimStruct and

// its associated macro definitions.

#include "simstruc.h"

#include "TML_lib.h"

//#include "TML_lib_compact.h"

#pragma comment(lib, "TML_lib.lib")

#pragma warning( disable: 4761 )

#define IS_PARAM_DOUBLE(pVal) (mxIsNumeric(pVal) && !mxIsLogical(pVal) &&\

!mxIsEmpty(pVal) && !mxIsSparse(pVal) && !mxIsComplex(pVal) && mxIsDouble(pVal))

// Function: mdlInitializeSizes ===============================================

// Abstract:

//    The sizes information is used by Simulink to determine the S-function

//    block's characteristics (number of inputs, outputs, states, etc.).

static void mdlInitializeSizes(SimStruct *S)

{

    // No expected parameters

       int i;

    ssSetNumSFcnParams(S, 0);

    // Parameter mismatch will be reported by Simulink

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

        return;

    }

    // Specify I/O

    if (!ssSetNumInputPorts(S, 3)) return;

    for(i=0;i<3;i++)

    {

        ssSetInputPortWidth(S, i, 1);//DYNAMICALLY_SIZED

        ssSetInputPortDirectFeedThrough(S, i, 1);

    }

    if (!ssSetNumOutputPorts(S,0)) return;

 //   ssSetOutputPortWidth(S, 0, DYNAMICALLY_SIZED);

    ssSetNumSampleTimes(S, 1);

    // Reserve place for C++ object

    ssSetNumPWork(S, 1);

    ssSetOptions(S,

                 SS_OPTION_WORKS_WITH_CODE_REUSE |

                 SS_OPTION_EXCEPTION_FREE_CODE |

                 SS_OPTION_USE_TLC_WITH_ACCELERATOR);

}

// Function: mdlInitializeSampleTimes =========================================

// Abstract:

//   This function is used to specify the sample time(s) for your

//   S-function. You must register the same number of sample times as

//   specified in ssSetNumSampleTimes.

static void mdlInitializeSampleTimes(SimStruct *S)

{

    ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);  //INHERITED_SAMPLE_TIME

    ssSetOffsetTime(S, 0, 0.0);

    ssSetModelReferenceSampleTimeDefaultInheritance(S);

}

// Function: mdlStart =======================================================

// Abstract:

//   This function is called once at start of model execution. If you

//   have states that should be initialized once, this is the place

//   to do it.

#define MDL_START

static void mdlStart(SimStruct *S)

{

    // Store new C++ object in the pointers vector

    DoubleAdder *da  = new DoubleAdder();

    InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);

    ssGetPWork(S)[0] = da;

   

}

// Function: mdlOutputs =======================================================

// Abstract:

//   In this function, you compute the outputs of your S-function

//   block. Generally outputs are placed in the output vector, ssGetY(S).

static void mdlOutputs(SimStruct *S, int_T tid)

{

    // Retrieve C++ object from the pointers vector

//    DoubleAdder *da = static_cast<DoubleAdder *>(ssGetPWork(S)[0]);

    // Get data addresses of I/O

    InputRealPtrsType  u = ssGetInputPortRealSignalPtrs(S,0);

    real_T *y = ssGetOutputPortRealSignal(S, 0);

//

    // Call AddTo method and return peak value

 //   y[0] = da->AddTo(*u[0]);

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

    short rtn;

       FILE *pfile;

    pfile=fopen("rtn.txt","wt");

       fprintf(pfile,"*u[0]:%ld\n",*u[0]);

       fprintf(pfile,"*u[1]:%f\n",*u[1]);

       fprintf(pfile,"*u[2]:%f\n",*u[2]);

    rtn=TS_MoveAbsolute(*u[0], *u[1] , *u[2], UPDATE_IMMEDIATE, FROM_REFERENCE);

    //rtn=TS_MoveAbsolute(2000, 5, 0.01, UPDATE_IMMEDIATE, FROM_REFERENCE); 

    fprintf(pfile,"TS_MoveAbsolute:%d\n",rtn);

    fclose(pfile);

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

}

// Function: mdlTerminate =====================================================

// Abstract:

//   In this function, you should perform any actions that are necessary

//   at the termination of a simulation.  For example, if memory was

//   allocated in mdlStart, this is the place to free it.

static void mdlTerminate(SimStruct *S)

{

    // Retrieve and destroy C++ object

  //  DoubleAdder *da = static_cast<DoubleAdder *>(ssGetPWork(S)[0]);

   // delete da;

}

// Required S-function trailer

#ifdef  MATLAB_MEX_FILE    /* Is this file being compiled as a MEX-file? */

#include "simulink.c"      /* MEX-file interface mechanism */

#else

#include "cg_sfun.h"       /* Code generation registration function */

#endif

c.       将小球分别放在横杆的远中近测距得到距离波形

d.      

e.       将小球放在衡量任意位置,输入平衡位置,观察横杆定位调节

POS=300

总结:

1.       收获与心得体会:

本次实验我们选到的题目是噪声的测量与声频分析,实验中我们的思想是先通过Simulink调用采集卡采集噪声信号,再将采集噪声传到Matlab工作空间,运行声频分析进行滤波后获取噪声波形及相应的频谱。实验过程中我们遇到许多问题,界面设计是我们经过多方修改,最终定下最后这个方案,采集原始信号并做频谱分析,然后进行滤波并获得频谱,观察两者差异。滤波子程序进过多方设计修改,然后在实验室现场调试,选取合适截止频率,获得理想波形信号。

通过噪声测量及声频分析实验,我们了解并熟悉了Matlab中界面设计的两种基本方法,实验中,我们是通过编写代码实现的,我们还学到了如何利用Simulink搭建模型实现硬件和软件的交互,通过实验我们深刻体会到Matlab是一个功能十分强大的软件,但是她的许多东西对于我们一个初学者是十分困难的,实验实践中需要我们付出时间去熟悉,去用心思考,去实际操作,从基础开始学习,认真走好每一步,才能顺利完成实验。

    通过这学期的工程测试综合实验,经过前面噪声信号的采集测试与频谱分析试验,我们还进行了球杆定位控制系统实验,首先搭建曲柄运动的速度、加速度位置控制系统,及小球位置采集系统,并且通过实验对小球的水平位置进行判定,通过该实验对机械机构,电气机构及传感器在工程中的运用有了进一步的认识。最后,我们在黄老师的指导下,对以上几个系统组合,建立PID控制器--控制小球在球杆的某个位置的Simulink控制模型,并通过调节测试实现了小球的位置控制。

    通过一系列实验,在黄老师的耐心辅导下,我们进一步了解了MATLAB这一强大的数学工具在工程中的应用,对工程测试知识在工程实际中的应用有了更深一层的认识,同时深刻认识到自己知识的匮乏,衷心感谢黄老师的指导!

2.       分工:

雷翔:matlab界面编写,数据采集滤波程序的编写和注释,simulink仿真模型调试运行

潘绪文:matlab界面编写,波形滤波程序设计,实验报告及总结

闫学文:球杆控制实验的搭建运行调试,simulink仿真模型运行

更多相关推荐:
熔点的测定实验报告

广东药学院实验报告纸成绩老师签名广东药学院实验报告纸成绩老师签名广东药学院实验报告纸成绩老师签名

实验三熔点的测定

实验三熔点的测定实验目的1了解熔点测定的意义2掌握测定熔点的操作实验原理每一个晶体有机化合物都具有一定的熔点熔点就是化合物熔化时固液两态在大气压下成平衡的温度一个纯化合物从始熔到全熔的温度范围称为熔距熔点范围或...

熔点的测定预习实验报告

河北北方学院20xx级工业分析与检验一班邢妍萍熔点的测定预习实验报告一、实验目的及要求1.了解熔点测定的意义和应用。2.掌握熔点测定的操作方法。3.了解温度计校正的方法。二、实验原理晶体化合物的固液两态在大气压…

熔点及沸点的测定实验报告

有机化学实验报告实验名称熔点和沸点及其测定学院化学工程学院专业化学工程与工艺班级姓名学号指导教师日期熔点及其测定实验目的1了解熔点和沸点测定的意义2掌握熔点和沸点测定的操作方法实验原理晶体化合物的固液两态在大气...

苯甲酸熔点的测定有机化学实验报告

苯甲酸熔点的测定一、实验目的:测定苯甲酸晶体的熔点范围。二、实验原理:有机化合物熔点通常用毛细管法来测定,实际上测得的是一个熔点范围,即试料从开始熔化到完全熔化为液体的温度范围,纯粹的固态物质通常有固定的熔点。…

熔点测定 有机化学实验预习报告 2

南昌大学有机化学实验预习报告实验项目名称熔点的测定一实验目的1了解玻璃温度计的种类和校正方法2掌握熔点测定的意义和操作二实验基本原理或主副反应式1称为熔点2初溶到全溶的温度范围一般不超过051C液两相间的变化非...

熔点.沸点的测定实验报告

有机化学实验报告实验学专班姓指导日名称院业级名教师期熔点的测定沸点的测定化学工程与工艺化工101班郭了了学号104020xx114房椒华沈梁钧20xx年10月13日一实验目的1了解熔点和沸点的意义和应用2掌握熔...

实验3 TG-DTA法测定材料熔点

实验3TGDTA法测定材料熔点实验学时数3学时每组核定人数5人适用专业金属材料工程焊接等本科专业一实验目的热分析thermalanalysis是在控制程序温度下测量物质或其反应生成物的物理性质与温度或时问的关系...

宁波工程学院熔点、沸点及其测定实验

实验学专班姓指导日机化学实验报告名称熔点沸点及其测定院化学工程学院业化学工程与工艺级化工126班名张敬文学号124020xx620教师房江华李颖期有一实验目的a了解熔点沸点的测量方法及常见物质的熔点b练习酒精灯...

结晶器保护渣熔点测试试验报告

结晶器保护渣熔点测定一文献综述保护渣是七十年代发展起来的一门学科是不可或缺的冶金材料对铸坯质量及连铸工艺顺行发挥着不可替代的作用与此同时其特性检测技术亦应运而生其中保护渣熔点的准确检测是保护渣研究及应用中不可缺...

实验名称-未知化合物熔点的测定

实验名称实验四未知化合物熔点的测定题目用户名权重10本模块得分满分100100模块你的回答仪器选取名称正确答案齐氏管玻璃管温度计开口橡皮塞表面皿橡皮圈熔点毛细管做错次数0做错一次扣2分题目做错一次扣2分模块试剂...

实验一.基本内容及有机物熔点的测定

实验一有机化学实验的基本内容及有机物熔点测定4课时一教学目的有机化学实验是一门以实验为基础的学科随着新的实验技术不断出现这门实验课程正在向用量少效率高绿色化的方向发展通过有机化学实验课程的学习使学生能够掌握有机...

熔点测定实验报告(24篇)