Change the simulation program

Is it possible to change the program of simulation when simulation is in run state?
I have multiple programs. Simulation start a socket. When socket gets the name of the program simulation need to switch the program and continue with another program.


what do mean by “program”?


I mean vcProgram which is runned in vcExecutor.

I want to change the program which is executed in the simulation or start another program when previous program is finished.


You can use the event functions of vcExecutor:

OnProgramFinished = function # gives vcExecutor object as argument
OnPostExecuteStatement = function2 # 2 arguments vcStatement and isImmediate

You could also use signals and change depending on them:

def OnSignal(signal):
   if signal.Value:
      # do something

If you want to start pre programmed routines or a certain statement then use the following methods of the vcExecutor objects:


Read the docu if you want more info about the arguments and all

so option is to have one program, with all the routines (not multiple programs) and than start routine which i want to be executed next.

i try this but when when i use callRoutine it executes only the first statement in that routine.

  rr = rx.Program.findRoutine('TakePanRed')
  print rr
  if rr:
	rx.callRoutine(rr, False)

If you call rx.callRoutine(rr, True) (you can leave the True out) does it still only perform one statement?

Yes, same as False. My program is KRL for Kuka robots.
Also i write sample for OnProgramFinished trigger and it never triggers.

from vcScript import *

comp = getComponent()
rx = comp.getBehaviour(‘Executor’)
print rx

def finished(ex):
print ‘finished’
rr = rx.Program.findRoutine(‘TakePanRed’)
print rr
if rr:

rx.OnProgramFinished = finished

Does only your roboter stop or the whole simulation?
Do you use the main routine? If not do you have the IsEnabled property of the executor unchecked?
Does your roboter move over the joint limit?

Only robot stops when it finish first “Main” routine. Simulation is still running. After that i want to start another routine from Main routine and program stops at the first statement and doesn’t run.
Robot doesn’t move over the joint limits.

Can you upload an example?

Hi, in this example i create a socket server.
Socket client send a name of the routine, and server then call that routine.
So basically, when client send name = “PROGRAM”, server receive that, and need to run routine “PROGRAM”.
When I run simulation, I wait for main program to finished and then send a name from the client socket.
Program then execute rx.callRoutine(rr, False) but nothing happend. Also there isn’t any error.

I also write smaller test program like this, but also after the end of the main program it doesn’t execute trigger OnProgramFinished.

I program this in Kuka Sim.

from vcScript import *

comp = getComponent()
rx = comp.getBehaviour(‘Executor’)
print rx
rou = rx.Program.findRoutine(‘PROGRAM’)
print rou

def finished(ex):
print ‘finisehd’
if rou:
rx.callRoutine(rou, False)

rx.OnProgramFinished = finished

Section_10_TrainingCell_KR6R700-2.vcmx (10.5 MB)

KUKA.Sim robot program execution is special and doesn’t necessarily support any of the VC APIs.

You could try with a normal VC robot program to check if this is a limitation with KUKA.Sim and / or the KRL programs.

Is that the reason I only get “Unknown statement”? Doesn’t work at all for me

If only the appearance of the kuka robot is necessary I would just copy the geometry and the joint offsets and paste them into a template robot with a similar amount of joints

Yes, it’s working in VC program. So probably it’s the problem with Kuka SIM. Then i can try with Kuka support, because we need to write programs in KRL.