Breakthrough Automated [K]annon Instrument (BAKI)
In my ongoing campaign to become a walking, talking Mobile Suit, after I finished the S.A.G.A. (Superior Assault Gauntlet Apparatus) project for my forearms, I decided the next body part I would โweaponizeโ would be my shoulders!
I wanted to create a camera-equipped shoulder cannon that could track, lock on, and fire automatically, like a Gundam!
The problem was, the only languages I had ever programmed in were MATLAB and C++, both for very simple applications.
An autocannon would surely be much more complicated, so I enrolled in ENGI 301: Practical Electrical Engineering to learn Python and power up my electrical & programming skills.
Raspberry Pi + OpenCV
Despite our instructor wanting us to use the Pocketbeagle microcontroller, I declined (๐คก) and used a Raspberry Pi instead because of its faster processor and larger RAM, more documentation, and it being more useful on my resume.
Both the Raspberry Pi and Pocketbeagleโs OS were based on Debian Linux, so while I may have been a little rebellious in disobeying my teacher, most of the things we learned in class could be mapped directly over - so no harm done!
This added computational power was absolutely critical for my project, because computer vision is a very resource-intensive task.
Speaking of which, I selected OpenCV (Open Computer Vision), an open source library (like a prepared code toolbox) to handle those tasks, because it paired well with Python and there was documentation readily available for it.
This was my workspace!
I had very little space in my dorm, but I made the most of it by borrowing a TV to use as a monitor, and laying a plank on a crate to use as a table. Thereโs a dumbbell weighing everything down ๐.
At one point I was worried that the Pi was throttling its processing speeds from excessive heat, so I put a bag of ice underneath it XD.
preliminary Electronics work
After getting fairly reliable results from OpenCV, it was time to add servo motors, to be able to move the cannon!
To do this, I bought a Servo Controller Pi Hat, a plug-in peripheral that allowed the Pi to control servo motors directly.
I removed the barrel connector and remounted the capacitor underneath the Hat to make things a bit more compact.
Here are the Pi and servo controller stacked on some nylon standoffs and bolted to a 3D-printed plate.
(1) Whereas usually the servo cables are attached vertically via header pins (circled in red) atop the Pi Hatโฆ
(2) By trimming them all and soldering in new 90ยฐ header pins below the board insteadโฆ
(3) I could attach the servo wires parallel to the underside, saving ~1cm of height and making things drastically more compact!
Here is the electronics โsandboxโ I tested everything in, and the servos Iโve been talking about this whole time, cycling.
Nothing too interesting, but part of the documentation nonetheless.
(I find it hilarious how the only part not being used in the 1st picture is the breadboard ๐)
fabricating cannon components
With a now mostly-working electronics loom, it was time to design some physical components!
Though some back-of-the-envelope calculations suggested my servos would be strong enough to move everything, the only way to be absolutely sure was to physically build and test everything!
I also needed to figure out how I would mount the electronics, camera, motors, and battery. Having a physical prototype would help visualize that problem immensely.
The system I planned on using to fire Nerf balls from the cannon was actually a direct import from my SAGA project, just with a longer cosmetic barrel and smoothed lines instead of the previous angular aesthetic.
It uses flywheel friction to grip and launch foam balls. A good analog for understanding would be a baseball pitching machine!
Here is the progression of my design, from sketch to early model, to final model!
Iโm good at conceptualizing designs on paper, and oftentimes skip the CAD step entirely before starting fabrication. This time, however, Solidworks helped me visualize how to best arrange and assemble those pesky few components I wasnโt sure about.
Basically, my design consisted of a base, a turntable, a pair of field goal-like uprights, and the aforementioned flywheel system.
The base / enclosure houses the Pi and auxiliary electronics, the turntable enables horizontal rotation for cannon panning, and bearings housed in the uprights allow for vertical tilt rotation! The flywheels handle the actual shooting, as previously mentioned.
Using a laser cutter, I made wood panels to form the electronics enclosure & base for the cannon.
I included decorative (semi-functional??) vents, as well as holes for switches, plugs, and displays to sit though.
After gluing the panels together, I applied body filler to hide the joints. Just to make things look that much more polished ๐๐ฝ.
I also designed the bearing mounts to be laser cut panels, and threw in some decor while I was at it!
By painting the wood black before laser etching it, I was able to get a โnegative filmโ effect of Baki flexing, and print the project name in block letters on the top panel.
It looks so freaking goodddd ๐ฉ
Gear Drives
Next, to properly enable my cannonโs 2-axis horizontal/vertical targeting,
I needed to think about how to take the servo torque and deliver them to the proper parts.
I went about this by using 2 gear trains!
To ensure parts would rotate smoothly with motor input, I went looking for bearings and turntables (basically a bearing with flanges).
Though I was planning on sourcing a turntable from the workshop part bins, no matter how much I rummaged, I couldnโt find one!
Had a mild panic attack until, on a whim, I climbed a chair and found one on top of a high shelf. It felt like a real life easter egg!
I bolted the turntable to a black 3D-printed cannon platform, and the two wooden bearing mounts to flanges on its side.
The gray gear on the bottom bolts into the black platform, and does so with a square taper for torque transfer. It links to a complementary servo-mounted gear for horizontal panning. Iโll cover the vertical panning in a later slide, butโฆ
Key takeaway is โ with all the elements described, this one subassembly can account for both my axes of cannon rotation!
(I know that might have been a lot, sorry!)
Onto the vertical rotation aspect: I found some gears online, 3D printed them, and epoxied them to my servo horns.
In addition to the flywheel cage I made earlier, I also made a geared shaft for it to sit on, that also slides into the bearings.
Electronics + Packaging
Stacking!
While the Pi and Pi hat were designed to with each other in mind & fit together wellโฆ The permproto boards werenโt, so I had to cut one down and make a custom mount plate to get everyone playing nice.
I routed the necessary wires between different layers of circuit boards. This was pretty challenging; I made sure to leave enough slack so that I could โunfoldโ the boards and make modifications if need be.
I added some rainbow jumper wires to the top board! Theyโre not actually connected to anything, but add to the a e s t h e t i c ๐
Finally, I bent the MOSFETs into a V-shape, because I am a car nerd and thought it would look like a V-block engine ๐
But yeah! Here are all three boards (five if you count the 3D-printed ones) stacked!
Camera Integration
Finally, it was time to mount the camera (Logitech C920 webcam)! I left this task until last, because I was pretty sure I wanted to disassemble the camera and rehouse the electronics in a smaller enclosure.
I didnโt want to disassemble it too early in the build, and have it sit around exposed to potential damage.
In the end, all that caution ended up being pointless because I just hacked away at the case with a dremel and snips until I had the circuit board extracted.
There was a very nice disassembly guide on iFixit, but the workshop didnโt have any screwdrivers small enough :(
The webcam has these 4 cool blue LEDs that, when exposed on a naked PCB, make the cannon look really menacing.
After I extracted the camera board, I test mounted it with a piece of cardboard, taped to my flywheel cage.
Once I was happy with fitment, I modelled the cardboard strip into a more robust 3D-printed ledge, threw on some black spray paint, and epoxied everything together. (The rubber band is there temporarily, to secure the bottom end as the epoxy cures)
On my computer screen is the camera / barrel view, as well as an anime girl playing guitar apparently!
final Assembly
With all of my so-very-painstakingly crafted systems tested and working, it was time to put it all together.
I used my Kronk meme in the last writeup, so Iโll show restraint and not use it again
After carefully installing my stack of circuit boards, the horizontal sliding servo, and the lipo battery, I used zip ties to keep the wiring relatively organized.
I velcroed the battery to the floor of the box so it wouldnโt slide around, and added a spiral wire sheath to protect / ornament the cables leaving the enclosure & running to the cannon pod itself.
I left a hole in the wall for an HDMI cable too! Just in case I want to use the Pi as a computer, and watch youtube or something.
Finally, I added a bunch of green LEDs to the interior to give it that radioactive green aesthetic. Had to do it
Some more close ups!
I painted the gears gold as well, and together with the wood looking gold-ish, I think it paired really well with the black paint job.
testing, testing
*cue Wild West staredown music*
Here I am testing tracking with one of the many cans of Monster I had throughout this build.
I have the HSV range set to that particular shade of pink, and the masking program blocks everything else out to target it.
next steps
As project b.a.k.i. is a stepping stone project for the full-spec Project B.A.K.I., the things I learned here will definitely be carried forward. Improvements I am hoping to make for the full shoulder cannon are:
Rotating barrels
Optional joystick override control (via Wii Nunchuk and SPI)
Remote keyboard access for another user to operate cannon as it sits on my shoulder
Instead of a 7-round magazine, implement a tank of Nerf balls and a blower air delivery system for sustained fire
Brushless motors to drive flywheels (higher performance, and I want experience using ESCs)
Preprogrammed firing patterns
Add a third degree of freedom by having the turret ride on a sliding stage up and down my back
Addition of Real-time Clock to Raspberry Pi
Optimize OpenCV further to reduce lag
Introduce better cooling system to be able to further overclock Pi
Just to name a few.
Conclusion (what is this, a high school English paper??)
This project definitely taught me a lot! By setting the bar high and rising to meet it, I learned much more than I would have by doing a safer project. Iโm absolutely ecstatic about how everything turned out. I got an A in that class too, so that was nice.
Thanks for reading!