Putting robotics at your service™

Free shipping on orders over $200

Visual Basic 2008 Express code for SSC-32

Print view Share :
Previous topicNext topic

Page 1 of 1 [ 9 posts ]

User avatar
Novice ( offline )
Posts: 81
Posted: 2008-06-09 22:43 
I spent all day digging through forums (here and programming sites) and help files and experimenting with code but finally got it working. There is some great posts on VB in these threads but there are some big changes from VB6 to 2005 to 2008 and each version handles the serial port differently. Once I got the port open and write syntax right, I rewrote some VB6 code from cwkoehler and got it working with my BRAT. It's just a single horizontal scroll bar in a small form. I wanted to keep it as basic as possible so I could see how little is needed to make it work.

So, since I'm not a programmer and spent all day putting this all together and don't want anyone else to have to dig as much, here's the simplest I can make the instructions. If anyone has anything to add or change, please reply.

-First, create a new Windows Form project
-Drag a serialport object onto the form
-Click on the serialport object and in the Properties window, change the BaudRate value of SerialPort1 to whatever you use (mine is 115200)
-Drag an HScrollBar object from the toolbar onto the form and resize as you want
-Doubleclick the form and replace everything with the code below

Code:
Public Class Form1
    Dim scroll1value As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.Open()

        HScrollBar1.SmallChange = 100 'sets up speed of movement within the form itself
        HScrollBar1.LargeChange = 200
        HScrollBar1.Minimum = 500 'sets scrollbar minimum equal to lowest Pulse width of SSC-32
        HScrollBar1.Maximum = 2500 'sets scrollbar maximum equal to highest Pulse width of SSC-32
        HScrollBar1.Value = 1500 'sets HscrollBar1 to center position which corresponds to servo center
        scroll1value = HScrollBar1.Value

    End Sub

    Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
        SerialPort1.Write("#0 P" & HScrollBar1.Value & "S750" + Chr(13))
    End Sub
End Class


Change the #0 in the SerialPort1.Write command to whatever pin your servo is connected to on the SSC-32 that you'd like to test. Mine was the right ankle on the BRAT. Hit F5 to run the program and hopefully it works as well as it did for me!


User avatar
Novice ( offline )
Posts: 81
Posted: 2008-06-11 00:00 
 Post subject: Updated code and video
I'll keep editing this post with up to date, better working code and leave the original post alone since it's the absolute basics needed to get started.

The first post shows you how to create a simple scrollbar control for a single servo. This post shows you how to create a Walk Forward control. It will just walk 2 steps forward then stop until you hit the button again. I don't have it looping yet but am working on a routine to do that.

Here's what I have so far. Keep in mind, I'm not trying to create a great piece of software like the Sequencer, RIOS, or even LynxTerm - this is just to see how the new language works for robotics. I'd also like to work with MSRS a bit but wanted to get a little more VB experience in first.

Code:
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.Open()
    End Sub

    Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '                     RA,      RK,      RH,       LA,       LK,       LH,   speed   Walk Forward - SEQ Servo Order
        SerialPort1.Write("#0 P1427 #1 P1292 #2 P1292 #16 P1573 #17 P1708 #18 P1708 T500" + Chr(13))
        Sleep(900)
        SerialPort1.Write("#0 P1573 #1 P1292 #2 P1292 #16 P1427 #17 P1708 #18 P1708 T500" + Chr(13))
        Sleep(900)
        SerialPort1.Write("#0 P1573 #1 P1708 #2 P1708 #16 P1427 #17 P1292 #18 P1292 T500" + Chr(13))
        Sleep(900)
        SerialPort1.Write("#0 P1427 #1 P1708 #2 P1708 #16 P1573 #17 P1292 #18 P1292 T500" + Chr(13))
        Sleep(900)
    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'RA,   RK,   RH,   LA,   LK,   LH, speed          Home Position
        SerialPort1.Write("#0 P1500 #1 P1500 #2 P1500 #16 P1500 #17 P1500 #18 P1500 T500" + Chr(13))
    End Sub

    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        'RA,   RK,   RH,   LA,   LK,   LH, speed          Servos off
        SerialPort1.Write("#0 P0 #1 P0 #2 P0 #16 P0 #17 P0 #18 P0 T500" + Chr(13))
    End Sub

End Class


If you have any interest in working with this, you'll need to drag over the appropriate objects on the form too. Here's a screenshot of what it looks like so far:



Here's a video of some of the basic functions so far: http://www.youtube.com/watch?v=cqfxVHDOm1Y


Last edited by Beave on 2008-06-11 21:13, edited 2 times in total.

User avatar
Guru ( offline )
Posts: 9256
Posted: 2008-06-11 09:43 
Checked out the video, nice work! One note, it looks as if the centered servos are not centered. In order to make it easy to share walking routines with others, or utilize others routines you should center the servos. It's best done using the registers if you have the SSC-32 V2.

Check out steps 1 through 10 in the following tutorial.

http://www.lynxmotion.com/images/html/build128.htm

Let me know if I need to clarify anything.

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...


User avatar
Novice ( offline )
Posts: 81
Posted: 2008-06-11 09:56 
Thanks! Yes, that was my next step. They are definitely not centered. I built the thing before I had a serial cable and I've been too lazy to take it apart. I figured I could get by with some basic steps until I start fine-tuning any code. Also, I had to sort of hit the ground running to justify the expense with my girlfriend :wink: Also, I was sort of waiting until I got the rest of my parts to build the Biped Pete Jr.


User avatar
Guru ( offline )
Posts: 9256
Posted: 2008-06-11 10:01 
Beave wrote:
Thanks! Yes, that was my next step. They are definitely not centered. I built the thing before I had a serial cable and I've been too lazy to take it apart. I figured I could get by with some basic steps until I start fine-tuning any code. Also, I had to sort of hit the ground running to justify the expense with my girlfriend :wink: Also, I was sort of waiting until I got the rest of my parts to build the Biped Pete Jr.


Ah I see, no problemo. BTW Thanks for making this post. I'm sure a lot of people will find it useful for making their own VB applications that can talk to the SSC-32. 8)

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...


New ( offline )
Posts: 5
Posted: 2008-07-05 20:26 
Thanks Beave for writing this code, Can you post the latest solution (pictures in the video with centering servos) as an attachment to kick start my project.

Just built a Rover with L5 arm and I want to start the programming work. I'll repost an additions I make to this thread to help anyone else out


User avatar
Novice ( offline )
Posts: 81
Posted: 2008-07-12 15:50 
I was simply going to follow the steps in the BRAT doc to center the servos. I haven't done so yet as I built a Biped Pete (with a few changes) but am waiting on 4 more servos before I do much more. I will put code in for that when I get them. My father passed away last week and I had to leave town and have had other priorities but will be back in the swing very soon.


User avatar
Veteran ( offline )
Posts: 170
Posted: 2008-07-13 04:46 
oh "Beave" sad to learn about the demise of your father, May God bless him with HIS benedictions.

Thanks Beave for starting this thread on communication using visual basic 2008 express. I have assembled a phoenix-like hexapod shown at
http://lynxmotion.net/viewtopic.php?t=4115 which is now ready to communicate with the SSC-32. My work flow from this stage would be as follows:

- Center all the servos [coxa, femur, tibia] and then determine the mid, max & min positions of each servo. I am using PEP developed by zenta for creating sequences so determining mid, max & min positions is the very first step.

- The reason I am interested in communicating using visual basic is that I do not have Visual Sequencer, so i am intending to create sequences using PEP and use them in my VB program to finally execute them on SSC-32.

I hope with your cooperation and collaboration I can work out a program capable of implementing a gait created through PEP just as the Visual Sequencer does.

Thanks,
umar


User avatar
Novice ( offline )
Posts: 93
Posted: 2009-04-03 23:22 
 Post subject: VB2008 to control SSC-32
Using 'Beave's code as a starting point, I started writing a VB program to control my 8DOF mech CLYDE. I intend to send gait sequences pre-made in SEQ and later implement a video window to connect to an IP camera. I successfully move one leg on Button_4 using the code provided, but it only sends the first line of servo positions. I am not clear if the 'Sleep' command is a VB statement or a SSC command. Also, when I connect a second button control (Button6_Click) to the same serial port control nothing is sent.
Code:
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.Open()
    End Sub

    Public Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        'Walk Forward       LH,       LT,       LK,       LA,      speed
        SerialPort1.Write("#28 P1500 #29 P1500 #30 P1500 #31 P1500 T1000" + Chr(13))
        Sleep(900)
        SerialPort1.Write("#28 P1573 29 P1292 #30 P1292 #31 P1427 T1000" + Chr(13))
        Sleep(900)
        SerialPort1.Write("#28 P1573 #29 P1708 #30 P1708 #31 P1427 T1000" + Chr(13))
        Sleep(900)
        SerialPort1.Write("#28 P750 #29 P750 #30 P750 #31 P750  T1000" + Chr(13))
        Sleep(900)
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        'Walk Backward       LH,       LT,       LK,       LA,      speed
        SerialPort1.Write("#28 P1500 #29 P1500 #30 P1500 #31 P1500 T1000" + Chr(13))
        Sleep(900)
        SerialPort1.Write("#28 P1573 29 P1292 #30 P1292 #31 P1427 T1000" + Chr(13))
        Sleep(900)
        SerialPort1.Write("#28 P1573 #29 P1708 #30 P1708 #31 P1427 T1000" + Chr(13))
        Sleep(900)
        SerialPort1.Write("#28 P750 #29 P750 #30 P750 #31 P750  T1000" + Chr(13))
        Sleep(900)
    End Sub
End Class

Can anybody figure out what I'm doing wrong?


 

All times are UTC - 5 hours [ DST ]. It is currently 2014-11-29 04:29
Feedback Form
Feedback Form