Previous

Up

Communication protocol

Message format

Messages sent to and received from the microcontrollers are byte oriented streams. All messages start with a caret sign ^ (0x5e) and end with a dollar sign $ (0x24).

Table 1. Message format
Bytes 1 n 1

^

n unsigned bytes

$

An exclamation mark ! inside a message body indicates a transmission error and invalidates the whole message. The characters ^, $, ! and \ are special and must be escaped with a backslash \ followed by the two’s complement of the escaped character (they are thus encoded on two successive bytes).

Table 2. Special characters
Special character Escaped version inside a message body

^

\ 0xa2

$

\ 0xdb

!

\ 0xde

\

\ 0xa3

All messages may embed signed or unsigned integers. They are encoded on 1, 2 or 4 bytes (depending on the message format decribred later), in big-endian format (most significative byte first).

Table 3. Integer encoding
Bytes 1 2 3 4

8 bits integer

n

16 bits integer

n >> 8

n

32 bits integer

n >> 24

n >> 16

n >> 8

n

Brushless controller messages

The brushless controller defines the following messages:

ID

This message queries the controller for it’s version, and motor id.

Table 4. ID query message
Bytes 1 1 1

^

?

$

Table 5. ID reply message
Bytes 1 1 1 (unsigned int) n>4 (string) 1

^

?

motor id

mkblX.Y

$

X.Y represent the software version running on board.

Clock timestamp

This message can be sent periodically to the controller so that is calibrates its internal oscillator. The message contains the local time on the sending machine, encoded in micro seconds (possibly wrapped around).

Table 6. Timestamp message
Bytes 1 1 4 (unsigned int) 1

^

t

local timestamp (µs)

$

Motor startup

This message starts the motor at a very low speed (about 16Hz).

Table 7. Startup message
Bytes 1 1 1

^

g

$

Motor stop

This message stops the motor.

Table 8. Stop message
Bytes 1 1 1

^

x

$

PWM duty cycle

This spins the motor at the given PWM duty cycle. The duty cycle is encoded as a 16 bit unsigned integer, but useful range is from 0 (0%) to 1023 (100%). The motor must be started for that message to be taken into account.

Table 9. PWM message
Bytes 1 1 2 (unsigned int) 1

^

p

pwm (0-1023)

$

Velocity control

This spins the motor at a given velocity. The velocity is encoded as the rotational period in micro seconds (the inverse of the velocity), on a 16 bit unsigned integer.

Table 10. Velocity message
Bytes 1 1 2 (unsigned int) 1

^

v

rotational period (µs)

$

Alternatively, an array can be broadcasted to all controllers. Each controller will take the i th value of the message where i is the motor id.

Table 11. Velocity array message
Bytes 1 1 2 (unsigned int) 2 (unsigned int) 1

^

w

rotational period for motor 1 (µs)

rotational period for motor motor n (µs)

$

Velocity query

This message queries the current spinning velocity. The reply contains a bit field with the current spinning state, as well as the current rotational period in microseconds.

Table 12. Velocity query message
Bytes 1 1 1

^

s

$

Table 13. Velocity query reply
Bytes 1 1 1 (bit field) 2 (unsigned int) 1

^

S

emergency (bit 7)
servo (bit 6)
spinning (bit 5)
starting (bit 4)
motor id (bits 0 to 3)

rotational period (µs)

$

Current query

This message queries the instantaneous current consumption. The reply contains the value in miliampers.

Table 14. Current query message
Bytes 1 1 1

^

a

$

Table 15. Current query reply
Bytes 1 1 1 (bit field) 2 (unsigned int) 1

^

A

emergency (bit 7)
servo (bit 6)
spinning (bit 5)
starting (bit 4)
motor id (bits 0 to 3)

current (mA)

$

Motor data query

This message ask for important values from the motor to be sent periodically.

Table 16. Motor data query
Bytes 1 1 4 (unsigned int) 1

^

m

period (µs)

$

Table 17. Motor data
Bytes 1 1 1 (bit field) 2 (unsigned int) 2 (unsigned int) 2 (unsigned int) 1

^

M

emergency (bit 7)
servo (bit 6)
spinning (bit 5)
starting (bit 4)
motor id (bits 0 to 3)

rotational period (µs)

pwm (0-1023)

peak current (mA)

$

The peak current is the maximum current recorded since the last time this message was sent by the microcontroller.

Sensor data query

This message queries values from various on board sensors.

Table 18. Sensor data message
Bytes 1 1 1

^

d

$

Table 19. Sensor data reply
Bytes 1 1 1 (bit field) 2 (unsigned int) 2 (unsigned int) 2 (unsigned int) 2 (unsigned int) 1

^

D

emergency (bit 7)
servo (bit 6)
spinning (bit 5)
starting (bit 4)
motor id (bits 0 to 3)

battery level (mV)

current (mA)

microcontroller temperature (0.1 ⁰C)

pcb temperature (0.1 ⁰C)

$

Velocity controller data query

This message queries values from the velocity controller.

Table 20. Velocity controller message
Bytes 1 1 1

^

k

$

Table 21. Velocity controller reply
Bytes 1 1 1 (bit field) 2 (unsigned int) 2 (signed int) 2 (signed int) 2 (signed int) 1

^

K

emergency (bit 7)
servo (bit 6)
spinning (bit 5)
starting (bit 4)
motor id (bits 0 to 3)

target velocity (µs)

bias

gain

error

$

Beep

This message plays a given sound tone with the motor, when it is stopped.

Table 22. Beep
Bytes 1 1 2 (unsigned int) 1

^

~

frequency (Hz)

$

Flight controller messages

The flight controller defines the following messages:

ID

This message queries the controller for it’s version, and motor id.

Table 23. ID query message
Bytes 1 1 1

^

?

$

Table 24. ID reply message
Bytes 1 1 n>4 (string) 1

^

?

mkflX.Y

$

X.Y represent the software version running on board.

Motors startup

This message starts all motors at a very low speed (about 16Hz).

Table 25. Startup message
Bytes 1 1 1

^

g

$

Motors stop

This message stops all motors.

Table 26. Stop message
Bytes 1 1 1

^

x

$

Velocity control

This spins motors at a given velocity. The velocity is encoded as an array of rotational period in micro seconds (the inverse of the velocity), on a 16 bit unsigned integer. Each motor takes the i’th value of the message where 'i is the motor id.

Table 27. Velocity control message
Bytes 1 1 2 (unsigned int) 2 (unsigned int) 1

^

w

rotational period for motor 1 (µs)

rotational period for motor motor n (µs)

$

Gyroscope calibration

This message runs a calibration procedure for the gyroscopes, for the given amount of time. The board should be still while this procedure runs. There flight controller reports when the procedure is done.

Table 28. Gyroscope calibration message
Bytes 1 1 1 1 (unsigned int) 1

^

z

g

time (s)

$

Table 29. Gyroscope calibration report
Bytes 1 1 1

^

Z

$

IMU query

This message ask for periodic IMU data.

Table 30. IMU query message
Bytes 1 1 4 (unsigned int) 1

^

i

period (µs)

$

Table 31. IMU data
Bytes 1 1 2 (signed int) 2 (signed int) 2 (signed int) 2 (signed int) 2 (signed int) 2 (signed int) 1

^

I

linear acceleration X (mm/s²)

linear acceleration Y (mm/s²)

linear acceleration Z (mm/s²)

angular velocity X (mrad/s)

angular velocity Y (mrad/s)

angular velocity Z (mrad/s)

$

Battery level query

This message ask for periodic battery level.

Table 32. Battery level query message
Bytes 1 1 4 (unsigned int) 1

^

b

period (µs)

$

Table 33. Battery level data
Bytes 1 1 2 (unsigned int) 1

^

B

battery level (mV)

$

Motor data query

This message queries important values from each connected motor.

Table 34. Motor data message
Bytes 1 1 4 (unsigned int) 1

^

m

period (µs)

$

There is one reply per connected motor, in the same format as the brushless controller message (see Motor data).

Beep

This message plays a given sound tone with the motors, when they are stopped.

Table 35. Beep
Bytes 1 1 2 (unsigned int) 1

^

~

frequency (Hz)

$