Pioneer 2TM Robotics User Manual


 
ActivMedia Robotics Operating System
always first. Some data are strings of up to a maximum 200 bytes, prefaced by a length
byte. Unlike common data integers, the two-byte checksum appears with its most-
significant byte first (opposite order).
Packet Checksum
Calculate the PSOS/P2OS/AROS client-server packet checksum by successively adding
data byte pairs (high byte first) to a running checksum (initially zero), disregarding sign
and overflow. If there are an odd number of data bytes, the last byte is XORed to the
low-order byte of the checksum.
int calc_chksum(unsigned char *ptr) // ptr is array of bytes
{ // first is data count
int n;
int c = 0;
n = *(ptr++); /* Step over byte count */
n -= 2; /* don't include checksum word */
while (n > 1)
{
c += (*(ptr)<<8) | *(ptr+1);
c = c & 0xffff;
n -= 2;
ptr += 2;
}
if (n > 0)
c = c ^ (int)*(ptr++);
return(c);
}
NOTE: The checksum integer is placed at the end of the packet, with its bytes in the
reverse order of that used for data integers; that is, b
0
is the high byte and b
1
is the low
byte.
Packet Errors
AROS ignores a client command packet whose byte count exceeds 204 (total packet
size of 206 bytes) or has an erroneous checksum. The client should similarly ignore
erroneous SIPs.
AROS does not acknowledge receipt of a command packet nor does it have any facility
to handle client acknowledgment of a SIP. Accordingly, when designing client
applications, keep in mind serial communication limitations, particularly data rates and
physical linkage. Communication between an onboard PC client connected with the
server via a signal cable is much more reliable than over radios, for example. And don’t
expect to send a client command every millisecond if the HOST serial port’s baud rate is
set to 9,600 kbps.
Because of the real-time nature of client-server mobile-robotics interactions, we made a
conscious decision to provide an unacknowledged communication packet interface.
Retransmitting server information or command packets would serve no useful purpose,
because old data would be virtually useless in maintaining responsive robot behaviors.
Nonetheless, the client-server interface provides a simple means for dealing with ignored
command packets: Most of the client commands alter state variables in the server. By
examining those values in respective SIPs, client software may detect ignored
commands and re-issue them until achieving the correct state.
32