For my mechatronics project, we decided to create a robotic goalie, like we have seen in a few videos. I accomplished this by using a camera and OpenCV, a computer vision library for Python to track the ball and move a servo motor to an angle calibrated through experimentation based on what "grid square" the ball was in.
Earlier prototypes I made attempted to use 2 cameras to triangulate the ball and note its position in 3d space and draw a line between the current point and previous point of the ball and determine if it will intercept the goal. If it does, it moves the servo to the angle required to intercept the prediction. While this method occasionally worked, it was overall inconsistent for me and I went with the simpler grid method.
More detail about the steps in the design process are below.
I designed this sheet metal enclosure for the box to house the electronics. It has mounting holes so it can be screwed into wood, or you can put tent stakes in them to hold it in the ground for outdoor use. It also has a handle to make it easily portable since we had to move it a lot. They ended up too uncomfortable for holding directly, but were still good for mounting a grip as seen below in the first picture on the left.
The hardware inside includes an Arduino Uno. I made a 2 part mount seen in the two pictures above on the right that allows the Arduino to easily slide out of the enclosure for editing wiring connections. The wiring was pretty simple, as the Arduino just connected to the servo and common ground between it and the power supply. The Arduino is connected through USB to my computer to receive commands from it. A bench power supply provided the 12 volts needed to power the motor and reliably regulated the current.
Mounts PVC goalie to servo motor
Mounts camera to PVC Goal
Cable management PVC Mount
The software was made in Python using a few key libraries:
Pyfirmata 2
Allows Python to talk to the Arduino
OpenCV
A computer vision library that allows tracking of the ball
Pickle
Saves and loads matrices that contain the "models" trained based on the grid size and camera position
Numpy
Allows for 3D math, used for the dual camera setup.
The software essentially makes a mask to reveal only the color of the ball and tries to put a point in the center of the color. It makes a grid and determines where the point is in the grid. Depending on what square the point is in, it pulls from the calibration matrix where the servo should turn to and makes the move.
Close up of the tracking dot on the ball with grid lines visible
Compilation of the goalie in action