Shop OBEX P1 Docs P2 Docs Learn Events
Servo controller directly from pc — Parallax Forums

Servo controller directly from pc

f0xdudef0xdude Posts: 5
edited 2008-03-18 21:07 in Robotics
Hello, I am trying to control the PSC ( Servo controller USB) with vbs and I just CAN't get it to work.

I have tried all the combinations using the documentation of the protocol.

I noticed that it is USB which emulates serial so I tried the following code.

Set com = CreateObject ("MSCommLib.MSComm")
com.CommPort = 5
com.Settings = "2400,N,8,1"
com.PortOpen = True
com.Output = "33 83 67 0 0 222 4 13"
com.PortOpen = False

It flashes the green light, but it does not move the servo

I also tried putting "!SC 0 8 250 1240" I also used \r and all kinds of tricks, but to no avail.

Please guys ( especially the tech guru of parallax crew) help me how to command it with raw commands over the terminal.

I want to start development of a video software reacting to light and etc the project is really interesting and the only thing left is to inteface it with the servos.

Thanks in advance.

Best regards

Post Edited (f0xdude) : 1/20/2008 2:48:24 PM GMT

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-01-20 02:13
    The Mscomm output should work in a form similar to this

    com.Output = "!SC" &·ch·& ra·& low_byte & high_byte & 13

    DIM ch As Byte·· (channel)
    DIM ra AS Byte·· (ramp)
    DIM position As Integer (16 bit integer)

    The position values·you have in your code are out of limits, position needs to be within 250 to 1250. Also the 16 bit integer position is transmitted as high byte and low byte. Use the following to split position into high_byte and low_byte

    low_byte=position AND &HFF
    high_byte=position>>8

    It's a long time since I messed with anything else but VB Express so you may have to juggle with this to get the syntax right.

    Jeff T.

    EDIT: BTW you might get more responses if you put a subject line to your post.·Edit 2: sorry I got high byte and low byte crossed I think one of your position values is just with the limits.

    Post Edited (Unsoundcode) : 1/20/2008 2:28:18 AM GMT
  • f0xdudef0xdude Posts: 5
    edited 2008-01-20 11:37
    Strange the code doesn't seem to work in VBS

    In visual basic it reports an error here high_byte=position>>8

    Can you give me some more info about the code or if you can a complete example.

    I can use code on c++ also if a full example source code is present i should be able to modify it.

    Does someone have examples in c or c++

    Thanks a million in advance.

    Best Regards

    Post Edited (f0xdude) : 1/20/2008 2:49:01 PM GMT
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-01-20 16:08
    It seems·there isn't a·bitwise shift operator in VB6, but that can be overcome by division

    DIM position As Long
    DIM low_byte As Byte
    DIM high_byte As Byte
    DIM i As Byte

    low_byte=position AND &HFF
    position=position AND &HFF00

    For i =1 to 8
    position /= 2
    Next

    high_byte=position

    Jeff T.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-01-20 18:29
    There is an example of interfacing VB to the USB-PSC in the Completed Project Forum. The link is listed below. I hope this helps. Take care.

    http://forums.parallax.com/showthread.php?p=546069

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • f0xdudef0xdude Posts: 5
    edited 2008-01-20 19:31
    Oh guys, thanks a million.

    However, if someone has C or C++ code please share it here.

    Best wishes!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-01-21 00:22
    Well, you originally mentioned VB so I posted the link to that example. You should definitely have a look in the Completed Projects Forum sometime as there was also a C# example in there.

    http://forums.parallax.com/showthread.php?p=611904

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • PoorYuppiePoorYuppie Posts: 13
    edited 2008-01-21 19:56
    So +1 to the topic here. I'm trying to do the same thing.
  • f0xdudef0xdude Posts: 5
    edited 2008-01-24 13:42
    Does anyone know how do I conver the servo position into High and low byte values in Perl. I was able to find very good scripts which are handling the serial port using a perl module.

    However, I can see that they send raw data and I am now sure about the high_byte and low_byte.

    Can anyone give a hint. Or more information about the high and low byte values themself. What exatly are they and how can they be emulated in the programming languages.

    I am good at perl and c, but I do not have any experience in serial port communication and I find it very hard to understand how to write my own code to control the PSCUSB using c or perl.

    Thanks in advance.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-01-24 15:54
    Okay, well, this is pretty basic integer math.

    A 'byte' can go from zero to 255 (0x00 to 0xFF). A two-byte 'unsigned short int' (aka 'Word' on BS2) can go from zero to 65535 (0x0000 to 0xffff).

    Now, serial communications using RS-232 can only send bytes. So, if you want to send a 16-bit value, you need to clip off the 'high' byte and the 'low' byte and send them as two separate bytes.

    So, if you had a 16-bit value 0xC0ff, you'd send the low-byte 0xFF, then the high-byte 0xC0, .

    Now, to convert 0xC0FF into those two bytes, you 'mask' off the top-bits, and keep the low byte.

    $MyLow = $FullValue & 0xFF;
    $MyHigh = $FullValue >> 8;
  • f0xdudef0xdude Posts: 5
    edited 2008-01-26 06:14
    Hello,

    Yeah! Hey, allanlane5 thanks dude. I'll do some more reading on the topic.

    However, I would like to leave this topic open for anyone who has developed projects regarding the PSC controlled from pc.

    Greetings!
  • kyosho1225kyosho1225 Posts: 1
    edited 2008-03-18 14:48
    Hello, I want use VB6 to communicate to the Parallax PSC(USB). But after looking for much reference for long time. Can't find any helpful.
    Who·can share the complete VB6 source code for me.
    Thanks very much
    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-03-18 21:07
    kyosho1225, your duplicate post in this forum was removed. You stated you could not find any useful information but this thread contains a link to a complete project using VB to control the PSC. Please read the information provided prior to posting requests since in this case that information was already provided. Please view the 6th post above this one.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.