This system holds a ball in balance on a plate. A webcam films the system and a python program analyzes the images to find the position of the ball. The python program calculates the tilting of the tray to prevent the ball from falling.
A proportional-integral-derivative (PID) regulator is used to compensate the movements of the ball. The position and speed of the ball are measured by the camera and these measurements are used by the PID regulator in the python program.
Sorry about the English faults, it’s not my mother tongue.
PCB manufacturing
I drew the pcb with eagle then PCBWay.com manufactured it.
PCB assembly :
I soldered all smd components without paste flux. I don't recommend you to do like me. Instead, follow this tutorial to solder smd components: https://www.instructables.com/id/SMD-Hand-Soldering/
The PCB is powered with a 5-6v 2A power supply.
PCB components :
Role of the PCB
The PCB communicates with the computer continuously. This PCB serves only to control the servomotors.
Warning : inferieur.stl, superieur.stl and plateau.stl files are not 3D printable. inferieur.stl and superieur.stl are made of acrylic. You can use a CNC to make these parts, but you can also cut them yourself in an acrylic sheet because these parts don't have a very complicated design. plateau.stl should be cut in cardboard.
Mechanical parts :
Aluminum tube : length 474mm ,diameter 8mm
The PCB contains the same microcontroller as the arduino leonardo. Therefore it can be programmed with Arduino software. The code can be downloaded here.
Before programming the PCB, you have to burn the bootloader: Arduino as ISP and Arduino Bootloaders
Burning the Bootloader
After this step you have to connect the pcb to the computer with a USB cable and upload this code.
The most important code is in the computer that controls the system. You can find the code here.
How does it work. The first step is to find the position of the ball. The camera sends the computer live video. The python program receives the video and has to process it. I use the OpenCV library to do the image processing. The program detects the ball thanks to its color. Here the ball is orange, the program will then average the position of all the orange pixels of the image to find the position of the ball. With OpenCV all this is quite simple. I recommend this tutorial for color recognition with OpenCV: https://www.pyimagesearch.com/2015/09/14/ball-tracking-with-opencv/
Now that we have the ball position we can calculate the inclination of the board with PID (proportional, integral, and derivative) control. The regulation is done in three stages. The first step is the simplest. Imagine that we want to stabilize the ball in the center of the board. The further away the ball is from the center, the more it will be necessary to tilt the board. Then you have to measure the speed of the ball: the faster the ball moves away from the center, the more you have to tilt the board.
Thanks for reading! If you have any questions, do not hesitate to write a comment.
You can also vote for me in the PCB contest.