Monthly Archives: September 2013

Depth Sensor Arrives

good_newsA depth sensor has arrived: a Measurement Specialties 5541C, which should be good to 14 bar (at least 450 feet of depth).  It’s quite simple, featuring 8 solder points, of which only 6 are needed for normal operation.

It uses the Serial Peripheral Interface, though not by name (the documentation merely mentions a “three-wire interface”).  However, a little research  shows that removing the device select wire from standard 4-wire SPI gives you the same connections as the sensor uses.  Like the camera (next post), the sensor operates with a lower supply voltage than the Arduino, so level-shifting is needed.

connections
SPI Connections

This should be relatively easy.  Here’s the hard part:

sensor and scale
Sensor, with scale

Mounting it to a PCB with some sort of 6-pin connector is going to be a major challenge.

Going Multi-lingual, Multi-OS

Long post – snacks are suggested…

Hardware development has been suspended for some time while some fundamental software improvements are made.   In an earlier post, a plan was shown to use an XBee connected to a PC to control Poolbot in remote mode.    This required some serious software changes, but hard work pays off.  The following features have now been implemented in the Arduino Mega 2560 R3 software inside Poolbot:

  • diagnostic checks of all sensors and electronics (except the motor shield), with timeouts, have been moved into the setup() function
  • reporting of diagnostics over hardware serial (usually over USB to a PC in drydock)
  • XBee communications with the base station include signal strength reporting and confirmation of successful receipt
  • (biggest of all) motor speed and direction are now controlled remotely; no more pre-programmed paths

The great XBee libraries for Arduino from Andrew Rapp enables transmission and reception of simple text string “payloads” (100 bytes each), taking care of the details of checksums and packet assembly between Poolbot and a base station.   Each payload can be used to carry commands, data requests, and the like.  To do this, Poolbot needed its own custom control protocol, so that the base station could command the motors to do something, or request sensor status, or even change operating state.  The format for the protocol was blatantly ripped off from lovingly constructed in homage to NMEA codes used for the GPS.  The format is comma-separated and looks like:

$M<2-character motor ID>,<motor speed percentage>,<direction>

So, to tell the right dive motor to spin backwards at 60% of maximum speed, the command would be:

$MDR,60,R

Using comma separators permits using strtok to token-ize the command string. The compact format also allows Poolbot to communicate without violating the 100-byte XBee data payload limit.  “P” is used in the second position to indicate propulsion motors, while “L” would indicate the left motor, and “F” indicates forward.  “$MAS” instructs all motors to stop.

In future, sensor status can be reported with a “$Sxx” structure, but other non-motor commands are possible.  The only limit to the language is the Mega’s storage.  The entire program is about 23 kB in size, which is 2/3 of the maximum supported by an Uno, but still pretty small for a Mega. 

On the PC side, lots of options exist for software (including a hardware cheat of connecting an XBee through an Arduino Uno to handle serial communications), but ultimately Python made the most sense.   Using Python 3.3 was made possible by Chris Liechti’s excellent set of libraries for serial communication (pySerial) and a similarly excellent library collection for XBee communication by Paul Malmsten.

This means that the PC side hardware can be reduced to this:

USB XBee
USB SparkFun XBee Adapter

This also means that a Linux box, or even a Raspberry Pi, could be used as the Poolbot base station (think battery-operated!) – multiple operating systems are now supported.  The Python program is somewhat simple at present, featuring a simple set of pre-programmed commands, but it does respond to user input and reports XBee status and received signal strength.

How does it all look working together?  Check out the results on a single 32-bit Microsoft Windows XP laptop, with Poolbot in drydock on COM5 (left side), and the Python input/output from the control XBee on COM4 (right side):

diags and commands
Diagnostics and comms

The commands are pretty obvious from the screen shot.  Further, the frame ID tracking ensures that commands aren’t accidentally missed.  The programs both wait for interaction, so Poolbot can be left on and waiting indefinitely – no more rushing to seal up the ‘bot before the motors click on.  And, yes, the correct motors turned off and on when expected.

The hardest part of all of this was, believe it or not, getting strings vs. bytes sorted out correctly in both Python and Arduino’s flavor of C. 

Future enhancements will include:

  • adding sensor $S reporting to the Poolbot language
  • fixing the XBee signal strength (yes, it’s really on the order of -80 dBm, even though the two XBees were only a few feet apart; this is likely due to bad soldering during recent repairs)
  • a control GUI…

That last one is the real reason for using Python – the tkinter binding/toolkit allows cross-platform graphical displays and controls.  This means that the command language can be abstracted away in favor of buttons, dials, text boxes, and pretty LED-like lights where appropriate.  Here’s the first crude attempt:

Tkinter
Python Tkinter controller prototype

At the very least, the speed adjustments shown will allow motor calibration without permanently adding encoders to each motor.

Three languages, multi-OS support, and a new GUI – not bad for five days’ work.

Space Available

Selecting batteries or even solidifying the electronics means figuring out the maximum dimensions of any given rectangular shape that will still fit within the tube.  If only the diameter is limited, then a variety of rectangles may fit.  Time to pull out some geometry…

Geometry
Geometry calculation

Thanks to a particularly good website for batteries, a complete set of dimensions for a variety of batteries is available.  The equation above can show whether a particular battery will fit in the tube or not, based on its width and length (assuming “depth” extends along the tube’s axis). Performing some calculations with the existing central tube, electronics and two batteries, some options emerge:

  • using an alternative 12 V battery, at 3.8 Ah, measuring 7.6″ x. 2.8″ x 1.85″
  • stacking the electronics within a 5″ x 2.25″ area gives 2.68″ of available height for both the electronics and ballast (not much, but usable) 
tube sizing
Tube size calculations

Motor load measurements are still needed to confirm that 3.8 Ah is sufficient for propulsion.  The Arduino Mega and Motor Shield fit within an area 5″ x 2.25″, but the connectors and DHT11 sensor need to be cleverly stacked on top.  And 2.5 lbs of ballast needs to fit under the electronics within about 2.28″ of space, total.  

It’s either this or recalculating displacement using a longer tube, plus actually building it.

Current Affairs

What’s Poolbot’s maximum operating time in-water before needing to recharge? 

The motors are tied to two (2) 6 V, 4.5 Ah batteries.  It would be convenient to use the same kind of supply for the electronics, but it depends on the current drawn.   For the electronics alone (not the motors), a quick set of measurements reveals some unfortunate numbers:

  • the Arduino Mega 2560 R3 alone draws a reasonable 70 mA, which would allow at least 70 hours of operation (assuming correct reading of the capacity charts) before needing a recharge
  • the GPS and XBee (1 mW) draw only about 7 mA
  • the current draw by the motor shield is a less reasonable 200 mA

At 277 mA, Poolbot will need a recharge after only about 17 hours of operation.  It’s also not known how long the 12 V solar panel will take to recharge the battery packs.  If it takes more than 7 hours, or if there’s less than full sunlight, Poolbot may need significant “basking”/sleeping time between operations.  This assumes that the electronics can be  effectively turned off, and doesn’t even count needing to charge the motor batteries.  What happens if Poolbot drifts while charging?

There’s another issue.  There’s no room left inside Poolbot for all the new electronics, ballast, and four 6 V batteries.  With two batteries for the motors, at 1.75 lbs of weight per battery, about 6.5 lbs of ballast and electronics battery weight remains to maintain Poolbot’s neutral buoyancy (see previous post). 

Using a single 6 V battery to power the Arduino Mega and its accompanying electronics is a bad idea; below 7 V, the Arduino’s on-board regulator won’t work well and operation will become unstable.  So, either a single 12 V battery with the right dimensions and similar Ah figure must be used (good luck) or some significant filtering must be used on a single supply for both the motors and the electronics. 

Bad choices all around…

Broken Propellers and Trial by Ordeal

One minor and one major update…

The minor update: a recent pool test showed Poolbot making only starboard turns; this turned out to be due to a broken starboard propeller.

The more significant issue involves ballast.

Both the ComPod and the main body of Poolbot were recently analyzed for displacement and overall ballast neededto dive.  Recall that ComPod has to protrude from the water at least partially in order to allow the XBee inside to communicate with the shore.

Previous displacement checks were done on Poolbot alone, less to get an actual displacement number and more simply to visually check buoyancy, and adjust trim and freeboard in the water.  The ComPod was tested for actual displacement in the kitchen at least once, but using some dificult and questionable methods.  To get a better number, the following extremely high-tech test bed was assembled:

Tank 1
High-Tech Displacement Tank 1

The hard plastic bowl is filled to just before overflowing.  The softer plastic bin will catch the water displaced by the ComPod once it’s inserted into the bowl.  Measure the water in the bin to get displacement.

This measurement went exceptionally well, and resulted in a displacement within about 12 mL of the previous ComPod checks.  The final numbers:

  • ComPod’s volume (displacement): approximately 1470 mL
  • ComPod’s weight: 549 g (including internal electronics)

For neutral buoyancy, the item weight must equal the weight of the volume of water displaced.  As 1 kg of fresh water = 1 L of fresh water (pretty clever that metric system is), ComPod’s required ballast is…  921 g, or 2 lbs, 0.5 oz.

To measure Poolbot’s displacement, aside from the ComPod, is harder.  Poolbot is rather large, requiring a tank at least 25 inches (sorry metric system) long and 11 inches wide, with about the same depth.  Any catch basin must be larger still, to accommodate the overflow without losing any.

tank 2
High-Tech Displacement Tank 2

Thanks to several smaller bins, four plastic bags, and some tape, a reasonable up-scaled version of the previous dunk tank was created; there’s just enough clearance to allow water to overflow straight down into the smaller bins.  The flaw in this design will be obvious from this post-dunking picture.

Tank 3
Post-dunking recovery

Key findings:

  • Use a rigid container, if possible, for the actual dunking.  The soft plastic deformed enough to raise concerns about accuracy.  The strap shown above is wrapped around the bin and several pieces of acrylic plastic and  plywood, to make the sides more stable.  The risk is that the plastic will deform, rather than water overflow, when the object is dunked.
  • Poolbot floats, so is obviously guilty of witchcraft.

Here are the numbers, +/- 100 mL or so for water loss and bin expansion:

  • Poolbot’s volume (displacement, without ComPod): 8050 mL
  • Poolbot’s weight (without ComPod or batteries): 3.6 kg

This means that Poolbot’s ballast must be 4.45 kg, or 9.82 lbs, to compensate for buoyancy.  This number includes all of its current electronics, but does not include batteries.

The challenges that remain:

  • Can the ComPod be kept sufficiently above the waterline to transmit and receive messages?  Or is it time for the extended antenna?
  • If ComPod protrudes enough for XBee communications, are the motors powerful enough to allow for diving without dive planes or some sort of ballast compensation system?

Unfortunately, there’s a third problem lurking, which will be addressed in the next post…

Designs Today and Tomorrow

The latest Poolbot program updates have enabled XBee transmission of arbitrary strings up to the 100 byte payload limit.  In drydock, the Arduino is connected via USB to a PC, used as a “dumb terminal”; the Arduino is doing all the display work, and the XBees operate in a simple loop confirming that a communications link exists. 

The next steps are to move all the serial link data processing from the Arduino Mega 2560 to a PC.  The Arduino can then transmit compressed sensor data via XBee payloads, and let the PC locally decompress the payload and print the information in a human-readable format.  Remote control of the motors becomes possible.

Pictures sometimes explain better than words, so here’s the design today, and what’s planned for the future.

today
Today’s Poolbot design

Next