Kilolib
Kilobot Library
Kilobot Library API

At its core the Kilobot Library library provides the function kilo_init() to initialize the hardware of the kilobots, and the function kilo_start() that uses a basic event loop programming paradigm (this relies on a setup and a loop callback, similar to those used in the arduino software).

The API also provides functions to read the various sensors available to the kilobots (get_ambientlight(), get_voltage(), get_temperature()), and also to control the individual pager motors and the RGB led present in each kilobot (set_motors(), set_color()).

The user can register callbacks to interact with the messaging subsystem. There are callbacks for the events of message reception (kilo_message_rx), message transmission (kilo_message_tx), and notification of successful transmission (kilo_message_tx_success). By default every kilobot attempts to send message twice per second. Advanced users can modify this through the kilo_tx_period variable, although this is discouraged unless you know what you are doing.

To prevent collisions the kilobot library uses a basic exponential back-off strategy with carrier sensing. There are no acknowledgement packets, and as such a message is considered to be successfully transmitted when a kilobot is able transmit a message without detecting any contention in the channel.