北航機電系統(tǒng)仿真實驗_第1頁
北航機電系統(tǒng)仿真實驗_第2頁
北航機電系統(tǒng)仿真實驗_第3頁
北航機電系統(tǒng)仿真實驗_第4頁
北航機電系統(tǒng)仿真實驗_第5頁
已閱讀5頁,還剩24頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、精選文檔機電系統(tǒng)仿真實驗實驗報告姓名:蘇森學號:SY1217227手機京航空航天大學儀器科學與光電工程學院2013年6月實驗一 :Maple 滑塊擺實驗一、實驗目的通過對滑塊擺進行Maple仿真,掌握Maple軟件的使用方法,掌握系統(tǒng)建 模方法,更進一步理解仿真對實際系統(tǒng)設計的指導意義。、實驗要求滑塊擺由一置于光滑桿上的質量為 m的滑塊A、一質量為M的小球B和長度為L,質量不計的剛性桿較接而成,不計各處摩擦,以過A點的水平面為零勢能面,通過Lagrange方程建立系統(tǒng)的運動方程,利用Maple軟件畫出:1 .滑塊A的位移x隨時間t的變化曲線2 .角度。隨時間t的變化曲

2、線3 .滑塊擺的運動動畫三、實驗設計可編輯1、系統(tǒng)的數(shù)學模型系統(tǒng)的運動遵循拉格朗日方程:LEc EpdLLDdtq'qq1其中:q: x(t)和e的自由度D:由于摩擦而消耗的能量Fq:自由度q產生的力Ec和Ep:系統(tǒng)的動能和勢能系統(tǒng)有兩個自由度,以x和 為廣義坐標,以過 A點的水平面為零勢能面,系統(tǒng)的動能和勢能分別為Ec 1mX2 1M X2 l282 2ba&cos221m M X2 1 Ml2 52 Mlx&cos 22Ep Mgl cos系統(tǒng)的Lagrange方程為Mgl cos1o 1L Ec EmMX2Ml2£ Mb&&cosc p

3、22計算出諸導數(shù)m M && Ml &&cos Ml &2 sind _Ldt &Ml2&& Ml&cos Ml &&sinMl &&sin Mgl sin帶入Lagrange方程,得到系統(tǒng)的運動微分方程M && Ml &cos Ml & sin 0X&cos g sin 0四、實驗結果1、滑塊A的位移x隨時間t的變化曲線回母2、角度()3、滑塊擺的運動動畫4、 源程序restart;with(DEtools):# 調用微分方程工具包with(plot

4、s):# 調用圖形包with(plottools):# 圖形工具包g := 9.8:m := 1:M := 1:l := 2:equ1 := (m+M)*(diff(x(t),t$2)+M*l*cos(phi(t)*(diff(phi(t),t$2)-M*l*sin(phi(t)*(diff(phi(t), t)2 = 0;equ2 := l*(diff(phi(t),t$2)+cos(phi(t)*(diff(x(t),t$2)+g*sin(phi(t) = 0;val := array(1 . 100):for i to 100 dovali := (1/10)*iend do:S :=

5、dsolve(equ1, equ2, phi(0) = 0, x(0) = 0, (D(phi)(0) = -1.3, (D(x)(0) = 1,phi(t), x(t), method = rkf45, type = numeric, output = val):eval(S):DEplot(equ1, equ2, x(t), phi(t), t = 0 . 10, x(0) = 0, (D(x)(0) = 1, phi(0) =畫 x(t)0, (D(phi)(0) = -1.3, stepsize = .1, linecolor = t);#DEplot(equ1, equ2, phi(

6、t), x(t), t = 0 . 10, x(0) = 0, (D(x)(0) = 1, phi(0) =畫 phi(t)0, (D(phi)(0) = -1.3, stepsize = .1, linecolor = t);# for t to 100 do # 求擺球圓心位置x(t) :=S2,1t,4:x1(t):=l*sin(S2,1t,2)+x(t):y1(t):=-l*cos(S2,1t,2):end do:for t to 100 dowall := curve(-4, 0, 0.5, 0):# 畫墻壁slider := rectangle(x(t)-.15, .15, x(t

7、)+.15, -.15, color = green): #畫綠色滑塊pendulum := disk(x1(t), y1(t), .2, color = red): #畫紅色小球lineW_P := curve(x(t), 0, x1(t), y1(t):# 畫擺線G1t := display(pendulum, lineW_P , wall, slider) :end do:display(seq(G1t, t = 1 . 100), insequence = true, scaling = constrained,axes = none, title = 'Singled Pen

8、dulum');實驗二:CVI傳感器靜態(tài)標定實驗、實驗目的掌握用CVI進行圖形化界面設計及仿真的方法、實驗要求i讀取數(shù)據(jù),顯示散點圖及擬合直線2計算斜率,截據(jù),均方差,線性度并顯示3生成.TXT報表、實驗設計測試系統(tǒng)的靜態(tài)特性就是指當被測量x不隨時間變化或隨時間的變化程度遠緩慢于系統(tǒng)固有的最低階運動模式的變化速度時,測試系統(tǒng)的輸出量y與輸入量x之間的函數(shù)關系,測試系統(tǒng)的靜態(tài)特性,是通過靜態(tài)標定的過程獲的。1線性度一般情況下,要求傳感器具有線性特性,但傳感器的實際特性卻是非線性的曲線,這種實際特性曲線與基準直線間的偏差稱為非線性誤差。傳感器的非線性誤差指標通常用線性度表示,線性度的定義為

9、:eLmax 100%yF.S式中:eL 線性度(非線性誤差)VLj在整個測量范圍內絕對值最大的非線性誤差yF.s 傳感器的滿量程輸出值由上面定義可以知道, 傳感器的線性度是以基準直線為參考的,實際測量中采用的是最小二乘線性度2重復性在相同的工作條件下, 在一段短的時間間隔內, 輸入量從同一方向作滿量程變化時,同一輸入量值所對應的多次測量所得到的一組輸出量值,他們之間相互偏離的程度便稱為傳感器的重復性。當傳感器在全量程范圍內多次重復測試時,同是正行程或同時反行程上對應同一輸入量,其輸出量之間的差值稱為重復性偏差。正、反行程的重復性偏差分別為:VRVRcccy 一 y 一j y j max y

10、j minfffy- yj y j max y j min在全量程內,重復性偏差的絕對值的最大值與基準直線上滿量程輸出之比為重復性誤差,定義如下:VRjJ maxyF.S100%虛擬傳感器的標定數(shù)據(jù)存儲為a.cld , b.cld兩個文件中,其數(shù)據(jù)定義為結構體CalibrateData聲明如下typedef struct CalibrateDataintinputnum;/輸入測量點數(shù)double*input;/輸入測量點的值,數(shù)據(jù)長度為inputnumcharinputunit10;/輸入物理量的單位introundnum;/測量的循環(huán)數(shù)charoutputunit10;/測量所得物理量的單

11、位double*output;測量的值,其排列順序為: A循環(huán)正行程,第一循環(huán)反行程,第二循環(huán)正行程, 第二循環(huán)反行程,依次類推。數(shù)據(jù)長度為/ inputnum*2* roundnumCALIDATA;在回調函數(shù)中利用 LinFit函數(shù)計算傳感器的基準直線,其函數(shù)原型如下:Int status = LinFit (double arrayX口,double arrayY口,int numberOfElements, double outputArray口,double *slope, double "intercept, double *meanSquaredError);數(shù)組X,

12、Y為用以計算擬合直線的點的 x軸和y軸的坐標值,數(shù)組 Z為得到的擬合直線值,intercept為基準直線的截距,數(shù)組X, Y, Z的長度均為 n , slope為基準直線的斜率, meanSquaredError 為均方差,Z, X滿足如下關系Zi = slope X +XnterceptmeanSquaredError計算公式如下n-1YimeanSquaredError=上0n四、實驗結果顯何昧用(.|談取數(shù)居Q圖1圖形化界面設計圖2運行結果圖三生成報表文件(F) 端蝎tEJ 佛式2J 絲:音VJ 快期(HJ圖4清空報表五、源程序#include <utility.h>#inc

13、lude <analysis.h>#include <ansi_c.h>#include <cvirte.h>#include <userint.h>#include "calibration.h"static int cal;/* 定義斜率、截距等全局變量*/char pathMAX_PATHNAME_LEN;double *x;double *y;/ 保存測量輸入如測量輸出double *z;double slope,intercept,square,linear,repeat;/* 定義數(shù)據(jù)結構體*/typedef st

14、ruct CalibrateDataintinputnum;/ 輸入測量點數(shù)double*input;/ 輸入測量點的值,數(shù)據(jù)長度為inputnumcharinputunit10;/ 輸入物理量的單位introundnum;/ 測量的循環(huán)數(shù)char outputunit10;/ 測量所得物理量的單位double *output;/ 測量的值,其排列順序為:第一循環(huán)正行程,/ 第一循環(huán)反行程,第二循環(huán)正行程,/ 第二循環(huán)反行程,依次類推。數(shù)據(jù)長度為/ inputnum*2* roundnumCALIDATA;CALIDATA data;/ 定義指針data 為結構體類型int main (int

15、 argc, char *argv)if (InitCVIRTE (0, argv, 0) = 0)return -1;/* out of memory */if (cal = LoadPanel (0, "calibration.uir", CAL) < 0)return -1;DisplayPanel (cal);RunUserInterface ();DiscardPanel (cal);return 0;int CVICALLBACK SHOWCallback (int panel, int control, int event,void *callbackD

16、ata, int eventData1, int eventData2)switch (event)case EVENT_COMMIT:FILE *file;file=fopen("report.txt","a");/ 若不存在,創(chuàng)建文件fclose(file);/* 顯示報表 */LaunchExecutable ("notepad.exe report") ;break;return 0;int CVICALLBACK AQUIRECallback (int panel, int control, int event, void

17、*callbackData, int eventData1, int eventData2)FILE *file;double *p;double *stack1,*stack2,*stack3,*stack4;double max,min;int maxindex,minindex;double a5;int flag=0;/ 加載文件標志switch (event)case EVENT_COMMIT:/* 讀取文件并保存*/flag = FileSelectPopup ("", "*.cld", "", " 載入數(shù)據(jù)文件

18、",VAL_LOAD_BUTTON, 0, 0, 1, 1, path);if(flag>0)file=fopen(path,"rb");fread (&data.inputnum, sizeof(int), 1, file);/ 讀取測量點數(shù)if(data.input=NULL)data.input=malloc(sizeof(double)*data.inputnum);elsedata.input=realloc(data.input,sizeof(double)*data.inputnum);fread(data.input,sizeof(d

19、ouble),data.inputnum,file);/ 讀取輸入測量點的值,為double 類型fread(data.inputunit,sizeof(char),10,file); / 讀取輸入物理量的單位 fread(&data.roundnum,sizeof(int),1,file);/ 讀取測量循環(huán)數(shù)fread(data.outputunit,sizeof(char),10,file);/ 讀取測量所得物理量單位if(data.output=NULL)data.output=malloc(sizeof(double)*2*data.inputnum*data.roundnu

20、m);elsedata.output=realloc(data.output,sizeof(double)*2*data.inputnum*da ta.roundnum);fread(data.output,sizeof(double),2*data.inputnum*data.roundnum,fil e);/ 讀取測量的值fclose(file);DeleteGraphPlot (CAL, CAL_GRAPH, -1,VAL_IMMEDIATE_DRAW);/ 刪除原有曲線for(int i=0;i<2*data.roundnum;i+)for(int j=0;j<data.i

21、nputnum;j+)PlotPoint (CAL,CAL_GRAPH, data.inputj, data.outputi*data.inputnum+j, VAL_EMPTY_SQUARE, VAL_RED);/* 為變量開辟堆棧區(qū)*/stack1 = malloc(sizeof(double)*data.inputnum*2*data.roundnum);stack2 = malloc(sizeof(double)*data.inputnum*2*data.roundnum);stack3 = malloc (sizeof(double)*data.inputnum);stack4 =

22、malloc(sizeof(double)*data.roundnum*2*data.inputnum);for(int i=0;i<2*data.roundnum;i+)for(int j=0;j<data.inputnum;j+) stack1i*data.inputnum+j= data.inputj;/* 擬合并顯示*/*for(int i=0;i<=data.inputnum;i+);*/LinFit (stack1, data.output, data.inputnum*2*data.roundnum,stack2,&slope, &interce

23、pt, &square);SetCtrlVal (CAL, CAL_SLOPE, slope);SetCtrlVal (CAL, CAL_INTERCEPT, intercept);SetCtrlVal (CAL, CAL_SQUARE, square);PlotLine (CAL, CAL_GRAPH, stack10, stack20,stack1data.inputnum*2*data.roundnum-1,stack2data.inputnum*2*data.roundnum-1, VAL_CYAN);/* 計算線性度誤差并顯示*/for(int i=0;i<data.i

24、nputnum*2*data.roundnum;i+)stack1i=abs(stack2i-data.outputi);MaxMin1D (stack1, data.inputnum*2*data.roundnum, &max,&maxindex, &min,&minindex);linear=max*100/(stack2data.inputnum*2*data.roundnum-1-stack20);SetCtrlVal (CAL, CAL_LINEAR, linear);/* 計算重復性誤差并顯示*/for(int j=0;j<data.input

25、num;j+)max=0;min=2*stack2data.inputnum*2*data.roundnum-1;for(int i=0;i<2*data.roundnum;i+)if(max<data.outputi*data.inputnum+j)max=data.outputi*data.inputnum+j;if(min>data.outputi*data.inputnum+j)min=data.outputi*data.inputnum+j;stack3j=max-min;MaxMin1D (stack3, data.roundnum, &max, &maxindex,&min,&minindex);repeat=max*100/(stack2data.inputnum*2*data.roundnum-1-stack20) ;SetCtrlVal (CAL, CAL_REPEAT, repeat);/* 生成報表 */file=fopen("report.txt","a");/ 以寫的形式打開,若不存在則創(chuàng)建 fprintf(file,"Slope Intercept MeanSquaredError LinearRepeatin

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論