PID Controlled Magnetic Levitation System
Hardware- 4 Devlogs
- 3 Total hours
A system that levitates a neodymium magnet using Hall Effect sensors and PID control.
A system that levitates a neodymium magnet using Hall Effect sensors and PID control.
This session, I made the PCB for the PID controlled levitation system after picking out the parts from LCSC. Then, I made a bill of materials. Using KiCad, I created the schematic and the PCB layout then manually routed and used a copper pour. I constrained the 12V high-current loop to a 1.0mm trace width to handle the 1-2A load without overheating.
I built the closed loop block diagram in Simulink to simulate my magnetic levitator before building the hardware. Initally, the Scope block appeared to show the position exploding at 10^259, but it was just an auto-scaling glitch. I manually tuned the PID controlled with P = -40 and D = -1. Then, I generated a root locus plot in MATLAB to verify my open-loop plant. The gain was 33.3 which was the value of the threshold I calculated earlier.
Timelapse: https://lapse.hackclub.com/timelapse/h0nwiXtD_xhi
The MATLAB script, Simulink structure, and images of graphs can be found on the project’s GitHub repo.
I verified my hand-derived equations from Devlog 1 using MATLAB, calculating the linearization using both the Jacobian method and a multivariable Taylor series expansion. Applying the multivariable Taylor expansion in code was a great way to put my recent calculus studying into practice, and it felt rewarding when MATLAB output the exact same a and b constants I calculated by hand. After confirming the symbols, I substituted in estimated physical constants to build the transfer function and run a system analysis. The resulting pole-zero map clearly displays the unstable pole sitting in the right-half plane, showing the open-loop is NOT stable.
Timelapse for Session 2: https://lapse.hackclub.com/timelapse/z6mQ9aBNONhu
The MATLAB script can be found on the project’s GitHub repo.
I derived the initial force-balance equation using Newton’s second law and then linearized it around the equilibrium point using a multivariable Taylor expansion. Applying the Laplace transform exposed the right-half-plane pole, mathematically proving why the system is naturally unstable without active correction. Setting up the closed-loop stability condition using the Routh-Hurwitz criterion felt familiar from my EE and calc coursework, but keeping track of the coefficients during the partial derivatives tripped me up for a second. I ultimately got it sorted and now have the exact mathematical thresholds required for my proportional and derivative gains.
Session 1 Timelapse: https://lapse.hackclub.com/timelapse/9LWAljPJ38Sr
The math images are on the GitHub repo!