Saturday, 24 September 2011

Fun with Robots, Arduino and Android

Together with Mike Hogg from my firm, Zühlke Engineering, I recently developed a demonstration project over a three-day training exercise. We purchased a simple robot and added a set of three infra-red sensors capable of detecting a black line marked out on the ground with electrician's tape. We had to develop a line-sensing algorithm and control logic to follow the line and stop at stations (a short length of tape at right angles to the line) until instructed to move on.

We followed a test-driven development (TDD) approach for C++ using CppUTest, as described by James Grenning, to create a state machine to turn sensor readings into motor control instructions (with hindsight, we might have saved time by resorting to the Machine Objects library). To my surprise, once we loaded the finished firmware to the Arduino board, it worked very well with only a bit of tweaking of the motor speed settings corresponding to "hard left", "slight left" etc.

Then we linked this with an application we developed for an Android tablet computer (Motorola Xoom) that could be used to instruct the robot to go to any selected station, pick up/drop a "payload" (only conceptually) and return to base. The two components communicated by Bluetooth radio link.

Finally, the tablet app was linked via a RESTful Web Service interface to an "enterprise" system developed by other colleagues on the training course, that controlled the whole delivery network and knew which consignments had to be delivered to what stations. The tablet would send a message to the enterprise server telling it where the robot had arrived, and receive back an instruction containing the name of the next station to move to. The robot would then move off automatically after 5 seconds.

The whole thing was enormous fun (as well as very instructive) and was demonstrated successfully to the entire group (see photo).

Jason Gorman and Simon Peyton Jones, among others, have recently been at pains to point out the shortcomings of IT education in the UK. Thinking about the above exercise, it occurred to me that it is just the sort of project that could engender enthusiasm for the subject from a wide range of school students. It involves lots of varied tasks from assembling the hardware to designing the user interface, and of course the devising of suitable protocols between all the components.

Simon Peyton Jones of Microsoft Research will be presenting an interactive talk about Computing At School on 2nd November in London, and the following month (6 December) Mike and I plan to do a session on the Robot Shop exercise at the same location. Anyone interested will be most welcome.

Wednesday, 10 August 2011

Generate test data for Java development easily

A colleague has just pointed out the release of Andy Gibson's DataFactory library as a Maven artifact. It generates arbitrarily long lists of random names and addresses, dates, date ranges (with arbitrary constraints), random selections from lists, numbers, strings, Internet addresses etc. etc.

Sunday, 19 June 2011

Inspiring the next generation of developers

Jason Gorman has published a thought-provoking opinion piece asking why schools are doing so little to promote IT as an enticing career option and to equip kids to take advantage of it. His analysis points to a lack of suitably qualified teachers (so what's new?) and a commensurate lack of ambition on the part of exam boards to make the syllabus industry-relevant.

Do get in touch with Jason to take part in a summit at Bletchley Park (where else?) on 25th August 2011 to identify practical measures that can be taken to improve this dire situation.

I think this is an issue the BCS should be addressing with all dispatch instead of tying itself in knots over some elusive ideal of making all IT practitioners professionally qualified. Some of the most proficient software practitioners I know have no professional qualifications at all.

Wednesday, 25 May 2011

Perils of using an elderly FitLibrary

I learned about a really useful tool today while trying to hunt down a bug in a set of Fit automated acceptance tests.

Last September, my colleague Darren Bishop had set up the automated acceptance test infrastructure for a Maven/Java project I subsequently joined. He used version 20080812 of the Maven dependency (org.fitnesse.fitlibrary), probably because it was the latest available in the Maven Central repository. Thus the stage was set for my troubles last night and this morning!

While working on a small enhancement with a developer in the customer's product support unit, I noticed that one of the Fit tests was producing a blank report and not being counted in the summary totals. A comparison with other spreadsheets that did run properly revealed no significant differences.

Back at base, it quickly became apparent that I had to single-step through the program to find out where it was going wrong. But I could find no source jar for this version of fitlibrary - the latest dependency version available with source was from 2006. What to do?

After a futile attempt to desk-walkthrough the code of FolderRunner and SpreadsheetRunner, Keith Braithwaite suggested decompiling the class files. JD-Eclipse to the rescue! I installed it in my Eclipse and found it so insanely useful that I will never want to be without it again. Basically it creates beautifully formatted source code for you on demand (obviously without the programmer's original comments and documentation). This means that you can set breakpoints and single-step through library code even if you have no source attachment for your library. Installation was really easy. After that, if you single-step into a library method, the "source" is opened automatically. You can also open a .class file directly in the package explorer by browsing the libraries on your project's build path.

There's just one slight gotcha: the line numbers in the decompiled code rarely match the original, so if the class file contains line number annotations your instruction pointer and breakpoints may appear to be a few lines away from the location reported in the debugger's thread view. Ignore the cursor and read off the current line number from the comment at the start of each line. You can turn off the display of metadata and line numbers in the JD preferences, and I have done so - it needs a restart of Eclipse to take effect, but setting breakpoints is much easier afterwards.

So, what was the solution to the mystery?

In the FitLibrary class SpreadsheetRunner, the method collectTables() used an Iterator to return the rows of the test script one at a time and convert them into arrays of values that the runner could subsequently invoke to execute the test:

HSSFRow row = (HSSFRow);
HSSFCell[] cells = getCells(row);
String[] borderedCellValues = getBorderedCellValues(cells, workbook);

Unfortunately, getCells() dimensioned an array of HSSFCell objects using the value returned by a row:

private HSSFCell[] getCells(HSSFRow row) {
int maxCell = row.getLastCellNum();
HSSFCell[] cells = new HSSFCell[maxCell];
return cells;

When the row was "empty", getLastCellNum() returned -1, which caused the next line to throw a NegativeArraySizeException. This exception was caught by FolderRunner.runFile(), which attempted to report the problem to the standard output, but this didn't appear in the Maven test log.

I have not found out what makes POI decide that a row is "empty". There was only a single spreadsheet row in the entire suite of tests that was interpreted in this way. I achieved a workaround by pasting a copy of another blank row of cells onto this row, but the danger is that anyone could inadvertently reintroduce the error.


  • You can still use the Java debugger if you don't have the source. JD-Eclipse worked very well for me, even though it is only at version 0.1.3. (I wonder if it will decompile classes written in other languages such as JRuby?)

  • It's time someone made a proper Maven dependency, with sources and javadoc, of the latest Fit, Fitnesse and FitLibrary versions - the current version of FitLibrary, dated April 5th, 2011 in fact solves the exact problem I encountered!

Friday, 11 February 2011

So long then, Ken Olsen

Ken Olsen, founder of DEC, passed away aged 84 on Sunday 7th February. Read a short obituary here. I used to consider DEC as the nimble young upstart snapping at IBM's heels and making computing affordable. My first real computing experience was on the undergraduate DEC-10 system (running TOPS10) at Leeds - and it shaped my subsequent career, though various PDP-8 and PDP-11 minis featured even before that. RIP Ken.

Saturday, 29 January 2011

The oddness of socks

In a moment of boredom, and prompted by a recent survey of wacky interview questions, I plotted out the probability graph of finding a matching pair of socks at random, based on the number of black ones among 25 grey ones. It turns out that you need only 3 black socks to drop the probability of a matching pair from 100% to 80%; 9 in 25 gets you to 60%. Anything over that makes very little difference up to 25, where the probability drops to a minimum as you would expect. After that it starts rising again slowly, but never reaches 100%. YOU NEVER HAVE A LESS THAN 48.9795918% CHANCE OF GETTING A MATCHING PAIR. I find that oddly comforting.

Friday, 14 January 2011

Oracle 10g problem under Windows Server 2003

It cost me the best part of two days' detective work to fix a problem with the Oracle DB Control service. Symptoms include:
  • "CONFIG: Waiting for service 'OracleDBConsoleorcl' to fully start" in cfgtoollogs\dbca\orcl\cloneDBCreation.log
  • "The oracleDBconsoleorcl service could not be started"
  • "[Orion Launcher] ERROR app.ContextInitializer contextInitialized.272 - Integration Class not found: oracle.sysman.ias.ias.IASIntegration" in emoms.log
This started to happen after a failed import using the data pump (impdp) trashed the database and I rashly thought that I might clear up the problem by uninstalling and reinstalling Oracle

Background: For a client project, we needed a local copy of the client's schema and stored procedures. I found it remarkably straightforward to install the Oracle product and a default database instance named orcl. However, attempting to import the client's exported schema and stored procs caused a rash of errors and then the SYSTEM user's password had been corrupted too. My suggestion: use the deprecated exp and imp tools instead. They're much more straightforward to use, AND the wonderful DDL Wizard is able to convert the exported file to DDL and PL/SQL that you can run in SQLPlus instead of overwriting your database contents willy-nilly.

Solution: I wish there was one. The problem appears to occur in the final phase of the database configuration assistant - after creating and configuring the database it tries to start up the console service for it and fails, for as-yet unfathomable reasons. Could it be to do with the fact that we also run MS SQL Server on the same box? Yet this was fine before I tried to reinstall Oracle. (As I eventually learned, I need not have redone the entire installation, because the database configuration assistant is quite good at deleting the database instance and creating a new one - in fact, this is what the installer invokes anyway).

Luckily the whole thing runs on a virtual machine, so I am going to get the previous week's VM backup image restored. Luckily we hadn't been doing a lot of work on that machine in the meantime.

My grateful thanks to the many bloggers who came up with possible solutions - none of which worked for me:

Wednesday, 12 January 2011

Software: Craft or Trade? You decide

Dan North has started a serious discussion with his insightful article about the Software Craftsmanship movement and where its manifesto possibly misses the point.

Thursday, 6 January 2011

Breaking up the big rocks

A colleague has circulated Richard Lawrence's nine patterns for dividing up user stories. These are going to be very useful. I wonder if someone will add more to make the magic Baker's Dozen?

New Ideas in Social Marketing

Attended a stunning event last night at the BCS London conference rooms. The speakers were Thomas Power of Ecademy and Lee Bryant of Headshift. The event was jointly organised by Richard Tandoh, Dalim Basu and Sara Misell on behalf of the North London Branch, Elayne Coakes on behalf of the BCS Sociotechnical specialist group and me on behalf of BCS Software Practice Advancement.

I learned that my use of social media was probably at the very raw beginner level - and moreover, that all the companies I have ever worked for, including my current employer, are at or below that level. If you want some insights into your level of influence measured by the effectiveness of your online behaviour (and how it compares to others), try Klout or PeerIndex. These applications use people's Twitter usernames as the primary key, so if you aren't on Twitter, you don't even get to first base.

Thomas showed how the stream of information we receive from the Web is growing exponentially - his FriendFeed home page was updating with new events more than once a second. A potentially incredibly useful tool for cutting this deluge down to size is made by My6Sense. They make a reader for iPhone, iPod Touch and Android devices that watches your Twitter, Facebook, News and RSS streams and brings the most important items to your attention. Thomas believes it takes around 30 hours to train it. More importantly, this being a social media world, once something has caught your attention, the my6sense app lets you share it easily with your own network of contacts.

In the Q&A session, I found out about a recently launched online service that is attempting to cross-fertilise a crowd-sourced knowledge repository (think Wikipedia) with a personal reputation index (like eBranding Me). A fun way to find out more is to take the Quora programming challenge.

The discussion in the pub afterwards was most illuminating too, though it veered away from social media to discussing the disaster that is likely to befall the civilised world when, not if, the next massive Coronal Mass Ejection occurs. This event is expected to occur within 10-24 months as of this writing and is likely to knock out not only communications networks (particularly satellite-based ones) but all manner of computer systems, data networks and power grids. Since everything these days is dependent on computers, we're likely to suffer supply shortages of everything from drinking water to fuel. As for withdrawing money from your bank account, you will probably be well advised to forget it for a few months. The guy telling us this has inside knowledge as a result of working for a major data security company and claims that they have working solutions to sell that will handle the backup and disaster recovery requirements of computer users from home users to data centres (remember that from the first detection of a CME, the world has only 15 minutes to secure everything before the plasma storm hits). His advice is to print out your bank statements and keep them safe along with non-perishable emergency supplies; also to have a spare laptop computer somewhere wrapped in several layers of tin foil to protect it from EMP. Contact me if you want to know more!

Monday, 3 January 2011

We need to re-learn that it's OK to fail

While trying to find the answer to a festive season quiz, I stumbled across this blog post. Check out the "more fialures" (sic) section - it makes reassuringly heartening reading...