南京工程学院数控原理与系统课程设计_直线-直线刀具补偿刀补程序源代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
数控122 太劣阿昕哥
四、程序设计
Public X0 As Double, Y0 As Double, X1 As Double, Y1 As Double, X2 As Double, Y2 As Double, R As Double
Public Xs1 As Double, Ys1 As Double, Xs2 As Double, Ys2 As Double
Public Ori As Integer
Public Xl1 As Double, Yl1 As Double, Xl2 As Double, Yl2 As Double, dX1 As Double, dY1 As Double, dX2 As Double, dY2 As Double, d1 As Double, d2 As Double
Private Sub Command1_Click()
Dim X1_FWD As Integer, Y1_FWD As Integer, X2_FWD As Integer, Y2_FWD As Integer
Dim alfa As Double, beta As Double
Call PaintAxis
'绘制补偿前图像
Picture1.ForeColor = vbBlue
Picture1.DrawWidth = 1
Picture1.Line (X0, Y0)-(X1, Y1)
Picture1.Line (X1, Y1)-(X2, Y2)
'算法设计
'计算坐标增量
dX1 = X1 - X0
dY1 = Y1 - Y0
dX2 = X2 - X1
dY2 = Y2 - Y1
alfa = Atn(dY1 / dX1)
beta = Atn(dY2 / dX2)
If dX1 >= 0 Then
X1_FWD = 1
Else
X1_FWD = -1
End If
If dX2 >= 0 Then
X2_FWD = 1
X2_FWD = -1
End If
If dY1 >= 0 Then
Y1_FWD = 1
Else
Y1_FWD = -1
End If
If dY2 >= 0 Then
Y2_FWD = 1
Else
Y2_FWD = -1
End If
'计算d1,d2
d1 = Sqr(dX1 ^ 2 + dY1 ^ 2)
d2 = Sqr(dX2 ^ 2 + dY2 ^ 2)
'计算方向矢量投影
Xl1 = dX1 / d1
Yl1 = dY1 / d1
Xl2 = dX2 / d2
Yl2 = dY2 / d2
'判断缩短型,伸长型,插入型
If Ori * (Yl2 * Xl1 - Xl2 * Yl1) >= 0 Then '缩短型
'刀补建立
If Combo1.ListIndex = 0 And Ori * (Yl2 * Xl1 - Xl2 * Yl1) <> 0 Then Xs1 = X1 - R * Ori * Yl2
Ys1 = Y1 + R * Ori * Xl2
X_0p.Text = X0
Y_0p.Text = Y0
X_s1.Text = Xs1
Y_s1.Text = Ys1
X_2p.Text = Xs1 + dX2
Y_2p.Text = Ys1 + dY2
Picture1.ForeColor = vbMagenta
Picture1.Line (X0, Y0)-(Xs1, Ys1)
Picture1.Line (Xs1, Ys1)-(Xs1 + dX2, Ys1 + dY2)
'刀补进行
ElseIf Combo1.ListIndex = 1 Then
If Yl2 * Xl1 - Xl2 * Yl1 = 0 Then 'l1与l2共线
Xs1 = X1 - R * Ori * Yl1
Ys1 = Y1 + R * Ori * Xl1
X_0p.Text = Xs1 - dX1
Y_0p.Text = Ys1 - dY1
X_s1.Text = Xs1
Y_s1.Text = Ys1
X_2p.Text = Xs1 + dX2
Y_2p.Text = Ys1 + dY2
Picture1.ForeColor = vbMagenta
Picture1.Line (Xs1 - dX1, Ys1 - dY1)-(Xs1, Ys1)
Picture1.Line (Xs1, Ys1)-(Xs1 + dX2, Ys1 + dY2)
Else ' l1与l2不共线
Xs1 = X1 + (Xl2 - Xl1) * Ori * R / (Xl1 * Yl2 - Xl2 * Yl1)
Ys1 = Y1 + (Yl2 - Yl1) * Ori * R / (Xl1 * Yl2 - Xl2 * Yl1)
X_0p.Text = Xs1 - dX1
Y_0p.Text = Ys1 - dY1
X_s1.Text = Xs1
Y_s1.Text = Ys1
X_2p.Text = Xs1 + dX2
Y_2p.Text = Ys1 + dY2
Picture1.ForeColor = vbMagenta
Picture1.Line (Xs1 - dX1, Ys1 - dY1)-(Xs1, Ys1)
Picture1.Line (Xs1, Ys1)-(Xs1 + dX2, Ys1 + dY2)
End If
'刀补撤销
ElseIf Combo1.ListIndex = 2 And Ori * (Yl2 * Xl1 - Xl2 * Yl1) <> 0 Then Xs1 = X1 - R * Ori * Yl1
Ys1 = Y1 + R * Ori * Xl1
X_0p.Text = Xs1 - dX1
Y_0p.Text = Ys1 - dY1
X_s1.Text = Xs1
Y_s1.Text = Ys1
X_2p.Text = X2
Y_2p.Text = Y2