Robot playing T-Rex Game

Arduino, C++, Manipulation, Signal Processing, Mechatronics, Circuit Design



Overview

This robot plays Chrome’s No Internet Dinosaur game by detecting the obstacles using an LDR and accordingly pressing the spacebar to make the dinosaur jump at the right time.



Personal Motivation

While I began delving deep into the world of building circuits and Arduino, my dear friend Effy John (great guy by the way, frightfully smart too) served as my sounding board for ideas. One of these was this, which he suggested I do as a software project completely in JavaScript or use Serial input, but I prefer to keep things more tangible :)


A Beignner’s Project with A Key Improvement

While this is a cliche beginner’s project, there is one major difference that makes the solution less reactive and more planning based, warranting the use of proper data structures and some parallelism:

  1. The LDR is placed at the edge of the screen rather than on it right in front of the dinosaur.

  2. This requires a queue to store a countdown of all incoming obstacles. These countdown timings also get dynamically smaller as the run progresses because the game speeds up.

  3. Further, the system needs to detect obstacles and press the space bar at the same time, which is impossible for a single-threaded Arduino. My solution to this was to make the servo’s angle a smooth function of the countdown time of the closest obstacle. This essentially primes the servo to press the button as an obstacle get closer, and keeps it primed depending on how close the next obstacle is.


Hardware

The hardware consists of an LDR 07 Light Dependent Resistor, a 5V Servo Motor, and an Arduino UNO R3.

Fig. 1. Schematic.


Conclusion

After spending around a day on this (because my laptop is kind of useless with an LDR and servo hooked up to it), it worked flawlessly for the first 10 seconds or so of a run, after which the dynamic speeding up of the code is unable to compensate for the inherent physical time delay of the servo pressing the spacebar. Of course I could get a faster servo/gearbox and see how long this thing runs, but I was quite satisfied with how far I reached with this project. This was also one of the first projects that got me interested in contact dynamics, owing to the fiddly spacebar.