Direction Training - Magnetometers and Gyroscopes

For what seems like far too long, we've been stuck on trying to teach our robot which direction it's facing in and change its direction based on this value, well, that was until now. 

For previous years we've used sensors to measure distance, both ultrasonic and laser-ranging TOF (Time-of-Flight) flavours, and these have proven very useful with challenges such as maze navigation. Last year we managed to achieve quite a good time in the maze but to say we were "winging it" would be a bit of an understatement, not so much with keeping away from the walls, but certainly in terms of which direction to take. Rotation was, for a want of a better word, blind. The robot was simply instructed to spin left or spin right for a period of time, but this is, as you can imagine, fraught with a number of issues. If the battery was a little low it wouldn't rotate enough and if it was freshly charged then it would rotate too much, then you have to take into account the grip of different flooring, how clean the tyres are etc etc. Of course, fully balancing the voltage to the motors would have solved some of that, but nowhere near enough to make it reliable and consistent to a level that we'd be happy with.

So this year we were keen to improve on that by giving the robot the ability to know which direction it was heading in. For us, the obvious first choice was to use what would effectively be a compass, which we'd achieve by using a magnetometer. It's fair to say that we spent quite a lot of time this year trying to get two different magnetometers to work, in fact we'd spent quite a lot of time fighting with them last year too. I have seen others achieve good results with magnetometers (not necessarily Pi Wars people), so I know it's possible, but sometimes you simply have to admit defeat, especially when the Pi Wars date is fast approaching. 

After conceding defeat to the little magnetometers, I reached out to a good friend (you know who you are and thank you once again) and they recommended that I try the BerryIMU v2 - Accelerometer, gyroscope, magnetometer and barometric/altitude sensor from https://ozzmaker.com, which if I'm perfectly honest is a little overkill for what need at this time, but I wasn't messing about now as this is beginning to hold up our progress quite a lot. 

Needless to say it works very well for us, with the key factor being the abandonment of the use of any reference to magnetic north and simply using the BerryIMU's built in Gyroscope. TOF sensors determine if the robot is square to a wall and the Gyroscope determines how much to rotate in relation to its current heading.

Below is a video of us testing 90 degree rotation and despite very little adjustment and tuning, it's proven pretty accurate so far.

We still have quite a lot more testing and coding to do to fully prove this concept, so tomorrow's blog post might be entitled "Direction Training - Back To The Drawing Board", fingers crossed that we've cracked it though, as this will open up quite a lot in our automated challenges.

Finally, the masking tape mounting of said BerryIMU is hopefully just a temporary solution.

Comments are closed