SCARA, 6-Axis and Modules
Technical Support Notes

Article ID: T39
Date: 6/17/99
Product: SPEL for Windows (all versions)
OS: Windows 3.11, Windows 95, Windows 98, Windows NT 4.0
Problem: How to calculate tool offsets with U axis at any angle

Here is a method to calculate tool offsets without having to start with the U axis at 0 degrees, as described in the Vision Guide manual.

Here are the basic steps. See the code examples below for details.
    1. Set the current tool to 0.
    2. Teach point 1 using the gripper and record x1, y1, u1
    3. Rotate 180 degrees.
    4. Teach point 2 using the gripper and record x2, y2
    5. Call the CalcTool routine:
        CalcTool x1, y1, u1, x2, y2, xTool, yTool.
        xTool and yTool contain the tool offsets
    6. Define the tool:
        In SPEL: TlSet 1, xTool, yTool, 0, 0
        In VB: SPELCom1.TlSet 1, xTool, yTool, 0, 0

Here are two code examples for SPEL and Visual Basic. The CalcTool routines do the actual tool calculations.



SPEL Code Example

Function MakeTool
    String msg$, title$
    Integer msgFlags
    Integer answer, toolOK
    Real x1, y1, u1, x2, y2, xTool, yTool

    SelRB 1
    toolOK=FALSE
    title$="Make Tool"
    msgFlags=MB_OKCANCEL
    Tool 0
    SFree 1, 2, 3
    msg$="Move gripper into fixture, click OK when done"
    Call ShowMsg
    If answer=IDCANCEL Then End
    x1=CX(P*)
    y1=CY(P*)
    u1=CU(P*)
    msg$="Ready to move U axis 180 degrees"
    Call ShowMsg
    If answer=IDCANCEL Then End
    SLock
    Jump P* +U180
    SFree 1, 2, 3
    msg$="Move gripper into fixture, click OK when done"
    Call ShowMsg
    If answer=IDCANCEL Then End
    x2=CX(P*)
    y2=CY(P*)
    Call CalcTool
    TlSet 1, xTool, yTool, 0, 0
    SLock
    Jump P* :Z0
    toolOK=TRUE
Fend


Function CalcTool
    #define PI 3.14159

    Real x, y
    Real toolRad
    Real theta

    x=(x2 - x1) / 2
    y=(y2 - y1) / 2

    toolRad=Sqr(x * x + y * y)

    theta=Atan2(x, y)
    theta=theta - (u1 * PI / 180)

    xTool=Cos(theta) * toolRad
    yTool=Sin(theta) * toolRad
Fend


Function ShowMsg
    MsgBox msg$, msgFlags, title$, answer
Fend




VB Guide Code Example

Function MakeTool() As Boolean

    Dim msg As String, title As String
    Dim x1 As Single, y1 As Single, u1 As Single
    Dim x2 As Single, y2 As Single
    Dim xTool As Single, yTool As Single

    title="Make Tool"
    With frmMain.SPELCom1
        .Tool 0
        .SFree 1, 2, 3

        msg="Move gripper into fixture, click OK when done"
        If ShowMsg(msg, title)=vbCancel Then
            Exit Function
        End If

        x1=.CX("P*")
        y1=.CY("P*")
        u1=.CU("P*")

        msg="Ready to move U axis 180 degrees"
        If ShowMsg(msg, title)=vbCancel Then
            Exit Function
        End If

        .SLock
        .Jump "P* +U180"
        .SFree 1, 2, 3

        msg="Move gripper into fixture, click OK when done"
        If ShowMsg(msg, title)=vbCancel Then
            Exit Function
        End If

        x2=.CX("P*")
        y2=.CY("P*")
        CalcTool x1, y1, u1, x2, y2, xTool, yTool

        .TlSet 1, xTool, yTool, 0, 0
        .SLock
        .Jump "P* :Z0"
    End With

    MakeTool=True
End Function


Sub CalcTool(x1 As Single, y1 As Single, u1 As Single, _
    x2 As Single, y2 As Single, xTool As Single, yTool As Single)

    Const PI=3.14159

    Dim x As Single, y As Single
    Dim toolRadius As Single
    Dim theta As Single

    x=(x2 - x1) / 2#
    y=(y2 - y1) / 2#

    toolRadius=(x ^ 2 + y ^ 2) ^ 0.5

    theta=frmMain.SPELCom1.Atan2(x, y)
    theta=theta - (u1 * PI / 180)

    xTool=Cos(theta) * toolRadius
    yTool=Sin(theta) * toolRadius
End Sub



Function ShowMsg(msg As String, title As String) As Integer

    ShowMsg=MsgBox(msg, vbOkCancel, title)
End Function




Click here to return to the EPSON Robots home page
The Power of Choice!