I would like to thank DFRobot for sponsoring this project. They provided the two MiniQ chassis kits for the tanks.
The rules of the game are pretty simple. Just shoot your laser at the opposing tank and hit it on one of the 4 sensors. Each sensor corresponds to a crew member: gunner, driver, commander, and machine gunner. If 3/4 of the crew is hit, you lose. If a gunner or driver is hit they can be replaced if you have enough crew remaining. There are also penalties to getting hit. If the gunner is knocked out, the tank can't fire for 6 seconds and the reload time increases. Additionally, if the driver is knocked out it reduces the speed of the tank and prevents movement for 6 seconds. My tank tag game is based off of the video game War Thunder.
2The Tank Chassis
DFRobot was generous enough to send me two of their MiniQ Robot chassis. The chassis have plenty of mounting holes that allow you to add brackets. They come with two motors and wheels, along with two sets of caster wheels to add strength. The assembly was easy and simple. All I had to do was attach 2 screws to each motor and caster ball.
Next, I 3D printed 8 rod supporters, which screw into the chassis using a 3mm machine screw and nut. Each pair lines up across the chassis, allowing for a brass rod to span them.
3Designing the Tanks
Fusion 360 is my CAD program of choice, so I used it to design the tank bodies. The Panther and Sherman are some of the most iconic tanks of WW2, but more importantly, they are simple to replicate and model. My friend Adam, who goes by “AceOfAces16”, designed a basic Panther hull and turret in Blender, which I then imported into Fusion 360. Next, I designed parts around the basic solid model. This was done once more to create the M4A3E8 Sherman.
4Tank Electronics Part 1: Motors and Brains
This was the most arduous step of creating the tanks.
The Raspberry Pi is unable to provide the current and voltage necessary to drive the motors, so a motor driver is needed. I chose the L293d H-bridge driver for its size and simplicity, as it uses only 4 pins from the Raspberry Pi. This driver can supply up to 12v at 1 amp to the motors, making it the perfect choice.
Second, I needed a way to measure the 4 LDRs (variable light resistors) that give a value based on the amount of light hitting them. Lower amounts of light increase the resistance, and higher amounts of light decrease it, making it impossible to read them digitally. The Raspberry Pi has no ADC inputs, so I had to find a chip that could do it. The ADS1115 is an amazing, tiny, 4 channel analog to digital converter that communicates over I2C, so it uses only 2 wires, which frees up some precious few GPIO pins. The ADS1115 also has a Python library that was made by Adafruit, which allows for the gain to be set and read each of the four channels. Optionally, you can add an lm386n if you want sound effects. Just connect IN to pin 18 and VCC to +5v.
5Tank Electronics Part 2: Power and Servos
Now there was the question of “How do I power this?” I had to provide power for 2 servos, a Raspberry Pi Zero W, an ADC, a laser diode, and 2 motors. First I divided up each component into voltage requirements. 5V for the Pi, laser, and servos; 3.3V for the ADC and servo driver; 6~12V for the motors.
2, 5V regulators can provide enough current (3 amps) to power all of the 5V components. For a power source, I chose to use a generic RC LiPo battery that could supply 11.7V at 30C and had 1800mAh of capacity.
Now that power and power delivery had been taken care of, I moved onto servo driving. At first I tried to use the GPIO PWM class to control the servos directly from the Pi’s GPIO pins, but a microprocessor can’t deliver the exact timings required unlike a dedicated chip. So I went searching, and eventually stumbled upon the PCA9685, an I2C 16 channel servo driver, exactly what I needed. Because it also uses the I2C protocol, I could easily connect it to the ADS1115.
Adafruit also provides a helpful library that controls each channel with a certain pulse. Using a dedicated chip offloads the processing from the Raspberry Pi, freeing up CPU cycles and simplifying the code.
You can find the ADS1115 library here: https://github.com/adafruit/Adafruit_Python_ADS1x15 and the PCA9685 library here: https://github.com/adafruit/Adafruit_Python_PCA9685
There are two boards that need programs, one is a Raspberry Pi that uses Python, and the other is an Arduino Nano that uses C++. For the Python code, I created a class that handles the motor and servo setup, receiving serial data, and controlling all of the tank’s electronics. All that was left was to create a main file that inputs the GPIO pin numbers and updates the serial buffer. Now for the controller code. The controller’s brain, an Arduino Nano, takes in four analog inputs, sends I2C data, and controls 4 LEDs.
It uses the Arduino Timer library to control how often analog data gets sampled, along with controlling reload speeds and laser firing time. View the attached code to see more.
After meticulously building each tank and controller, it was finally time to use them in a game, but first I had to pair each tank with its respective controller. To do that, I turned on one controller and then typed
scan onand after the controller showed up as HC-05 I typed
scan offthen entered
MAC_ADDRis the MAC address that showed up for the HC-05 module. It will ask for the PIN to pair, which is 1234. Now just type
exitand then run the program by first typing
sudo rfcomm bind /dev/rfcomm1 MAC_ADDR. This will bind the Bluetooth port to a serial port, allowing the pyserial library to read the data from the HC-05.
And that’s it! I drove my tank and my dad drove the other one, circling and firing at each other until one of us had our crew knocked out. This is a fun and entertaining take on laser tag, and I would again like to thank DFRobot for supplying the MiniQ Robot Chassis Kits.