Need help with Python

 

Hello I’m new to python and I’m trying to make the robot to pick a part from a pallet on the ground and then place it on another part that’s on a conveyor while its moving . I’m doing it wrong I guess………….can someone help me with that?
That’s the code I’m using:

from vcScript import *
from vcHelpers.Robot2 import*
import vcMatrix
app = getApplication()
comp = getComponent()
path = comp.findBehaviour(“OneWayPath”)
#now get robot
part = app.findComponent(“Parts”)
robot_comp = app.findComponent(“KR 120 R3500 prime K”)
robot = getRobot(robot_comp)
def OnRun():
while app.Simulation.IsRunning
if path.ComponentCount > 0:
if robot.GraspContainer.ComponentCount == 0:
pallet = app.findComponent(“Euro Pallet”)
robot.pick(part)
robot.pickFromPallet(pallet)
else:
mtx = vcMatrix.new()
mtx.translateRel(0,0,200)
mtx.rotateRelY(180)
robot.linearMovetoMtx_ExternalBase(pallet,mtx)
conveyor = app.findComponent(“Conveyor”)
robot.place(conveyor)
break

When you want to post code on forum, click Visual tab, and then click <> to display a widget for pasting code that is formatted correctly. Python depends on indentation, so edit or submit your post again.

Also, indicate what step in the process is giving you an error. Are you able to pick the part? Are you able to place the part on a pallet? Are you able to place the part on a conveyor? Are you able to place the part on another part that is on the conveyor?

From your code, I don’t see any instruction that indicates the robot should place something on another part.

Are you trying to do this tutorial?

http://academy.visualcomponents.com/lessons/place-parts-on-moving-objects/?course=136

from vcScript import *
from vcHelpers.Robot2 import*
import vcMatrix
app = getApplication()
comp = getComponent()
path = comp.findBehaviour(“OneWayPath”)
#now get robot
part = app.findComponent(“Parts”)
robot_comp = app.findComponent(“KR 120 R3500 prime K”)
robot = getRobot(robot_comp)
def OnRun():
while app.Simulation.IsRunning
if path.ComponentCount > 0:
if robot.GraspContainer.ComponentCount == 0:
pallet = app.findComponent(“Euro Pallet”)
robot.pick(part)
robot.pickFromPallet(pallet)
else:
mtx = vcMatrix.new()
mtx.translateRel(0,0,5)
mtx.rotateRelY(180)
robot.linearMovetoMtx_ExternalBase(pallet,mtx)
conveyor = app.findComponent(“Conveyor”)
robot.place(conveyor)
break

Yes. I tried this tutorial and I’m trying to figure it out
I want to pick a part from a pallet that’s near the robot and then place it on a part that’s coming out from the feeder on the conveyor.

To give you a better idea of the simulation I’m trying to do I’m going to explain it (its very simple but still hard for me :frowning: )

The robot picks a part from a pallet that’s near him then place it on a moving part (folding box) on the conveyor and that’s the whole process that’s going to loop over and over again. (simple production line)