3MEMS3: Building the Obstacle Course and Programming the Robot
As I've said many times now in this blog, my robot has to navigate a course to catch ping pong balls fired from a launcher then return to the start. While the end function could be considered somewhat trivial getting to this stage from what we started with proved to hold some challenge and allowed us to explore some new areas of design while drawing in what we already know.
The obstacle course which the robot has to navigate was outlined with the following diagram. This course would have to be constructed and tested.
The construction of the course was very simple, it was made using cardboard and masking tape on the floor. Space in the room was tight but we made do.
A measuring tape and some scissors were all that was needed to do this. Some flexibility was allowed in the construction of this course as original dimensions were very tight with the dimensions of the robot.
The robot uses an Elegoo made Nano board. This is compatible with Arduino IDE, an open-source software that allows code to be easily uploaded to a board. This is the software I used to ensure the robot could reliably and repeatedly complete the course.
There were a few methods by which one could go about programming the robot.
Setting out the steps that need to be taken for the robot to move through the course, so the microcontroller can systematically run through the code and execute the required movements in order. The other more complicated programming option is to make the robot navigate fully autonomously using feedback from the ultrasonic sensor and IR sensors built into the robot.
Due to how tight the course was and a lack of accuracy of some of the sensors, the IR sensors in particular, a fully autonomous run through would be difficult and likely beyond my programming skills in the timeline I had.
For this reason, I decided to keep things simple and effective. I made functions for the robot to turn left and right and move forward back with its dc motors and outlined the steps which it would have to go through to navigate the course.
Some of my code was adapted from the code that was pre-installed on the Elegoo Tumbeller but there's nothing revolutionary here, all was completed quickly.
My code starts with some basic preamble, this just outlines what is contained within the code.
The Pin.h library has all pins named so I don't need to reference numbers in the script. This helps a lot, especially with busier scripts.
The universal variables are also declared at the beginning.
The void setup() is a function at the top of the program, this runs at the start of the program and is the place where you set things like pinMode.
From here I used the ultrasonic sensor as a trigger to start the robot into the obstacle course, this script sets up the sensor appropriately.
Different motor pin permutations were then used to build the functions needed for turning and moving.
The ultrasonic trigger is then set and the functions are ordered in the sequence needed to complete the course. This was done in the void loop(). The void loop() allows the robot to re-run the course after it has completed without the need to reset anything, just trigger the sensor and it’ll go for another run.
A little testing was needed to dial in the turning angle and speed but it didn't take long all things considered.
The stops between functions were added to ensure the robot was most stable before a direction change or acceleration.
With a little more time I would have liked to employ some more complex functions to trigger different steps of the program, and progress to allowing the robot to make decisions for itself. I did experiment with this and while I don't think I was too far off, it was ultimately lacking in reliable consistency.
Once the robot made it to the end of the course I use my launcher to shoot ping pong balls into the box (with varying levels of success).
The robot could smoothly run through the course and return to the beginning.
One this particular run the launcher wasn’t too successful but space was tight!
That's all for now, but very soon on this blog, I will reveal a new project that’s been in the works for some time and once again it involves the little Elegoo robot.