Tool changer

Hi,

I have a machine in VC that needs to pick and sort products from a plate to pallets. The geometry of the products are random so I created 2 grippers (one small and one large gripper). At the moment i have just one of the grippers placed on the mount plate. But I would like to make a Python script for automatically changing the tools on the mount plate. Is this possible?

Screenshot of the machine:

The 2 blue tables you see are the positioning bases for placing the grippers if they are not used.

Can someone help me? It would be highly appreciated!

Louis

If you need to, you can just add the action script for the component (in the wizard) and then use any of OUT[33]-OUT[48] on the program page for quick-change jaws to tool coordinates.
If Python is your hard requirement, you can also add a component container directly at the end of the right-angle robot, using ComponentContainer.grab (gripper/part) at the appropriate time in python.

Hi BAD,

Is it possible to visualize a toolchange like it would happen in the real world (robot detaches small gripper → moves to the large gripper and attaches it)?

Highly recommend to use vcHelpers.Robot2, syntax is intuitive and script is flexible to configure
https://help.visualcomponents.com/4.10/Premium/en/Python_API/vcHelpers.Robot2.htm

vcHelpers.Robot2

from vcScript import *
from vcHelpers.Robot2 import *

app = getApplication()
comp = getComponent()

def OnRun():
  gripper1 = app.findComponent("Single-Cup Vacuum Gripper")
  target1 = app.findComponent("Cylinder Geo")
  gripper2 = app.findComponent("Parametric Suction Cup Gripper")
  target2 = app.findComponent("Block Geo")
  table = app.findComponent("Table A")
  
  robot = getRobot(comp)
  
  robot.jointMoveToComponent(gripper1, OnFace = "bottom", Rz = 180.0)  
  robot.mountTool(gripper1)
  robot.ActiveTool = 17
  robot.pick(target1)
  robot.linearMoveRel(Tx = -500.0)
  robot.linearMoveRel(Tz = 200.0)
  robot.releaseComponent(table)  
  robot.moveAway()
  robot.unmountTool(gripper1, table)
  robot.ActiveTool = 0
  
  robot.jointMoveToComponent(gripper2, OnFace = "bottom", Rz = 180.0)   
  robot.mountTool(gripper2)
  robot.ActiveTool = 17
  robot.pick(target2)
  robot.linearMoveRel(Tx = -500.0)
  robot.linearMoveRel(Tz = 200.0)  
  robot.releaseComponent(table)    
  robot.moveAway()
  robot.unmountTool(gripper2, table)
  robot.ActiveTool = 0
  
  robot.moveAway()
2 Likes

idkfa is talking about a python script solution, in fact there are many ways to do this thing, the easiest and simplest is to use the bot’s own action scripts to achieve this, check the tutorial below.

Hey Bad, thanks for the info. This is a easy way to mount the tool. I have incorporated it into a python script which moves the mountplate to the gripper, and then activates the output (OUT34). This worked, but after a few tries and debugging VC crashed. Now my code doesn’t work anymore. The robot moves to the gripper, sets the output on True but it doesn’t mount the gripper to the mountplate.

Any idea what the problem is?

My debug code:


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

comp = getComponent()
controller = comp.getBehaviour('RobotController')
executor = comp.getBehaviour('Executor')
app = getApplication()
sim = getSimulation()

def goToTarget(x, y, z, base="main_base", tool=None):
    #print("🔄 Bewegen naar: X=%.1f Y=%.1f Z=%.1f | Base: %s | Tool: %s" % (x, y, z, base, tool))

    # Check geldige base
    base_names = [b.Name for b in controller.Bases]
    if base not in base_names:
        print("❌ Ongeldige base:", base)
        return

    # Check geldige tool
    tool_names = [t.Name for t in controller.Tools]
    if tool and tool not in tool_names:
        print("❌ Ongeldige tool:", tool)
        return

    m = vcMatrix.new()
    m.translateRel(x, y, z)
    m.setWPR(180, 0, 0)

    motionTarget = controller.createTarget()
    motionTarget.TargetMode = VC_MOTIONTARGET_TM_NORMAL
    motionTarget.BaseName = base
    motionTarget.MotionType = VC_MOTIONTARGET_MT_LINEAR
    motionTarget.RobotConfig = 0
    motionTarget.Target = m

    if tool:
        motionTarget.ToolName = tool

    try:
        controller.moveTo(motionTarget)
    except Exception as e:
        print("❌ Beweging mislukt:", e)

def OnRun():
  #sim.reset()
  
  robot = getRobot(comp)

  print("Tools:", [t.Name for t in controller.Tools])
  print("Bases:", [b.Name for b in controller.Bases])
    

  for i, tool in enumerate(robot.Tools):
    if tool.Name == "Tool1":
        robot.ActiveTool = i
        break

  tool = robot.ActiveTool
  tools = robot.Tools
  print tools[tool].Name
  for i in range(33, 49):
      executor.setOutput(i, False)

  goToTarget(977.461,-411.685, 828.483, base="main_base", tool="Tool1")
  executor.setOutput(35, True)
  for i, tool in enumerate(robot.Tools):
    if tool.Name == "Tool3":
        robot.ActiveTool = i
        break
  tool = robot.ActiveTool
  delay(1.0)
  goToTarget(1278.557, 365.182, 0, base="grasp_base", tool="Tool3")

  goToTarget(2484.207, -417.062, 979.1, base="main_base", tool="Tool3")
  executor.setOutput(1, True)
  goToTarget(2484.207, -417.062, 1050, base="main_base", tool="Tool3")

def OnReset():
    return

type or paste code here

I’m already on off hours so I can’t use VC to provide you with help, however, my suggestion is that if there is an error message, sending the error message along with it can be a better way to get help.
However, I’ve had a brief look at your code and you’re using absolute values, and “executor.setOutput(1, True)”, I’m not quite sure if this has anything to do with the bot crawl range setting, but I’d suggest that you could check.
I’m sorry that my reply wasn’t always helpful, I hope you find the right solution to your problem and have a nice weekend.