Air Hockey Robot

By Nicola King. Posted

When Ondřej Sláma and Dominik Jasek, two students from the Czech Republic studying at Brno University of Technology, needed to write their course thesis, they chose a rather engaging project – an Air Hockey Robot controlled by Raspberry Pi.

“I always dreamed of building some human vs machine project,” Dominik tells us. “At the university, I got an idea to build an air hockey robot. What inspired me the most in designing the robot was definitely a project from JJRobots. I chose good parts from that and replaced bad ones and hopefully improved it. Luckily for me, Ondřej joined me very soon and took care of the Raspberry Pi. We made a great duo.”

Out of thin air

The pair built the whole project from scratch, taking about a year. “A lot of work had to be done before even thinking about the actual implementation of the robot controlling the other side of the table,” reveals Ondřej. “It would be hard to pick the most difficult element. We had to overcome a lot of challenges, including electrical wiring of all the chosen hardware, robot movement control algorithms, computer vision, game strategy algorithms, user interface etc.”

After designing the table in Fusion 360, it was constructed from spruce and plywood with an Alubond playing surface. To ensure smooth gliding of the puck, a square mesh of 920 holes was drilled into the game board, enabling air to flow through from two fans located under the table.

As for the mechanical aspect, the pair opted for an ‘H-bot’ design to move the robot’s paddle. Held in a 3D-printed housing, the paddle is moved around using a pulley and belt system, with two stepper motors controlled by an Arduino Micro. “[The H-bot design] is really the best solution for this problem as both steppers are stationary,” explains Dominik.

Look and learn

The inner workings of the table revealing the two fans and extensive wiring required

The processing power for the robot’s optical puck recognition and AI strategy is provided by a Raspberry Pi 4. It is connected to a Camera Module V1 mounted in the overhead part of the frame, along with LED strips to ensure good lighting. With the camera capturing frames at around 80 fps, OpenCV is used to recognise the bright green puck so its position can be determined.

For the robot’s strategy, Ondřej and Dominik originally planned to use machine learning. That proved a step too far, however, given all the other fine-tuning issues that they faced in making the project. “Using machine learning was the plan from the beginning,” says Ondřej. “But, trust me. We tried. We tried a lot to make it work. But it was literally impossible to implement, given how hard it is to train an agent in such a complex state space with even more complex action space.”

Instead, they manually programmed four types of strategies with slightly different algorithms – you can find the code on GitHub.

The project’s Raspberry Pi is also connected to a touchscreen with a GUI made using Kivy. Apart from the purposes of setting up the game and keeping score, this makes it possible to “set all kinds of parameters ranging from camera properties/calibration and motor speeds to the type of strategy,” explains Ondřej.

The Air Hockey Robot was a very complicated and time-consuming project, but the result is indeed a brilliant piece of engineering and programming, where only the quick-witted can win. So, how often have they actually beaten the robot? “30-40% of the time. More at the beginning when things were not tuned out,” says Dominik. “But, it got harder and harder. Especially for the not so good players that we are.”

From The MagPi store

Subscribe

Subscribe to the newsletter

Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.