Shop OBEX P1 Docs P2 Docs Learn Events
Servo Control Education Request — Parallax Forums

Servo Control Education Request

PoorYuppiePoorYuppie Posts: 13
edited 2008-04-22 19:03 in Robotics
So go easy on the new guy.... I could use some help and I think this is the right forum.
I'm basically building a remote camera,· which will always be controlled by a pc/user via the mouse.· I know there is stuff out there like this, but nothing with an interface I want to work with so I'm building my own.
I'm using the following:
-Futaba servos
-USB Parallax 16 servo controller
-VB express(not a requirement, but it's what I have right now)

I've searched this forum and the crust crawler forums.· I understand how to open and write to the comm port, but that's where everyones examples seem to break down.· The actual syntax and commands that drive the servos always seem to be missing or burried under a mountain of code and multiple piles of over complicated/redundant variables to where I can't understand what the programmer is doing.·
I never plan on using a stamp or anything like that, I'm just trying to build the link between the mouse and multiple axis' of servos at the same time.
I learn best by example, so if anyone has simple snipits of code for connecting to a comm port and driving a servo in VB Express I would really appreciate the help.
Thanks,

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2008-01-08 20:29
    Well, first of all, you need the PDF manual for the non-USB version. The USB version only describes how to use the 'animation tool' that Parallax provides. If you want to work from VB, you need the non-USB manual. The non-USB manual describes the command sequences to send to the controller in order to move the servo's under your program's control.

    http://www.parallax.com/Store/Robots/RoboticAccessories/tabid/145/List/1/ProductID/376/Default.aspx?txtSearch=PSC++USB&SortField=ProductName%2cProductName

    See the bottom of the page for the PDF link.

    OK, now the examples on the non-USB version expect you to be using a BS2, but instead you're using the PC.· This is not a problem.

    So, VB Messages example:

    DIM MyStr as STRING
    Dim GetVer as String
    Dim ReplyStr as String
    Dim ChanStr as String· ' Is the Servo 'Channel Number' string.· With one PSC, will be CHR(0) through CHR(15)
    Dim RateStr as STring· ' Is the Servo 'Ramp rate' value string.· CHR(0) == fast as possible, CHR(63) == slowest
    Dim PosVal as Long····· ' Is the desired position -- 16 bits unsigned.
    Dim PosLow as BYTE, PosHigh as BYTE


    GetVer = "!SCVER?" + CHR(13)· ' Chr(13) is the ending "$0D" from the examples.

    MSComm.Send(GetVer)· ' Or something like this...
    MSComm.Get(ReplyStr)· ' Or something like this -- should have "1.3" or similar.

    ChanStr = CHR(0)· ' Command channel zero
    RateStr = CHR(0)· ' Move as fast as possible
    PosVal = 1500
    PosLow = PosVal & $FF
    PosHigh = PosVal >> 8

    MyStr = "!SC" + ChanStr + RateStr + CHR(PosLow) + CHR(PosHigh) + CHR(13)
    MSComm.Send(MyStr);





    Post Edited (allanlane5) : 1/8/2008 8:47:49 PM GMT
  • PoorYuppiePoorYuppie Posts: 13
    edited 2008-01-08 22:04
    Perfect, Thanks!
    I'll try and post a video when I get it up and going.
  • PoorYuppiePoorYuppie Posts: 13
    edited 2008-01-21 19:51
    So I've seen people post this code around a few times and VB express doesn't like some of it.·
    None of these lines from the code above work in Express for me.

    MSComm.Send(GetVer)· ' Or something like this...
    MSComm.Get(ReplyStr)· ' Or something like this -- should have "1.3" or similar.

    PosLow = PosVal & $FF
    PosHigh = PosVal >> 8

    The "MSComm" and· "$FF" throw errors.· I figured out how to send stuff to the controller, and I'm sending the closest thing to the controller I can, it just repeats everything back to me and does nothing.· So I'm just trying to get it to reply to the request for version that I'm sending.· I'm sending the following:
    ·"!SCVER?" + CHR(13)

    and all I get back is "!SCVER?· "
    Any ideas on what I'm doing wrong?
  • stephenwagnerstephenwagner Posts: 147
    edited 2008-01-21 21:07
    You may also want to try the co-processors from AWC Electronics and avoid the PC altogether.

    http://www.awce.com/pak11.htm

    http://www.awce.com/pak6.htm

    BS2 code is provided with the application notes. These co-processors allow you to hook a PS2 mouse and or keyboard to the basic stamp.

    I use one to control two servos X and Y motion and I am also using one as an infrared remote in an assisted living facility. Move the mouse to change the volume and or select a channel.

    I use the servos and RANDOM to move a laser pointer to keep my dog busy.

    I hope this helps.

    SJW
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-01-21 21:08
    Well, the "MSComm" was a reference to the serial port class under VB6 -- while I'm SURE VB.NET Express has a serial port control, I have no idea what they call it.

    $FF is VB6-ism for a "hexadecimal literal". You can replace it with 255, if that helps.

    If you're using the right baud-rate, serial port, and USB driver, then you should get back "1.3" or so. But you need to verify baud-rate, serial port, and USB driver.
  • PoorYuppiePoorYuppie Posts: 13
    edited 2008-01-21 22:05
    Agreed, I'm looking to get back "1.4", but I just want to iron out the communication to the board. The usb version is supposed to automatically set the baud rate, and I know the port and Usb drivers are right(functions with the PSCI). I think the board is actually repeating what I send back to me once, then it stops. I can't query it again and get the same response, after the first time I get nothing.
  • bennettdanbennettdan Posts: 614
    edited 2008-01-28 05:15
    I have worked with various serial controlled products in the past and I use VB.net alot so maybe I can help.

    First thing i would do is open HyperTerminal it is a program on your PC its under START>ALL PROGRAMS>ACCESSORIES>COMMUNICATIONS>HYPERTERMINAL this program allows you to set up a connection to your serial port on the PC and send command via text to the servo controller.·Set the device to what Com port you are using then 2400 baud, no parity, eight data bits, two stop bits and no flow control.

    Second you can just type in !SCVER? and press enter and it should return the Firmware # say...1.3

    If it works in hyperterminal then you can start on a VB.net program.

    I will work on a simple VB.net program and hope this helps.




    Post Edited (bennettdan) : 1/28/2008 5:42:46 AM GMT
  • bennettdanbennettdan Posts: 614
    edited 2008-01-28 06:34
    Try this and see if it works, without having one infront of me its a little harder to make work. I attached the program in VB.net 2005
  • PoorYuppiePoorYuppie Posts: 13
    edited 2008-02-09 03:21
    So, thanks bennettdan for the code. It has some issues(had to get the high and low bytes a different way) but it looks like I'm still having the same problem. It looks like the "serialPort.Write" writes either characters or bytes, but can't combine them. I'm putting that issue aside for the moment.

    Now I can query the PSC and get the version back. I can also get the position of the servos but that's the next piece of the puzzle. They come back as squares(unknown characters). I have an array of characters 10 places long, and I need to change the last two(position high and low bytes) from unknown characters into something usable. If I could figure out how to do that, I think I could do the same in reverse to drive the servos. Any ideas?
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-02-09 06:34
    Hi PoorYuppie, although I don't have the PSC I have looked at the example Parallax code and it seems the values for channel, ramp, highbyte and low byte are sent as 1 byte for each value and not as a string of characters representing the values. There is an option in VB to write the bytes from a byte sized·array buffer. I was thinking the array would be set up similar to this

    Public sData As Byte() = New Byte(7) {&H21, &H53, &H43, &H0, &H0, &H0, &H0, &HD}

    ······· sData(3)=channel
    ······· sData(4) = ramp
    ······· sData(5) = lo_byte
    ······· sData(6) = hi_byte
    If SerialPort.IsOpen Then
    ··········· SerialPort.Write(sData, 0, 8)
    End If

    the first three bytes represent the ASCII codes for " !SC·", then come the parameter bytes terminated with &HD (CR), obviously you will have to determine how and where to fill in the other parameters.

    perhaps you could try·placing it in·bennettdan's example,·I'm not sure whether this is the answer but from looking at other PSC code it seems like it would·work.

    Jeff T.
  • PoorYuppiePoorYuppie Posts: 13
    edited 2008-02-11 17:28
    I've got a comm port monitoring program setup now and I'm writing the same exact(bit for bit) information to the PSC as the PSCI program, and it still has issues reading/sending info back.· Unfortunately it looks like because of the limited use of some of the VB·express read commands, I won't be able to read information back from the psc effectively so I'm bailing on the VB express idea.· I know it can be done but everyone I've seen do it is really over complicated.· I think I'll try it in VBA, so most of the code examples people around here are posting up will be valid help.· Thanks for the all the help so far guys.
  • computer guycomputer guy Posts: 1,113
    edited 2008-03-23 08:13
    PoorYuppie,

    Just wondering if you got this working or if you still need help? smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale
  • PoorYuppiePoorYuppie Posts: 13
    edited 2008-04-15 18:58
    Thanks for asking.· Yes, I have some of it working.· I snagged some of Unsoundcode's stuff, and it works very well.· The next step is to hack together that code with some usb streaming webcam stuff, then I can start shooting cats in the dark.· My biggest problem is finding time right now, I know how to do 90% of what I need at this point, but I just can't seem to get in the mood to code/debug after a 10+ hr days.·
  • T0mT0m Posts: 124
    edited 2008-04-15 23:47
    I would be interested to know how long the PSC lasts. I have had 2 of them and they stopped working after a short while.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robot vision is the the future, and Vision will take us there.


    http://www.youtube.com/watch?v=gbf0zaxWjvI
  • PoorYuppiePoorYuppie Posts: 13
    edited 2008-04-17 18:45
    What killed yours? I plan to have mine in a decent enclosure outside. Did you have a good 5v power supply?
  • HansMHansM Posts: 6
    edited 2008-04-20 10:44
    Hi! thanks to this forum I can control my servos with the USB PSC. It looks like it's a little slow, maybe because the baudrate is low? Do I have to change this also in the USB version?

    (If so: how?burger.gif )
  • PoorYuppiePoorYuppie Posts: 13
    edited 2008-04-22 19:03
    No, it shouldn't have anything to do with the baud rate.· I've got mine set at the default minimum and it responds very well(no delay) to the inputs.· Are to talking about response time to the input, or the actual speed the servo moves at?· If it's the servo speed, you set that in your input string (rate) to the psc.· Maybe if you've already checked that it could be your servos?
Sign In or Register to comment.