Sometimes it's a good idea to pause when things are going well

Today I've been writing code. I love writing code. Perhaps too much. If a program is going well I have to reminded to do things like eat and drink etc etc. 

This was one of those occasions. But as I was munching my sandwich I came up with a way to make the program even neater. If I'd carried on at full speed I'd not have spotted this for a while and then either missed out on a trick, or had to do some rework later on. 

Having thought about this a bit more I think that it is actually quite a good idea to walk away from a programming task for a little while and go back to it, even if you are coding up a storm at the time. On any programming project (particularly programming coursework) I strongly advise people to start early so that they have time to fail. But it also means that you can stop and smell the roses every now and then, and this can make the result even better. 

Caution Horses

So, we're driving back down the motorway on Sunday and we pass a huge van with the above message on the back. 

For a moment I had this vision of a the van containing a pair of specially trained equines who turn up when you do something stupid and say things like "Just this once, we'll let you off. But if you'd better not do it again". 

After some discussion we decided that it could also be an instruction to pull into the next field and tell the occupants not to eat grass like that, or whatever. 

HoloLens and Occulus Rift at c4di

I've not got a HoloLens. Or an Occulus Rift. Yet. But I've had a go with both of them and they are really, really interesting. The way I see it, there are two game changers coming round the corner as far as computers are concerned. One is the Internet of Things, the other is virtual/augmented reality.  You need to know about both of them.

You can get to play with the new versions of reality  at a c4di event on Thursday morning this week, which is open to all. Sign up here. It's free. I'm going.

New to Newcastle

I've not been to Newcastle for a holiday before. I've been for external examiner duties and up until now it's primary claim to fame as far as I'm concerned is that there once I found two "extra tall" shops next to each other on the road up from the station. I hope they're still there. 

Anyhoo, we came up to Newcastle for the weekend and it is a lovely place. We found a hotel close to the Millennium Bridge and, although the weather hasn't been the best, we've had a bit of a chance to make the most of the splendid architecture around here. 

As we walked around the riverside I found myself thinking about what's happening in the Fruit Market in Hull. We have a similar waterfront setting and even a fancy bridge or two of our own. I'd love to see the same kind of thing happen where I come from. 

Beamish is Wonderful

We'd never been to Beamish before. People had told us that it's great. Turns out they were wrong. 

It's awesome. 

It's history meets Disney in a wonderful way. Think of something on the scale of a theme park, but with a strong historical strand running all the way through. It has themed areas, rapid transit all around and helpful and enthusiastic staff everywhere. Plus you learn stuff. 

We didn't quite see it at its best, what with the weather and all, but we saw enough to make us want to go back there. 

Very Busy Hardware Group at c4di

We had a really busy Hardware Meetup last night at c4di. Plenty of new faces, and quite a few folks who'd taken HullPixelBot kits and brought them back made up. I showed off the latest software and the HullPixelBot improvements and it was lovely to see so many people on the night. 

I'm going to be releasing some new software for HullPixelBot in the next week or so, to coincide with the first public appearance of HullPixelBot at the Amy Johnson Maker Fest on August the 27th next week. If you want to come along and see what we are doing we'll be in Zebedee’s Yard, Whitefriargate, Hull HU1 2EX along with lots of other folks between 10:00am and 16:00 pm. 

If anyone fancies helping me "man the stand" over the day then I'd love to hear from you. Ping me a message via twitter (@robmiles) or email (rob@robmiles.com) and we can get some kind of timetable together. 

If you want to come along and take part in the hardware group (you don't have to build a robot, but we'd love it if you built something) then you can keep track of the meetups and sign up here

Thanks for the Trombone Tom

I've no idea who Tom is. But he has been reading my blog from 12 years ago. He noticed my lament that I'd failed to find any hits for the search "trombone playing dog" and responded with a link.  Thanks for that. Made my day. 

In fact, things have really moved on. I've just done my own search for "trombone playing dog" and found loads of hits. Such is progress. All we need now is world peace and a cure for cancer.

Hull Pixelbot Version 2.0

I've just released a new set of design files for the HullPixelBot. I've made some improvements and also added holders for the pixel lights (always useful in a pixelbot) and the distance sensor. I was quite proud of the design for the distance sensor holder, until I tried to use it. 

I thought I'd been clever by providing mounting slots for the distance sensors so that the wires could come through the slots for the connections on the back. Turns out this was actually stupid. It turned out to be really hard to make the connections with the hole. 

The new design (which you can see above) has separate holes for the two sensor wires, and they are arranged vertically so you can just connect all the bottom wires together to a common ground (or reference voltage) and then take each of the top wires and connect them to their potential divider resistor and reference voltage (or ground). I'll be doing a detailed post about wiring things up a little later. 

Interrupts Interrupted

I've spent some time writing smooth movement routines for the motors for the HullPixelBot. I want the motor movement to run in the background, so that the program can do other things as the robot moves. This will make the drive very like the behaviour that you get from a traditional "servo" motor that starts turning when the program switches it on.

Thing is, the stepper motors only turn if the program sends the appropriate set of signals to the coils in them. The solution to this problem is to use the timer on the Arduino processor. This can repeatedly trigger a bit of program code at regular intervals using a hardware technique called an interrupt.

Interrupts are used by a computer to respond to real world events. Tapping a touch sensitive screen, moving the mouse or pressing a key are all things that interrupt a running program and cause the computer to run a special piece of code called an interrupt handler which deals with the event. In the case of a key press, for example, the operating system (perhaps Windows 10) responds to the interrupt by sending a keyboard message to the currently active program.

In the case of the HullPixelBot I'm using a timer to produce a sequence of interrupts at regular events which are then used to trigger code which moves the stepper motors to their next position. The code required to do this is quite tiny, and so once the move has been completed the "normal" program can be resumed.

I don't reckon you can call yourself a programmer unless you've written an interrupt handler or two. I've done quite a few and they are rather fraught bits of code. You're not allowed to touch any of the things used by the "normal" program (in case you confuse it), and you must complete your action in the shortest possible time, otherwise you'll bring the computer to a halt. Programming ninjas can write code that uses multiple interrupts from different sources at the same time. 

Which is what I want to do. 

I want programs to be able to use the distance sensor and the motors, and for both of these devices to work using interrupts. Now, I think of myself as a bit of a programming ninja, so I knock out the code and fire it up. And it doesn't work. 

I can have motors, or distance sensor, but not both. 

I'm not surprised by this because it can be tricksy if interrupts occur during interrupt handlers. So I check the hardware manual for the processor and get myself into a state where I'm convinced it should work, but it doesn't. Hmm. Perhaps I'm not a ninja after all. 

So it was back to the start, and a careful re-write of the code to make it as smooth as possible, and remove any ways in which the two handlers (one for the timer, one for the distance sensor) could interact. And it still didn't work. No fair. 

Of course, I eventually figured it out (otherwise you would not be reading this blog post). It turns out that it had nothing to do with the interrupts. It was just that when the program turned the motors on it dropped the voltage level in the robot power supply to such a low level that the distance sensors stopped working. I was testing the code on a machine on my desktop and I'd left the motor power supply turned off so that the robot wouldn't try to run away. That lack of power was my undoing. 

The good news is that I'm now pretty confident that the code I've written is solid, and the HullPixelBot can move in a very nice, precise way, measuring distance values as it goes. And I've learnt something about motor power and distance sensors, which is useful. 

I'll be showing the code off at the hardware meetup on Thursday this week. 

HullPixelBot is going places

I spent a happy chunk of today designing and printing a front sensor assembly for the Hull PixelBot. The new part provides an ultrasonic distance measure and three light sensors. 

This will mean that the robot will be able to find and move towards light sources and also detect obstacles in its path. 

You can find out more about HullPixelBot at the next C4DI hardware meetup on Thursday 18th August. Sign up here (it's free). Anyone can come along and get into building tiny cheap robots. I'll have some more chassis kits to give away. All you need to do is add around 10 pounds worth of parts and you have a wandering pixel bot. 

And if you want to see a bunch of HullPixelBots in action I'm taking a mini-swarm to the Amy Johnson Festival Makerfest in Hull on 27th of August. 

Who knows what they'll be doing by then....

Hull Looks Great

Every now and then I take a picture that I'm really, really, pleased with. This is one of them. I took it today wandering round the waterfront in Hull. This is fast becoming one of my favourite places. The Fruit Market is coming along a treat and interesting cafes and shops are springing up. It's a pity you have to cross the A63 to get to this part of town, but it's well worth a few seconds waiting at a pedestrian crossing. 

I took a few more pictures that I'm happy with. You can find them here

Star Trek Beyond

Star Trek Beyond is a Star Trek film. It's a good one. I reckon it's the first "proper" one of the new movies, because it has a proper element of "boldly go" about it. They really are meeting strange new worlds etc etc. That said, it does have remarkable similarities to the other two movies, which both had a plot where someone tries to take over/destroy everything. But that's Federation life I guess.

For me, the best thing about it was the way that, now we've had a couple of movies to properly establish the characters, we can sit back and enjoy how they interact. The special effects are good, and there are some suitably silly moments too. Go see. 

Candy Chaser Game

This is a neat little game which gave us a diverting few minutes this lunchtime. Each player is trading in a particular type of sweet and players take it in turns to move the price of any the sweets up or down. Once trading is over you have round where everyone tries to figure out who is selling which kind of sweet. If someone works out which sweet you are trading, you are out. If they get it wrong, they're out. Last player standing with the highest score wins. 

Games last around 20 minutes or so maximum. It's quite fun to play, although in typical Computer Science fashion we all massively overthought the situation and I managed to win one by just doing the simple, stupid thing. 

Quite fun. 

HullPixelBot can now turn corners

Spent a bit of time today fiddling with timer interrupts so that I can get fine control of the speed of the motors on the HullPixelBot. Because they are steppers they are quite precise, which means I can get the bot to trace accurate curves. 

The next thing I have to do is put the light and distance sensor on the front (along with a bumper) and then we'll have a proper robot. 

Bristol Board Game Cafe

I didn't take this picture at the cafe. But I'm still very pleased with it. 

A while back we went to the board game cafe in London.  We had a great time there and so today we went out to the one in Bristol. Just as much fun. In fact it was even better because we had more time to play, with no train to catch this time.

We had a proper go at the Thunderbirds board game. And by proper I mean that we played it long enough to lose. Oh well. As with the one in London, the service and knowledge of games was first rate and the food was excellent.

By the time we left the place was filling up nicely and what sounded like an uproarious session of Cash and Guns was going on in the back. Next stop, the cafe in Hull.....