Simulation crashing repeatedly

Hello,

I am having trouble simulating a robot routine beacuse one out of every two times the software crashes when I press “Play”. When I open the software again the following message is printed in the Output panel:

Traceback (most recent call last):
    File "conveyor::PythonScript_2", line 17, in <module>
    File "C:\Program Files\KUKA\KUKA Sim Pro 3.0\Python\Commands\vcHelpers\Robot2.py", line 973, in getRobot
      return vcRobot2(roboComp, controller, executor, graspContainer, signalMapIn, signalMapOut)
    File "C:\Program Files\KUKA\KUKA Sim Pro 3.0\Python\Commands\vcHelpers\Robot2.py", line 73, in __init__
      self.Program = executor.Program
    File "C:\Program Files\KUKA\KUKA Sim Pro 3.0\Python\Commands\vcHelpers\Robot2.py", line 31, in __setattr__
      if name == 'Speed':
  ReferenceError: Executor does not have a program associated.
I am using the KUKA version of Visual Components but the software is essentialy the same.

The application I am trying to reproduce is very similar to the “Place parts on moving objects” lesson (http://academy.visualcomponents.com/lessons/place-parts-on-moving-objects/) so I don’t know where I might be going wrong.

Also here is the python script running on a conveyor which receives components from a feeder and these are supposed to be marked by a robot:

from vcScript import *
from vcHelpers.Robot2 import *
import vcMatrix

robot_name = "KR 10 R1100 sixx"

x_dots = 3
y_dots = 3
d_dots = 50

x_offset = x_dots%2
y_offset = y_dots%2

app = getApplication()          
comp = getComponent()           
path = comp.findBehaviour("OneWayPath")   
robot = getRobot(app.findComponent(robot_name))   

def OnRun():
    while app.Simulation.IsRunning:     
      if path.ComponentCount > 0:       
        part = path.Components[0]       
        robot.ActiveTool = 'Marking_tool'   
        mtx_dots = vcMatrix.new()            
        mtx_dots.rotateRelZ(-90)
        mtx_dots.translateRel(-10)
        mtx_loop = vcMatrix.new()
        mtx_loop2 = vcMatrix.new()
        mtx_loop = mtx_dots
        for i in range(0,x_dots):            
          mtx_loop.translateRel((i-x_offset)*d_dots,0,0)        
          for j in range(0,y_dots):
            mtx_loop = mtx_dots
            mtx_loop.translateRel(0,(j-y_offset)*d_dots,0)        
            robot.linearMoveToMtx_ExternalBase(part,mtx_loop)    
          mtx_loop = mtx_dots
          delay(0.5)
        delay(5)

Thank you

simulacion_marcado.vcmx (1.01 MB)

Hello Agustin,

Please check the changes in the following script. I will advice you to add the variables to the OnRun or OnStart method.

Use while True as a condition, as OnRun method is only executed while the simulation is running.

from vcScript import *
from vcHelpers.Robot2 import *
import vcMatrix



def OnRun():
    robot_name = "KR 10 R1100 sixx"
    x_dots = 3
    y_dots = 3
    d_dots = 50

    x_offset = x_dots%2
    y_offset = y_dots%2

    app = getApplication()          
    comp = getComponent()           
    path = comp.findBehaviour("OneWayPath")   
    robot = getRobot(app.findComponent(robot_name))
    while True:     
      if path.ComponentCount > 0:       
        part = path.Components[0]       
        robot.ActiveTool = 'Marking_tool'   
        mtx_dots = vcMatrix.new()            
        mtx_dots.rotateRelZ(-90)
        mtx_dots.translateRel(-10)
        mtx_loop = vcMatrix.new()
        mtx_loop2 = vcMatrix.new()
        mtx_loop = mtx_dots
        for i in range(0,x_dots):            
          mtx_loop.translateRel((i-x_offset)*d_dots,0,0)        
          for j in range(0,y_dots):
            mtx_loop = mtx_dots
            mtx_loop.translateRel(0,(j-y_offset)*d_dots,0)        
            robot.linearMoveToMtx_ExternalBase(part,mtx_loop)    
          mtx_loop = mtx_dots
          delay(0.5)
        delay(5)

 

t