Parallax Servo Controller (PSC)(Serial) example code
diafysal
Posts: 92
Parallax Servo Controller (PSC)(Serial) example code ?
Hi
I read the line “Uart updated to support bidirectional communication using a single I/O pin. “ on the download page (Javelin Stamp IDE Installer - Version 2.0.3 ).
And I have tried to find example code.
Could someone please translate this? (from ServoController.pdf)(The VER? command causes the PSC to reply with its firmware version number.)
(see below for finished code)(2005 08 01)
Post Edited (diafysal) : 7/31/2005 11:45:13 PM GMT
Hi
I read the line “Uart updated to support bidirectional communication using a single I/O pin. “ on the download page (Javelin Stamp IDE Installer - Version 2.0.3 ).
And I have tried to find example code.
Could someone please translate this? (from ServoController.pdf)(The VER? command causes the PSC to reply with its firmware version number.)
'{$PBASIC 2.5} Sdat PIN 15 ' Serial Data I/O pin Baud CON 396 ' Constant for 2400 baud buff VAR Byte(3) ' temporary variable FindPSC: ' Find and get the version DEBUG "Finding PSC", CR ' number of the PSC. SEROUT Sdat, Baud+$8000, [noparse][[/noparse]"!SCVER?",CR] SERIN Sdat, Baud, 500, FindPSC, [noparse][[/noparse]STR buff\3] DEBUG "PSC ver: ", buff(0), buff(1), buff(2), CR STOP
(see below for finished code)(2005 08 01)
Post Edited (diafysal) : 7/31/2005 11:45:13 PM GMT
Comments
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Tech Support
dandreae@parallax.com
Http://www.parallax.com
·
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Tech Support
dandreae@parallax.com
Http://www.parallax.com
·
I have been programming Java for only a few days/hours (and Javelin stamp for a few days/hours).
Personally, if I don't find example code it is (for the moment) really difficult for me to write programs.
See the restart method in class Uart. Restart allows you to change direction, pins, baud etc
without the need to create a new uart (remember there is no garbage collection,
so this restarting is very economic regarding resources)
regards peter
eg.
Uart myUart = new Uart(Uart.dirTransmit,CPU.pin0,Uart.dontInvert,Uart.speed1200,Uart.stop1);
//send command
myUart.sendByte(aByte);
//multiple sendByte() if necessary
//wait for buffer empty
while (!myUart.sendBufferEmpty()) ;
//change direction
myUart.restart(Uart.dirReceive,CPU.pin0,Uart.dontInvert,Uart.speed1200,Uart.stop1);
//receive response
response = myUart.receiveByte();
//multiple bytes receive if necessary
regards peter
Post Edited (Peter Verkaik) : 7/30/2005 5:43:40 PM GMT
I get stuck on receiveByte.
Dont mind the missing [noparse]/noparse (not my fault]
You probably get stuck on receiveByte because you missed a byte.
Comment out the System.out.print("1") etc,
as these consume time, and you don't want to consume
time between sending and receiving.
If that still doesn't work, try replacing the while (!sendBufferEmpty())
with just CPU.delay(105); //105 equals 10 msec, increase if not delay enough
to tune time before direction change.
At 2400 baud, bytetime is 10 * 1 / 2400 sec = 4.17 millisec
so 10 msec should allow for two bytes send
Also note that the restart method consumes alot of time also.
regards peter
·
A combination of:
I have the habit of using a current limiting resistor in series with the CPU.pin
Did NOT work well in this case, with the pull up resistor(led) on the PSC
PSC had a tendensy to hang when I started the servo(powered on the servo)
And I get out 3 numbers instead of 3 characters !
So.. how sensitive is the PSC regarding voltage supply?
And the servo power on/off switch. Am I NOT supposed to switch it on/off while running stamp and PSC?
regards peter
The "system out 1 2 3 4" was just something I tried with to see where it stopped.
I have not fixed the display "1.4" instead of "494652" yet.
Should fix that first and then post the code here.
I read the "AN012 - The Text Format Library" but I'm not wiser.
How do I get System.out.print to display the asci character "1" instead of integer "49" ?
myUart.receiveByte() receives 3 integers "49 46 52", how do I convert it to character/string "1.4" ?
How do I store one byte from "public int receiveByte()" in a char ?
Post Edited (diafysal) : 7/31/2005 11:14:35 PM GMT
I read the "AN012 - The Text Format Library" but I'm not wiser.
How do I get System.out.print to display the asci character "1" instead of integer "49" ?
myUart.receiveByte() receives 3 integers "49 46 52", how do I convert it to character/string "1.4" ?
You receive the ascii values of the characters you want to print.
If data holds such a value, then
· Format.printf("%c",data);
will print that character.
System.out.print(data) should print the character also, if data is of type char.
If data is of type int, this will print the decimal number.
regards peter
·
http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/peripheral/servo/psc/
The class allows servo control using 0.1 degree resolution angles.
It supports bidirectional data over a single I/O line or seperate transmit/receive·lines.
I do not have the PSC board and servos, so if you like to test it,
let me know the results.
The PSC class requires the UnsignedIntMath class here:
http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/math/
regards peter
·
But I do not have the time at the moment to test it.
Maybe someone else has?
http://forums.parallax.com/showthread.php?p=556854
regards peter