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.
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 |

