RX-TX examples
updated on 06-11-2009

dsNav communication

Protocol description

In order to allow a quick developing of a communication program with dsNav in whatever language, a vey simple communication protocol has been implemented. The dsNav board is a "slave" from the communication point of view. It is waiting for commands from COMM1 or COMM2 and never starts a communication sequence by itself. After the whole command packet has been received and verified, an internal action is performed by dsNav or the requested parameters are sent back to the master as required by that specific command. If the command is unknown or if the packet is not coherent (invalid length or wrong checksum) it is discarded and no action is performed.- Some examples will be provided in some free development environments such Arduino for a microcontroller board, and Processing for any kind of computer operating system. They are so simple and wide open that can be considered as a meta-language easy to be converted in other languages.- A full working Processing computer program that acts as a complete console is provided as well to immediately start configuring and working with dsNav board.

Command protocol

Command strings are variable length type. Any string is composed by an array of N unsigned char:

Pos.  Name              Values range     Description

0       Header            @                      Always present. Needed to synchronize communication

1       Id                    0-9 ASCII         The id of the board addressed by this command.

           Not used here, may be used if more devices are present

2       Cmd                ASCII                All ASCII printable characters may be used

3       CmdLen          Binary               Number (N) of bytes following (checksum included)

                                  ...                      data 0

                                  ...                     

                                  ...                      data x

N      Checksum       0-255                 obtained by simply adding up in a 8 bit variable, all bytes

                                                           that compose the message (checksum itself excluded)

Following an example of such a protocol in Arduino language for command d

- w  

This is a write only command, it sends to dsNav the values read from the sensor board regarding the distance from the obstacles on Left, Center and Right side; the distance from the targets (light sources) on Left, Center and Right side and the value read from digital compass as an integer (2 bytes).

            - TX:

                        CmdLen = 9 , Params 8 (6 bytes + 1 int)      

(6 char values one byte each + 1 int value + checksum)

Example in Arduino language:

void DataPrint(void)

{// send acquired data on serial port to Navigation Control Board

  int i;                      // generic index

  byte TxBuff[16];

  byte ChkSum=0;

  TxBuff[0] = 64;             // Header = "@"

  TxBuff[1] = 0;              // Id = 0

  TxBuff[2] = 100;            // command = "d"

  TxBuff[3] = 9;              // command length

  TxBuff[4] = Dist[L];        // data 0

  TxBuff[5] = Dist[C];        // data 1

  TxBuff[6] = Dist[R];       // data 2

  TxBuff[7] = Target(L);      // data 3

  TxBuff[8] = Target(C);      // data 4

  TxBuff[9] = Target(R);      // data 5

  TxBuff[10]= (byte)(CmpBearing >> 8);// data 6

  TxBuff[11]= (byte)(CmpBearing); // data 7 (data 6 + 7 = int)

  for (i=0; i<=11; i++)

  {

    ChkSum += TxBuff[i];

    Serial.print(TxBuff[i], BYTE);

  }

  Serial.print(ChkSum);

}

            - RX:

                        N/A

(The sender doesn't wait for any parameter back)