Table of Contents
Mags, Chess Robot - This article is part of a series.
My friends Claudius, Eric, Gloria, and I built a robot named Magnets, or Mags for short.
Mags can play chess. We put magnets inside every piece so that it can detect their positions using reed switches underneath the board. It moves the pieces using an electromagnet that can move to anywhere under the board. It decides what move to play using an open source chess engine called Stockfish. It’s almost unbeatable.
We showed off the robot at the MIT xFair.
I managed to win a game against it with pure skill.
You can view our CAD here.
Mags is like a 3D printer. Instead of a hotend, we have an electromagnet. We designed a CoreXY gantry that is only 30mm tall so that the robot could be as thin as possible. When assembling the frame and gantry, we had to make everything perfectly square and parallel, or the linear rails would not slide smoothly. I described this process here.
The motors are fast!
We got our final parts printed for us by Formlabs on the Fuse 1. SLS Nylon is precise and stiff, which allowed us to make our gantry stiffer and straighter.
We waterjet the carbon fiber board:
Our board is like a keyboard. We used reed switches to detect the magnetic fields of the chess pieces. By wiring them up in an input matrix, we are able to sample all 64 squares with just 16 pins. I had to wire it up by hand because I ran out of time to design a PCB. In hindsight I really should have designed a PCB.
Above is the wiring diagram for the board. It’s exactly how high performance keyboards are wired. We set one column to high and see which rows get power. This tells us which reed switches are triggered in that column. Repeating this for all 8 columns gives us all of the sensor values. Having diodes on each reed switch gives us n-key rollover.
The electromagnet is controlled with a power transistor and a flyback diode. The stepper motors are controlled by TMC2209 drivers, which are controlled by a RasPi Pico running a 3D printer firmware called Klipper. The reed switches are wired directly to the RasPi 4B, which handles the high level code.
You can look at our code here. It’s mostly written in python. We used the A* algorithm to find the shortest path to remove captured pieces from the board without collisions, as shown in the screenshot above. The RasPi was too slow, so we ended up doing all the compute on a laptop which updates the display and sends g-code to Klipper via websockets.
We got $500 of funding from ProjX and $850 of funding from the MIT IAP Minigrant. Here’s our budget spreadsheet.
This project was really fun. I learned a lot of things, but most importantly I learned:
- Assembly is hard (if anything isn’t assembled properly, the linear rails will bind)
- Motivation is the bottleneck (most of our work was done as close as possible to the career fair demo)
- Do what needs to be done first. Making this project work required focusing on the most urgent things, from manual labor to code.
Areas for improvement:
- Reed switches suck. They have blindspots and are unreliable. We should have a 400x400mm PCB that has a ton of SMD hall-effect sensors on it instead.
- We spent too much money. We could’ve built Mags for $500 if we needed to, but having such a large budget made us spend money on things we probably shouldn’t have.
- People have told me we should make Mags have an easier difficulty. But I’d rather make Mags a robot hustler. When you make a blunder, Mags will let you know. When it wins, Mags should say something. Maybe arrange the pieces to form a big L on the board.