Shop OBEX P1 Docs P2 Docs Learn Events
help with PSC interface — Parallax Forums

help with PSC interface

grindelgrindel Posts: 68
edited 2005-08-22 15:31 in Robotics
I would like to know what exactly the PSCI.exe servo control program is doing, I have gotten it to work correctly. I bought the USB version of the servo controller. I assume the interface is the same as ther serial servo controller but it doesn't actually say that anywhere in the documentation. I have also tried to connect to the servo controller via Hyperterminal and send it commands to move the servos but have not been successful. I am trying to build a web interface to control the servos.

any suggestions?

Thanks,
Nick

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-08-07 04:47
    Nick,

    ·· The USB version functions just as the standard serial version does...Yous end the same commands as you would from a BASIC Stamp.· Have you checked your baud rate settings?· As for controlling from Hyper Terminal, my concern there is you won't be able to send a valid position value.· The same could be said for some of the other values that are sent.· You may need to write a VB application or similar.· Perhaps someone on here has already done this and can share their experience.· I know I have seen previous messages about it.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • grindelgrindel Posts: 68
    edited 2005-08-07 13:04
    Thanks for the info Chris,

    I'm trying to control it in much the same way as this
    http://www.geocities.com/zoomkat/byte.htm

    all the solutions I have seen so far on the forum use a basic stamp.

    Thanks,
    Nick Sturm
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-08-07 21:36
    Nick,

    ·· That's kind of an interesting, if not round-about way to do something like this.· Most people have a language in mind, such as C++ or VB for doing this.· On the other have, you could just use the PSCI software and store your sequences for later playback.· What exactly are you trying to be able to do?· There might be a more elegant way to accomplish it than through re-directed DOS ECHO calls...



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • grindelgrindel Posts: 68
    edited 2005-08-10 01:57
    I am building a web controlled robot that will have audio and video capabilities. Basicly I have a 400 Mhz laptop that I have built a base for. I am using 17 RPM 540 sized planetary gear motors each connected to an ESC controlled by a USB parallax servo controler. It is for friends that live all over the country to take turns logging into and attending and interacting with others during a party by driving the robot around, aiming the camera, and talking using skype. As you can see I have a specific goal in mind. Unfortunately I have Very little software or hardware experience. I understand the batch files are an inelligant solution, but I think that it will be the easiest for me to set up and understand unless I run into something that is really intuitive.

    I think if I can get this figured out the only thing left is getting the laptop to run the web server, actually serve the web cam at a good resolution with as little lag as possible. I have pretty much used up my budget for hardware so I don't want to get into any more complicated hardware solutions since I have a laptp sitting here just collecting dust.
  • Rick KRick K Posts: 18
    edited 2005-08-10 03:45
    I have done it in vb.net. Here's the 2 lines of code from the driver class that format the command and send it:

    cmdstr = cmd + Chr(port).ToString + Chr(speed).ToString + _
    Chr(pos Mod 256).ToString + Chr(pos \ 256).ToString _
    + vbCrLf

    gMSComm.Output = cmdstr

    You can figure that port, speed and pos are parms, and that gMSComm has been set up by the driver class, but this will format the command to be sent.

    Let me know if this approach is of interest to you.
  • grindelgrindel Posts: 68
    edited 2005-08-10 20:49
    Forgive my ignorance,

    like I said, I have very little programming experience (some Basic and FORTRAN)...

    So Rick, is this really what you use to output data directly to the servo controller? I expected to see the !SC preamble like it says in the instructions. unless cmd is set to "!SC", then I understand. also, I guess Chr turns a decimal number into hex? .ToString adds it to the end of cmdstr? vbCrLf is a variable set to $0D?

    I am having trouble figuring out what lowbyte and highbyte are.

    thanks,

    -n
  • Rick KRick K Posts: 18
    edited 2005-08-11 01:39
    yes. this is the line from the vb.net program that formats the command string. You're right, cmd is set to "!SC". Sorry, I didn't catch that omission until later.

    The Chr function converts an ascii code into a character.

    ToString is vb.net's way of turning the resultant character into a string object on which the concatenation operator "+" will work. All of this is pretty basic VB - you might want to get yourself a vb6 or vb.net primer to guide you.

    Oh, and vbCrLf is a constant in VB which gets converted to ascii 10 and ascii 13 (carriage return and line feed) - I just found this to work, honestly, as it's a common way to terminate a string·and don't remember if I tried the ascii or hex equivalent of "$0D". I did this several months ago.

    If you really want to do without, though, here is a snippet from an early test program I wrote that shows what comes before the lines I gave you earlier:

    NOTE: also note that this is for vb.net, not vb6. They're a little bit different, but the idea is the same. I didn't go much further than this with with the PSC, as I found a controller which better suited my needs. I can give you the actual class file for my PSC driver class, but that uses some conversions to go from degrees to PWM values, so I didn't want to confuse you.

    This program takes the minimalist approach, which I've always found helpful.

    '********************************************************************
    'you can see that this is taking what's typed into two text boxes and using one for
    'the port num and one for the position
    'I created vars for the other parms like cmd and speed so I could easily change them
    'as I was experimenting.
    '********************************************************************

    Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click

    Dim cmd
    Dim port
    Dim pos
    Dim speed
    Dim cmdstr

    'initialize in case nothing in text boxes

    cmd = "!SC"
    port = 0
    pos = 750
    speed = 7

    MSComm1.DTREnable = True
    MSComm1.PortOpen = True

    pos = CInt(TextBox1.Text)
    port = CInt(TextBox2.Text)

    cmdstr = cmd + Chr(port).ToString + Chr(speed).ToString + _
    Chr(pos Mod 256).ToString + Chr(pos \ 256).ToString _
    + vbCrLf

    MSComm1.Output = cmdstr

    MSComm1.PortOpen = False

    End Sub

    Post Edited (Rick K) : 8/11/2005 1:41:37 AM GMT
  • GerhardGerhard Posts: 17
    edited 2005-08-11 17:48
    Hi Rick, hi grindel!

    I have the same problem. I would like to use C under Linux to do the communication with the serial controller. Somehow I can not figure out to generate the correct sequence in order to make any servo move. I attach a snipplet of the program with the hoe that someone could help me.

    Cheers,
    Gerhard

    .
    .
    .
    unsigned char getLowByte (unsigned int value);
    unsigned char getHighByte (unsigned int value);


    unsigned char getLowByte (unsigned int value)
    {
    unsigned char result = (unsigned char) value & 0xFF;
    return result;
    }

    unsigned char getHighByte (unsigned int value)
    {
    unsigned int tmp = value;
    unsigned char result;

    tmp = tmp & 0xFF00;
    tmp = tmp >> 8;
    result = (unsigned char) tmp;

    return result;
    }


    // this is the mainline thingee
    int main(int argc, char *argv[noparse]/noparse)
    {

    if (OpenAdrPort("1") < 0)
    {
    printf ("konnte Port nicht oeffnen\n");
    return 1;
    }


    int i;
    int j;
    unsigned int pw;
    unsigned char ra ;
    unsigned char ch ;
    unsigned char cr ;
    unsigned char cposh;
    unsigned char cposl;
    char preamble = "!SC";


    pw = 300;
    ra = 0;
    ch = 1;
    cr = 0x0D;

    for (j = 0; j < 10; j++)
    {

    pw+=10;
    cposh = getHighByte (pw);
    cposl = getLowByte (pw);

    for (i = 0; i < strlen (preamble); i++)
    {
    printf("%c", preamble);
    WriteBinAdrPort(preamble);
    }

    printf("%c", ch);
    WriteBinAdrPort(ch);
    printf("%c", ra);
    WriteBinAdrPort(ra);
    printf("%c", cposl);
    WriteBinAdrPort(cposl);
    printf("%c", cposh);
    WriteBinAdrPort(cposh);
    printf("%c", cr);
    WriteBinAdrPort(cr);

    sleep (1);

    }

    CloseAdrPort();
    return 0;
    } // end main
  • grindelgrindel Posts: 68
    edited 2005-08-21 13:08
    I can't find anywhere to get a good definition of high byte and low byte
    it is my understanding that this is how it works
    for
    2000
    the binary = 11111010000
    0000011111010000
    00000111 | 11010000
    high byte | low byte
    $07 $d0

    is this wrong?

    ok secondly in my ignorant wanderings I have downloaded a usb port sniffer to figure out how exactly "!SC" is turned into hex since echoo doesn't seem to be able to handle anything but hex numbers:
    it appears that the preamble is translated into $f1, but I am not tottally sure about this. There is a bunch of other stuff going on that I have to sort through

    I have gotten the servo to respond, a couple of times, but usually it just rotates to the stops and I have to shut it off and reset it using the parallax supplied software, here is what I have so far:

    test.bat

    @echo off
    mode com3:2400,N,8,1 >nul
    echoo $f1$01$00$5c$01$0d> com3
    pause
    echoo $f1$01$00$d0$07$0d> com3
    pause

    this attempt is to take servo 1 from 500 to 2000, and it doesn't work. I can see the green light flash and the past successes seem to indicate I'm doing everthing but the high byte and low byte right.

    thanks in advance
    -n
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-08-21 15:05
    grindel -

    I honestly don't understand what ECHOO is supposed to do, but regardless of what it·is expected to do, a positioning command to the Parallax SSC looks basically like this:

    ···················· Preamble········· C············· P··········· R······· Terminator
    Typical············· !SC···············1··········· 128·········· 7············ $0D
    Type·············· ASCII·········· binary······ binary····binary······ binary
    Size in bytes······ 3················· 1············· 1·········· 1·············· 1
    Range·············· n/a············· 0-31······ 0-255····· 0-15·········· n/a

    Where:············C = servo number, P = position, R = ramping

    Thus, an SSC positioning command is a total of 3 + 1 + 1 + 1 + 1 = 7 bytes long. All of the commands you have shown above are 6 bytes long. Right there, I'd say there's a problem, if I understand the SSC syntax for a positioning command correctly, regardless of what the contents of those bytes turns out to be, after processing by the ECHOO program.

    Regards,

    Bruce Bates
  • grindelgrindel Posts: 68
    edited 2005-08-21 15:58
    Bruce,

    thanks a lot! I thought !SC would be three bits but the usb sniffer said otherwise, but it was also giving me all kinds of wierd information.

    I thought (and the documentation seems to support) that Position was a 2 byte word that was then split up into high byte and lowbyte

    echoo is a program I got off of the zoomkat page
    http://www.geocities.com/zoomkat/byte.htm
    that explains, in a cookbook method, how to make a pan/tiltable web cam using redirected echo commands. The difference is he is using a mini-SCC which I guess, has a 3 byte format.

    but like I said, it only handles hex information (or at least that is my understanding
    http://www.lookuptables.com/
    is where I got the info for turning !SC into hex

    test5.bat:

    @echo off
    mode com3:2400,N,8,1 >nul
    rem this is for position 700
    echoo $21$53$43$01$00$5c$01$0d> com3
    pause
    rem this is for position 2000
    echoo $21$53$43$01$00$d0$07$0d> com3
    pause

    note: position 2000 still seems to be high as it is still straining

    but this makes servo 1 turn one way, then the other, whether or not it is actually position 700 and 2000 I don't know yet.

    Woops:
    Reading the servo controller instructions again, it appears that 1250 is the highest I can go. Since each step is 2 microsecs

    Post Edited (grindel) : 8/21/2005 3:57:51 PM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-08-22 15:31
    grindel said...
    Bruce,

    thanks a lot! I thought !SC would be three bits but the usb sniffer said otherwise, but it was also giving me all kinds of wierd information.

    You would need three BYTES to contain any three characters of text.

    I thought (and the documentation seems to support) that Position was a 2 byte word that was then split up into high byte and lowbyte

    My sincere apologies on that miscue on my part. I didn't realize there were 3-4 different PSC Manuals (Version 1, Version 2, Serial, USB). I apparently grabbed the Version 1 documentation without realizing it. In Version 1, only one byte was required for the position parameter. Later that requirement became a WORD (two bytes), as with your version apparently.

    echoo is a program I got off of the zoomkat page
    http://www.geocities.com/zoomkat/byte.htm
    that explains, in a cookbook method, how to make a pan/tiltable web cam using redirected echo commands. The difference is he is using a mini-SCC which I guess, has a 3 byte format.


    If you're speaking here of the Scott Edwards Serial Servo Controller, I'd honestly have to look that up, but regardless of that input format, ·it has no bearing here.

    but like I said, it only handles hex information (or at least that is my understanding
    http://www.lookuptables.com/
    is where I got the info for turning !SC into hex

    There seems to be some great mystery about HEX. Hex is just a convenient form of binary reperesentation. All data inside a Stamp or any other "computer" is in binary. It may be represented in many different EXTERNAL formats merely for the convenience of the programmer.

    test5.bat:

    @echo off
    mode com3:2400,N,8,1 >nul
    rem this is for position 700
    echoo $21$53$43$01$00$5c$01$0d> com3
    pause
    rem this is for position 2000
    echoo $21$53$43$01$00$d0$07$0d> com3
    pause

    note: position 2000 still seems to be high as it is still straining

    but this makes servo 1 turn one way, then the other, whether or not it is actually position 700 and 2000 I don't know yet.


    Unless I'm misreading the PSC manual, I honestly don't see why that's working at all, without the leading "!SC" header, unless that's being supplied by the ECHOO program.

    Woops:
    Reading the servo controller instructions again, it appears that 1250 is the highest I can go. Since each step is 2 microsecs

    According to the PSC Revision B Manual, 1250 IS the end of the range for that parameter. There is also a warning in the text that you may have to back off slightly from that 1250 value if your servo seems like it's straining.
    ·
    Regards,
    ·
    Bruce Bates
Sign In or Register to comment.