DMC1380的使用:專案例項講解
阿新 • • 發佈:2019-02-17
由於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