下面是AC标准五轴的VB计算程序
PS()是数组。
ps(2)=X
ps(3)=Y
ps(4)=Z
ps(5)=I
ps(6)=J
ps(7)=K
ENDOFPI-圆周率倒数,这是个常量
Private Sub mcs_07(ps() As Double) '标准五轴(A,C)座标转换过程
Dim xt As Double, yt As Double, zt As Double'xt yt zt 老的xyz数据
Dim it As Double, jt As Double, kt As Double‘老的ijk数据
Dim ax As Double, ay As Double, az As Double
Dim t_c As Double
Dim a As Double, c As Double'AC数据
Dim delat_2 As Double, delat_3 As Double, delat_4 As Double'机床坐标系与工件坐标系的原点差值
kt = 1
c = 0
xt = ps(2)
yt = ps(3)
zt = ps(4)
it = ps(5)
jt = ps(6)
kt = ps(7)
ax = Sgn(it)
ay = Sgn(jt)
az = Sgn(kt) '取正负号
If ax = 0 Then
t_c = PI / 2
Else
t_c = Atn(Abs(jt / it)) 't_c---C轴数值预准备
End If
If az = 0 Then
a = PI / 2
ElseIf az > 0 Then
a = Atn(Sqr(it * it + jt * jt) / kt)
Else
Load Form5
Form5.Print " 报警信息:"
Form5.Print " " & file_name(Cls_Index) & "文件的刀轴矢量方向错误! 程序中止."
Print #2, Chr$(13) + Chr$(10) + path_fname + " 文件的刀轴矢量方向错误!"
Form5.Show 1
Exit Sub
End If
If ax >= 0 And ay >= 0 Then c = PI / 2 + t_c
If ax <= 0 And ay >= 0 Then c = 1.5 * PI - t_c
If ax <= 0 And ay <= 0 Then c = 1.5 * PI + t_c
If ax >= 0 And ay <= 0 Then c = PI / 2 - t_c
If ax = 0 And ay = 0 Then c = 0 '求C轴数值
delat_2 = x_dist * Cos(c) + y_dist * Sin(c)
delat_3 = y_dist * Cos(c) * Cos(a) - x_dist * Sin(c) * Cos(a) + z_dist * Sin(a)
delat_4 = x_dist * Sin(c) * Sin(a) - y_dist * Cos(c) * Sin(a) + z_dist * Cos(a)
ps(2) = xt * Cos(c) + yt * Sin(c) + delat_2
ps(3) = yt * Cos(c) * Cos(a) - xt * Sin(c) * Cos(a) + zt * Sin(a) + delat_3
ps(4) = xt * Sin(c) * Sin(a) - yt * Cos(c) * Sin(a) + zt * Cos(a) + delat_4
ps(11) = EndOfPI * a
ps(12) = 0
ps(13) = EndOfPI * c
End Sub |