搬家第二天-39.Wincc V7.3 模拟饮料灌装生产线动画效果(1)-一个瓶子初试

在QQ群聊天时,有人发布了一个悬赏,要求做一个饮料厂罐装生产线的简单动画模拟,要求step7+wincc结合,step7和Wincc变量连接没什么难度,Wincc动画效果还没有认真尝试过,于是自己试着做了一下,先从简单的生产线上一次只有一个瓶子的情况做起。

    任务简介:生产线上有四个工位,分别是起始位、罐装位、封装位、终止位,要求四个工位之间移动有移动效果,罐装和封装要有动画效果。

一 准备工作

  1. Wincc变量管理新建一个32位浮点数变量Start,新建一个1280*1024页面,用多边形画一个瓶子,名字修改为bottle,瓶子宽30高110,取消全局颜色方案,使用动态填充,填充颜色为黑色,起始位置(起始工位)left=60,top=600;画一个长方形盖子,名字改为cover,宽11高10,盖子填充绿色(像啤酒瓶盖),初始位置left=790,top=347,盖子盖上的位置left=790,top=591;画一个机械手,名字修改为robot,初始位置left=150,top=770;画一条传送带,一个原料罐,一根罐装管;画一个长方形模拟流出的液体,名字修改为fillin,宽70,高120,默认不可见;画一个启动按钮,一个停止按钮;画一个圆用于显示工作状态,圆全局颜色方案为否,填充量100,背景颜色根据内部变量Start数值改变,当Start=1为真,绿色,为假,红色。编辑状态下各控件如下:

2. 项目计算机属性启动项目勾选全局脚本功能

二 新建一个VBS全局动作,触发器为循环类型,周期1秒,脚本如下:

Option Explicit
Function action
Dim bottle,cover,robot,fillin
Dim Start
Set bottle=HMIRuntime.Screens("1bottle").ScreenItems("bottle")
Set cover=HMIRuntime.Screens("1bottle").ScreenItems("cover")
Set robot=HMIRuntime.Screens("1bottle").ScreenItems("robot")
Set fillin=HMIRuntime.Screens("1bottle").ScreenItems("fillin")
Set Start=HMIRuntime.Tags("Start")
'从最左边往填充工位移动
If Start.Read =1 And bottle.left<420 Then
  bottle.left=bottle.left+20
End If

'填充液体
If Start.Read =1 And bottle.left=420 And bottle.FillingIndex<90 Then
   fillin.Visible =True
  bottle.FillingIndex=bottle.FillingIndex+10
End If

'从填充工位往封装工位移动
If Start.Read =1 And bottle.FillingIndex=90 And bottle.left<780 Then
   fillin.Visible=False
  bottle.left=bottle.left+20
End If

'封装盖盖
If Start.Read =1 And bottle.left=780 And cover.top<591 Then
   cover.top=cover.top+122
   cover.left=790
   robot.top=robot.top+122
   robot.left=770
End If

'盖完盖子,机械手复位
If cover.top=591 And robot.top>150 Then
'If bottle.left>=780  Then
   robot.top=robot.top-12
   robot.left=770
End If

'瓶子继续前进
If Start.Read =1 And robot.top<396 And cover.top=591 And bottle.left<1140 Then
  
  bottle.left=bottle.left+20
   cover.left=cover.left+20
End If

'到了最终位,参数回到初始状态
If Start.Read =1 And bottle.left=1140 Then
   bottle.left=60
   bottle.top=600
   bottle.FillingIndex=0
   cover.left=790
   cover.top=347
End If
End Function

保存后运行,就能看到简单的动画效果了,如果希望动作平滑一点,可以把移动步长改小,把触发器周期改小一点。

一条生产线上往往紧密排列了很多瓶子,下一篇博客将介绍模拟整条生产线的动作制作。

 

posted @ 2021-01-30 20:50  来自金沙江的小鱼  阅读(1136)  评论(1编辑  收藏  举报