'**************************************************************************** 'This is a test program of a five-axis robot arm. 'Developed by PlayRobot Lab Dec. 2003 'Never operate or test this machine without the authorization of PlayRobot. 'Any accident happned would not be guaranted under this circumstance '**************************************************************************** Private sp_configure As Integer Public ax1_position As Integer Public ax2_position As Integer Public ax21_position As Integer Public ax3_position As Integer Public ax4_position As Integer Public ax5_position As Integer Private Sub Command2_Click() Text1.Text = 255 Text2.Text = 0 Text3.Text = 255 Text4.Text = 0 Text5.Text = 255 Text6.Text = 0 Text7.Text = 255 Text8.Text = 0 Text9.Text = 255 Text10.Text = 0 End Sub Private Sub Command3_Click() Slider1.Max = Text1.Text Slider1.Min = Text2.Text Slider2.Max = Text3.Text Slider2.Min = Text4.Text Slider3.Max = Text5.Text Slider3.Min = Text6.Text Slider4.Max = Text7.Text Slider4.Min = Text8.Text Slider5.Max = Text9.Text Slider5.Min = Text10.Text If (Slider1.Max > 255) Then MsgBox "最大值不可超過 255, 請重新輸入" Slider1.Max = Text1.Text ElseIf (Slider2.Max > 255) Then MsgBox "最大值不可超過 255, 請重新輸入" Slider2.Max = Text3.Text ElseIf (Slider3.Max > 255) Then MsgBox "最大值不可超過 255, 請重新輸入" Slider3.Max = Text5.Text ElseIf (Slider4.Max > 255) Then MsgBox "最大值不可超過 255, 請重新輸入" Slider4.Max = Text7.Text ElseIf (Slider5.Max > 255) Then MsgBox "最大值不可超過 255, 請重新輸入" Slider5.Max = Text9.Text End If End Sub Private Sub Forward_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim Buffer As Variant Dim ByteArray() As Byte ReDim ByteArray(0 To 2) ByteArray(0) = 255 'Required 1st Byte to signal SSC ByteArray(1) = 0 'Servo Number. This can be changed. ax1_position = ax1_position + 5 Sleep (sleep_time) ByteArray(2) = ax1_position 'Slider's MAX value shouldn't exceed 255. Buffer = ByteArray 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer End Sub Private Sub Origin_Click() Dim Buffer01 As Variant Dim ByteArray01() As Byte ReDim ByteArray01(0 To 2) 'MsgBox ax1_position & ax2_position ' Axis 1 ByteArray01(0) = 255 'Required 1st Byte to signal SSC ByteArray01(1) = 0 'Servo Number. This can be changed. ByteArray01(2) = 127 'Slider's MAX value shouldn't exceed 255. "127" equals to center point Buffer01 = ByteArray01 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer01 'Sending position data to SSC ax1_position = 127 ' Axis 2 left ByteArray01(0) = 255 'Required 1st Byte to signal SSC ByteArray01(1) = 1 'Servo Number. This can be changed. ByteArray01(2) = 127 'Slider's MAX value shouldn't exceed 255. "127" equals to center point Buffer01 = ByteArray01 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer01 'Sending position data to SSC ax2_position = 127 ' Axis 2 right ByteArray01(0) = 255 'Required 1st Byte to signal SSC ByteArray01(1) = 2 'Servo Number. This can be changed. ByteArray01(2) = 127 'Slider's MAX value shouldn't exceed 255. "127" equals to center point Buffer01 = ByteArray01 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer01 'Sending position data to SSC ax21_position = 127 ' Axis 3 ByteArray01(0) = 255 'Required 1st Byte to signal SSC ByteArray01(1) = 3 'Servo Number. This can be changed. ByteArray01(2) = 127 'Slider's MAX value shouldn't exceed 255. "127" equals to center point Buffer01 = ByteArray01 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer01 'Sending position data to SSC ax3_position = 127 ' Axis 4 ByteArray01(0) = 255 'Required 1st Byte to signal SSC ByteArray01(1) = 4 'Servo Number. This can be changed. ByteArray01(2) = 127 'Slider's MAX value shouldn't exceed 255. "127" equals to center point Buffer01 = ByteArray01 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer01 'Sending position data to SSC ax4_position = 127 ' Axis 5 ByteArray01(0) = 255 'Required 1st Byte to signal SSC ByteArray01(1) = 5 'Servo Number. This can be changed. ByteArray01(2) = 127 'Slider's MAX value shouldn't exceed 255. "127" equals to center point Buffer01 = ByteArray01 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer01 'Sending position data to SSC ax5_position = 127 End Sub Private Sub CycleTest_Click() Dim Buffer01 As Variant Dim Buffer02 As Variant Dim Buffer03 As Variant Dim Buffer04 As Variant Dim Buffer05 As Variant Dim Buffer06 As Variant Dim ByteArrayRun1() As Byte Dim ByteArrayRun2() As Byte Dim ByteArrayRun3() As Byte Dim ByteArrayRun4() As Byte Dim ByteArrayRun5() As Byte Dim ByteArrayRun6() As Byte Dim step_increment As Integer Dim count As Integer Dim sleep_time As Integer ReDim ByteArrayRun1(0 To 2) ReDim ByteArrayRun2(0 To 2) ReDim ByteArrayRun3(0 To 2) ReDim ByteArrayRun4(0 To 2) ReDim ByteArrayRun5(0 To 2) ReDim ByteArrayRun6(0 To 2) ByteArrayRun1(0) = 255 'Required 1st Byte to signal SSC ByteArrayRun1(1) = 0 'axis 1 ByteArrayRun2(0) = 255 'Required 1st Byte to signal SSC ByteArrayRun2(1) = 1 'axis 2 ByteArrayRun3(0) = 255 'Required 1st Byte to signal SSC ByteArrayRun3(1) = 2 'axis 2 ByteArrayRun4(0) = 255 'Required 1st Byte to signal SSC ByteArrayRun4(1) = 3 'axis 3 ByteArrayRun5(0) = 255 'Required 1st Byte to signal SSC ByteArrayRun5(1) = 4 'axis 4 ByteArrayRun6(0) = 255 'Required 1st Byte to signal SSC ByteArrayRun6(1) = 5 'axis 5 'initial all axises Call Origin_Click sp_configure = 0 'default set speed to slow Sleep (300) 'speed set-up If sp_configure = 0 Then step_increment = 5 '5 : is a experiment number, it shoould less than var "step_increment" sleep_time = 100 ElseIf sp_configure = 1 Then step_increment = 15 '15 : is a experiment number, it shoould less than var "step_increment" sleep_time = 65 ElseIf sp_configure = 2 Then step_increment = 30 '30 : is a experiment number, it shoould less than var "step_increment" sleep_time = 50 End If count = 0 Do While (count) < 5 count = count + 1 '*********** positure 1 *********** Call Origin_Click Sleep (150) 'axis 1 I = 127 Do While (I + Abs(step_increment)) < 200 I = I + Abs(step_increment) Sleep (sleep_time) ByteArrayRun1(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer01 = ByteArrayRun1 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer01 ax1_position = I Loop ' MsgBox "a1" 'axis 2 left I = 127 Do While (I + Abs(step_increment)) < 150 I = I + Abs(step_increment) Sleep (sleep_time) ByteArrayRun2(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer02 = ByteArrayRun2 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer02 ax2_position = I Loop 'axis 2 right I = 127 Do While (I + Abs(step_increment)) < 150 I = I + Abs(step_increment) Sleep (sleep_time) ByteArrayRun3(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer03 = ByteArrayRun3 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer03 ax21_position = I Loop ' MsgBox "a2" 'axis 3 I = 127 Do While (I + Abs(step_increment)) < 190 I = I + Abs(step_increment) Sleep (sleep_time) ByteArrayRun4(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer04 = ByteArrayRun4 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer04 ax3_position = I Loop ' MsgBox "a3" 'axis 4 I = 127 Do While (I + Abs(step_increment)) < 185 I = I + Abs(step_increment) Sleep (250) ByteArrayRun5(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer05 = ByteArrayRun5 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer05 ax4_position = I Loop ' MsgBox "a4" 'axis 5 I = 127 Do While (I + Abs(step_increment)) < 200 I = I + Abs(step_increment) Sleep (250) ByteArrayRun6(2) = 200 'Slider's MAX value shouldn't exceed 255. Buffer06 = ByteArrayRun6 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer06 ax5_position = 200 Loop ' MsgBox "a5" '*********** positure 2 *********** 'axis 1 I = ax1_position 'start from the above end point If (I > 150) Then 'CCW move step_increment = 0 - Abs(step_increment) Do While (I + step_increment) > 150 I = I + step_increment Sleep (sleep_time) ByteArrayRun1(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer01 = ByteArrayRun1 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer01 ax1_position = I Loop Else Do While (I + step_increment) < 150 'CW Move I = I + step_increment Sleep (sleep_time) ByteArrayRun1(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer01 = ByteArrayRun1 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer01 ax1_position = I Loop End If 'MsgBox ax1_position 'axis 2 left I = ax2_position 'start from the above end point If (I > 130) Then 'CCW move step_increment = 0 - Abs(step_increment) Do While (I + step_increment) > 130 I = I + step_increment Sleep (sleep_time) ByteArrayRun2(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer02 = ByteArrayRun2 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer02 Loop Else Do While (I + step_increment) < 130 'CW Move I = I + step_increment Sleep (sleep_time) ByteArrayRun2(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer02 = ByteArrayRun2 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer02 Loop End If 'axis 2 right I = ax21_position 'start from the above end point If (I > 130) Then 'CCW move step_increment = 0 - Abs(step_increment) Do While (I + step_increment) > 130 I = I + step_increment Sleep (sleep_time) ByteArrayRun3(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer03 = ByteArrayRun3 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer03 Loop Else Do While (I + step_increment) < 130 'CW Move I = I + step_increment Sleep (sleep_time) ByteArrayRun3(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer03 = ByteArrayRun3 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer03 Loop End If 'axis 3 I = ax3_position 'start from the above end point If (I > 160) Then 'CCW move step_increment = 0 - Abs(step_increment) Do While (I + step_increment) > 160 I = I + step_increment Sleep (sleep_time) ByteArrayRun4(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer04 = ByteArrayRun4 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer04 Loop Else Do While (I + step_increment) < 160 'CW Move I = I + step_increment Sleep (sleep_time) ByteArrayRun4(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer04 = ByteArrayRun4 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer04 Loop End If 'axis 4 I = ax4_position 'start from the above end point If (I > 120) Then 'CCW move step_increment = 0 - Abs(step_increment) Do While (I + step_increment) > 120 I = I + step_increment Sleep (sleep_time) ByteArrayRun5(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer05 = ByteArrayRun5 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer05 Loop Else Do While (I + step_increment) < 120 'CW Move I = I + step_increment Sleep (sleep_time) ByteArrayRun5(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer05 = ByteArrayRun5 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer05 Loop End If 'axis 5 I = ax5_position 'start from the above end point If (I > 140) Then 'CCW move step_increment = 0 - Abs(step_increment) Do While (I + step_increment) > 140 I = I + step_increment Sleep (sleep_time) ByteArrayRun6(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer06 = ByteArrayRun6 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer06 Loop Else Do While (I + step_increment) < 140 'CW Move I = I + step_increment Sleep (sleep_time) ByteArrayRun6(2) = I 'Slider's MAX value shouldn't exceed 255. Buffer06 = ByteArrayRun6 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer06 Loop End If Sleep (150) Loop Call Origin_Click End Sub Function Delay(Optional mTime As Single = 0) Lt = Timer Do Until Timer - Lt > mTime If Lt > Timer Then Lt = Lt - 86400 Loop End Function Private Sub Fast_sp_Click() sp_configure = 2 ' 2 means fast motion End Sub Private Sub Form_Load() Dim Buffer As Variant Dim ByteArray() As Byte ReDim ByteArray(0 To 2) MSComm1.Settings = "9600,N,8,1" 'COM Port Setting MSComm1.CommPort = 1 'Set Port Number MSComm1.PortOpen = True 'Open COM Port 'Initial parameter setting 'Axis limits Slider1.Max = Text1.Text Slider1.Min = Text2.Text Slider2.Max = Text3.Text Slider2.Min = Text4.Text Slider3.Max = Text5.Text Slider3.Min = Text6.Text Slider4.Max = Text7.Text Slider4.Min = Text8.Text Slider5.Max = Text9.Text Slider5.Min = Text10.Text 'Axis position initialize 'axis 1 ByteArray(0) = 255 'Required 1st Byte to signal SSC ByteArray(1) = 0 'Servo Number. This can be changed. ByteArray(2) = 127 'Slider's MAX value shouldn't exceed 255. Buffer = ByteArray 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer ax1_position = 127 'axis 2 right ByteArray(0) = 255 'Required 1st Byte to signal SSC ByteArray(1) = 1 'Servo Number. This can be changed. ByteArray(2) = 127 'Slider's MAX value shouldn't exceed 255. Buffer = ByteArray 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer ax2_position = 127 'axis 2 left ByteArray(0) = 255 'Required 1st Byte to signal SSC ByteArray(1) = 1 'Servo Number. This can be changed. ByteArray(2) = 127 'Slider's MAX value shouldn't exceed 255. Buffer = ByteArray 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer ax21_position = 127 'axis 3 ByteArray(0) = 255 'Required 1st Byte to signal SSC ByteArray(1) = 3 'Servo Number. This can be changed. ByteArray(2) = 127 'Slider's MAX value shouldn't exceed 255. Buffer = ByteArray 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer ax3_position = 127 'axis 4 ByteArray(0) = 255 'Required 1st Byte to signal SSC ByteArray(1) = 5 'Servo Number. This can be changed. ByteArray(2) = 127 'Slider's MAX value shouldn't exceed 255. Buffer = ByteArray 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer ax4_position = 127 'axis 5 ByteArray(0) = 255 'Required 1st Byte to signal SSC ByteArray(1) = 7 'Servo Number. This can be changed. ByteArray(2) = 127 'Slider's MAX value shouldn't exceed 255. Buffer = ByteArray 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer ax5_position = 127 End Sub Private Sub Middle_sp_Click() sp_configure = 1 ' 1 means middle-fast motion End Sub Private Sub Right_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim Buffer As Variant Dim ByteArray() As Byte ReDim ByteArray(0 To 2) ByteArray(0) = 255 'Required 1st Byte to signal SSC ByteArray(1) = 0 'Servo Number. This can be changed. ax1_position = ax1_position - 5 Sleep (sleep_time) ByteArray(2) = ax1_position 'Slider's MAX value shouldn't exceed 255. Buffer = ByteArray 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer End Sub Private Sub Slider1_Scroll() Dim Buffer As Variant Dim ByteArray() As Byte ReDim ByteArray(0 To 2) ByteArray(0) = 255 'Required 1st Byte to signal SSC ByteArray(1) = 0 'Servo Number. This can be changed. ByteArray(2) = Slider1.Value 'Slider's MAX value shouldn't exceed 255. Buffer = ByteArray 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer 'Sending position data to SSC ax1_position = Slider1.Value 'MsgBox ax1_position End Sub Private Sub Command1_Click() MSComm1.PortOpen = False 'Closing COM Port -> Ending application. End End Sub Private Sub Slider2_Click() Dim Buffer_S1 As Variant Dim Buffer_S2 As Variant Dim ByteArray_S1() As Byte Dim ByteArray_S2() As Byte ReDim ByteArray_S1(0 To 2) ReDim ByteArray_S2(0 To 2) ' right motor driven ByteArray_S1(0) = 255 'Required 1st Byte to signal SSC ByteArray_S1(1) = 1 'Servo Number. This can be changed. ByteArray_S1(2) = Slider2.Value 'Slider's MAX value shouldn't exceed 255. ' left motor driven ByteArray_S2(0) = 255 'Required 1st Byte to signal SSC ByteArray_S2(1) = 2 'Servo Number. This can be changed. ByteArray_S2(2) = Slider2.Value 'Slider's MAX value shouldn't exceed 255. Buffer_S1 = ByteArray_S1 Buffer_S2 = ByteArray_S2 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer_S1 MSComm1.Output = Buffer_S2 ax2_position = Slider2.Value ax21_position = Slider2.Value 'MsgBox ax2_position End Sub Private Sub Slider3_Click() Dim Buffer As Variant Dim ByteArray() As Byte ReDim ByteArray(0 To 2) ByteArray(0) = 255 'Required 1st Byte to signal SSC ByteArray(1) = 3 'Servo Number. This can be changed. ByteArray(2) = Slider3.Value 'Slider's MAX value shouldn't exceed 255. Buffer = ByteArray 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer ax3_position = Slider3.Value 'MsgBox ax3_position End Sub Private Sub Slider4_Click() Dim Buffer As Variant Dim ByteArray() As Byte ReDim ByteArray(0 To 2) ByteArray(0) = 255 'Required 1st Byte to signal SSC ByteArray(1) = 4 'Servo Number. This can be changed. ByteArray(2) = Slider4.Value 'Slider's MAX value shouldn't exceed 255. Buffer = ByteArray 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer ax4_position = Slider4.Value 'MsgBox ax4_position End Sub Private Sub Slider5_Click() Dim Buffer As Variant Dim ByteArray() As Byte ReDim ByteArray(0 To 2) ByteArray(0) = 255 'Required 1st Byte to signal SSC ByteArray(1) = 5 'Servo Number. This can be changed. ByteArray(2) = Slider5.Value 'Slider's MAX value shouldn't exceed 255. Buffer = ByteArray 'Transfer ByteArray to Variant(Required for MSCOMM control) MSComm1.Output = Buffer ax5_position = Slider5.Value End Sub Private Sub Slow_sp_Click() sp_configure = 0 ' 0 means slow motion End Sub