Tom's March Blog
- Tom Hall
- Mar 31, 2020
- 2 min read
This month was devoted entirely to coding (before it was cut short). I wanted to optimize the code for obstacle avoidance as well make the line following as smooth and fast as possible. The first stage was to remove anything from the code that was unused; inside the default program Dr Davies had kindly included a speed control function that allowed the mouse to more easily travel in a dead straight line. The two issues with this was that it was constantly using the CPU's time and resources so the mouse was slower to react and it also meant that I couldn't code one wheel to deliberately go slower for a turn as this function would try and undo that. I decided to remove all the movement functions as well because each would turn for a set distance which meant the mouse was always over turning and missing its mark.
After creating my own new set of movement functions, I included them into the Obstacle avoidance code and moved onto line following. With the increased number of sensors it meant there were now 32 possible inputs, fortunately I didn't have to code each option as some were physically impossible because of the width of the line and others even if they did occur would be recalculated microseconds later as the mouse carried on moving from the previous input. I used a switch case statement to keep things neat, and had it so each LDR would send back if it was on or off. The code would then assign each LDR a power of 2 if it was on so the first would send back 1 if it was on, the second would send back 2, the third 4 and so on. It would then add these together and get a unique number for that input and that would correspond with a setting for the motors.
Comments