Micromouse encoders to measure distance
Encoders give a micromouse the power to measure the distance it travels so that it can build a mental map of a maze. Read on to see how I measure the movement of the wheels to calculate turns and forward movements.
When we left our heros,
In previous posts I got continuous servos and analog distance sensors attached to an Arduino. With those I can move and see the walls. By watching the wheels spin with encoders I can count how far the robot moves and turns. My micromouse encoders are sensors I’m familiar with, the AS5045.
The AS5045 micromouse encoders
The AS5045 gives a 12-bit value, or 4096 fractions of 360 degrees. It uses two hall effect sensors to measure the spin of a magnet. I put the magnet on the axle of a wheel and then float the AS5045 in the right location to read the magnet. A 3D printed frame will hold everything together.
In the picture above, the cardboard has a magnet taped to the end for easy handling and testing.
The magnet sensor has lots of pins, but we only care about five of them: GND, 5v, CLK, SD_OUT, and CSEL. GND and 5v will go to the power source on my robot. The other three will go to available Arduino pins 5,6,7 (for left wheel) and 8,9,10 (for right wheel). Then I’ll copy some code from my 2015 robot arm project to read the sensors.
Because the code is getting quite long, here’s a link to the AS5045 encoder test code on Github. I’ve trained the robot to move one wheel so it always matches the angle of the sensor. There are examples in the code showing how to do the same for both wheels and sensors at the same time.
Meanwhile, behind the scenes
This story doesn’t show the 45 minutes I spent looking for a wiring problem that was actually a problem inside my old Arduino. It doesn’t show the next two hours I spent looking for a separate problem inside my Arduino that were caused by bad wiring. It doesn’t show the sketches I developed that aren’t ready for tutorials yet.
Designing the frame
I used Fusion360 to build a model of every part in my robot. Then I placed the parts together and filled the gaps with a 3D printed shape.
I used to go crazy trying to guess which parts would not fit right. Now I print it and measure. Less stress, faster results. Case in point, only one of the parts fits correctly. I found four things to print it better in just a few seconds of looking.
Print a better fit, put it all together, attach a battery, and start moving through the maze.