Error processing

Program Example 6.1

Example Type:
Handling a potential error condition inside the Callback Function

Configuration

  • Number of Robots: 1
  • Number of Feeders: 1
  • Number of Parts Types on the Feeder: 1
  • Number of Placement Positions: 1
  • Camera Orientation: Fixed Downward Camera over Feeder#1

Description
This example detects and handles a potential error condition inside a callback function so that the error does not occur inside the main Part Feeding process loop. For this example, the PF_Vision callback is used to acquire an image and load the part coordinate queue with the vision results. The robot has a large tool offset. In some instances, the Tool cannot align with the part angle (determined by vision) because the robot would have to travel outside its work envelope.
If left unhandled, this condition would result in a "coordinate conversion" error. This sample code checks whether the robot can pick up the part with the Tool at the vision angle prior to loading the coordinates into the part queue. This is achieved with the TargetOK statement.

Sample Code
Main.prg

Function main
    If Motor = Off Then
        Motor On
    EndIf
    Power Low
    Jump Park
    PF_Start 1
Fend

PartFeeding.prg

Function PF_Robot(PartID As Integer) As Integer

    ' Tool 1 will be used to pick up the part
    Tool 1

    Do While PF_QueLen(PartID) > 0
        P0 = PF_QueGet(PartID)
        Jump P0
        On Gripper; Wait 0.2
        Jump Place
        Off Gripper; Wait 0.2
        PF_QueRemove PartID
        If PF_IsStopRequested(PartID) = True Then
            Exit Do
        EndIf
    Loop
    PF_Robot = PF_CALLBACK_SUCCESS

Fend

Function PF_Vision(PartID As Integer, ByRef numBack As Integer) As Integer
    Boolean found
    Integer i, numFront
    Real RB_X, RB_Y, RB_U, RB_Z

    ' Tool 1 will be used to pick up the part
    Tool 1

    ' Pick Z coordinate
    RB_Z = -132.0

    ' Initialize coordinates queue
    PF_QueRemove PartID, All
    PF_Backlight 1, On
    ' Detect the parts
    VRun UsrVisionSeq
    PF_Backlight 1, Off

    VGet UsrVisionSeq.Geom01.NumberFound, numFront	'Front Parts
    VGet UsrVisionSeq.Geom02.NumberFound, numBack	'Back Parts
    If numFront <> 0 Then
        For i = 1 To numFront
            VGet UsrVisionSeq.Geom01.RobotXYU(i), found, RB_X, RB_Y, RB_U
            If found Then
                If TargetOK(XY(RB_X, RB_Y, RB_Z, RB_U)) Then
                    PF_QueAdd PartID, XY(RB_X, RB_Y, RB_Z, RB_U)
                EndIf
            EndIf
         Next
    EndIf

    PF_Vision = PF_CALLBACK_SUCCESS

Fend

Program Example 6.2

Example Type:
Handling a process error inside the Callback Function

Configuration

  • Number of Robots: 1
  • Number of Feeders: 1
  • Number of Parts Types on the Feeder: 1
  • Number of Placement Positions: 1
  • Camera Orientation: Fixed Downward Camera over Feeder#1

Description
For this example, the PF_Vision callback is used to acquire an image and load the part coordinate queue with the vision results. In this example, a minimum number of pickable parts must be on the feeder tray to load the part queue. If the part queue is not loaded after 3 attempts, a message is displayed asking the operator whether to continue trying to find parts or Stop.

Sample Code
Main.prg

Function main
    If Motor = Off Then
        Motor On
    EndIf
    Power Low
    Jump Park
    PF_Start 1
Fend

PartFeeding.prg

Function PF_Robot(PartID As Integer) As Integer

    ' Tool 1 will be used to pick up the part
    Tool 1

    Do While PF_QueLen(PartID) > 0
        P0 = PF_QueGet(PartID)
        Jump P0
        On Gripper; Wait 0.2
        Jump Place
        Off Gripper; Wait 0.2
        PF_QueRemove PartID
        If PF_IsStopRequested(PartID) = True Then
            Exit Do
        EndIf
    Loop
    PF_Robot = PF_CALLBACK_SUCCESS

Fend

Function PF_Vision(PartID As Integer, ByRef numBack As Integer) As Integer
    Boolean found
    Integer i, numFront
    Real RB_X, RB_Y, RB_U, RB_Z
    Integer RetryCount
    String msg$
    Integer mFlags, answer

    ' Pick Z coordinate
    RB_Z = -132.0

    ' Initialize coordinates queue
    PF_QueRemove PartID, All
    RetryCount=0

    Do
        PF_Backlight 1, On
        ' Detect the parts
        VRun UsrVisionSeq
        PF_Backlight 1, Off

        VGet UsrVisionSeq.Geom01.NumberFound, numFront	'Front Parts
        VGet UsrVisionSeq.Geom02.NumberFound, numBack	'Back Parts
        If numFront >= 5 Then 'Min number of parts = 5 for this example
            For i = 1 To numFront
                VGet UsrVisionSeq.Geom01.RobotXYU(i), found, RB_X, RB_Y, RB_U
                If found Then
                    PF_QueAdd PartID, XY(RB_X, RB_Y, RB_Z, RB_U)
                EndIf
            Next
            Exit Do
        Else
            If RetryCount < 3 Then
                PF_Center 1, PF_CENTER_LONG_AXIS
                PF_Center 1, PF_CENTER_SHORT_AXIS
                PF_Flip 1, 500
                RetryCount = RetryCount + 1
             Else
                msg$ = PF_Name$(PartID) + CRLF + CRLF
                msg$ = msg$ + "Min Number of Parts Cannot be Loaded." + CRLF
                msg$ = msg$ + "Do you want to Continue trying?"
                mFlags = MB_YESNO + MB_ICONQUESTION
                MsgBox msg$, mFlags, "Minimum Number Parts", answer
                If answer = IDNO Then
                    PF_Stop(PartID)
                    Exit Do
                Else
                    RetryCount=0
                EndIf
            EndIf
        EndIf
    Loop

    PF_Vision = PF_CALLBACK_SUCCESS

Fend

Program Example 6.3

Example Type:
Handling a Status Error in the PF_Status Callback

Configuration

  • Number of Robots: 1
  • Number of Feeders: 1
  • Number of Parts Types on the Feeder: 1
  • Number of Placement Positions: 1
  • Camera Orientation: Fixed Downward Camera over Feeder#1

Description
For this example, the last part in the tray is detected as a wrong part. The tray has the Purge Gate option installed and enabled. The detected "wrong part" will be Purged from the tray, new parts will be fed from the hopper and the parts will be centered & flipped.

Sample Code
PartFeeding.prg

Function PF_Status(PartID As Integer, Status As Integer) As Integer

    Select Status

        ' Other Status Cases have been removed from this sample code for simplicity

        Case PF_STATUS_WRONGPART
            ' There may be a wrong part on the feeder platform.
            ' Purge Part 1 without vision feedback. Purge duration is default.
            ' The Purge Gate automatically opens and closes
            PF_Purge 1, PF_PURGETYPE_NOVISION
            ' Turn on the hopper for 3 sec
            PF_OutputOnOff 1, On, 1, 3000
            Wait 3.0
            PF_Center 1, PF_CENTER_LONG_AXIS
            PF_Center 1, PF_CENTER_SHORT_AXIS
            PF_Flip 1, 500

        ' Other Status Cases have been removed from this sample code for simplicity

     Send

    PF_Status = PF_CONTINUE
Fend

Program Example 6.4

Example Type:
Handling a User Error inside the PF_Status Callback

Configuration

  • Number of Robots: 1
  • Number of Feeders: 1
  • Number of Parts Types on the Feeder: 1
  • Number of Placement Positions: 1
  • Camera Orientation: Fixed Downward Camera over Feeder#1

Description
The robot has a vacuum cup gripper with a vacuum switch to detect that the part has been properly picked up. If the vacuum sensor fails to detect the part, the robot will attempt to re-pick the part. After 3 unsuccessful attempts, a User Error (8000) is generated.
The User Error is sent to the PF_Status callback by setting the PF_Robot return value to the User Error number. The PF_Status call back displays a message box allowing the operator to Continue or Exit the application.

Sample Code
Main.prg

Function main
    If Motor = Off Then
        Motor On
    EndIf
    Power Low
    Jump Park
    PF_Start 1
Fend

PartFeeding.prg

Function PF_Robot(PartID As Integer) As Integer

    Integer PickRetryCount	' Pick Retry Count

    Do While PF_QueLen(PartID) > 0

        ' Get position of part to be picked
        P10 = PF_QueGet(PartID)

        PickRetryCount = 0
        Do
            Jump P10
            On Vacuum
            Wait Sw(VacOn), 0.5 ' 0.5 second timeout on
            Vacuum switch
            If TW = False Then	' Vacuum successful
                Exit Do ' Exit Do Loop and place the part
            EndIf
            Off Vacuum
            PickRetryCount = PickRetryCount + 1 ' Increment retry count
            If PickRetryCount = 3 Then
                ' Vacuum retries were not successful
                Jump Park
                PF_QueRemove PartID
                PF_Robot = 8000 ' Set the return value to user
                Error 8000
                ' PF_Status callback will be called with status value 8000
                 Exit Function
             EndIf
         Loop

        ' Part detected in vacuum gripper
        Jump Place
        Off Vacuum
        Wait 0.25

        ' Deque
        PF_QueRemove PartID

        'Check Cycle stop
        If PF_IsStopRequested(PartID) = True Then
            Exit Do
        EndIf

     Loop

    PF_Robot = PF_CALLBACK_SUCCESS

Fend

Function PF_Status(PartID As Integer, Status As Integer) As Integer
    String msg$
    Integer mFlags, answer

    Select Status
        ' Other Status Cases have been removed from this sample code for simplicity

        Case 8000 ' User Error 8000 occured.

            msg$ = PF_Name$(PartID) + CRLF + CRLF
            msg$ = msg$ + "Vacuum Pick error has occurred." + CRLF
            msg$ = msg$ + "Do you want to Continue?"
            mFlags = MB_YESNO + MB_ICONQUESTION
            MsgBox msg$, mFlags, "Vacuum Pick Error", answer
            If answer = IDNO Then
                PF_Status = PF_EXIT
            Else
                PF_Status = PF_CONTINUE
            EndIf

            Exit Function
    Send

Fend

Program Example 6.5

Example Type:
Handling a Controller Error inside a Part Feeding Callback

Configuration

  • Number of Robots: 1
  • Number of Feeders: 1
  • Number of Parts Types on the Feeder: 1
  • Number of Placement Positions: 1
  • Camera Orientation: Fixed Downward Camera over Feeder#1

Description
Normally when a controller error occurs, the Part Feeding Process automatically sets the constant PFSTATUSERROR to the Status parameter and the PF_Status function will be called. This happens without any additional user code. PF_Status typically prints or displays the error number and message. The Part Feeding process will terminate once the PF_Status function ends.
In this example, however, we want to handle a specific controller error inside the PF_Robot callback.
All other controller errors will be sent to the PF_Status callback with the Status parameter set to PFSTATUSERROR.
In this case, the gripper’s electrical and pneumatic lines prevent the U axis (SCARA robot) from rotating the full +/-360 degrees.
The Joint 4 motion range has been limited inside the Epson RC+ Robot Manager. Limiting the Joint 4 motion range prevents the electrical and pneumatic lines from being damaged. If a part on the feeder would require Joint 4 to rotate beyond its motion range, an Error 4001 "Arm reached the limit of motion range" will occur. The error handler removes the part from the queue and the robot will resume picking up all the remaining parts.
To prevent the vision system from re-acquiring an image of the same rejected parts and re-adding them to the queue, a PF_Flip is executed after all parts have been picked and the queue is empty.

Sample Code
Main.prg

Function main
    If Motor = Off Then
        Motor On
    EndIf
    Power Low
    Jump Park
    PF_Start 1
Fend

PartFeeding.prg

Function PF_Robot(PartID As Integer) As Integer
    Integer errNum

    OnErr GoTo ehandle	' Error Handler

retry:
    Do While PF_QueLen(PartID) > 0

        ' Get position of part to be picked
        P10 = PF_QueGet(PartID)

        'Error 4001 can occur if the part's angle
        ' causes Joint 4 to rotate beyond its motion range
        Jump P10

        On Gripper
        Wait 0.25
        Jump Place
        Off Gripper
        Wait 0.25

        'Deque
        PF_QueRemove PartID

        'Check Cycle stop
        If PF_IsStopRequested(PartID) = True Then
            Exit Do
        EndIf

    Loop

    PF_Flip PartID

    PF_Robot = PF_CALLBACK_SUCCESS
    Exit Function

ehandle:

    errNum = Err
    If errNum = 4001 Then ' Example of Handled error
        Print "Error 4001: Arm reached the limit of motion range"
        PF_QueRemove PartID ' Remove the part from the queue
        EResume retry ' Continue picking the remaining parts in the queue
    Else
        ' Other unhandled errors
        ' PF_Status is called with the PF_STATUS_ERROR status parameter
        PF_Robot = PF_STATUS_ERROR
    EndIf
Fend

Function PF_Status(PartID As Integer, Status As Integer) As Integer

    Select Status

        ' Other Status Cases have been removed from this sample code for simplicity

        Case PF_STATUS_ERROR ' Error.
            msg$ = PF_Name$(PartID) + CRLF
            msg$ = msg$ + "Error!! (code: " + Str$(Err) + " ) " + ErrMsg$(Err)
            MsgBox msg$, MB_ICONSTOP

        ' Other Status Cases have been removed from this sample code for simplicity

     Send

    If Status = PF_STATUS_ERROR Then
        ' A controller error occurred. Terminate the Part Feeding Process.
        PF_Status = PF_EXIT
    Else
        ' Otherwise Continue running the Part Feeding Process.
        PF_Status = PF_CONTINUE
    EndIf

Fend