This was our final project for TECHIN 514: apply machine learning to create an agent that could play Mario Kart on the Nintendo Switch using a physical controller. It pulled together the three things the class covered, rapid prototyping, embedded systems and machine learning, with a clear goal anyone can watch: can the agent drive?
How it fit together
A webcam and OpenCV captured the Switch’s screen as the state. Optical flow, also in OpenCV, turned the motion on screen into a reward. An MXNet actor-critic (A2C) model picked the actions, and those went over websockets to an ESP32, which drove PWM servos that pushed the Joy-Con’s joystick and buttons. We also had an Arduino UNO acting as a controller emulator over serial.
The hardware started as cardboard and tape, cut with a ruler and a box cutter. Then laser-cut cardboard, then laser-cut plywood and some rudimentary 3D printing. The final version had precision servo housings, 3D-printed parts and magnets holding the Joy-Con in place.
What worked
Breaking it into clear blocks from the start: actuation (servos and Lego wheels), communication (the ESP32) and acquisition (a webcam) on the hardware side, with matching modules and classes in the software, and a clear map of how they talked to each other. Formal GitHub collaboration with branches and pull requests, classes for separation of concerns, and lots of small iterations.
What didn’t
We built bottom-up, hardware first, then software. Our time estimates were off for designing the actuator and for training and data collection. We didn’t identify the risks in the software methods early, A2C reinforcement learning and optical flow as the reward. Reusing snippets of code was less effective than we hoped, and the physical controller and the emulated one didn’t coexist well.
Where it ended
A fully functional training pipeline, with Mario evolving from episode to episode, and hardware that received commands and actuated reliably: a robust physical assembly and reliable wireless communication. Reinforcement learning wasn’t really working yet, optical flow wasn’t as great a reward function as we’d hoped, and the physical rig couldn’t be used together with ML training yet.