ADVENTURES IN PROPELLER PROGRAMMING
record that I'm not the first to do this.
When Lou sent the Dynamixels, I
checked the Object Exchange (ObEx)
and found a driver called
DynaComV3 by Dave Ratcliff. It
works and got me very excited about
using Dynamixels. That said, there
were several aspects of Dave's driver
that didn't suit my particular
programming style. I decided to
"liberate" the good ideas that stuck
out, and write the rest of my driver
from scratch.
Communications
Breakdown
■ FIGURE 3. Dynamixel network.
Communications between the
master controller (Propeller) and the Dynamixel follow a
standard command/response model. The master will send
an instruction packet that includes the address of the
intended target. If that target exists on the buss, it should
respond with a status packet. Valid IDs for individual units
are 0 ($00) to 253 ($FD); ID 245 ($FE) is used as a
broadcast ID for packets intended for all devices.
The checksum algorithm used is very simple; it's the
low byte of the inverted sum of the ID, length,
Instruction/Error, and parameter bytes. The Dynamixel
object uses this method to calculate the checksum of an
<$FF>
<$FF>
<ID>
<Length>
<Error>
<Parameter1>
...
<ParameterN>
<Checksum>
pub checksum(p_buf) | len, cs
In this case, however, the master does not expect a
response. The value 255 ($FF) is not available as an ID as
it is used as part of the packet header. A simple checksum
is included in command and response packets to validate
the message.
len := byte[p_buf][3] + 1
cs := 0
p_buf += 2
The command (instruction) packet is constructed like
this:
repeat len
cs += byte[p_buf++]
<$FF>
<$FF>
<ID>
<Length>
<Instruction>
<Parameter1>
...
<ParameterN>
<Checksum>
return !cs & $FF
At the top, we grab the length byte from the buffer
and add one to it; we do this to account for the length
byte in the message. Then, we clear the working
checksum value and skip past the two header bytes. A
simple loop accumulates the rest of the bytes in the
packet. At the end, we invert the checksum and then trim
to eight bits.
The response (status) packet is similar, with the
instruction replaced by an error byte:
By having this method use a pointer to a buffer, we
can utilize it to create the checksum for an instruction
(command) packet, and use it to calculate the checksum
of a status (response) packet. By comparing what we
calculate with the checksum contained in the status
packet, we can validate the response.
The communications between the Propeller and the
Dynamixels are serial which means we'll need a UART to
handle the details. We've done this before, and with the
Propeller it's quite easy. In this particular case, I've unrolled
the transmit and receive code so that it's as fast as
November 2013 13