This project applies control systems to build a platform that automatically balances a table tennis ball in its centre.
Modelled the plant dynamics
Analysed the system using root locus and bode plot methods
Tuned the PID controller
Inverse Kinematics and Workspace plotting
Designed the physical platform using SolidWorks CAD
3D Printed and assembled the physical platform
Wired electrical components and soldered connections
Implemented the control law in C++ with Arduino Uno
Motivation:Personal Controls Project
Collaborators:Solo project
Date:December 2025
Key skills:Feedback Control Systems, MATLAB, Root Locus, Bode Plots, PID Tuning, SolidWorks CAD, Arduino, C++, 3D Printing, Mathematical Modelling
Video
IMG_9922 (1).mov
CAD (SolidWorks)
Below are renderings of the CAD assembly for this project. All modelling was completed using SolidWorks, with renderings from SolidWorks Visualize. The design of each part was iterated many times over to improve tolerances, durability, reliability, and overall function. These iterations can be classified into two main versions of the design, as explained below. To build the physical rig, parts were 3D printed and assembled using a combination of press fits and superglue. All SolidWorks files are available for download at the bottom of this page.
Version 1
Final Version
In this final version of the design the track was lengthened, a housing for the servo was added and the force transmission rod design was made more reliable
Plant Dynamics
Assuming no friction, I took the equation for motion down an inclined plane, x''= g sin(θ). I then linearised it about θ = 0, letting sin(θ) = θ. I took the Laplace transform of this equation and solved for X(s). This was implemented in the block diagram and the control algorithm. For the root locus and bode plots, the open loop transfer function was obtained by setting x(0) and x'(0) equal to 0.
Block Diagram
This Block Diagram displays the logic used in this PID feedback control algorithm. This block diagram is implemented in the Arduino C++ code which can be downloaded at the bottom of this page.
Root Locus
The root locus was created using MATLAB. (Code available at the bottom of the page)
The uncompensated plant dynamics of the balancing platform act as a double integrator g/(s^2), resulting in two open-loop poles sitting exactly at the origin of the s plane. Adding the integral term of the PID controller introduces a third pole at the origin. Because of these three poles, the system is inherently eager to become unstable, as the root locus branches naturally want to diverge into the right half plane. To stabilise the platform, I used the proportional and derivative terms of the controller to introduce two zeros in the left half plane. These zeros attract the root locus branches and successfully bend the trajectory of the closed-loop poles into the stable region. By iteratively tuning the Kp, Ki, and Kd gains, I was able to place these zeros in locations that dragged the dominant poles far enough into the left half plane to ensure a fast settling time, while maintaining an optimal damping ratio to prevent the platform from over correcting and ejecting the ball.
Bode Plot
The bode plot was created using MATLAB. (Code available at the bottom of the page)
Analyzing the system in the frequency domain revealed the primary challenge of the double integrator plant: it permanently contributes a -180 degree phase shift across all frequencies. If left uncompensated, this forces the system to operate constantly on the boarder of instability, resulting in catastrophic oscillation. To overcome this, I relied heavily on the derivative action (Kd) of the PID controller. The derivative term provides "anticipatory" control, which translates to critical phase lead in the frequency domain. Looking at the Bode phase plot, this compensation manifests as a distinct "bump" that lifts the phase curve well above the -180 degree threshold at the gain crossover frequency. I tuned the controller to maximize this bump, targeting a robust Phase Margin of roughly 45 to 60 degrees. This specific margin ensures the physical robot can smoothly reject external disturbances and sensor noise without violent vibrations, maintaining a tight, responsive bandwidth to keep the ball centered.
Workspace simulation and Inverse Kinematics
To understand the valid range of servo motor angles for the mechanical linkage assembly and their corresponding ramp angles, I solved for the servo angle in terms of the ramp angle analytically, then wrote some MATLAB code to find and plot all the valid (real) solutions. This gave the above plot of all possible ramp and servo angles, as well as the inverse kinematics for the ramp angle to be used in the C++ code.