Ali HakamControls / Mechanical / Systems Back to selected work

02 / Feedback control

Ball-and-plate control

I built a two-axis platform that uses camera feedback to balance a ball. The work covered the mechanism, vision pipeline, dynamics model, and controller implementation.

My role
Mechanical build, modeling & software
Period
Jan – Apr 2026
Tools
Python/OpenCV, Raspberry Pi & MATLAB/Simulink
Evidence
Hardware video, simulation model & calculations
Physical demonstration · Camera-based balancing on the two-axis platform.

The feedback loop

Measure the ball.
Correct the plate.

  1. 01Camera image
  2. 02Ball position & estimated velocity
  3. 03Controller
  4. 04Plate tilt → servo pulses
01 / Sensing

Turn an image into a position.

The camera sees pixels; the controller needs a position on the plate. I use a perspective transform to map the camera view into plate coordinates, then convert the detected ball center into a distance from the target.

The vision code filters orange regions and scores their shape to select a ball candidate. An alpha-beta tracker estimates velocity from successive position measurements, so the controller can respond to both position and motion.

02 / Controller design

One platform, several controllers.

I used the ball-and-plate dynamics to build PID and state-feedback implementations and a discrete LQR design. The saved controller calculations distinguish the hand-tuned runtime gains from a separate model-derived PID version.

PID

Position, velocity, and accumulated error produce a desired acceleration. The model-based version derives gains by matching a desired characteristic polynomial.

State feedback & LQR

The state-space model represents position and velocity on both axes. The LQR solver discretizes that model and computes feedback gains from state and input weights.

MATLAB & Simulink

My Simulink model connects the ball-and-plate mechanics with position feedback, state estimation, and plate-tilt commands.

Ball-and-plate Simulink model connecting multibody mechanics, ball-position feedback, estimated states, and plate-tilt commands.
Simulink model · Mechanics, position feedback, state estimation, and tilt commands.
03 / Hardware constraints

The controller

A requested acceleration becomes a plate-tilt command, then a servo angle and PWM pulse. The software limits plate tilt and the rate at which it changes, keeping commands within the mechanism’s configured range.

Tracking confidence and elapsed time since the last detection determine whether a ball measurement can be used. These checks matter because a camera can lose the ball while the servos still have a command.

04 / Results

Centering and path tracking

I completed the build, modeling, software, and hardware testing, and earned the highest mark in the course.

The simulation results cover two cases: returning the ball to the center from an offset starting position and following a circular reference. The X–Y plots below show the path in each case.

Simulated X–Y path approaching the plate center from an offset starting position.
Return to center · Simulation. The path approaches the origin after a small overshoot.
Simulated X–Y path transitioning from its starting position into a repeating closed loop.
Circular reference · Simulation. After the initial transition, the path forms a repeating loop.
Model-derived PID calculations

The saved derivation uses the augmented per-axis state: position error e, error velocity v, and integrated error z.

a = −kpe − kdv − kiz

Matching coefficients of the desired polynomial gives:

kd = 2ζωn + ωi

kp = ωn² + 2ζωnωi

ki = ωn²ωi

With ζ = 1.05, ωn = 2.5 rad/s, and ωi = 0.18 rad/s, the calculated gains are kp = 7.195, kd = 5.430, and ki = 1.125.

Design parameters from the March 2026 calculation document. The final saved runtime uses separate hand-tuned gains; these values are not a measured performance result.

Next projectUnderwater ROV
Open original ↗