由于1380属于低端板卡,提供的回远点函数较为简陋,调用回原地函数后,会先要求的方向运动。遇到原点或者极限就会停止。所以正常的使用三个感应器的情况就需要自己写了
下面就提供一段回原点函数作为参考
'***************************************************************************************
'初始化函数 *
'***************************************************************************************
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
workthread = New Thread(AddressOf home)
workthread.Start()
Button10.Enabled = False
End Sub
'***************************************************************************************
'回原点函数:向负方向回原点 *
'***************************************************************************************
Public Sub home()
Dim ret As Long
Dim cd As Long
Dim cd1 As Long
Dim cd2 As Long
Dim cd3 As Long
Dim cd4 As Long
Dim a As Long
'如果在原点, 轴就向正方向移动一段距离
cd4 = d1000_check_done(0)
If cd4 = 4 Then
d1000_start_ta_move(0, 20000, 2000, 20000, 0.5)
MsgBox("在原点")
Do Until cd4 = 1
cd4 = d1000_check_done(0)
Loop
End If
Do Until cd = 4
cd = d1000_check_done(0)
MsgBox("不在原点,往负方向")
ret = d1000_home_move(0, -200, -10000, 0.4)
Do Until cd1 = 3
cd1 = d1000_check_done(0)
If cd1 = 3 Then
MsgBox("遇到负极限,往正方向")
d1000_home_move(0, 200, 5000, 0.4)
ElseIf cd1 = 4 Then
MsgBox("初始位置在原点,又回到原点")
Exit Do
'中途遇到原点就继续往正方向移动 然后继续向负方向回原点
'(备用代码:遇到原点就像正方向走一段相对位置,然后在向负方向回原点)
'If cd1 = 4 Then
' cd1 = d1000_check_done(0)
'd1000_start_ta_move(0, 10000, 2000, 20000, 0.5)
' End If
'Do Until cd2 = 4
'cd2 = d1000_check_done(0)
' d1000_home_move(0, -200, -5000, 0.4)
'Loop
'Exit Do
End If
Loop
Exit Do
Loop
Do Until cd2 = 4
cd2 = d1000_check_done(0)
If cd2 = 4 Then
MsgBox("向正方向移动")
d1000_start_ta_move(0, 10000, 2000, 30000, 0.5)
End If
Loop
Do Until cd2 = 1
cd2 = d1000_check_done(0)
Loop
'碰到原点停止
MsgBox("第二次回原点")
d1000_home_move(0, -200, -5000, 0.4)
Do Until cd3 = 4
cd3 = d1000_check_done(0)
Loop
'手动设置原点位置
MsgBox("手动设置原点位置")
d1000_set_command_pos(0, 0)
If ret <> 0 Then
MsgBox("报警代码:" & ret)
End If
'调用命令 退出线程
Invoke(New delegatesub(AddressOf butchange), "")
workthread.Abort()
End Sub
下面这段是一部分的动作代码。
<pre name="code" class="csharp"> Private Sub OutPutRun()
'清除CT计算时间
'start_now = 0
'end_now = 0
'开始CT计时
d1000_immediate_stop(1)
ListBox1.Items.Insert(0, Now.TimeOfDay.ToString & "送料轴停止等待动作")
d1000_out_bit(3, 1)
ccd_judge = Trim(0)
start_now = My.Computer.Clock.TickCount
Dim t As Long
Dim x As Long
Dim time_save As Long
'd1000_out_bit(2, 0)
'd1000_out_bit(3, 0)
'd1000_out_bit(4, 0)
'd1000_out_bit(1, 1)
'动作备用代码
'Select Case ccd_judge
'Case "a"
' d1000_start_ta_move(0, TextBox3.Text, 2000, TextBox7.Text, 0.5)
' a += 1
'Case "b"
' d1000_start_ta_move(0, TextBox4.Text, 2000, TextBox7.Text, 0.5)
' b += 1
'Case "c"
' d1000_start_ta_move(0, TextBox5.Text, 2000, TextBox7.Text, 0.5)
' c += 1
'Case "d"
' d1000_start_ta_move(0, TextBox6.Text, 2000, TextBox7.Text, 0.5)
' d += 1
'Case "f"
' f += 1
' Exit Sub
'End Select
If ccd_judge = n2 Then
d1000_start_ta_move(0, TextBox3.Text, 2000, TextBox7.Text, 0.5)
a += 1
x = TextBox3.Text
ListBox1.Items.Insert(0, Now.TimeOfDay.ToString & "走位置a")
ElseIf ccd_judge = n3 Then
d1000_start_ta_move(0, TextBox4.Text, 2000, TextBox7.Text, 0.5)
x = TextBox4.Text
b += 1
ListBox1.Items.Insert(0, Now.TimeOfDay.ToString & "走位置b")
ElseIf ccd_judge = "f" Or ccd_judge = "" Then
d1000_start_ta_move(0, TextBox5.Text, 2000, TextBox7.Text, 0.5)
x = TextBox5.Text
f += 1
ListBox1.Items.Insert(0, Now.TimeOfDay.ToString & "走位置F")
ElseIf ccd_judge = "d" Then
d1000_start_ta_move(0, TextBox6.Text, 2000, TextBox7.Text, 0.5)
x = TextBox6.Text
d += 1
ListBox1.Items.Insert(0, Now.TimeOfDay.ToString & "走位置d")
End If
ListBox1.Items.Insert(0, Now.TimeOfDay.ToString & "等待轴到位")
Do Until x < pos + 10 And x > pos - 10
wait(10)
t += 100
ListBox1.Items.Insert(0, Now.TimeOfDay.ToString & "轴走位置" & pos & ccd_judge)
'MsgBox("轴走位置" & pos)
If t = 2000 Then
ListBox1.Items.Add("没有轴停止信号")
Exit Sub
End If
Loop
t = 0
ListBox1.Items.Insert(0, Now.TimeOfDay.ToString & "吹气")
d1000_out_bit(3, 0)
wait(TextBox15.Text)
d1000_out_bit(3, 1)
d1000_start_tv_move(1, 100, TextBox17.Text, 0.5)
f += 1
TextBox9.Text = a
TextBox10.Text = b
TextBox11.Text = f
TextBox12.Text = c
TextBox13.Text = a + b + c + d + f
end_now = My.Computer.Clock.TickCount
Threading.Thread.Sleep(TextBox15.Text)
TextBox8.Text = (end_now - start_now) / 1000
IsTestOver = True
End Sub