Balancing a ball on a flat surface is a difficult task. Johan Link’s PID-based table, however, can not only balance a ball, rolling it around its circumference, but can also catch it when tossed through the air. It does this using three servo-driven linkages to compensate for the ball’s motion with the tilt of the table.
Ball tracking is accomplished with the help of a webcam, positioned overhead of the off-white, circular surface. Images are continuously taken of the ball and surface, then fed into a Python program running OpenCV in order to calculate its position. A PID (proportional-iterative-derivative) routine is used to raise and lower the servos to compensate for the ball’s position and motion. Direct control of the servos is via a custom PCB is with an ATmega32U4 at its heart, but the heavy lifting is done via the Python routine.
Instructions for this incredible device are found here. Most of the mechanical parts are 3D-printed (or purchased), but a few items will need to be cut out by CNC or other means. It’s an excellent contraption as-is, but Link notes that as it’s using the same microcontroller as the Leonardo, it could also be programmed using Arduino software if you’d like to make any changes.