Working with the Veyron Servo Controller VB6 Part 2

Welcome to Part 2 of Working with the Veyron Servo Controller.

In part 1 we learned how to setup communication with the serial port using MScomm and how to send a signal to the Veyron that would control its Direction of movement.

In this part we are going to go a a step further and learn how to control the speed of the servo using the Veyron Servo Controller.

Lets first begin by opeing up the project you save from part 1.

Now lets begin.

1) You are going to need to first add 1-Scroll Bar and 1-Label to your form.

Here is my form.

 

2) Position your new label over the new scroll bar, rename the label to lblSpeed.

3) Click on the new scroll bar and change the Max value to 5000 and then change its value to 5000.

 

4) Now double click on the new scroll bar and add the following to its event.

lblSpeed.Caption = VScroll2.Value
B = Cint(VScroll2.Value)
Servo

5) Now we need to add another event for the scroll bar called Scroll.

Private Sub VScroll2_Scroll()
lblSpeed.Caption = VScroll2.Value
B = Cint(VScroll2.Value)
Servo
End Sub

6) We now need to define another variable. So at the top of your code you will see these lines.

Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Dim A As Integer

Add the following line right under Dim A as Integer.

Dim B As Integer

7) Remember the Function we created for the Veyron, well we are going to edit it so you can control the speed. Change the following line to match this,

MSComm1.Output = "S" & B & vbCr  'was 5000 

In part 1 the line was this: MSComm1.Output = "S" & 5000 & vbCr this set the speed of the servo to its Maximum, we can now change the speed of the servo just like we can change the direction of the servo.

So now are full code is this:

Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Dim A As Integer
Dim B As Integer

 

Private Sub cmbPort_Change()
startup
End Sub

Private Sub cmbPort_Click()
startup
End Sub

Private Sub Form_Load()
cmbPort.Clear
cmbPort.AddItem "1"
cmbPort.AddItem "2"
cmbPort.AddItem "3"
cmbPort.AddItem "4"
cmbPort.AddItem "5"
cmbPort.AddItem "6"
cmbPort.AddItem "7"
cmbPort.AddItem "8"

cmbChannel.Clear
cmbChannel.AddItem "0"
cmbChannel.AddItem "1"
cmbChannel.AddItem "2"
cmbChannel.AddItem "3"
cmbChannel.AddItem "4"
cmbChannel.AddItem "5"
cmbChannel.AddItem "6"
cmbChannel.AddItem "7"
cmbChannel.AddItem "8"
cmbChannel.AddItem "9"
cmbChannel.AddItem "10"
cmbChannel.AddItem "11"
cmbChannel.AddItem "12"
cmbChannel.AddItem "13"
cmbChannel.AddItem "14"
cmbChannel.AddItem "15"
cmbChannel.AddItem "16"
cmbChannel.AddItem "17"
cmbChannel.AddItem "18"
cmbChannel.AddItem "19"
cmbChannel.AddItem "20"
cmbChannel.AddItem "21"
cmbChannel.AddItem "22"
cmbChannel.AddItem "23"


End Sub

Private Sub VScroll1_Change()
lblAmt.Caption = VScroll1.Value
A = Cint(VScroll1.Value)
Servo
End Sub

Private Sub VScroll1_Scroll()
lblAmt.Caption = VScroll1.Value
A = Cint(VScroll1.Value)
Servo
End Sub

Private Sub VScroll2_Change()
lblSpeed.Caption = VScroll2.Value
B = Cint(VScroll2.Value)
Servo
End Sub

Private Sub VScroll2_Scroll()
lblSpeed.Caption = VScroll2.Value
B = Cint(VScroll2.Value)
Servo
End Sub

Private Function startup()

    On Error GoTo ClearError
    If MSComm1.PortOpen = True Then
        MSComm1.PortOpen = False
        MSComm1.Settings = "9600,N,8,1"
        MSComm1.CommPort = CLng(cmbPort.Text)
        MSComm1.OutBufferCount = 0
        MSComm1.PortOpen = True
    Else
        MSComm1.Settings = "9600,N,8,1"
        MSComm1.CommPort = CLng(cmbPort.Text)
        MSComm1.OutBufferCount = 0
        MSComm1.PortOpen = True
    End If
    
ClearError:

    Err.Clear
    
    End Function
    
    Private Function Servo()
    On Error GoTo Errorhandler
    If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
    
   
        MSComm1.Output = "#" & CLng(cmbChannel.Text)
        MSComm1.Output = "P" & A
        MSComm1.Output = "S" & B & vbCr  'was 5000
        MSComm1.Output = Chr$(85) 'Update
        MSComm1.OutBufferCount = 0 'Clear Buffer
      
        Sleep 60
        MSComm1.RThreshold = 0
        If Mmscomm1.OutBufferCount = 0 Then
        MSComm1.PortOpen = False
        MSComm1.RThreshold = 0
        End If
        DoEvents
    
Errorhandler:
        Err.Clear
        
    End Function

Comments

Submitted by fhareide on Mon, 2015-11-16 07:50

fhareide's picture

I want to try making something like this.. I use some VB at work and this would be a good way to practice it more. Do you think I could do something similar with this product? http://www.dx.com/p/32-ch-servo-motor-control-driver-board-for-arduino-w...

 

Submitted by JeffRo on Tue, 2015-11-17 01:36

JeffRo's picture

I would think so. It would just be a matter of getting the characters that need to be sent to the board. I know what the Veyron uses and the Micro Maestro from Pololu. Did some searching and found the character set needed to drive it. If you use the code I have provided and just replace the lines as noted here: MSComm1.Output = "#" & CLng(cmbChannel.Text) "This is the channel"
MSComm1.Output = "P" & A "This is the position"  
MSComm1.Output = "S" & B & vbCr  "This is the speed replace "S" with "T"

Here is a link to the page I found it on. 

Submitted by Roxanna77 on Mon, 2015-11-16 19:39

Roxanna77's picture

Great post

I haven't gotten a chance to tinker with it yet, hopefully by the weekend.

Thanks!!!