I am trying to connect the VC sim with PLC for virtual commissioning so I have to programm in VC some movements triggered by the PLC. The problem is that these signals could trigger at any time so they should be able of moving whenever they are triggered. There wouldn’t be any problem if I could do a script per movement but since this consumes computer resources and I’m already using physics (which consumes a lot), I’m trying other ways.
Therefore, I am struggling with programming a script in which I can trigger signals in parallel. For what I’ve been trying, this is the closest I have gotten, but since I use suspendRun() it stops and then accelerates to continue. The movements should be triggered by boolean signals and in each state(True or False), the link should move to the target position.
I’d really appreciate some tips on how to program this. Thanks a lot.
from vcScript import * app = getApplication() sim = app.Simulation comp = getComponent() sensorSignal=comp.findBehaviour('BooleanSignal') signal_1=comp.findBehaviour('Q_A_1A') signal_2=comp.findBehaviour('Q_A_1B') `...............................` signal_12=comp.findBehaviour('Q_D_1A') servo = comp.findBehaviour("Servo Controller") list=[sensorSignal,signal_1,.............,signal_12] def OnSignal(signal): suspendRun() global go go=True resumeRun() def OnRun(): global go while sim.IsRunning == True: triggerCondition ( lambda:go==True) for i in range(0,len(list)): if list[i].Value: servo.setJointTarget(i,30) elif list[i].Value==False: servo.setJointTarget(i,0) servo.move()