Sample Program

Vision conveyor programming

Typically, two tasks are used to operate a vision conveyor.

One task finds parts with the vision system and adds them to the conveyor queue.

The other task checks for parts in the Pickup Area of the conveyor queue. When a part is in the Pickup Area, the robot is commanded to pick up the part and place it to the specified position.

The following example is a sample program that uses Xqt to execute two tasks from the "main" function.

  • First task: "ScanConveyorStrobed" function
  • Second task: "PickParts" function

A corresponding program is shown below.

Wiring Example of Vision Conveyor Tracking System

This sample program is a hardware trigger structure that uses controller I/O to trigger the camera and latch the encoder.

The following program is a sample with Conveyor #1.

This sample program automatically recovers when the robot tracks the workpiece that is out of the Pickup Area.

Function main
  Motor On
  Power High

  Speed 30
  Accel 30, 30

  Xqt ScanConveyorStrobed  'Task that registers queues
  Xqt PickParts            'Task that tracks parts (queue)
Fend

Function ScanConveyorStrobed
  Integer i, numFound, state, trigger
  Real x, y, u
  Boolean found
  trigger = 10             'Allocates pin10 of controller I/O
  Off trigger              'Turns OFF the camera trigger and encoder latch I/O
  Do
    VRun FindParts         'Searches for parts on the conveyor
    On trigger             'Turns ON the camera trigger and encoder latch I/O
    Do
      VGet FindParts.AcquireState, state
    Loop Until state = 3
    VGet FindParts.Parts.NumberFound, numFound
    'Registers the part that has been shot as a queue
    For i = 1 to numFound
      VGet FindParts.Parts.CameraXYU(i), found, x, y, u
      Cnv_QueAdd 1, Cnv_Point(1, x, y)
    Next i
    Off trigger            'Turns OFF the camera trigger and encoder latch I/O
    Wait 0.1
  Loop
Fend

Function PickParts
  OnErr GoTo ErrHandler
  Integer ErrNum
  Cnv_Mode 1,1             'Selects the tracking mode
  WaitParts:
  Do
    'Waits until a part (queue) enters the Pickup Area
    Wait Cnv_QueLen(1, CNV_QUELEN_PICKUPAREA) > 0
    'Starts tracking the part
    'When using the SCARA robot
    Jump Cnv_QueGet(1)
    Wait 0.1               'The robot moves at the same speed as the conveyor for the Wait time specified to this part
    Jump P1                'Moves the picked part to a specified place
    Cnv_QueRemove 1, 0           'Clears the picked part (queue)
  Loop
  'Clears the parts (queue) in the downstream side from the Pickup Area
  'Automatically recovers from the error '"The specified queue data is outside the set area"
  ErrHandler:
    ErrNum = Err
    If ErrNum = 4406 Then
      Cnv_QueRemove 1, 0
      EResume WaitParts
'Displays an error other than "The specified queue data is outside the set area"
    Else
      Print "Error!"
      Print "No.", Err, ":", ErrMsg$(Err, 1)
      Print "Line :", Erl(0)
      'User error occurred
      Error 8000
    EndIf
Fend

KEY POINTS


When you use software trigger, use the "ScanConveyorStrobed" function shown below.

Function ScanConveyorNonStrobed
  Integer i, numFound
  Real x, y, u
  Boolean found
  Do
    'Searches for parts on the conveyor
    VRun FindParts
    Cnv_Trigger 1          'Latches the encoder with software trigger
    VGet FindParts.Parts.NumberFound, numFound
    'Registers the part as a queue
    For i = 1 to numFound
      VGet FindParts.Parts.CameraXYU(i), found, x, y, u
      Cnv_QueAdd 1, Cnv_Point(1, x, y)
    Next i
    Wait 0.1
  Loop
Fend

Sensor conveyor programming

Typically, two tasks are used to operate a sensor conveyor. One task waits for a part to trip the sensor and add it to the conveyor queue. The other task checks for parts in the Pickup Area of the conveyor queue. When a part is in the Pickup Area, the robot is commanded to pick up the part and place it to the specified position.

This sample program automatically recovers when the robot tracks the workpiece that is out of the Pickup Area.

Function main
  Motor On
  Power High

  Speed 30
  Accel 30, 30

  Xqt ScanConveyor               'Task that registers queues
  Xqt PickParts                  'Task that tracks parts (queue)
Fend

Function ScanConveyor
  Double lpulse1                 'Previous latch pulse
    lpulse1 = Cnv_LPulse(1)      'Registers the latch pulse as lpulse1
    Do
      'Registers a part as a queue only when it passes the sensor
      If lpulse1 <> Cnv_LPulse(1) Then
        Cnv_QueAdd 1, Cnv_Point(1, 0, 0)
        lpulse1 = Cnv_LPulse(1)   'Updates lpulse1
      EndIf
    Loop
Fend

Function PickParts
  OnErr GoTo ErrHandler
  Integer ErrNum
  Cnv_Mode 1,1             'Selects the tracking mode
  WaitParts:
  Do
    'Waits until a part (queue) enters the Pickup Area
    Wait Cnv_QueLen(1, CNV_QUELEN_PICKUPAREA) > 0
    'Starts tracking the part
    'When using the SCARA robot
    Jump Cnv_QueGet(1)
    Wait 0.1                     'The robot moves at the same speed as the conveyor for the Wait time specified to this part
    Jump P1                      'Moves the picked part to a specified place
    Cnv_QueRemove 1, 0           'Clears the picked part (queue)
  Loop
  'Clears the parts (queue) in the downstream side from the Pickup Area
  'Automatically recovers from the error '"The specified queue data is outside the set area"
  ErrHandler:
    ErrNum = Err
    If ErrNum = 4406 Then
      Cnv_QueRemove 1, 0
      EResume WaitParts
'Displays an error other than "The specified queue data is outside the set area"
    Else
      Print "Error!"
      Print "No.", Err, ":", ErrMsg$(Err, 1)
      Print "Line :", Erl(0)
      'User error occurred
      Error 8000
    EndIf
Fend