Obstacle Course and Launcher: Best laid plans of mice and men go awry

Donal Murray
3 min readApr 19, 2021

On the surface it felt like a simple task, send the robot through a simple course and use a homemade launcher to fire ping pong balls at and hopefully into a container mounted on top of the robot. How hard could it be? Lets just say that my hairline may have creeped back a few inches as I watched my launcher fail to hit the target on the fifteenth try. After assembling the robot I took a look at the code online, and I really didn't know where to start. Having looked at it and the other materials provided I came up with a prospective plan for the code. I like to write out exactly what I intend for the robot to do before I start. This basically consists of things like “The robot moves forward. The robot detects first object….”. things like this generally help when focusing on a task. As I mentioned before, things don’t always go smoothly, more often than not actually in my experience, it’s for this reason that you should never be afraid of a plan B or C.

My original plan for the code was simple, I would use a mix of timing and the robots Ultrasonic to navigate the course with ease. This worked really well until once again the technology turned on me at a moments notice and left me with egg on my face. Here is an example of what I was trying to do:

I was writing functions e.g. obstacleAvoidanceMode1 and obstacleAvoidanceMode2 that would trigger after a certain amount of time. ObstacleAvoidanceMode1 was coded to sense an object in either side of the sensor and turn 90 degrees left. My robot would move forward, sense the obstacle was close than the max distance I had designated and then turn in the specified direction. I was essentially creating functions with if statements like this:

I was using the pre-existing code which I found online to set this up, however, for this to work the sensor must accurately read the obstacles in front of it. I am still confused as to where I went wrong here, I was able to navigate half the course using the method shown until it all fell apart. I still can’t figure out what it is that is causing it but the robot would stop sensing objects and plough forward like a kamikaze pilot on the third turn. after an exhausting week I turned to plan B, timing it.

It is basically the most simplified way of doing something like this, use trial and error to create a time based program that could navigate the course consistently. I have included a snippet of that code below

It pains me to say I resorted to this because it is the most rudimentary way to achieve results but I simply could find no other way to do it consistently.

Some background code:

The motor control on the robot is probably most important when navigating the course. The concept is relatively simple , make the wheels spin the way you want them to. Here we use a digitalWrite function with the input and assign it a value low or high. You do this for each wheel for each action and then assign it to a command like FORWARD. Again I made use of online resources I found online to assist me in this.

Eventually it was time to let this speed demon of a robot loose on the course and see how she faired. I detailed this on my Instagram page. The original aims were achieved and it felt like I had achieved something even if it wasn’t exactly how I had envisioned it. here is a link to the robot completing the course.

https://www.instagram.com/p/CN0dw_kB5k_/

--

--