So… I’m a pretty experienced programmer. I wrote computer games in BASIC many years ago, back when I was in primary school. Although I took an undergraduate degree in Electrical Engineering, I actually took more Computer Science units than was necessary to get a BSc (Computer Science) at my university. I beta-tested two agent programming languages in the 90s. I was writing commercially-deployed software in C++ when they were still messing about with how to do I/O in that language. I’ve taught Computer Science at university for many years, in a huge variety of languages, including (but not limited to) Pascal, C, Java, Miranda, Haskell, Prolog, and various flavours of assembly language. I’ve programmed in even more. My current favourite teaching subject is on compiler design and implementation.
Yet in all this experience, I’d had very little exposure to Python before I started messing about with Raspberry Pis a few months ago. When I started messing about with Python, I was just throwing things together, reusing a lot of other people’s code. I got the basic motor control and line following working on our Glitterbot quite happily this way. But now that I want to do more with it, I want to do it properly. And I want my son to use my code too, so I want to make sure that it’s really clear. So this weekend, I started tidying it up, putting things into classes and adding appropriate methods. And you know what? It’s not easy to do it right. There’s a lot of stuff out there on the web about Python – and some of it is really good, but none of it answers the questions that I have. Particularly, what makes Python different to other languages that I know? Scoping seems to be part of the answer, but I think that there’s more than that. So one of the things I’ve done this weekend is seek advice from my friends and order a reference book (Python Essential Reference, by David Beazley). It’s on its way, and hopefully will improve things.
The other hard lesson learnt this weekend is: when testing software to drive hardware, make sure you have the hardware connected correctly first! Fortunately I didn’t blow anything up, but I did waste at least an hour, thinking that in cleaning up the code I’d broken it, whereas the actual problem was that I had the wrong connections at the hardware level. 🙄 Anyway, the software is coming along now, but we do seem to have a dead line follower – another (and some spares) have been ordered. Fairly happy that I can do basic line following with a single sensor, but I’d rather work with three together.
Next thing that will be attached hardware-wise is a camera, and we will also add some sort of distance sensors shortly. And some lighting, just for fun. And maybe a speaker too. From the software perspective, my big task is to get the boy up to speed with Python – but before that, I want to make sure that I am!
The other issue that we’re dealing with at the moment is that when the batteries get too low, the Pi won’t boot properly. This is a problem with running both the motors and the Pi off a single Lego battery pack (6xAA batteries). We’re thinking about solutions to this one…