2. Protocol Design - maxosprojects/open-dobot GitHub Wiki

Protocol Design

Requirements

Protocol must support:

  • acknowledgement of receipt of command
  • command cancellation
  • emergency actions
  • command buffering and buffer dropping
  • provide both low-level (step) and mid-level (step tuples, sequences, etc.) commands for different kinds of applications
  • be simple enough for applications to implement
  • have reference application implementation in C++, Python, Java and other languages, as well as ROS node (implementing geometry messages http://wiki.ros.org/geometry_msgs)

Current implementation

The protocol format is as follows:

Field Size Description
Command ID 1 byte
Payload arbitrary Determined by command ID
Checksum (CRC) 2 bytes CCITT CRC

Checksum is calculated from Command ID and Payload fields and added as Checksum field following Payload.

The algorithm in firmware (the piece of software that runs on Arduino) for command handling is the following:

  1. Compute checksum for every received command when all the bytes for that command are received, including checksum
  2. The computed checksum is compared to the one sent with the command
  3. If checksums don't match the command is ignored and algorithm returns to item 1
  4. If checksums match the command is processed further
  5. If command does not assume any return value the algorithm goes to item 7
  6. If command assumes a return value(s) the value(s) are sent via the serial interface and checksum computed for the received command is updated to include checksum for the returned value(s) (as if the values immediately followed the command's payload)
  7. The computed checksum is sent via serial interface to confirm successful command receipt and ensure consistency

In the DobotDriver (and SDK, consequently) every read from the serial interface (for command confirmation and returned values) is set to time out after a while (default is 25ms). In case timeout occurs the return from the command will be False if a boolean is expected or 0 as the first element of the returned tuple if the command assumes a value returned. See the following example:

Command Expected return Return when command confirmed Return when command was lost, corrupted or timed out
SetCounters No return needed True False
GetCounters Base,Rear,Front Tuple(1, Base, Rear, Front) Tuple(0, 0, 0, 0)