Not long after my last post, I tried a few things and got it to work. (I read Amanda’s reply a bit closer)!
Like Amanda said, I had to go to the Properties of each control and set the minimum and Maximum values, then set the “Value” propertie to 1500 which centered the control on startup.
Here is the Modified example code “a bit sloppy, I’m a newbie”
’ Simple example GUI for the Maestro USB Servo Controller, written in
’ Visual Basic .NET.
’ Temporary native USB connection using Usc class.
’ Button for disabling channel 0.
’ Button for setting target of channel 0 to 1000 us.
’ Button for setting target of channel 0 to 2000 us.
’ NOTE: Channel 0 should be configured as a servo channel for this program
’ to work. You must also connect USB and servo power, and connect a servo
’ to channel 0. If this program does not work, use the Maestro Control
’ Center to check what errors are occurring.
Public Class MainWindow
‘’’ This subroutine runs when the user clicks the Target=1000us button.
’ Sub Button1000_Click(ByVal sender As Object, ByVal e As EventArgs)
’ TrySetTarget(1, 1000 * 4) ’ Set the target of channel 0 to 1000 microseconds.
''' This subroutine runs when the user clicks the Target=2000us button.
' Sub Button2000_Click(ByVal sender As Object, ByVal e As EventArgs)
' TrySetTarget(1, 2000 * 4) ' Set the target of channel 0 to 2000 microseconds.
' End Sub
''' This function runs when the user clicks the Disable Servos button.
Sub ButtonDisable_Click(ByVal sender As Object, ByVal e As EventArgs)
' Set target of channels 1,2 to 0. This tells the Maestro to stop
' transmitting pulses on that channel. Any servo connected to it
' should stop trying to maintain its position.
''' Attempts to set the target of
''' <param name="channel">Channel number from 0 to 23.</param>
''' <param name="target">
''' Target, in units of quarter microseconds. For typical servos,
''' 6000 is neutral and the acceptable range is 4000-8000.
Sub TrySetTarget(ByVal channel As Byte, ByVal target As UInt16)
Using device As Usc = connectToDevice() ' Find a device and temporarily connect.
' device.Dispose() is called automatically when the "Using" block ends,
' allowing other functions and processes to use the device.
Catch exception As Exception ' Handle exceptions by displaying them to the user.
''' Connects to a Maestro using native USB and returns the Usc object
''' representing that connection. When you are done with the
''' connection, you should close it using the Dispose() method so that
''' other processes or functions can connect to the device later. The
''' "Using" statement can do this automatically for you.
Function connectToDevice() As Usc
' Get a list of all connected devices of this type.
Dim connectedDevices As List(Of DeviceListItem) = Usc.getConnectedDevices()
For Each dli As DeviceListItem In connectedDevices
' If you have multiple devices connected and want to select a particular
' device by serial number, you could simply add some code like this:
' If dli.serialNumber <> "00012345" Then
' Continue For
' End If
Dim device As Usc = New Usc(dli) ' Connect to the device.
Return device ' Return the device.
Throw New Exception("Could not find device. Make sure it is plugged in to " & _
"USB and check your Device Manager.")
''' Displays an exception (error) to the user by popping up a message box.
Sub displayException(ByVal exception As Exception)
Dim stringBuilder As StringBuilder = New StringBuilder()
stringBuilder.Append(exception.Message & " ")
If TypeOf exception Is Win32Exception Then
Dim win32Exception As Win32Exception = DirectCast(exception, Win32Exception)
stringBuilder.Append("Error code 0x" + win32Exception.NativeErrorCode.ToString("x") + ". ")
exception = exception.InnerException
Loop Until (exception Is Nothing)
MessageBox.Show(stringBuilder.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Private Sub MainWindow_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Private Sub VScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) Handles VScrollBar1.Scroll
TrySetTarget(2, VScrollBar1.Value * 4)
Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
TrySetTarget(1, TrackBar1.Value * 4)