Showing posts with label system control. Show all posts
Showing posts with label system control. Show all posts

CANBoat Design part III - Choosing the server hardware

The server that CANBoat runs on was always designed to run 24 by 7. This means that it must be reliable and use little power. Power usage adds up over longer periods. Something that uses 3W will use 6 Ah @ 12 V per day. So every Watt counts!

For a long while I thought that I would end up with some form of embedded ARM board running Linux. I bought a number of ARM based systems to run field tests.

However as I started to develop software it soon turned out that the criteria list contained three items, not two:
  • Power usage - as low as possible IN REAL LIFE.
  • Connectivity - USB 2.0 Host, Ethernet, Wifi.
  • Up-to-date Linux kernel with distribution that provides lots of packages.

I was surprised to find that in practice a small x86 server based on the AMD Geode ran with almost as little power as an ARM board. Unlike the ARM boards it had all the I/O that I wanted. Furthermore it was cheap and reliable to procure. You can get cheap ARM boards based on commercial items such as routers but these usually have a very short lifetime as manufacturers continuously drive down prices by bringing out new hardware. Embedded systems are usually a lot more expensive.

The clincher was that most ARM board manufacturers have a hard time keeping up with the Linux distributions, so they usually run out-of-date kernels and weak distributions. Support for FTDI serial converters was not a given, and these are used in many devices such as the Actisense NGT-1. I had to backport many fixes for the FTDI serial converters to the older Linux kernels to get reliable serial USB connections. Not Good.

So in the end I decided on low power x86. The PC Engines ALIX 2d.13 has exactly the interfaces I needed, but is available in a range of different systems. They run about € 100 / $ 140 which is still very reasonable. It runs a very nice mini Debian release named Voyage Linux with a kernel that is new enough to run stuff like the FTDI interfaces reliably. As it is just a pruned Debian release getting an additional package is just an apt-get away. The processor is a 500 MHz AMD LX800 which is plenty fast for Linux server needs.

CANBoat Design Part II - why a website, and why TCP and JSON

One of the first things that people ask me when I show them my app on the iPhone or iPad is where they can download it from in the App Store. My answer is simple: you can't. Nor do you need to. It would be bad design if you had to!

The idea is that all devices on board that have a decent web-browser can access the CANBoat data. This means I save development effort, as I don't need to write custom apps for Blackberry, Android, iPhone, Windows Mobile, etc. All I need to do is make sure the webpage renders nicely in modern browsers. I did make a decision that I'm not going to cater to Internet Explorer, not unless it is IE 9 that is.

The choice for a webserver hosted on a permanently running small (Linux) server and clients running a web browser has two other very big benefits.

First of all, since there is no need to install anything the client hardware becomes expendable. If you lose one (for instance it gets soaked) then you just get a new one. For use in the cockpit you'll still be using some protection, but that's true of your phone itself anyway. Yesteryear's iPod touch that your kids no longer want because it is 2 generations behind will serve as an excellent client. And it gives you an excuse to get a bigger screen -- as in an iPad which you suddenly have a "very good reason to buy" for.

Secondly, because all state is carried in the server you can switch off the client for as long as you like. When you start it again the page refreshes or you restart the 'web app', and all data is there as the server knows what the system state is. All logging etc. does NOT require a permanently running iPhone app. Even the anchor alarm (once I get around to implementing it) will work this way!


The webpages


The beauty of modern browsers is that they can accomplish a lot in just a little Javascript. For instance, the following gauges are all rendered client-side in a few hundred lines of Javascript code:

javascript gauges

The above gauges are how clients that are connected via a slow link will see the page. If they are connected using Wifi the gauges are shown with a nice image that has reflection in it, upscaling the experience.

Also, the server side examines the browser capabilities so that the page is tuned to the capabilities of the device. At the moment I change the tab bar to a drop down list if I detect a small screen. Various Apple Webkit items are sent to make it possible to run the application without a page header on iOS devices.

Refreshing the on-screen data


As browsers are not capable of receiving UDP packets yet, they need to get their data in a different way. The only capability that they have is creating TCP connections to refresh their data. That technique is called AJAX (Asynchronous Javascript and XML), but instead of XML I use JSON format. JSON is ideal for Javascript as it is translated easily into real Javascript object data.

The JSON that would be sent for the above three dials is something like this:

[ 
{"name":"Heading","units":"°","value":357.7},
{"name":"Batt Voltage","units":"V","value":"27.06"},
{"name":"NMEA Voltage","units":"V","value":"12.65"}
]

CANBoat Design part I - A simple data viewer and boat remote control

Today I'd like to tell you a little more about the hardware/software stack that I have developed to control and navigate a small to medium pleasure boat. The basic idea is to re-use the mobile devices that most boaters will have, such as their smart phones, tablets, laptops or computers.0

If you've ever stumbled across Panbo then you may have realised that there are many folks that want open access to environmental and navigation data. There are plenty of mobile navigation software programs that show a chart, but there aren't so many that show instrument or actually sensor data on mobile devices.

My own boat has a PC running Nobeltec and, since recently, Expedition navigation software with CMap charts as well as a Lowrance HDS chartplotter with Lowrance and Navionics charts. I also have the Navionics Mobile charts on my iPhone. That means that charts are very well covered, thank you.

What I did not have was:

  • Remote control over heating. We have under floor heating, so switching this on a few hours before we actually leave for the boat is very welcome in winter.
  • A way to control the power circuits from other locations than the central switchboard.
  • A way to monitor the boat's systems from home or from my bunk.

So I built my own solution to cover this.

CANBoat is a software solution running on a 'standard' Linux system and consists of the following software:

  • A cellular modem stack to provide as-reliable-as-possible data connection over cellular, as well as a SMS service interface.
  • A NMEA 2000 'reader' interface that receives all NMEA system data. The data is logged to rrd database and provided to Ethernet clients.
  • An interface to the PLC (made by Wago) to control power circuits and measure tank levels. The PLC is running software by me as well, which provides the same Ethernet interface as the NMEA and temperature subsystems.
  • A temperature subsystem that uses the Maxim 1-Wire network to measure temperature in various locations in the boat. The data is logged and provided to Ethernet clients.
  • A webpage that integrates the above live data in a format that is usable on the small screen of a mobile device.
Here are some screenshots of CANBoat:

NMEA dataNMEA 2000 data coming from various sources

Tank levelsTank levels

Interior power circuitsInterior power circuits


As you can see I have some work to do still on improving the layout -- optimizing font sizes etc.

In the next part I'll show some details of the implementation.

DC (and AC) power control

Our new sailing boat is proving to be a new playground for exercising some skills that I haven't used for 25 odd years. In particular, designing the DC and navigation systems that are going on board. I have slowly been coming up with what I think is a good mix of reliability, ease of use and high tech. This last bit just for the fun of it. But, let me start at the beginning...

We really like sailing, and sailing should be simple and fun. To make that come true you need to be comfortable as well. Over here in Northern Europe this means that during the colder months of the year you want heating on board. That and shelter from the rain. After some to-and-fro we decided to heat the boat using an ultra-reliable diesel-fired Kabola stove that is going to distribute the heat using hot water. As space is at a premium and we didn't like to have normal radiators in sight, we decided to go for floor heating. There is a Dutch company called Yacht Floor Heating that has come up with a solution that 'works' for yachts.

Floor heating does have the disadvantage that it takes a long time to heat up the interior initially, so we really needed a method of being able to switch the heating on remotely before we get to the boat in winter. Once you can remotely switch on the heat the question soon came up why the system should be limited to just that. Why not be able to do more, like monitor bilge water, battery charges and switch on fridges, deck lights? Why can't I check what the wind conditions are remotely? Maybe even put a camera on board?

Looking at the various options it soon was apparent that there are many systems on the market, but not one that integrated everything that I wanted from such a system.

What I wanted is something that:
  1. Does not interfere with manual operation. If the fancy electronics fail, the system should still be operable by hand. This rules out all new technologies that do distributed DC switching, as they rely on the electronic DC bus to be able to switch stuff on and off.
  2. Should offer a simple switches-and-lights interface that is easy to understand for people that are not comfortable with computers.
  3. Allows integration with modern technologies such as remote controls (locally and remotely) and Google Maps mash-ups.
  4. Can be replaced, extended and modified over time.
The DC wiring and all consumers are going to be installed by the builder. They pointed out that the relatively low complexity of the boat in terms of electrical consumers meant that a distributed DC layout was not going to provide many advantages, if at all. A single cabinet that is centrally located will suffice. This will also simplify fault detection and maintenance: all circuit breakers are located in the same spot.

The system that I have come up with is as follows:
  • The distribution cabinet will contain circuit breakers and old fashioned mechanical latching relays. As they are latching they don't use power in use. It also gives the opportunity to have multiple switches that toggle the relay state.
  • The switches can be located anywhere in the boat. They are momentary action switches coupled with a feedback LED. We've chosen to centralize them in a single board near the entrance, hidden behind a frosted glass panel.
  • A small Linux driven PLC contains digital I/Os as well as analog inputs. It can toggle the relays and measure their state. The analog inputs are used to measure all tank levels and possibly bilge levels. The WAGO PLC is modular and extendable but proven technology.
  • A 2nd computer will provide on-board WiFi and a cellular link to the Internet. This can be extended to a satellite link later on. This computer will also have a CAN bus interface so that it can talk with the NMEA 2000 bus that all the navigation systems are connected to. Finally it will also talk directly to the Mastervolt DC and AC power systems.
  • Local control is via an interactive AJAX driven website that is accessible, for instance, via an iPod touch or iPhone over WiFi, as well as any other computer that is onboard -- including the navigation computer.
  • Remote control is via any computer or phone connected to the internet. The actual connection will be via a proxy located in a data-center, as the cellular end of the boat does not have a fixed IP address. Access to the data will be using a form of authorization, of course.
I've started some prototypes for all this, and it seems that this will come together nicely. I'm working on a NMEA 2000 packet sniffer as well as a web application for the iPhone/iPod touch. You can see the "Fluid and battery level" screen of the app in action at the top of this entry.