Shop OBEX P1 Docs P2 Docs Learn Events
Serial PSC Commands — Parallax Forums

Serial PSC Commands

WaldoDTDWaldoDTD Posts: 142
edited 2006-01-24 16:26 in General Discussion
Hey, does this command work for the PSC? I am using a Javelin Stamp and I am sending this string using a char array and sending letter by letter to the PSC using a Uart class on the string. I know that someone has interfaced the PSC with a Javelin before so how would you handle the transmission from the stamp to the PSC.
Command array =·!SC1085.LOWBYTE2304.HIGHBYTE
-Hacker
«1

Comments

  • Jon KeinathJon Keinath Posts: 146
    edited 2005-11-07 00:01
    Hacker,
    Here is a code snipit of what I used to communicate with the psc on my javelin based robot...Perhaps this will help.

        txUart.sendString("!SC");         //Servo Controller
        txUart.sendByte(pscChannel);      //Channel of Servo
        txUart.sendByte(ramp);            //Ramp Rate
        txUart.sendByte(pulseWidth);      //Pulse Width
        txUart.sendByte(pulseWidth>>>8);
        txUart.sendByte(0x0D); 
    
    



    here is the setup for the txUart
         static Uart txUart = new Uart(Uart.dirTransmit,CPU.pin13,Uart.dontInvert,
                                                 Uart.speed2400,Uart.stop1);
    
    



    more examples can be found here

    www.kettering.edu/~kein0105/robotics.html

    -Jon
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-11-07 21:57
    Wow, Thanks!-Hacker
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-11-07 23:41
    I am assuming that the .Lowbyte is just like the second int value that you enter for a PWM class on the regular javelin stamp correct?-hacker
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-11-16 00:30
    Ok, attached is the new code that I am using for the Javelin stamp, I need to know why the commands aren't going through, the green light on the Servo controller comes on indicating that it recieved something from the stamp but there is no movement in the servos. txUart is for the SC/BOE connection and comUart is to send stuff to the computer, rxUart is the same.
  • Jon KeinathJon Keinath Posts: 146
    edited 2005-11-16 00:54
    I think that the problem may be the line
    txUart.sendByte(pscChannel);
    


    is missing, it tells the psc which servo to move.
    It should go after the !SC like this:
    txUart.sendString("!SC");
    txUart.sendByte(pscChannel); <<insert this line
    txUart.sendByte(ramp);
    
    



    -Jon
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-11-16 00:58
    wow that was a large oversight thanks, Also if you don't mind I am going to use some of your protocols for the servos.-Hacker
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-16 01:06
    Here is the·com port wiring

    attachment.php?attachmentid=73916



    I think your SERIAL_CTS_PIN is actually your SERIAL_RTS_PIN.

    In hardware flowcontrol , tx is paired with cts, and rx is paired with rts.

    tx and rts are outputs, rx and cts are inputs.

    tx connects to rx, rts connects to cts (eg. output connects to input)



    Do you really want the PSC to wait transmitting until javelin is ready to receive (current rxUart),

    or do you want the javelin to wait transmitting until the PSC is ready to receive?

    Current txUart lets the javelin transmit to PSC at will.



    regards peter
    236 x 299 - 6K
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-11-16 01:11
    So your saying that i should add in a CPU.delay for the Servo controller to setup correct? Also the Uart that is set to the TX and RTS pins is comUart which uses the variable SERIAL_TX_PIN2 for it's normal TX pin and the SERIAL_RTS_PIN for the RTS So I do believe that I have the right pin configuration. Also, should it be that the Javelin waits for the SC or should the SC wait for the Javelin (current setup).
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-11-16 01:50
    Wait nevermind I got the servos to work! roll.gif
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-16 02:01
    What I was saying is your pin naming is confusing.
    Current setup:

    · static Uart comUart = new Uart( Uart.dirTransmit,SERIAL_TX_PIN2,Uart.dontInvert,
    ························· SERIAL_RTS_PIN, Uart.dontInvert, Uart.speed9600,
    ························· Uart.stop1 );

    You define a transmit uart for the pc, SERIAL_TX_PIN2 is the pin that the
    javelin uses to transmit data to the pc, and at the pc side it connects to RX.
    For hardware handshake, tx is paired with cts. So it should be

    · static Uart comUart = new Uart( Uart.dirTransmit,SERIAL_TX_PIN2,Uart.dontInvert,
    ························· SERIAL_CTS_PIN, Uart.dontInvert, Uart.speed9600,
    ························· Uart.stop1 );

    SERIAL_CTS_PIN is the pin that the javelin uses to check if it may transmit,
    and at the pc side it connects to RTS.
    Javelin will transmit if pc is ready to receive.



    · static Uart txUart = new Uart( Uart.dirTransmit,SERIAL_TX_PIN,Uart.dontInvert,
    ························· Uart.speed2400, Uart.stop1 );

    You define a transmit uart for the PSC, SERIAL_TX_PIN is the pin that the
    javelin uses to transmit data to the PSC, and at the PSC side it connects to RX.
    Javelin will immediate transmit data if available (does not wait for PSC to be ready)



    · static Uart rxUart = new Uart( Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert,
    ························· SERIAL_CTS_PIN, Uart.dontInvert, Uart.speed9600,
    ························· Uart.stop1 );

    You define a receive uart for the PSC, SERIAL_RX_PIN is the pin that the
    javelin uses to receice data from the PSC, and at the PSC side it connects to TX.
    For hardware handshake, rx is paired with rts. So it should be

    · static Uart rxUart = new Uart( Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert,
    ························· SERIAL_RTS_PIN, Uart.dontInvert, Uart.speed9600,
    ························· Uart.stop1 );

    SERIAL_RTS_PIN is the pin that the javelin uses to inform PSC that·it may transmit,
    and at the PSC side it connects to CTS.
    PSC will transmit if javelin is ready to receive.



    regards peter
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-11-17 03:31
    Well that should be a moot point because I have taken out tranmission protocols to the computer in my program on the stamp. I am having trouble again with the main PC program link (if this isn't the appropriate forum please reccomend one for the Java comm api). I have set the program to setup the parameters for the stamp to equal those set by the uart that recieves but I think the problem is what name it sets the application as ("simplewrite") would this parameter make a difference?-Hacker
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-17 11:59
    There is an example of Basic Stamp communicating with Java API on pc here
    ·http://www.geocities.com/navacrony/toddler.html
    You should be able to get the Javelin communicate in the same way using I/O pins and Uarts.
    regards peter

    ·
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-11-19 22:38
    ok, The stamp code works, I have tested it in the hyperterminal. Now the COMM API program is not working correctly. I have the code and it opens the COM port and sends data but it doesn't do anything else ie there is no movement in the stamp. Is there a difference between the way the hyperterminal sends data and the Java API? Thanks!-Hacker
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-19 22:46
    Check if your program is sending ASCII bytes. When I compiled a source
    for the udp programs for the PINK (it was a VB source) it first didn't work because
    it was UNICODE encoded. After I changed it to ASCII encoding it worked.
    I don't know if encoding is used in your program but do check.

    regards peter
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-11-20 00:15
    I am using the .getBytes() method in the JDK 1.5
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-11-20 07:37
    Does this return ASCII or Unicode?
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-11-24 03:59
    Ok, I have had enough of this. Is there any particular protocol that the code has to follow when it is transmitting to a recieve Uart on a Javelin Stamp? The Hyperterminal program in windows seems to handle this easy enough I just type in the characters in the program and the stamp picks it up no sweat. However, when I try to run the Java program to get it to run, this is an entirely different story. I am posting the code of what I have so far with the code, it is basically a modified version of the sample "SimpleWrite" included in the Java COMM API. I have just made this thing send asd instead of "Hello World!". I know that the code on the Javelin is ok because that works out fine when I tested it with the Hyperterminal. Here is what I have so far, Wintermute is loaded onto the Stamp while SimpleWrite is the program that runs on the computer.-Signol
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-24 04:45
    Run the attached program on the Javelin.

    It displays whatever is received by the Uart. Let your pc program send its data

    and see in the javelin ide message window what is received.

    Set pin and baudrate for your setup.

    You require 2 com ports on your pc.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-24 05:55
    I found some errors·in your Javelin file.

    Be sure your pc program sends a '\r' (13 decimal) otherwise

    bufferMessage() never returns.

    regards peter
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-11-30 02:18
    Ok, I ran the test, the program returned the values 61,73,64,0D. These values correspond with the correct characters in my program, a,s,d. Also the 0D is CR right? Taking this into account, I have been trying to understand your code a bit better and I would like to know how you turned the bytes into the hex numbers. Is it the line
    Format.printf("%02x ",0xFF & c); //display hex value
    where 0xFF & c turns the byte into a hex value? I tried to run my original wintermute program again but it didn't work. I just need to know if you changed the bytes to hex values in some way similar to the way you find the highbyte of a number by adding >>>8 to the int number. Would it be more relevant if I create a buffer and store the bytes in there and then terminate the handling when it comes accross the the value 0D? Thanks!-Signol
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-30 05:17
    The line
    Format.printf("%02x ",0xFF & c);
    displays the parameter as a hexvalue. Because the parameter is an integer (not a char)
    I use c&0xFF to make sure the integervalue equals the·value of c.·If c >= 0x80 and you don't
    use &0xFF than the resultvalue would be 0xFF80-0xFFFF (the parameter gets sign extended).
    %02x instructs printf to display the integervalue as 2 hexbytes, preceeded by 0's if
    the value < 16 (so 11 is printed as 0B, not just B).
    Suggested handling:
    wait for cmd false; then you know previous command was sent
    place command in cmdbuf,·for example "asd",0 (closing 0 !!) in·the cmdbuf, then set cmd true.
    Notice that the state machine adds CR,LF to the bytes in cmdbuf (so 'a','s','d',CR,LF gets sent)
    On the javelin you assemble the received bytes until CR,LF is received. On the fly you
    change the received CR,LF to·just a newline ('\n') or discard it altogether.
    So a complete message received would be "asd\n" or "asd". Then you can let the javelin
    execute the·command.
    Notice that I use CR,LF as end of message marker so do not use those as regular data.
    If you do need to send binary values, either send them as hextext (11 would be send as 0x0B)
    or figure out another way to let the javelin know the message has ended.

    regards peter

    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-30 05:27
    Here is a test program that displays in the IDE message window

    what command was received. If your command is "asd"

    it will display CMD: asd

    regards peter
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-12-01 01:15
    Ok, Ran this program, nothing was returned, I don't think that a Uart was added for the send/recieve of the command set. I ran the test again and it returned the same values. I was wondering if I could instead use hexadecimal bytes rather than ascii characters and when the byte array hits 0D it returns the command set. -signol01
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-12-01 01:20
    Strike that last post I added in the rxUart object to the program and ran it, it returned asd, here is the revised code attached!-signol01

    Post Edited (Signol) : 12/2/2005 5:07:44 PM GMT
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-12-01 01:52
    Ok, got it. Here is the updated Wintermute Source Code for all those who want it. Also I am including a sample program to communicate with the stamp in java code for anyone who wants to incorporate this in their project and need help. It uses the Java COM API version 2.0 from java.com. Here it is.-Signol01

    Post Edited (Signol) : 12/1/2005 2:06:49 AM GMT
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-01 02:36
    Sorry about that.

    I was thinking you tried to send commands via the JIDE port, but that was another thread,

    so I used Terminal for input. You send commands via a Uart so your change is correct.

    Can you rename the attachement JideTerm_protocol_test in your previous post to

    Uart_command_receive_test or something like that.·To avoid confusion.

    regards peter
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-12-02 17:09
    done
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-12-09 16:07
    Ok, another problem, the servo positions don't correspond to the positions I find using the PSC software. When i put in the value 1144 the servos go straight to 2500 all of them!! What am I doing wrong? here is my code that I am using the servo program is in the stamp core.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-09 16:45
    You need to change the line

    ··········· index = 0;

    in main()

    into

    ··········· cmdlen = 0;

    otherwise you don't parse a received command from the start.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-09 16:59
    Sorry, I missed that index is a global var.

    Add the line

    ··· cmdlen = 0;

    after the line

    ··· index = 0;

    regards peter
    ·
Sign In or Register to comment.