Tech: Simpilot boat autopilot simulator for Arduino


Ever since writing a Seatalk test program last year, I've been toying with the idea of developing an autopilot simulator. Well, after a few long flights and one rainy weekend too many, I have Simpilot, a simple boat autopilot simulator that runs on Arduino. Simpilot is controlled by a simple command language. For example, the following simulates sailing a triangular course around the intersection of the equator and the prime meridian (shown above):

add waypoint S1E1,-1.0,1.0
add waypoint S1W1,-1.0,-1.0
add waypoint N1E0,1.0,0.0
set position N1E0
set speed 10
set mode L
goto waypoint S1E1
sim on

Commands are entered via the Arduino device's serial port. In the above example, the add commands define a waypoint for each vertex of the triangle, the set commands specify the vessel position, speed and pilot mode respectively, and the goto specifies the first destination. The simulation is started and stopped with sim on/off respectively. You can find this and other sample simulations in the sims directory.

Simpilot currently implements the following pilot modes:
  • Heading (H) mode: maintain current heading.
  • Waypoint (W) mode: go to a waypoint, then stop.
  • Track (T) mode: go from one waypoint to the next, then stop at the last one.
  •  Loop (L) mode: as above, but loop continuously.
There is also a Standby (S) mode, but since there is no one to take the helm, it functions similarly to Heading (H) mode, albeit without any pilot messages.

Simpilot produces either NMEA 0183 or Seatalk messages depending on how it is compiled (look in port.h). The following messages are currently supported.
  • NMEA 0183: DBT, GGA, VTG, RMB, APB
  • Seatalk: 00 (DBT), 11 (AWS), 58 (GGA), 84 (RMB,APB), 89 (HDG), A1 (RMB,APB)
With the exception of DBT and AWS, these are common messages generated by an autopilot. DBT (Depth Below Transducer) and AWS (Apparent Wind Speed) would normally be produced by a depth sounder and anemometer respectively. Note that Simpilot does not currently accept any messages that would normally sent to an autopilot.

A few useful commands:
set mode S Switch to Standby mode. Any waypoint remains in effect.
set heading <x> Set the heading to <x> and switch to Heading mode (unless already in Heading Mode).
goto waypoint <x> Go to waypoint <x> and switch to Waypoint mode (unless already in Waypoint, Track or Loop mode).
goto off Cancel current waypoint and switch to Heading mode.
sim reset Reset the simulation to the initial position and waypoint, if any. If the simulation is running it takes effect immediately.
If the simulation is not running, you need to start it with sim on.

For testing purposes, Simpilot can also be compiled and run as a standalone (non-Arduino) command-line program using the supplied makefile.

Here's another simulation, along the north coast of Kangaroo Island, which can be found in KI_wineries.txt.

The following screenshot of the Arduino IDE serial monitor shows the start of the simulation, with the simulation commands being entered followed by NMEA 0183 messages being generated.


The following shows OpenCPN's NMEA debug window (a little later on): 


To date I've just tested the NMEA 0183 functionality using OpenCPN 3.2.2 on a PC and Simpilot on a Mega running Arduino  1.6.11. 

Note that since NMEA0183 signals are inverted, they need to be inverted for devices such as PCs that expect TTL logic. In my setup, COM3 is the Arduino serial port and COM4 is the inverted serial output that OpenCPN listens on.

Simpilot is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. The full source code can be found here.

NB: Simpilot is a simulator, it is is not intended to be used an actual autopilot.

OVER.

Comments