A Year Later: OpenCPN on a Raspberry Pi 3

It’s been over a year since I’ve tried to use OpenCPN on a Raspberry Pi, and I thought I’d see what the community has done since then.

Wow.

Simply Wow.

A Raspberry Pi 3, with the latest versions of Raspbian/PIXEL and OpenCPN matches up as good as commercial entry-level chartplotters on the market today. This platform has really come a long way in the past year, and I’m truly impressed.

Recipe:

Hardware

  • Raspberry Pi 3, Power and HDMI cables, SD card, & case
  • HDMI Monitor
  • USB Keyboard with integral trackpad
  • USB Wifi Adapter
  • GlobalSat BU-353-S4 USB GPS Receiver
  • dAISy Hat AIS Receiver

Set Up Rasbian

  • I burned the most recent version of Raspbian/PIXEL (March 2017) onto a 32GB SD card, inserted it into a RPi3, and booted. In seconds I had a desktop.
  • Connect to WiFi with a USB dongle
  • I removed the products I don’t need:
    sudo apt-get purge wolfram-engine mathematica-fonts sonic-pi nodered libreoffice
    sudo apt-get autoremove
  • Update Kernel to latest for OpenGL
    sudo branch=next rpi-update
  • Reboot
  • sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install mesa-utils
  • sudo raspi-config
    • Set Timezone
    • Set Locale and Keyboart to US English
    • Change graphics memory split to 128MB
    • Enable OpenGL Driver
      • With Full KMS, I had problems with the display not working after a reboot, so I needed to use Fake KMS, Option G2. To recover, edit config.txt and comment out the dtoverlay=vc4-kms-v3d (or edit to be vc4-fkms-v3d)
  • Turn off screen blanking
    • sudo nano /etc/lightdm/lightdm.conf
      • [SeatDefault]
      • xserver-command=X -s 0 dpms
  • Reboot
  • Run glxgears
    • I was running glxgears at 60fps and 2% CPU
    • At full screen I saw 30fps and 11% CPU
  • Run glxinfo
    • Direct Rendering: yes
    • Renderer string is the Gallium renderer, and not Software Rasterizer
    • OpenGL Version string is 2.1 Mesa 13.0.0

Install OpenCPN

  • Install required supporting tools
    • sudo apt-get install gpsd gpsd-clients screen
      • This required a reboot to work properly
  • Install the OpenCPN software from the Ubuntu PPA
    • In previous recipes I have built from source. To save time, and because building from source truly isn’t necessary, this time I just used the pre-built packages
    • sudo nano /etc/apt/sources.list
    • sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C865EB40
      sudo apt-get update
      sudo apt-get install opencpn
  • Download charts from NOAA
    • I simply create a directory under the user account to hold all OpenCPN files, and a Charts subdirectory
    • After extracting, to pre-render all the charts, from a terminal window run:
      • opencpn -unit_test_1 0
  • Set up GPS
    • I actually had a bit of difficulty for the first time in a while getting GPS set up. If I ran cgps or xgps I got no data, but running gpsmon showed a good solid fix
    • This is the sequence of commands I followed to get it working (and works on subsequent reboots):
      • sudo dpkg-reconfigure gpsd
      • sudo nano /lib/systemd/system/gpsd.socket
        • Change ListenStream=127.0.0.1:2947
          to
          ListenStream=0.0.0.0:2947
      • sudo nano /etc/default/gpsd
        • START_DAEMON="true"
          USBAUTO="true"
          DEVICES="/dev/ttyUSB0"
          GPSD_OPTIONS="-n"
          GPSD_SOCKET="/var/run/gpsd.sock"
      • sudo killall gpsd
        sudo gpsd /dev/ttyUSB0 -F /var/run/gpsd.sock
    • Connect GPS to Opencpn
      • Open Settings, Connections Tab. Click Add Connection
        • Type: Network
        • Protocol: GPSD
        • Address: localhost
        • DataPort: 2947
        • Priority: 1
        • Control Checksum: Checked

Setup dAISy Hat

  • Update config.txt to enable UART
    • sudo nano /boot/config.txt
      • add the following lines
        • # Enable UART
        • enable_uart=1
        • dtoverlay=p3-disable-bt
  • Disable Console Serial
    • sudo nano /boot/cmdline.txt
      • remove the following:
        • console=serial0,115200
  • From the Menu, select Preferences->Raspberry Pi Configuration
    • Interfaces Tab
      • Enable Serial
  • Reboot
  • Test Hat Serial communication
    • screen /dev/serial0 38400
      • [ESC] brings up a menu
      • ‘T’ sends a test message every 5 seconds
      • [CTRL-A], ‘K’, ‘Y’ to exit
  • Add AIS stream to OpenCPN
    • Open Settings, Connections Tab. Click Add Connection
      • Type: Serial
      • DataPort: /dev/serial0
      • Baudrate: 38400
      • Priority: 1
      • Control Checksum: Checked

Results

OpenCPN running ENC charts, with location set by GPS, and AIS contacts listed.

This also shows 24 AIS Targets in a list, as well as xgps running in the background. 6% CPU.

AIS Target Query. Deep zoom into the Hylebos waterway to find three vessels currently underway, including the cargo ship Indigo Lake. These vessels were approximately three miles away from my current location

References

RPi2 with Hardware OpenGL & OpenCPN Recipe

On and off for the past few months I’ve been trying to figure out a problem with OpenGL and the Raspberry Pi 2. Quite simply I want to be able to build, from bare metal, a chartplotter system on a RPi2 that has AIS, GPS, Vector charts, and 10fps. Based on the hardware specs, it should be very possible. However, in practice, I have seen only 1-2fps.

The very good folks on cruisersforum have been hard at work trying to solve this problem, and over the past few days I resurrected this project took a stab at using the latest versions.

On a new board and SD card, the recipe below was used to create a working version of the RPi2 that meets these performance goals. With this setup, I get very usable performance with OpenGL enabled, less than 5% CPU with a satisfactorily responsive UI, USB AIS and GPS, and Vector Charts.

Hardware

  1. Raspberry Pi 2
  2. 16G micro SD card
  3. Tontec 7″ HDMI screen
  4. USB keyboard and touchpad
  5. USB WiFi Dongle
  6. USB GPS Puck
  7. dAISy USB AIS receiver

Build the Pi with a Jessie Distribution and the open source OpenGL drivers

Image the most recent version of Raspian onto a class-10 sd card. I used Raspbian Jessie, with a build date of 3-18-2016.

Once booted, connect to the internet, and then in Raspi-config:

  • Expand file system to full card
  • Change user password
  • Automatically boot to desktop
  • Set overclock to high
  • Set language, keyboard, and locale appropriately.
  • Enable the experimental GL driver in Advanced Options

Reboot, and then:
sudo apt-get upgrade
sudo apt-get update
sudo rpi-update
sudo ldconfig
sudo reboot

Install required libraries

apt-get install cmake gettext gpsd gpsd-clients libgps-dev wx-common libwxgtk3.0-dev libgtk2.0-dev wx3.0-headers libbz2-dev libtinyxml-dev portaudio19-dev libcurl4-openssl-dev libcairo2-dev mesa-utils

Build OpenCPN

git clone git://github.com/OpenCPN/OpenCPN.git
cd OpenCPN

Optionally, get the tides & currents, and high-resolution shoreline data.

  • From  http://sourceforge.net/projects/opencpnplugins/files/opencpn_packaging_data/ download the latest opencpn-gshhs and opencpn-tcdata files
  • Extract their contents into data/gshhs

mkdir build
cd build
cmake -DBUNDLE_DOCS=ON -DBUNDLE_TCDATA=ON -DBUNDLE_GSHHS=FULL ../
make
sudo make install

Download the appropriate charts:

  • For all US waters, it’s very easy to find appropriate charts at NOAA
  • I decided to try ENC vector charts this time.
  • Expand into an appropriate directory. I used /usr/local/include/Charts
  • run opencpn with the -unit_test_1 flag to ingest and process all the charts that were downloaded

Run OpenCPN and set the chart directory to wherever you’ve downloaded the NOAA charts. Exit OpenCPN and then edit .opencpn/opencpn.conf and add the following lines:

MEMCacheLimit=20
NCacheLimit=5

Setup USB

  • Start the gpsd service
    • sudo gpsd /dev/ttyUSB0 -F /var/run/gpsd.sock
  • Launch OpenCPN
  • Add a connection for the gpsd service
    • Settings -> Connections -> Add Connection
      • Network
      • GPSD protocol
      • localhost address
      • 2947 port
  • To get GPSD to run on startup automatically, modify the /etc/default/gpsd file like so:
    START_DAEMON="true"
    GPSD_OPTIONS="-n"
    DEVICES="/dev/gps0"
    USBAUTO="false"
    GPSD_SOCKET="/var/run/gpsd.sock"

Setup AIS

  • sudo apt-get install screen
    sudo usermod -a -G dialout $USER
    screen /dev/ttyACM0
  • CTRL-A, K exists screen
  • Start OpenCPN and go to Options -> Connections | Data Connections, and Add Connection. Select a Serial message, and set the DataPort to the dAISy USB message port (generally /dev/ttyACM0). Set the Baudrate to 9600, and uncheck Control checksum. Apply and return to OpenCPN.

Finalize the Setup

  • Install VNC Server so you can easily access the device from other computers on the network
    • apt-get install tightvncserver
    • tightvncserver :1
      • enter a password twice, and optionally a view-only password
      • Then you can VNC into the device from a computer running on the attached network
  • Remove extraneous packages
    • sudo apt-get  remove --purge wolfram-engine minecraft-pi libreoffice xscreensaver
  • Disable screen blanking
    • sudo nano /etc/lightdm/lightdm.conf
      [SeatDefault]
      xserver-command=X -s 0 dpms

References

OpenCPN Chartplotter Software Plugins

The Chartplotter functionality of my off-season project is complete, due to the fact that the OpenCPN software package is, for the most part, a turn-key solution that had all the necessary features already included. It is a remarkable solution. I prefer the Raspberry Pi platform, for a low-powered dedicated device, but on a small laptop or dedicated PC, it is even faster and extremely effective.

However, like any piece of software, it doesn’t have every feature that every user desires. So they also have a plugin mechanism that allows a user to build their own extensions to the base system, and create those features themselves.

I have done exactly this during the winter, writing a pair of plugins that I think enhance product and make it even more perfectly suited to my particular desires.

Remembrancer

The first plugin is Remembrancer. Remembrancer is a mostly-made-up word that describes the notion that it is used as a reminder. The concept is simple. All it does is bring up an alert box, and play a sound, after a configured length of time.

The idea is that on a long route, with the autopilot steering, the helmsman may become distracted or forgetful, and this plugin will force him/her to remember to do a safety sweep of the water, route, and equipment. The time delay is fully configurable, as is the sound that is played.

Remembrancer

The source files for the plugin can be found on GitHub.

NOAA Doppler

The second plugin, NOAA Doppler, is much more involved. Quite often while cruising we just want to know where it’s raining, so we jump online or on our phone, and view one of the many apps that show the current weather map. This plugin is designed to incorporate that feature into OpenCPN, and renders doppler radar imagery directly over the chart.

NOAA provides free images of the current radar returns for all domestic ground stations. If you live in the United States and know your station ID (Seattle area is ATX (Everett), you can find the live reflectivity, storm velocity, precipitation, and other readings. They also provide a GIS “world file”. The values in this file can then be used to calculate the projection.

I also added a blur factor to the image before rendering, so that the blockiness is reduced. It works fairly well.

Weather Out

Weather In

However, the NOAA Doppler plugin is still not complete:

  • The rendering works, though there are bugs with OpenGL’s transparency
  • The blur feature works perfectly
  • The overlay is correctly positioned, and matches up with NOAA’s own rendering as well as Google Earth
  • It does not download live images, and instead only uses the image previously stored
  • The world file values are hard-coded and don’t change when the stations change

The source files can also be found on GitHub

Resources

 

Chartplotter/Autopilot Design Overview

Over the past few weeks I haven’t had much opportunity to work on this project, but I have tossed around some ideas.

I have found that the project is now complicated enough that I needed to mock up a design for what I plan to do. Here’s the current design, mocked up on Fritzing :
Design

This way I can make sure that the required (and desired) components would be available without needing to add expansion boards. For example, by doing this exercise, I have discovered that a future capability – to be able to consume AIS signals – would require additional components. Most likely in the form of a powered USB hub, but possibly as additional Arduino-based devices to save on power.

A DIY Chartplotter

It only took two evenings to get a Raspberry Pi chart plotter built out.

Yesterday I got OpenCPN up and running following instructions found on the web, and today I finished the process to the point that the hardware is a fully functional chart plotter.

The first improvement that had to be made was getting charts installed in OpenCPN. Thankfully NOAA provides free versions of nautical charts for US Waters and most frequented coasts regionally. It was simply a matter a downloading the appropriate charts (Washington State, and Region 15, Puget Sound) and unzipping them to a folder. I then added that folder to OpenCPN using the built-in options screen, and after a few minutes of compiling, the charts displayed.

IMG_20130821_174054

Then I needed to add GPS capability. First, I hacked together a few wires to an existing Venus GPS Module that I had from a previous Arduino project. This was a simple matter of soldering 3.3v power, ground, and TX/RX digital inputs between the items:

IMG_20130822_181042

Then I installed the GPSD service from the web, run the service, create a socket for it, and verify that the hardware is receiving the signal. Currently I need to hand-type this sequence each time I reboot the microcomputer: 
$ sudo service gpsd restart
$ sudo killall gpsd
$ sudo gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock

Eventually this will be added to a script that will run on boot.

And then to test: 
$ sudo cgps
or
$ sudo xgps

And behold, signals from outer space:

IMG_20130821_191632

Now that all the pieces are in place, the final step is to add this GPS device to OpenCPN so that it can read the information:

IMG_20130822_180807

In this picture you should be able to see a rendered nautical chart of Puget sound, Heading, GPS satellite status, GPS location, and  Compass gauges on the left, and my “boat”, sitting off in Issaquah, since that’s where my GPS device is located.

It’s running at about 80% of the Raspberry Pi’s capability, at 1280×1024 with no overclocking.

And boom goes the dynamite.