Issue interfacing the Parallax Servo Controller - USB
I am writing an interface for the USB Parallax Servo Controller in C# (Microsoft 2005 Express). I have a working set-up now.
However:
If I send a command e.g. !SCVER? the result in the buffer is not 3 bytes as listed in the documentation, but 11 bytes. That is 8 bytes for the (repeated) command including $0D and 3 bytes for the result.
For the "set position" command 8 bytes are returned instead of "none" as stated in the documentation.
Question:
Is there a way to disable the echo of the command by the PSC ?
Or is this an error in the documentation ?
Herman.
However:
If I send a command e.g. !SCVER? the result in the buffer is not 3 bytes as listed in the documentation, but 11 bytes. That is 8 bytes for the (repeated) command including $0D and 3 bytes for the result.
For the "set position" command 8 bytes are returned instead of "none" as stated in the documentation.
Question:
Is there a way to disable the echo of the command by the PSC ?
Or is this an error in the documentation ?
Herman.
Comments
Is it possible that you have the "echo" turned on as part of the serial connection. (i.e. You're getting the "local" echo from the send because of the settings on the port or stream object you're using.)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John R.
8 + 8 = 10
But as far as I discovered, the "echo" is a feature of the "serial device recieving" and not the device that is sending. I could not find any clues in the SerialPort class documentation...
So now my assumption is that the PSC USB should get a command to turn off "echo", or that the PSC USB is programmed to give an echo. In both cases the documentation needs an update.
Herman.
It sounds like you have this 'half-duplex' echo turned on in C#.
·
·· I am in the process of confirming this, but I believe due to the nature of the main serial interface (being a single I/O pin) that data is always going to be echoed back as it is sent.· Your C# program must filter what it sends from the responses.· Hence the ‘set position’ command isn’t really returning a response, but rather you’re seeing echo from the serial I/O pin.· I hope this helps.· Take care.
EDIT: Confirmed, since there is a single I/O pin anything sent is connected to, and therefore sent back to the PC.· This doesn't affect the BASIC Stamps since they have no FIFO buffer.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Post Edited (Chris Savage (Parallax)) : 10/16/2006 10:55:15 PM GMT
This should probably be an "addendum" to the docs, especially as the USP version of the PSC seems targeted at a PC interface application.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John R.
8 + 8 = 10
·
·· I will pass this information along.· As a note, while the USB-PSC does have a USB Port, it isn’t specifically targeted at PC use.· It is essentially a serial version with the USB Port added and can work in place of the serial version on a BASIC Stamp just fine.· It is the nature of the single I/O pin interface that causes the echo.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I didn't realize the serial port was still available. I guess I didn't look at the specs very well. I now see the reference to connecting the BOE or other device. What "threw me" was that the connections weren't labeled on the board diagram in the user manual. My bad for not looking closer.
I'll have to keep this in mind...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John R.
8 + 8 = 10
Thanks for your help. I can go ahead now
My sugestion is to update the manual of the PSC-USB (it is a great product).
Additionally the actual documentation of the PSC-USB does not refer to the programming options.
This is only mentioned at the page on the site where a reference is included to the documentation of the PSC-serial for programming.
Combining the documentation to 1 will to my opinion make the PSC-USB product more accessible.
When I finish testing in the next weeks I post the C# interface (as is) in the "Completed projects" forum. Since it is .NET it can also be used for VB etc.
Herman.
I am also using the parallax servocontroller 28823 (USB). In my program, I basically wait until all 8 characters are echoed back before
continueing, but I found that from time to time, not all characters are echoed back, and my program gets stuck waiting for the 8th
character. Also, the !SCVER? command seems to be interpreted as a move command to servo channel 0 occasionally.
My (c++) program runs on an armadillo-9 processorboard (www.atmark-techno.com/en/products/armadillo/a9).
Linux kernel 2.4.27-a9-1 with support for the FTDI-chip is installed on the armadillo-9, and I'm using
libSerial to talk to the servo controller.
Any help is much appreciated.
thanks,
Kwokkie
I have found a version v2.3 of the PSC 28023 documentation on this website :www.zerko.ch/parallaxshop/motorservo/50150395c006d2559.php.
While the version on www.parallax.com is v2.2. Is the documentation on zerko.ch an unofficial one? (The only difference that I spotted is that in
v2.3 is mentioned that the serial port settings are 8 bits, no parity, 2 stopbits.)
also, the documentation states that the reply of the !SCRSPx command is x y z, where x is the channel, and z:y is the value reported.
This was a bit confusing to me, as I interpreted z:y as z being the most significant byte, and y being the least significant.
I'm fairly certain that it's the other way around (z is low byte).
kind regards,
Kwokkie
What I do is to clear the buffer before I issue the commands where a result is read: !SCVER?, !SCSBR... and !SCRSP.
I have (till now) no problem reading the results.
For the "move" command I empty the buffer after the instruction to prevent buffer overflow.
Note that for comands where you read a result, your need to give the PSC USB some time to process.
If you read too quickly you will not recieve all the output characters (e.g. only the first 2 out of 3 of the version number).
For the commands !SCVER?, !SCSBR... and !SCRSP I use a delay of 0.4 seconds.
For the application I build this waiting time is not an isue.
I hope this helps.
(It would be nice if the manual was more specific about this ...)
Herman.
PS: the z:y specs in the docs are correct ...
·
·· We are looking into revising the manuals.· Thanks for your continued input.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I'm not sure I understand your comment about reading too quickly though. If I read my input buffer too early, it should simply be empty until the characters actually arrive. I'm not sure I can miss incoming characters by reading my input buffer too early.
I use a timeout of 4 seconds to wait for the characters to echo back, but still get a timeout occasionally (if I run my program for an hour or so).
I'll go study the libSerial library some more, maybe my understanding of libSerial is off.
thanks,
Kwokkie
This is just a mere passing comment relative to your question:
You asked:
"I'm not sure I can miss incoming characters by reading my input buffer too early."
I am NO EXPERT on the PSC, however, it _may_ be necessaey for one to pause or wait before accessing any given input/output device to permit it to operate within in its operational parameters.
Regards,
Bruce Bates
Post Edited (Bruce Bates) : 10/19/2006 1:17:14 PM GMT
That is really odd. When I reset the servo controller, all control signals are set to 750, and if I issue a !SCRSPx command, the only way I get the number 750 back is when I treat the 2nd character (y) as high byte and 3rd character(z) as low byte.
Well, I'm using the libSerial to receive incoming characters. If I understand the library correctly, the library handles incoming signals or interrupts from the serial port, and pushes the data in the input buffer, if there is any, on a seperate queue for me to read. Basically, I just wait until this queue reaches a certain size (8 characters in my case) before flushing the queue and continueing, with a timeout of 4 seconds. I am assuming that 4 seconds is more than enough time for the PSC to send me the characters. You do have a point that the way the OS accesses the PSC might cause trouble, though. I hope not, because I have little control over that
thanks for your explanation,
Kwok
I can confirm that z is the lowbyte and y the highbyte.
Sometime ago I wrote a java class and encountered this
documentation error also.
For your convenience I have attached that java class.
It also has info in it, regarding networked board and
how to handle replies.
regards peter
PS. You can open the file with notepad.
I only get correct results if I swap the results in PSCBuffer.
Herman.
public UInt16 GetServoPosition(byte Channel)
{
byte[noparse]/noparse Token = new byte[noparse][[/noparse]8];
byte[noparse]/noparse PSCBuffer = new byte[noparse][[/noparse]11];
// The buffer may not be empty, so this is done explicitly
Com.DiscardInBuffer();
//································01234567
Token = Ascii.GetBytes("!SCRSPc\x0D");
// Syntax: !SCRSP x $0D (no spaces)
//············ x = servo channel, binary number 1 - 31 (16 - 31 on second board)
// Reply: x y z (no spaces / 3 bytes)
//·········· z:y = 2 bytes (uint16) for position
Token[noparse][[/noparse]6] = Channel;
PSCWrite(Token);
// wait 0.4 seconds to give the PSC the chance to respond
Pause(0.4);
// returns the command (8 positions) and x y z (3 positions)
Com.Read(PSCBuffer, 0, 11);
// High and Low byte have to be in different order for BitConverter.ToUInt16
PSCBuffer[noparse][[/noparse]0] = PSCBuffer[noparse][[/noparse]10];
PSCBuffer[noparse][[/noparse]1] = PSCBuffer[noparse][[/noparse]9];
// return only the position
return (UInt16) (BitConverter.ToUInt16(PSCBuffer, 0) - ServoStart);
}
PSCBuffer[noparse][[/noparse]0] = PSCBuffer[noparse][[/noparse]10];
PSCBuffer[noparse][[/noparse]1] = PSCBuffer[noparse][[/noparse]9];
// return only the position
return (UInt16) (BitConverter.ToUInt16(PSCBuffer, 0) - ServoStart);
}
You put z in [noparse][[/noparse]0] and y in [noparse][[/noparse]1],
and since [noparse][[/noparse]0] is the lowbyte, z:y in the doc should by y:z
(it is normal practice to name highbyte first in case of 16bit value)
regards peter
on x86 architecture CPU's, multibyte numbers are stored in Little Endian order, meaning that the least significant bytes are stored in the lower memory adresses.
When converting the first two bytes of PSCBuffer to a 16bit integer, PSCBuffer[noparse][[/noparse]0] will be treated as low byte, and PSCBuffer as high byte. If you would compile
your code for a Motorola processor, for example, it would be the other way around.
Peter,
thank you for your source code. Is the source for the Uart class that you use available too?
regards,
Kwok
This psc code and more is available at the yahoo group
http://tech.groups.yahoo.com/group/JavelinCode/
The Uart class is located here:
http://tech.groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/core/
but I attached it also for you.
regards peter
anyway, thanks everyone for your help!
--Kwokkie
Post Edited (kwokkie) : 10/23/2006 4:15:11 PM GMT