Back in the summer of 2018, Joseph and I found ourselves at a ‘super secret’ meal after the first evening of Raspberry Fields. Apparently, staying in the same seats for the duration wasn’t allowed, and as such, we chatted to a few different people. Luckily, for our dessert, we ended up sitting opposite Michael Horne and Tim Richardson – famed for creating the infamous Pi Wars robotics competition. I had heard about the event on Twitter, and was especially interested in having a go.
To cut a long story short, I was very keen to take part! Furthermore, Joseph was definitely up for sponsoring the event with some prizes.
The good news came on the 30th of September 2018. Our application had been successful and we were set to compete in Pi Wars 2019! I was to take the reins on our entry, as Joseph is a very busy person, and as I was fairly new to python, it would be a great learning experience.
“I knew it was going to be challenging, but I hoped it would be rewarding as well”
The process of learning how to do any of this was going to be quite extensive. I’m a Raspberry Pi Certified Educator, and I had tinkered with the Pi on the odd occasion, including making a Wiimote controlled vehicle using the CamJam kit but I had never completed anything beyond this. I knew it was going to be challenging, but I hoped that it would be rewarding as well. One of the best ways to learn a programming language is to use it in context; a real application.
When discussing ideas for the robot (before we had applied), Joseph had mentioned that there was a Python library to control the Crumble over USB. This was brilliant. We could use the Pi for all of the processing power (to stick within the rules!) and the Crumble could be used as our Motor Driver board, and power any Sparkles we may want to attach.
My first step was to focus on learning Python. I’d become familiar with a couple of written/block-based languages in the past, and I had even gotten halfway through a Python course, but unfortunately it had been a while so I needed to start from scratch. I made it part way through an Udemy course, and then I started and completed the free Python course from Codeacademy. This was a big step for me. I had reached the end of a programming course, and I was feeling much more confident in getting started.
“After swearing I would get started before Christmas… January arrived”
After swearing that I would get started before Christmas, and not do my usual procrastinating, January arrived. It was very busy – we were heading to BETT this year to exhibit. I knew I wasn’t going to get started until February. As a part of a conversation with our Spanish distributor for the Crumble (Complubot), Joseph had been made aware of something very useful – The Pixy Cam.
After getting back from BETT, we looked into the Pixy2. It looked incredibly easy to use, it could detect coloured objects and lines, and it was possible to interface with it via Python – perfect! We purchased the camera, along with a pan and tilt mechanism, and couldn’t wait to get stuck in.
The included software for the camera was simple to use, and offered some great features – especially when it came to tweaking the camera’s settings to recognise colours (signatures) and lines (vectors). One of the steepest learning curves, however, involved interfacing with the camera via Python. It seemed that the device was much more suited to controlling via an Arduino than a Raspberry Pi, and as such, it was hard to find a great deal of information about using it with Python.
As a part of the installation process, four example Python programs were generated. I would rely heavily on these to work out what to do!
I was becoming overwhelmed with the ever-decreasing time left, and this caused me to take some drastic action – a mind map! I planned a very basic chassis to get something moving, and then wrote down what steps needed to be completed before the big day. This is called decomposition – breaking down a problem into smaller, more manageable pieces.
“I was feeling much better about the still mammoth task ahead”
One of my first steps was to control a motor connected to the Crumble, by using Python This would become my ‘Hello World’ style program. After this small, but important step, I was feeling much better about the still mammoth task ahead.
The remote control portion of the project was quickly finished – I had used the ApproxEng library for connecting to, and controlling motors, in the past, so it didn’t take much to adapt the code to work for the Crumble. Theoretically, that was the programming completed for half of the challenges!
The steepest learning curve, and the point at which I repeatedly questioned why I was doing any of this, was programming the autonomous challenges. After tinkering with the example Python programs, I decided to start with the Line following program. This wasn’t too difficult to do – I had experience with various algorithms for line following. Once I had worked out what information I could use from the Pixycam, it all fell into place quite quickly! After this, I set to work on driving towards a colour signature. This was with the autonomous maze in mind as I felt that this would be more challenging than the Nebula. Once I had the working maze code, I could reuse elements of it to help recognise, and correctly approach the four colours in the Nebula task.
I learnt a lot whilst programing these challenges:
- Things fail – a lot. I spent a lot of time thinking, staring at code trying to make sense of why it wasn’t working.
- Take breaks. I regularly found myself slumped at my desk, getting increasingly frustrated. I stopped, came back to it the next day and more often than not, immediately solved my issue.
- Don’t be afraid to redo something. Some of the functions I had written were messy, and didn’t work properly. A whole new line of thinking enabled me to produce better, and more efficient code!
- Not everything has to be perfect. This is was an amateur robotics competition, of which I am a beginner. It was better to have something clunky but working, than something that doesn’t work at all. The day before the competition, in consultation with Joseph, I decided to put my ‘fancy’ maze following code to bed, and develop a simpler version. Given that the maze was preset, and we had access to the plan, why would I even bother looking for the next alien to the left, if i knew it was a right turn?
We both thoroughly enjoyed our time at Pi Wars. It was a day of both success and failure, but it was a very rewarding task to undertake. I managed to battle my way through to the Grand Final of Pi Noon ( a 1v1 balloon popping battle), coming second after a close final. But more surprisingly, we won the beginner category! Our slow, solid and steady Crumble Robot had powered its way round to victory!
Here are just a few pictures from the day!
This whole experience has proven that one of the best ways to learn programming is to give it a context. Trying to learn something whilst not giving it a real-life context makes it very difficult, and it doesn’t ‘stick’. It is worth mentioning that this is one of the main ideas behind physical computing – blurring the lines between a computer and physical components and pieces. Programming and controlling something that you’ve made yourself gives you a fantastic feeling, and I definitely have a stronger urge to continue, more so than in the past.