Sample Conveyor Tracking with Vision Program

The following is a sample GPL conveyor-tracking program that employs vision to locate parts.  It assumes that parts come down the conveyor and pass below an upstream camera.  When each part is in range, this program will move the robot from a safe position, through an approach position, to a position just above the part.  The system will dwell for 1 second and track the part on the moving conveyor.  The robot will then return to the safe location until the next part is detected.

This sample program includes the manual teaching of all positions and a continuous loop that automatically tracks parts that come down the conveyor.  If required, the accuracy of the part position can be improved by latching the belt encoder value based up a hardware trigger signal generated by the camera.

To execute this procedure, perform the following steps.

  1. Ensure that you have performed all of the conveyor setup that has been described in the previous sections and that Robot #2 has been configured as a conveyor robot module.  If the robot number is different, edit the CNV_ROB constant in the program.
  2. AFTER THE CONVEYOR IS SETUP, execute the PreciseVision camera calibration procedure to determine the camera to conveyor belt relationship.
  3. Create a PreciseVision process called "Main" that returns the location of a part in a tool named "part1".
  4. Stop the conveyor belt and clear the conveyor of all parts.
  5. Load the following GPL program into your controller and begin its execution.
  6. Start the conveyor and place a part upstream of the camera.  When the part passes the camera and comes into the range where the robot can reach it, stop the conveyor.
  7. Position the robot's tool just above the part and press the "Teach" button on the pop-up displayed by the sample application.
  8. Move the robot to a safe position that is above the conveyor.  Ensure that the robot is in computer mode with power on.
  9. Press the "Go" button on the next pop-up when you are ready to track sample parts.
  10. Start the conveyor and feed parts.  The sample program will track each part that comes down the conveyor.

The following is the complete sample program.  No global data need to be defined for this program.

Public Sub MAIN
Dim belt1 As New RefFrame
Dim
vsRefFrame As New RefFrame
Dim
loc1 As New Location
Dim
vsLoc As New Location
Dim
safe As New Location
Dim
pf1 As New Profile
Dim
encoder_offset As Double
Dim
msg As String
Dim
btn_idx As Integer

Const CNV_ROB As Integer = 2 ' Robot #2 is the conveyor

belt1.Type = 2 ' Conveyor reference frame
belt1.ConveyorRobot = CNV_ROB ' This is the conveyor robot
vsRefFrame.Loc.RefFrame = belt1 ' Vision image relative to belt
loc1.RefFrame = vsRefFrame ' loc1 is relative to vision/belt
loc1.ZClearance = 25.4

pf1.Speed = 20 ' Move slow
pf1.Straight = True ' Must be Cartesian motion

' Take pictures until we find a part.

msg = "Place a part upstream of the camera, press the Take_Pictures "
msg &= "button, and start the conveyor to move the part into the "
msg &= "camera's field of view."
Controller.Showdialog("Take_Pictures", msg, btn_idx)

GetPart(CNV_ROB, vsLoc, encoder_offset) ' Run vision to find part
vsRefFrame.Loc.PosWrtRef = vsLoc.Pos ' Set part location
belt1.ConveyorOffset = encoder_offset ' and offset when picture taken

msg = "Stop the conveyor when the part is in range of the "
msg &= "robot. Position robot over the part and press Teach."
Controller.Showdialog("Teach", msg, btn_idx)
loc1.Here ' Record vision/belt rel position

' Automatically track a series of parts on the conveyor.

msg = "Move robot to a safe position. Send parts down the "
msg &= "conveyor and press Go to momentarily track each part."
Controller.Showdialog("Go", msg, btn_idx)

Robot.Attached = 1
safe.Here ' Record safe location

While True
GetPart(CNV_ROB, vsLoc, encoder_offset) ' Run vision to find part
vsRefFrame.Loc.PosWrtRef = vsLoc.Pos ' Set part location
belt1.ConveyorOffset = encoder_offset ' and encoder offset

Move.Approach(loc1,pf1) ' Go touch the part
Move.Loc(loc1,pf1)

Move.Delay(1) ' Demonstrate tracking

Move.Approach(loc1,pf1) ' Back to safe position
Move.Loc(safe,pf1)
End While

End Sub

' Continuously take pictures and save belt encoder until part found

Public Sub
GetPart(CnvRob As Integer, ByRef vsLoc As Location, _
ByRef EncoderOffset As Double)
Dim cnt As Integer
Dim
vis As New Vision
Dim
vResult As New VisResult

Do

EncoderOffset = Robot.WhereAngles(CnvRob).Angle(1)
' Save current belt position
vis.Process("Main") ' Run vision process "Main"
cnt = vis.ResultCount("part1") ' Found a part?
If (cnt = 0) Then
Thread.Sleep
(30) ' No, sleep and try again
End If
Loop While
(cnt = 0)

vResult = vis.Result("part1", 1) ' Get results
vsLoc = vResult.Loc ' Return part location

End Sub