エラー処理

プログラム例 6.1

例タイプ:
コールバック関数内の潜在的なエラー状態の処理

構成

  • ロボットの数:1
  • フィーダーの数:1
  • フィーダー上のパーツの種類数:1
  • 配置場所の数:1
  • カメラの向き:フィーダー#1上の固定下向きカメラ

解説
この例では、コールバック関数内の潜在的なエラー状態を検出して処理し、Part Feedingプロセスループ内でエラーが発生しないようにします。この例では、PF_Visionコールバックを使用して画像を取得し、パーツ座標キューにビジョン結果をロードします。ロボットには大きなツールオフセットがあります。場合によっては、ロボットが作業範囲の外になってしまうため、ツールをパーツの角度(ビジョンによって検出される)に合わせることができないことがあります。
エラー処理をしない場合、「座標変換」エラーになります。このサンプルコードは、座標をパーツ座標キューにロードする前に、ロボットがパーツをピックアップできる角度であるかどうかを確認します。これは、TargetOKステートメントで実現されます。

サンプルコード
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

プログラム例 6.2

例タイプ:
コールバック関数内処理で発生したエラーの処理

構成

  • ロボットの数:1
  • フィーダーの数:1
  • フィーダー上のパーツの種類数:1
  • 配置場所の数:1
  • カメラの向き:フィーダー#1上の固定下向きカメラ

解説
この例では、PF_Visionコールバックを使用して画像を取得し、パーツ座標キューにビジョン結果をロードします。この例では、パーツ座標キューをロードするために、最小数のピッキング可能なパーツ(この例では5個)がフィーダー上にある必要があります。3回試行してもパーツ座標キューがロードされない場合は、パーツの検索を続行するか、停止するかをオペレーターに尋ねるメッセージが表示されます。

サンプルコード
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

プログラム例 6.3

例タイプ:
PF_Statusコールバックでのステータスエラーの処理

構成

  • ロボットの数:1
  • フィーダーの数:1
  • フィーダー上のパーツの種類数:1
  • 配置場所の数:1
  • カメラの向き:フィーダー#1上の固定下向きカメラ

解説
この例では、トレイの最後のパーツが不良パーツとして検出されます。トレイには、パージゲートオプションがインストールされ、有効になっています。検出された「不良パーツ」はトレイから排出され、新しいパーツがホッパーから供給され、センタリングとフリップが実行されます。

サンプルコード
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

プログラム例 6.4

例タイプ:
PF_Statusコールバックでのユーザーエラーの処理

構成

  • ロボットの数:1
  • フィーダーの数:1
  • フィーダー上のパーツの種類数:1
  • 配置場所の数:1
  • カメラの向き:フィーダー#1上の固定下向きカメラ

解説
ロボットには、パーツが適切にピックアップされたことを検出するための、真空スイッチ付きの、真空カップグリッパーがあります。真空センサーがパーツの検出に失敗した場合、ロボットはパーツの再ピックアップを試みます。 3回失敗すると、ユーザーエラー(8000)が生成されます。
ユーザーエラーは、PF_Robotの戻り値をユーザーエラー番号に設定することにより、PF_Statusコールバックに送信されます。 PF_Statusコールバックは、オペレーターがアプリケーションを続行、または終了できるようにするメッセージボックスを表示します。

サンプルコード
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

プログラム例 6.5

例タイプ:
Part Feedingコールバック内のコントローラーエラーの処理

構成

  • ロボットの数:1
  • フィーダーの数:1
  • フィーダー上のパーツの種類数:1
  • 配置場所の数:1
  • カメラの向き:フィーダー#1上の固定下向きカメラ

解説
通常、コントローラーエラーが発生すると、Part Feedingプロセスによって定数PF_STATUS_ERRORがStatusパラメーターに自動的に設定され、PF_Statusコールバック関数が呼び出されます。これは、追加のユーザーコードなしで発生します。PF_Statusコールバック関数は、エラー番号とメッセージを出力、または表示します。PF_Statusコールバック関数が終了すると、Part Feedingプロセスは終了します。
ただし、この例では、PF_Robotコールバック関数内の、特定のコントローラーエラーを処理する必要があります。
他のすべてのコントローラーエラーは、StatusパラメーターにPF_STATUS_ERRORが設定された状態でPF_Statusコールバック関数が呼び出されます。
この場合では、グリッパーの電気配線、および空気圧配管の損傷を防止するために、U軸(スカラロボット)が+/-360°以上回転しないことが必要です。
軸4の動作範囲は、Epson RC+ のロボットマネージャーで制限されています。軸4の動作範囲を制限すると、電気配線、および空気圧配管が損傷するのを防ぐことができます。フィーダー上のパーツが、軸4をその動作範囲を超えて回転させる必要がある場合、エラー4001「アームが動作範囲の限界に達しました」が発生します。エラーハンドラーはキューからパーツを削除し、ロボットは残りのすべてのパーツのピックアップを再開します。
ビジョンシステムが同じ拒否されたパーツの画像を再取得してキューに再度追加するのを防ぐために、すべてのパーツが選択されてキューが空になった後に、PF_Flipが実行されます。

サンプルコード
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