Day 9- Jerry Completes his Mission

Inga Bourke Mullaney
3 min readApr 19, 2021

--

So here we are, the final hurdle. Getting Jerry to navigate through the maze and catch some ping pong balls.

I started with the code that comes with the buggy, but I found most of the built-in functions bulky and completely uncommented so therefore really hard to navigate (comment your code people!!). I decided to just use the bare minimum from that and then rewrite the main code myself. I also decided to write some new turning functions as the left and right functions in the motor code provided were not smooth. The movement functions I used in the main code are shown below. I also took 3 away from the left motor speed, for some reason, the left one goes faster and makes Jerry drift off to the side… odd bug but hey we do what we can.

Movement Functions

I wanted to navigate the maze using the ultrasonic sensor, which emits a sound wave and measures the time between sending and receiving a pulse. In the code, I converted the time measured to distance by multiplying by the speed of sound in air (units cm/milliseconds) and dividing by two as the sound wave has to travel both ways.

Code for distance measurement

Then, for maze navigation, I added a counter and used a switch statement to tell Jerry which way to turn (left or right) after detecting each obstacle. After detecting a wall, the correct function would be called and one would be added to the counter to move it through the maze.

This worked well until I reached turn 5 at which there was no wall in the course for the sensor to detect… Annoying. While there may have been a less bulky way to achieve it, I solved the problem by writing a final turn function that incorporated all the last movements Jerry needed to complete the course and catch the balls in the collection zone.

After a few tests to perfect speed and adding a stop between each turn to make it a smooth ride, Jerry was finally ready to conquer the maze and collect his prize. I managed to land 3/4 balls into the container which I was really happy with and after a few runs to ensure consistency, I called it a day!

So without further ado, here it is — >

Maze completed and 3 balls landed!!

--

--

No responses yet