maanantai 30. syyskuuta 2013

Yay, working multigauge with chart display

Well, I got the things done I outlined in the last post.

I had two sails with a working setup: Pi with incoming N2K and NMEA 0183 data feeds providing a browser-based navigation display over the Pi-hosted wifi hotspot. I captured the data sets from both occasions, so now I have two real world data sets to play back and tweak functionality with.

Basic functionality in the general purpose multigauge is done, it shows now
  • speed over ground
  • depth with sparkline
  • heading
  • bearing & distance to waypoint
  • true & apparent window
  • laylines with history sectors
Real world data brought out a bunch of simple bugs, such as errors in the true wind calculation. Some known bugs still exist, like updating the layline sectors when the sector should cross origin (0 degrees).

Just staring at the data got boring pretty fast, so I added a map pane with Leaflet using open nautical chart layer from Finnish Transport Agency. I also wanted to see the data on my IPad navigation apps, so I added UDP broadcast with just a few lines of code.

The screen capture video below shows the course plotted on the chart and streaming navigation data on the SVG multigauge. 

Working with this stack has been a breeze: data from different sources (json from Canboat, raw nmea from gpsd, multiplexed json from file) is converted to streams that can be mixed and matched with Bacon. SVG is easy to experiment with and I got a dip into real D3 in addition to its JQuery-like select-and-manipulate functionality when I implemented the sparkline with a time window.

The fusion of different messages from two different data realms is not clean or clear, but utilitarian: just pull the data you need from the messages that you need and ignore everything else. Where this falls apart is outputting data as NMEA 0183 sentences as UDP broadcast on the wifi: there is no translation yet from N2K PGN's to NMEA 0183 sentences so only data from the plotter is available on my IPad, no tridata info.

I guess the main point here is that streaming navigation data with a Pi to browser is rather straightforward and opens up a lot of possibilities. Instead of code-compile-deploy2emulator-start cycle that you need to work with on mobile apps you just save the js/html/svg, reload and changes are there on the browser. And not just one platform - even if my multigauge is pretty simple it has worked on all the browsers & devices I have tested it with. 

I also noticed that Navico has a pretty similar strategy with their Wifi1 product: it makes NMEA 0183 and N2K data from their plotter/MFD available on wifi. Wifi1 retails about 200 euros or dollars, but it seems you need a modern MFD to connect it to. 

With a Raspberry Pi, Actisense NGT-1 and RS-422 to USB converter or two you can route all the data from your existing instrument set to wifi for less than 300 euros  and have it on your IPad in app - or you can roll your own displays armed with Javascript, SVG and Node. The expensive piece of kit is NGT-1, so plain NMEA 0183 is a lot cheaper.

Next steps for me: 

  • clean up the code so that it is fit for exposure on Github
  • tridata PGN translations to NMEA 0183 for IPad apps

torstai 29. elokuuta 2013

First Gauge with SVG and Node.js

I couldn't get javascript access to Canboat's streaming json working with my meager js skills.  I need anyway access also to another streaming source, namely gpsd nmea 0183 data, so I figured I would give wind data a try with Node.js and Websockets.

This turned into a proto with a Node http server that
  • spawns "source" process that mimics canboat:
    • actual captured N2K data from our boat in a file
    • read by simple shell script, output a line per second and piped to
    • canboat analyzer that outputs the message in json, message per line
  • serves a single html file with embedded SVG wind gauge & websocket client that updates the wind direction based on the streamed json messages
  • streames N2K messages in json over websockets with Primus
The whole stack was a breeze and I made really good progress with almost no sidesteps.
The result is in my humble opinion a pretty neat in-browser wind direction visualization that handles  issues such as reconnects automatically. Responsive UI no less, sizes to the size & orientation of your screen/window.

Next steps:
  • capturing a real data set: actual sail or at least motoring around rather than just sitting at the docks
  • getting the whole thing up and running on Pi, accessible via a wifi access point on the Pi
  • adding the gpsd NMEA 0183 data from the plotter (COG etc)
  • calculating and displaying TWA
Apparently there are multiple (1, 2, 3) simple NMEA 0183 parsers in Javascript, have to see which one suits my needs best.

sunnuntai 25. elokuuta 2013

Actisense NGT-1: shortcut to N2K data

After googling around for CAN on Raspberry and looking at Pican installation instructions with associated kernel tweaking I decided to cough up the cash for Actisense NGT-1.
Instead of using Raspberry for the initial test I decided that everything would be a tad easier with my Macbook. I would have needed the Macbook for ssh to Raspberry anyway, so I decided to try NGT-1 out with that.
After a bit of jury rigging the cabling (NGT-1 comes with Micronet connector, I have SeaTalk NG) and installing the Actisense FTDI driver I could admire flashing lights, but actisense_serial was not giving me anything. Debug messages showed that open() call never returned, so after  a bit of googling I added the O_NONBLOCK flag in the best "try something, maybe it will work" programming fashion and lo and behold, I got data!

{"timestamp":"2013-08-24-15:36:10.113","prio":"3","src":"105","dst":"255","pgn":"128267","description":"Water Depth","fields":{"SID":"0","Depth":"8.50","Offset":"0.000"}}
{"timestamp":"2013-08-24-15:36:10.140","prio":"2","src":"105","dst":"255","pgn":"130306","description":"Wind Data","fields":{"SID":"0","Wind Speed":"2.93","Wind Angle":"341.9","Reference":"Apparent"}}
{"timestamp":"2013-08-24-15:36:10.140","prio":"2","src":"105","dst":"255","pgn":"128259","description":"Speed","fields":{"SID":"0","Speed Water Referenced":"0.00","Speed Water Referenced Type":"-0"}}
{"timestamp":"2013-08-24-15:36:10.140","prio":"6","src":"105","dst":"255","pgn":"128275","description":"Distance Log","fields":{"Log":"1424188","Trip Log":"1424188"}}

Now I have all the data I need from the N2K bus, plus some unrecognized PGN 130822, coming from either i70 or ITC-5:

{"timestamp":"2013-08-24-15:36:09.140","prio":"7","src":"105","dst":"255","pgn":"130822","description":"Unknown PGN","fields":{ "Manufacturer Code": "Raymarine","Industry Code":"Marine"}}


perjantai 9. elokuuta 2013

The starting point

The starting point is our 35ft sailing vessel with basic navigation instrumentation including a chart plotter, echosounder, mechanical log and wind instrument.

The target is to have all current & other nice to have boat data available on wifi as data for other applications such as iNavX and a simple (sic) platform to create whatever navigation displays I can think of displayed on browsers connected to the boat's wifi.

Current inventory:
My first experiment was to get AIS targets to display in the navigation apps on the iPad. Once I got the cable connected with correct polarity I was able to stream the AIS data as UDP packets on the local wifi and have it show up in iNavX on iPad.

AIS targets from VHF in iNavX on iPad

For lack of time I decided to postpone Raspberry installation for this season and instead hooked the VHF up with the plotter to get usable AIS display no matter the state of my Raspberry setup.

As to the goal that I'm after: the built in layouts on my i70 are somewhat lacking. You can configure different layouts for a bunch of numbers on a display that is really readable, but the visualizations are pretty lame. Or what do you think of the graphical temperature "gauge" in the picture below? Another good example is history graphs that have no indication of the range of the values.
Dumb sea water gauge
Since it appears that the manufacturer is not about to give us incrementally better firmware build your own is starting to sound like a viable option.

And btw I have currently no way to upgrade the firmware on my i70 with my minimal N2K setup...

So what I'm after is an easy way to develop new gauges and displays. One example would be a multi-gauge in the likeness of B & G Sailsteer: one gauge to visualize multiple data points in an easy to grasp way. As a starting point I wrote some Javascript based on Steelseries gauges to mimic Sailsteer.
Sailsteer-like gauge drawn with custom JS.
Freeboard is a real life project with somewhat similar goals, but I would rather skip the Arduino and have just the Raspberry directly off the N2K bus with PICAN and Canboat.