Tuesday, May 1, 2018

AMOS Takes a Dip

I spent about another day trying to get Bluetooth communications to work between AMOS and my iPhone before giving up. I think it can be done, probably using the iOS Core Bluetooth libraries for Bluetooth Low Energy (BLE) communications, but it looks like a lot more work than what I'm willing to dedicate to it at this point. I believe getting Bluetooth working between the Android phone and AMOS won't be too bad; it should be similar to what I did a couple of weeks ago, getting Bluetooth software working between the PC and AMOS.

To that end, I've started writing a version of BoatCaptain for the Android phone. There isn't much functionality in it yet, but here is a cool screen shot to look at:


The PC version of BoatCaptain also now has a stop sign button, for immediately cutting power to the propellers. It makes driving AMOS quite a bit easier, since it gives the driver a sort of "mental" reset so that they immediately know the state of the propellers (i.e. stopped) without needing to look at the propeller speed controls in the graphic user interface.

The PC version now also gets GPS, magnetometer compass, roll & pitch angles, and temperature from AMOS. These were initially set to update every 2 seconds, but it was found that this tended to cause connection problems over Bluetooth, so the interval was reduced to once every 10 seconds for Bluetooth. The data rate should be fairly small, so I'm not sure why the Bluetooth connection was adversely affected by the 2 second update rate. Internal to AMOS, GPS data arrives once every second, and the compass heading, pitch, and roll angles and temperature are collected at 50 Hz, with a 5 sample running average. So this should allow for pretty good real-time navigation later on. The compass data looks reasonable, probably to within 20 degrees or better, and I verified that the GPS latitude and longitude changed slightly when I carried the boat around the backyard.

The iceberg in our pool has almost melted. Here is a video that Kirsten took of me carefully piloting the craft around the perimeter of the berg: https://www.youtube.com/watch?v=p4Y3qhnZCIo  The interior of AMOS also now features a 2.5 kg weight velcroed to the bottom of its interior for ballast; I think it helped a little, although it could probably use even more. The boat is already a bit heavy to carry though, so I'm reluctant to add too much. After this video was made I did some more testing / fooling around and somehow lost the network connection while AMOS had its propellers set to the maximum backward speed. It gyrated a number of times around the pool, out of control, but luckily I was able to grab a hold of it when it came close with one hand, release the cap with the other hand, and then unplug the power wire. Later on I changed the software so that it should kill the motors when the connection gets lost. Should probably also add a master power switch to the exterior of the boat for easier on / off control.






Wednesday, April 25, 2018

Where AMOS Fits In

In contrast to last week's progress, this week seemed a lot slower. I was hoping to get the BoatCaptain PC software ported over to iOS to make it easier to control the boat from a kayak on the water. I was also hoping to integrate GPS and navigation software into BoatCaptain. Unfortunately I only partly succeeded in porting the software over to iOS and didn't even start the GPS / navigation integration. Here is a screenshot of the working version of BoatCaptain on iOS:


The code for controlling the boat over a network interface works fine, but it's the Bluetooth connectivity stuff that is giving me lots of grief. Unfortunately Apple doesn't make it simple for developers to integrate Bluetooth into their software. Apple's "CoreBluetooth" libraries for low energy Bluetooth devices look promising, but they are quite a bit different than any other Bluetooth software I have done in  the past for Android or the PC, so may require a lot of time to figure out. At this point I'm considering just setting it aside and moving on to other things. 

The North American cell modem that was back ordered and scheduled to ship this week got delayed again, so I canceled that order and decided to look for an alternative. Similar standalone cell modems seemed to be priced at ~ $300 or more, but something like a Bell or Rogers turbo stick (for getting cell data on a tablet or laptop) were less than $100, although they required signing  up for some sort of plan which I didn't look into. Since I already had the SIM card with 100 MBytes / month of data from Bell, I decided to just get an Android smart phone for a little over $100. It can be added to the boat for cell / data connectivity, communicating to the Raspberry Pi Compute module over Bluetooth. It will also afford some gigabytes of data storage.

There was a steering committee report released recently to the New Brunswick government that provides a good summary of the testing and results that have been accomplished in the Parlee Beach and surrounding area. The report itself is available here: http://www2.gnb.ca/content/dam/gnb/Departments/eco-bce/Promo/Parlee_Beach/pdfs/parlee_beach_water_quality_finalreport-e.pdf  
The results indicated that the water quality at the beach location was nearly always within the safe limits specified in the Canadian Recreational Water Quality Guidelines (https://www.canada.ca/en/health-canada/services/publications/healthy-living/guidelines-canadian-recreational-water-quality-third-edition.html). The times when the limits were exceeded seemed to be strongly correlated with wind direction (higher bacteria concentrations were measured at the beach when the wind was from the north or northwest), and possibly some weaker correlation with tides, rainfall, and beach traffic. It was also interesting to note that the bacteria levels measured in the watershed around Shediac Bay were considerably higher than those measured at the beach itself. That could be why winds from the north or northwest resulted in higher concentrations of bacteria at the beach: the bacteria from the watershed were pushed back to the beach by the wind.

So where does AMOS fit in with the testing that has been done so far and the recommendations for future work that the steering committee report described? The second recommendation that the report listed was to "Apply the hydrodynamic model to validate the transport paths related to actual discharges into the Bay (concentrations, volumes, weather conditions)." In addition to collecting samples at various locations in the Bay itself or in the surrounding rivers and streams, AMOS could be allowed to drift at various times and locations in order to estimate probable transport directions that bacteria might follow due to winds, tides, and currents. With a relatively rapid sample evaluation time (less than 12 hours vs. the current 48 hours) this might be able to provide a reasonable estimate of beach water quality, thereby accomplishing the 6th recommendation of the report: "Develop and validate a tool for predicting water quality, based on relevant environmental and meteorological data, which could be used by the Medical Officer of Health (MOH) to issue “No Swimming Advisories” at Parlee Beach. A predictive tool would address concerns with the 48-hour delay related to analyzing water quality samples". Of course, even better than a predictive tool would be a device for obtaining real-time bacteria concentrations on an ongoing, continuous basis. That is the long-term goal of AMOS.

Wednesday, April 18, 2018

Bluetooth and Blue Skies

A lot of progress was made this past week. After printing several parts for the solar panel framework and bolting them together, it became readily apparent that this method of construction would not result in something rigid enough to work well. So I visited Home Depot and found some 8 foot long bronze tile edge things that looked like they would be suitably stiff and lightweight when bolted to the solar panel. Here is the result with some more scrap wood from the garage added to connect it to the rest of the framework:


The solar panel is elevated above the boat significantly more than it will be in the final design; this is necessary for now so that there is lots of room to stick my big head inside the hull and make electronics modifications. The panel is held to the framework with 6 bolts and wingnuts, so isn't difficult to remove should the need ever arise. Also, I ordered some neat little waterproof connectors (~ $1 each from Amazon) and am using one of them for the solar panel wiring:


Perhaps in a future revision the solar panel could be much closer to the boat and have a sort of hinge / latch mechanism for making it easy to get inside the hull.

The client / server software that I began the week before is also coming along well. The server resides on the boat and waits for incoming network and / or Bluetooth connections. The client (for now) is just a quick and dirty PC program (called "BoatCaptain") that lets you connect over the network (WiFi at this point) or Bluetooth, and has 4 buttons for controlling propeller speed and direction:


Over time, this will expand to include GPS location, magnetic heading, temperature readings, battery voltage, route planning, sample collection, etc. Also, I would like to have a mobile version as well, since it can be tricky to kayak and work a laptop at the same time.

Our recent rainy weather has abated this morning and I just noticed that there is a relatively deep section of the stream bordering our neighbour's property that is free of ice, so I think it's time for a field test...

EDIT: And here is the video of the first field test: https://www.youtube.com/watch?v=H5xzWFsAKhc

Wednesday, April 11, 2018

Ready For Europe

The 4 volt power supply for the cell modem arrived last week, so on Friday night I soldered it up to the cell modem and connected it to the 5 volts from the new 7-port USB hub which had also recently arrived. The documentation for the 4 volt supply claimed that there were two 4 volt output pins on the little circuit board, so I picked one of them, but after an hour or so of frustration realized that only one of the output pins seemed to be functional. Not sure if that was a fault of the documentation or the board itself, but based on the remainder of the documentation I suspect the former. The documentation for the power supply and cell modem are scattered throughout a number of places on this site: https://itbrainpower.net/. Personally, I much prefer having a single product PDF, rather than having to flip through multiple pages on the web. It just seems so much easier to find what you need later on, if you can open that one document every time.

So once the correct 4 volt output was connected to the cell modem, some LEDs flickered on, and when the power button on the cell modem was pressed, a green light flashed on and off ~ every 1.5 seconds. Something in the documentation indicated that this was as it should be. I then downloaded and installed the Windows drivers, thinking that it might be easier to test out in Windows and confirm that it was working. Indeed a number of new serial COM ports showed up in Device Manager, but the test program the documentation referred to for Windows was not available, and did not seem to be readily available on the Internet. Oh well, back to the Pi for testing then. After a few hours of careful reading and searching, I was able to find out how to correctly (I think) set the Compute Module for use with the modem.  This involved specifying the Bell APN information, and downloading some Python serial libraries to work with the modem sample code. Running the sample code appeared promising at first, as it found the chip device number and SIM card ID, but it was unable to establish any sort of a wireless signal, and did not actually appear to make any sort of wireless connection to the Bell network.

Looking through my purchase records, it turns out that I actually bought a cell modem intended for Europe. So I'm guessing that it works at 900 MHz / 1800 MHz, instead of the frequencies used in North America (850 MHz / 1900 MHz). There is a North American model available, so I ordered it and should have it in a couple of weeks. Hopefully that is the only other obstacle remaining before getting a working cell connection. Maybe the European modem will be useful someday if I ever sell anything overseas!

In the meantime, I can use WiFi for network connectivity software and testing purposes. I'm still working on some client / server software for communications between AMOS and a PC (or phone) and hope to have a simple version of it ready before the massive block of snow and ice in our pool melts. I noticed that there are large sections of the St. John River that are free from ice, but I'm too nervous to do any emergency kayaking at this time of year :-).



Tuesday, April 3, 2018

It's All About The Printing

The 3D printer showed up last Thursday, so I dove into the poorly translated instructions and got to work trying to assemble all 300 or so pieces of it. For the most part, I was able to understand the intent of the instructions, but there were a few instances where things were unclear, or just didn't seem to make sense. For these, I found a pretty good video on YouTube that was able to fill in the gaps.

Although others claimed to have assembled the printer in about 6 hours, I'm quite sure that it took me at least 12 hours. I guess you could say that I was being careful. Finally on Easter Sunday I had it all put together, installed and configured the software, read through the user guide, and was ready to go. The printer only came with a few grams of filament, so I didn't want to waste any time on the example models that came with the software, and instead opted to build my own using openSCAD (http://www.openscad.org/). Since the cable penetrators that I bought to go through the hull of the boat were too short, and I wasn't able to find any online that were long enough (stem needs to be ~ 1.5 inches to get through the insulation) I thought it would be a good idea to make my own. openSCAD is pretty slick, especially if you're used to scripting or programming. I was able to make a simple function call to create a metric M16 screw, and then a 2nd function call to create a hollow 8 mm hole down the middle of it. The model looked great! I then exported to an STL file, brought it into some 3D printing software (Cura), re-saved it as a GCODE file, and then issued the command to start printing.

Before all this, I had eye-balled the heating bed to make sure that it appeared to be level and that the nozzle head was pretty close to the bed surface. Rookie mistake. My first print was a strange jumble of filament in the center of the bed that got pushed around randomly by the nozzle head. So I used the recommended technique of placing a sheet of paper on the bed and moving the head over the surface of the paper to see that it just barely touched everywhere. This seemed to help, although my next two prints (of two separate models on different parts of the bed) also failed... in retrospect I think this failure might have been due to a position error, caused by one of the belts being too loose. Eventually, after midnight I was able to get a not too bad looking penetrator screw. It looked like it was slightly squashed though, again probably due to the loose belt. Tightening the belt the next day seemed to result in better print symmetry.

On Monday I moved the printer out into the playhouse:


My first couple prints out there did not go particularly well. Tightening the belt improved the symmetry of the modeled screw, but the parts of the screw that were more than about an inch from the heating bed were fairly weak, and tended to tear apart when stressed or torqued with a nut. I think it might have been too cold (~ 10 deg C) in the playhouse. So I tried using the printer's own packaging to insulate the printing volume a bit.


This seemed to do the trick, and  I was able to get some better prints, but still not quite strong enough to actually tighten a nut over it. After shortening the threaded section of the screw, and reducing the hole diameter to 6 mm, I was finally able to make something useful:


Now I'm creating models of parts that will make up the framework for holding the solar panel on AMOS. As these are larger parts, they will require about 5 hours each to print... so a little bit longer between iterations!

While waiting for stuff to print, I also started work on a sort of generic server program for AMOS that would allow it to receive TCP/IP or Bluetooth / serial commands from a host controller.

EDIT (April 4, 2018): I think I can dispense with the ridiculous box around the printer; I was able to do a number of good prints today at an ambient temperature of ~ 0 degrees C. Suspending the filament reel from a beam in the ceiling seemed to greatly improve the quality and precision of the prints, as the reel was much more free to rotate, and the filament didn't get snagged on anything.

Wednesday, March 28, 2018

The Pretty Print Shop

For a birthday present, my parents gave me some money to buy a 3D printer: I'm getting the "MagicD A8 RepRap 3D Printer" from Amazon. I'm hoping to use it to better organize the jumble of electronics and interconnecting cables that this project is starting to accumulate, and also find some way of making a structural framework that securely connects the solar panel to the boat. It should also come in handy for building a structure to hold the camera boards, as I discovered this week that my crude vision algorithms are highly sensitive to misalignment of the camera boards (one screw per board into a block of wood didn't really cut it).

I read that this printer in particular is a bit noisy, and like any 3D printer needs to be in a place where it will not get disturbed. For that reason, I decided to clean out my daughters' old playhouse and move an old table into it, to hold the printer. I'm a bit worried that it might be too cold, at least for the next few weeks but other users have claimed that it should work OK (at least with the default PLA filament) if you build a bit of an enclosure around it to keep the air around the printer at a reasonable temperature. And during the daytime, it might be warm enough in there anyway.


 This past week I was able to get GPS data into the Compute module with only a few minor hiccups along the way. The module I was using (https://www.seeedstudio.com/Raspberry-PI-GPS-Module-p-2731.html) could be used over USB, so to keep things simple I hooked it into my 4-port Belkin USB hub. Unfortunately though the hub is not a powered hub, i.e. the only power it supplies to the 4-ports comes from the USB bus itself, so maybe something like 100 mA total spread around the 4 ports, I'm not sure. Anyway, the GPS module's spec sheet mentioned that it required at least 100 mA for startup, so I guess I shouldn't have been too surprised that the Compute module completely failed to detect it at bootup. At this point, I figured it couldn't hurt to just try connecting the 5 V available on my I/O board to the GPS module, while leaving the USB cable intact. This resulted in a red LED turning on on the GPS module. I then installed the recommended GPSd client software (http://www.catb.org/gpsd/) and tried to run one of their sample programs. No dice. The LED was still on, but the program said that it couldn't get a satellite lock. Some quick Internet research explained that the first time a GPS tries to get a lock or fix on the orbiting satellites can sometimes take over 10 minutes. So I took the dog for a walk, and came back an hour later to check on it. Still no luck and no lock. More careful study of the spec sheet indicated that although the main chip on the board had an internal antenna, it was really better suited to outdoor operation. So maybe there just wasn't enough signal in my basement? I carried the setup upstairs into our living room and set it near the window, hoping that would be good enough. It wasn't. I then brought the thing outside, and sure enough that red LED that had been solid the whole time suddenly started flashing once per second. I left it outside and logged into it using PuTTY and sure enough it was now providing latitude, longitude, and signal to noise ratio for the satellites that it was receiving. I also tried compiling and running some other GPSd sample C++ code and it too worked great. The GPSd project won the first "Good Code Grant" from the Alliance for Code Excellence, so it should serve me well. Sometimes adding things like this feels a bit like "standing on the shoulders of giants".  I've ordered a magnetic mount GPS antenna so that I can keep the GPS electronics on the inside of the boat. Hopefully the magnet won't mess with my compass too much!

I also made an effort to try to get the cell modem (https://itbrainpower.net/micro-3G-shield-module-du3G/3G-UMTS-micro-shield-board-module-RaspberryPI-Arduino-d-u3G-presentation.php) working too, but fell a bit short in that regard. I signed up for a $10 / month data plan on the weekend, and plopped the SIM card into the module, but again the Compute module failed to detect the board over the USB connection. This time, my more careful read of the datasheet revealed that in fact the USB connection was only used for communications, i.e. not power. For power, this thing actually requires +4V. Not sure if +5V would have worked or not, but at ~ $100 for the modem I didn't want to chance it. Ordered a +4V supply from Robotshop for a few dollars instead.

It turns out that the water tight cable fittings that I bought for getting cables in and out of the boat are too short. There is actually about an inch-thick layer of Styrofoam housed inside the yellow plastic shell of the boat. So I'll need to see if I can find some longer ones I guess.

Finding a suitable depth sounder for the boat has been surprisingly difficult. Pretty much all depth sounders that you can buy seem to be fish finders, with portable graphics displays. You can get some that are kind of cheap (< $100 knockoffs) but they don't seem to have NMEA data outputs that would allow me to "see" the data. The good fish finders with NMEA outputs seem to cost ~ $500 or so. Ugh. I did happen to find this standalone transducer with a NMEA output (http://cruzpro.com/active.html) that only cost about half that. It's from New Zealand; I'm waiting to hear back from their Canadian distributor about buying it.

Wednesday, March 21, 2018

Solar Power: Vroom Vroom!

So now that the solar panel, battery, and solar charge controller had all arrived, there were really no excuses left. It was time to hook everything together, see if the battery would charge properly without exploding or starting a bad fire, and see what these T200 Thrusters (http://docs.bluerobotics.com/thrusters/t200/) were really capable of.


This past Saturday was a clear crisp day, about -10 °C, perfect for testing out charging of the new battery (Dakota Lithium 12 V, 10 Amp-hr https://www.dakotalithiumbattery.com/12-v-10-ah-lithium-battery). Everything seemed to go well. The voltage jumped immediately from about 12.6 V to 13 V or so, and then steadily climbed throughout the afternoon until it reached the pre-programmed limit for the charger of 13.7 V. No fires or explosions, so far so good.

The next couple of days were spent building something of a crude wooden framework around AMOS for supporting the solar panel and possibly the thrusters as well.


The framework is not done yet, but if it works I'll make a better one out of plastic or aluminum.

On Monday, I finished up some code for the electronic compass module (https://www.robotshop.com/en/lsm303d-3-axis-accelerometer-compass.html). At first I was worried that it would prevent the cameras from working, since it was using the first I2C channel on the Raspberry Pi Compute module, which also happened to be used by the graphics processor for the cameras. Fortunately though, switching to the 2nd I2C channel worked fine, and did not interfere with the cameras (er the remaining working camera). It would be possible to try to calibrate this thing, but it appears to work well enough just by normalizing the two's complement digital outputs, so that you get acceleration and magnetic vectors in 3D, which can then be used to compute the device orientation (i.e. roll, pitch, and heading angles). The heading seems reasonably accurate when the device is close to horizontal, so it should be good enough for my navigation purposes. It won't matter too much I guess if AMOS heads off in a direction towards its intended target that is 20 ° or so off... by continuously collecting GPS data, the desired direction to the target can be refined and it should still arrive at the correct location.

Now back to the T200 thruster: yesterday had some hours of frustration initially, as the GPIO pin I was using to control the thruster speed did not seem to be working. Eventually I figured out that the electronic speed controller for the thruster (http://docs.bluerobotics.com/bescr3/) was pulling the output of my Compute module GPIO pin high all the time, i.e. the output from the Compute module was too weak. So it looks like the previous issue with the ill-advised camera repair may have damaged more than just the camera interface... perhaps the entire 2nd bank of GPIO has gone bad. Anyway, switching over to a GPIO pin from the 1st bank worked fine, with an impressive level of thrust when the output was cranked up. The output was fairly jerky and inconsistent though, stemming from the fact that the Raspbian operating system is not real time, so it is not really possible to control the output of a GPIO pin with software to microsecond precision. Fortunately though, the Compute module has a couple of PWM outputs that are perfectly suited to driving this sort of motor controller. Switching the software over to use these instead worked quite nicely, allowing for nice smooth control of the thruster speed. Here's a short Youtube video of a 5 second blast on one of the T200 thrusters: (https://www.youtube.com/watch?v=DUQfTLgzaeM) The video doesn't quite do the thruster justice, you really need to hold it in your hand to get a feel for how much force it exerts. Suffice to say that 2 of these things on the back of the boat should be enough to drive it through some pretty strong seas!