用ToolBook实现液压回路的动态模拟
江苏省淮阴市淮阴工专机械系
(223001) 许军 摘要 本文介绍用ToolBook实现液压回路的动态模拟的一种方法和过程 关键词 CAI课件 对象(object) 脚本 属性ToolBook是一款优秀的多媒体著作工具,十分适于CAI课件的制作。它具有灵活的控制结构,其内嵌的openscript语言功能十分强大,对对象(object)的控制十分完全,这对编制复杂的对象属性十分有效。本文介绍实现液压回路的动态模拟的一种方法和过程。以下图的差动连接回路为例。
to handle buttonclick --
换向阀进出油if name of target = "hf_l1" then
set fin to searchfin(name of self) --
取油压凾数if fin > 0 then
set rgbStroke of target to fin,0,255-fin
get givefout(name of self,fin)
--送油压凾数end if
end if
if name of target = "hf_l2" then
set rgbStroke of target to 2,0,255-2
end if
end buttonclick
to handle buttoncon
---换向阀通电换向local int i
set bas to vertices of item 1 of my objects
set angl1 to item 2 of my objects
set angl2 to item 3 of my objects
set gro to item 4 of my objects
set ll1 to item 4 of objects of gro
set ll2 to item 5 of objects of gro
set ll3 to item 8 of objects of gro
set ll4 to item 7 of objects of gro
set ll5 to item 6 of objects of gro
set strokecolor of self to black
if (name of target = "hf_dl") and (see of target = true) then
step i from item 1 of bas to item 3 of bas by 20
move gro by 20,0
increment item 1 of bounds of angl2 by 20
increment item 3 of bounds of angl1 by 20
end step
increment Pos of self --
设位置属性end if
if (name of target = "hf_dr") and (see of target = true) then
step i from item 1 of bas to item 3 of bas by 20
move gro by -20,0
decrement item 3 of bounds of angl1 by 20
decrement item 1 of bounds of angl2 by 20
end step
decrement Pos of self
end if
conditions
when (Pos of self = -1) and (see of target =false)
step i from item 1 of bas to item 3 of bas by 20
move gro by 20,0
increment item 1 of bounds of angl2 by 20
increment item 3 of bounds of angl1 by 20
end step
increment Pos of self
when (Pos of self = 1) and (see of target =false)
step i from item 1 of bas to item 3 of bas by 20
move gro by -20,0
decrement item 3 of bounds of angl1 by 20
decrement item 1 of bounds of angl2 by 20
end step
decrement Pos of self
end conditions
end buttoncon
notifyAfter ASYM_SummonWidgets
send ASYM_IAmWidget to self
end
to handle ASYM_Reset --
回路复位set strokecolor of self to black
end
其次,将创建好的各液压元件组合在一起,成为一个完整回路。为回路中每个元件规定一个名字,不要重复。液压回路可以看成一个图状数据结构,将差动回路连接状况用数组表达如下:notifyAfter ASYM_SummonWidgets
send ASYM_IAmWidget to self
end
to handle ASYM_Reset --
复位SYSTEM YY[100][6][2] --
定义数组FILL YY WITH 0 --
数组清零YY[1][1][1]=B1; YY[1][2][1]=YG1
YY[2][1][1]=YG1; YY[2][2][1]=B1; YY[2][3][1]=YF1; YY[2][4][1]=HF1
YY[3][1][1]=YF1; YY[3][2][1]=YG1; YY[3][3][1]=YG2
YY[4][1][1]=YG2; YY[4][2][1]=YF1
YY[5][1][1]=HF1; YY[5][2][1]=YG1; YY[5][3][1]=YG3; YY[5][4][1]=YG4
YY[6][1][1]=YG3; YY[6][2][1]=HF1; YY[6][3][1]=YG5
YY[7][1][1]=YG4; YY[7][2][1]=HF1; YY[7][3][1]=YG10; YY[7][4][1]=YG12
YY[8][1][1]=YG5; YY[8][2][1]=YG3; YY[8][3][1]=TF1; YY[8][4][1]=DF1;
YY[9][1][1]=TF1; YY[9][2][1]=YG5; YY[9][3][1]=YG8; YY[9][4][1]=YG9
YY[10][1][1]=DF1; YY[10][2][1]=YG5; YY[10][3][1]=YG8
YY[11][1][1]=YG8; YY[11][2][1]=TF1; YY[11][3][1]=DF1; YY[11][4][1]=YG9
YY[12][1][1]=YG10;YY[12][2][1]=YG4; YY[12][3][1]=YG12; YY[12][4][1]=YG11
YY[13][1][1]=YG11;YY[13][2][1]=YG10;YY[13][3][1]=HF2
YY[14][1][1]=HF2; YY[14][2][1]=YG9; YY[14][3][1]=YG11; YY[14][4][1]=YG13
YY[15][1][1]=YG13;YY[15][2][1]=HF2; YY[15][3][1]=G1
YY[16][1][1]=YG12;YY[16][2][1]=YG4; YY[16][3][1]=YG10; YY[16][4][1]=G1
YY[17][1][1]=G1; YY[17][2][1]=YG13;YY[17][3][1]=YG12
YY[18][1][1]=YG9; YY[18][2][1]=YG8; YY[18][3][1]=TF1; YY[18][4][1]=HF2
end
同时还需要特定函数处理此关系,使程序执行中,各液压元件能知道自己的位置,正确接收上个元件传来的数据(如:油压),并正确传给下个元件。特定函数脚本如下:
to get searchfin fname --
接收数据凾数SYSTEM YY[100][6][2]
fin =0
step i from 1 to 100
if YY[i][1][1]=fname then
step j from 2 to 6
cname=YY[i][j][1]
step k from 1 to 100
if YY[k][1][1]=cname then
step l from 2 to 6
if (YY[k][l][1]=fname) and (YY[k][1][2]<>0) then
fin=YY[k][1][2]
break step
end if
end step
end if
end step
end step
end if
if i=0 then
break step
end if
end step
return fin
end searchfin
to get givefout mname,fout
--传递数据凾数SYSTEM YY[100][6][2]
step i from 1 to 100
if YY[i][1][1]=mname then
YY[i][1][2]= fout
break step
end if
end step
return 1
end givefout
最后,教师在讲解回路原理时,利用鼠标点取,使回路执行,由于有了元件的动作,使回路执行过程可见,避免了过去静止的挂图讲解。通过上述方法,笔者已制作了一批基本回路用于液压教学,效果很好。 对上述过程的进一步研究,利用ToolBook的消息(message)传递语句可以实现回路的自动执行,也可以自己搭建回路进行模拟运行。希望对此感兴趣的同志来信交流,我的e-mail是[email protected]