boatd documentation


Boatd is designed to be the manager for a boat control system, granting graceful startup, telemetry, logging and a built in simulator.

There are two main components of a system written using boatd:

  • the driver interfaces with the particular set of hardware in the boat.
  • the behaviour performs a set of actions to make the boat do a particular task. The API available for these scripts is supposed to be declarative, with the idea that for any boat with a driver written, any behaviour script will work.


Boatd is currently tested and supported on Python 2.7 and 3.4. Support for python 2 may be dropped in the near future.

Installing for development

First, clone the repository and change to the directory:

$ git clone
$ cd boatd

Create a new virtualenv:

$ virtualenv boatd-dev-env

Activate this virtualenv:

$ source boatd-dev-env/bin/activate

Install boatd in editable mode from the local copy:

$ pip install --editable .

Installing when you don’t care and live life on the edge (system wide installation)

First install dependencies:

On any Debian based distribution (Debian, Ubuntu, Mint etc):

$ apt-get install python-yaml

On Red Hat systems (Fedora, CentOS, etc):

$ dnf install PyYAML

Then clone the repository and change to the directory:

$ git clone
$ cd boatd

Run the installer:

$ sudo python install

Running boatd

$ boatd --help
usage: boatd [-h] [--version] [CONFIG FILE]

Experimental robotic sailing boat daemon.

positional arguments:
  CONFIG FILE  a path to a configuration file

optional arguments:
  -h, --help   show this help message and exit
  --version    show program's version number and exit

After you have installed boatd, it can be run with $ boatd.

You will need to create a configuration file. It should look something like:

  port: 2222

plugin_directory: null

  - logger:
    period: 10
    filename: logs/gps_trace

            file: example/

            - example:
                    file: example/

The example config file (boatd-config.yaml.example) can be modified for your boat.

Output will be similar to:

$ boatd
[15:43:55] loaded function heading as "heading"
[15:43:55] loaded function get_wind as "wind_direction"
[15:43:55] loaded function get_wind_speed as "wind_speed"
[15:43:55] loaded function position as "position"
[15:43:55] loaded function rudder as "rudder"
[15:43:55] loaded function sail as "sail"
[15:43:55] loaded driver from example/

The original aim was this command would also run your behaviour directly after startup, but this functionality is not yet implemented (see the issue). After boatd is running, you should run your behaviour manually.

If you would like to use a different config file in a different location, pass the path as an argument to boatd. For example, $ boatd /etc/boatd/fancy-conf.yaml.

Using the boatd API

Boatd’s main method of interaction is via the JSON API.


  • GET

    Returns the current status and version of boatd. Example output:

       "boatd": {
         "version": 1.1


  • GET

    Returns attributes about the current state of the boat. Example output:

      "active": false,
      "position": [2.343443, null],
      "heading": 2.43,
      "wind": {
        "direction": 8.42,
        "speed": 25


  • GET

    Returns properties of the wind. Example output:

      "direction": 8.42,
      "speed": 25


  • GET

    Returns data about available and current behaviours. Example output:

      "current": null,
      "behaviours": {
        "basic": {
          "filename": "example/",
          "running": false
  • POST

    Change the currently running behaviour. Setting the current behaviour to null will cause no behaviour to be run.


      "current": null
      "current": "basic"


Driver basics

Boatd drivers are implemented as a simple user defined class in a loadable python module. When a behaviour script requires information about the current state of the boat or needs to send a command to some hardware, boatd runs one of the methods in the driver.

To write a driver, a python module should be created that contains an object named driver. This object must be an instance of a class inheriting from and implementing the interface defined in BaseBoatdDriver:

class boatd.BaseBoatdDriver[source]

Must return the direction the wind is blowing in degrees, relative to the world.

Return type:float between 0 and 360

Must return the heading of the boat in degrees, relative to the world.

Return type:float between 0 and 360

Must return a tuple containing the current latitude and longitude of the boat, in that order.

Return type:tuple of two floats - (float, float)

Reconnect the driver to boat devices. It is recommended that initial connections are made using this function by calling it in the __init__ method. If the driver does not require any persistent connections, this method may be empty.


Set the boat’s rudder to angle degrees relative to the boat.

Parameters:angle (float between -90 and 90) – target number of degrees

Set the sail to angle degrees relative to the boat.

Parameters:angle (float between -90 and 90) – target number of degrees

Must return the speed the wind is blowing in knots.

Return type:float

Note that the driver instance must be named driver, otherwise boatd won’t know where to find it.

Example driver

An example:

import boatd

class MyFancyBoatDriver(boatd.BaseBoatdDriver):
    def __init__(self):
        # initialize some things here

    def heading(self):
        return 30.0

    def wind_direction(self):
        return 45.0

    def wind_speed(self):
        return 4.0

    def position(self):
        return (0, 0)

    def rudder(self, angle):
        print('moving rudder to', angle)

    def sail(self, angle):
        print('moving sail to', angle)

    def reconnect(self):
# create an instance of the driver class
driver = MyFancyBoatDriver()

Configuring boatd to use a driver

Once you’ve written a driver, you can tell boatd to load it as the active driver by setting scripts.driver in your configuration file. Eg:

    driver: example/

This can be a relative path, as with the example above. It can also be absolute. boatd will also expand ~ to your home directory:

    driver: ~/git/sails-boatd-driver/


Plugins are loadable python modules that run in a separate thread inside boatd. They have access to the current data about the boat.

Plugins are enabled with the main boatd configuration file. Each plugin may have a few extra parameters, but all have the enabled parameter to enable or disable it.


  - some_plugin_name:
    enabled: true

Bundled plugins

Boatd comes with a few plugins preinstalled. These are:

  • logger

    This logs data about the current state of the boat to a file periodically.

    Configuration parameters:

    • period - the time in seconds between each logged line
    • filename - the path to the file logs will be written to


      - logger:
        enabled: true
        period: 10
        filename: logs/log_trace
  • gpx_logger

    This logs data about the current state of the boat to a GPX formatted file periodically.

    Configuration parameters:

    • period - the time in seconds between each logged line
    • filename - the path to the file logs will be written to, the filename

    will be appended with a timestamp


      - gpx_logger:
        enabled: true
        period: 1
        filename: logs/gpx_log
  • mavlink

    This allows boatd to communicate using a subset of the mavlink protocol.

    Configuration parameters:

    • device - the serial port to use
    • baud - baud rate to use with the serial port


      - mavlink:
        enabled: true
        device: /dev/ttyUSB0
        baud: 115200

Writing new plugins

To implement a plugin, a class must be implemented that conforms to a certain interface (similar to how drivers are defined). The interface is simple:

class boatd.BasePlugin(config, boatd)[source]

The main method for a plugin. This should contain a loop if the plugin is intended to be long-running.

An example implementation would be:

from boatd import BasePlugin

class ExamplePlugin(BasePlugin):
    def main(self):
        while self.running:
            position = self.boatd.boat.position()
            print('logging some stuff ', position)

plugin = LoggerPlugin

Some things to note:

  • You automatically get access to an object called self.boatd. This contains a boat attribute which you can use to interact with the live boat.
  • self.running can be used to check if the plugin should end. When the plugin is started by boatd, this will be set to True. When boatd is about to quit or plugins need to be stopped for some other reason, it will be set to False.


Boatd has a client library written for python. It contains a python wrapper module and a command line client.

You can install python-boatdclient from PyPi by running:

$ pip install python-boatdclient

Boatdclient includes the following user facing classes:

class boatdclient.Boat(boatd=None, auto_update=True)[source]

A boat controlled by boatd

Parameters:auto_update – automatically update properties when they are requested.

Return the current heading of the boat in degrees.

Returns:current bearing
Return type:Bearing

Return the current position of the boat.

Returns:current position
Return type:Point

Set the angle of the rudder to be angle degrees.

Parameters:angle (float between -90 and 90) – rudder angle

Set the angle of the sail to angle degrees

Parameters:angle (float between -90 and 90) – sail angle

Return the direction of the wind in degrees.

Returns:wind object containing direction bearing and speed
Return type:Wind
class boatdclient.Behaviour(boatd=None)[source]

Return a list of the available behaviours to run.


End the current behaviour and run a named behaviour.

Parameters:name (str) – the name of the behaviour to run

Stop the current behaviour.

Boat returns and uses special classes for bearings and latitude longitude points. These contain some common functionality.

class boatdclient.Point(latitude, longitude)[source]

A point on the face of the earth


Return the bearing to another point.

Parameters:point (Point) – Point to measure bearing to
Returns:The bearing to the other point
Return type:Bearing
cross_track_distance(start_point, end_point)[source]

Return the cross track distance from this point to the line between two points:

           * end_point
        /   * this point
  • start_point (Point) – First point on the line
  • end_point (Point) – Second point on the line

The perpendicular distance to the line between start_point and end_point, where distance on the right of start_point is positive and distance on the left is negative

Return type:



Return the distance between this point and another point in meters.

Parameters:point (Point) – Point to measure distance to
Returns:The distance to the other point
Return type:float
classmethod from_radians(lat_radians, long_radians)[source]

Return a new instance of Point from a pair of coordinates in radians.


Return the latitude in degrees


Return the latitude in radians


Return the longitude in degrees


Return the longitude in radians

relative_point(bearing_to_point, distance)[source]

Return a waypoint at a location described relative to the current point

  • bearing_to_point (Bearing) – Relative bearing from the current waypoint
  • distance (float) – Distance from the current waypoint

The point described by the parameters

class boatdclient.Bearing(degrees)[source]

An angle between 0 and 360 degrees


>>> Bearing(100)
<Bearing (100.00 degrees clockwise from north) at 0x7f25e22b3710>
>>> Bearing(100) + Bearing(100)
<Bearing (200.00 degrees clockwise from north) at 0x7f25e22b3940>
>>> Bearing(100) + Bearing(300)
<Bearing (40.00 degrees clockwise from north) at 0x7f25e22b37b8>
>>> Bearing(0) - Bearing(100)
<Bearing (260.00 degrees clockwise from north) at 0x7f25e22b3940>
>>> import math
>>> Bearing.from_radians(math.pi)
<Bearing (180.00 degrees clockwise from north) at 0x7f25e22b3828>
>>> int(Bearing(120.4))
>>> float(Bearing(120.4))

Return the error between this and another bearing. This will be an angle in degrees, positive or negative depending on the direction of the error.

Parameters:other (Bearing) – bearing to compare to
Returns:error angle
Return type:float


To run tests, install tox

$ pip install tox

and run tox. If all the tests pass, the output should be similar to:

$ tox
GLOB sdist-make: /home/louis/git/boatd/
py27 inst-nodeps: /home/louis/git/boatd/.tox/dist/
py27 installed: boatd==1.1.3,coverage==4.0.2,coveralls==1.1,docopt==0.6.2,p
py27 runtests: PYTHONHASHSEED='2985615961'
py27 runtests: commands[0] | py.test -v --cov boatd boatd
========================= test session starts ==========================
platform linux2 -- Python 2.7.10, pytest-2.8.2, py-1.4.30, pluggy-0.3.1 --
cachedir: .cache
rootdir: /home/louis/git/boatd, inifile:
plugins: cov-2.2.0
collected 50 items

boatd/tests/ PASSED
boatd/tests/ PASSED

... snipped

====================== 50 passed in 1.39 seconds =======================
_______________________________ summary ________________________________
  py27: commands succeeded
  py34: commands succeeded
  pypy: commands succeeded
  flake8: commands succeeded
  congratulations :)

This will run all test environments. To run an individual environment, run tox -e py27, or more generally tox -e <env>, replacing env with py27, py34, pypy or flake8 (style checks).

The current test results from the head of the master branch can be found here.