Project Purpose
The objective of this project was to design, implement, and optimize a closed-loop control system for a lab-scale car to achieve precise straight-line movement. The system was powered by a Raspberry Pi and employed a Proportional-Integral-Derivative (PID) controller to regulate motor speeds based on real-time feedback from wheel encoder sensors. This approach aimed to correct discrepancies between the left and right wheel speeds, which otherwise caused drift and reduced trajectory accuracy. The project involved multiple stages—construction, open-loop testing, steady-state operating curve (SSOC) determination, step response characterization for First-Order Plus Dead Time (FOPDT) modeling, and final controller tuning. By combining experimental data with control theory, the project sought to achieve stable and responsive performance with minimal steady-state error, reduced overshoot, and fast settling times.
Raspberry Pi – central processing unit executing control logic.
L293D Motor Driver – regulated voltage and current supplied to motors.
Optical Encoder Sensors – measured wheel rotation for real-time RPM feedback.
DC Motors (rear-mounted) – provided propulsion.
Breadboard & Jumper Wires – facilitated wiring connections.
Battery Pack – powered both motors and Raspberry Pi.
Python – primary programming language for control algorithms, data acquisition, and logging.
Excel – used for analysis, regression modeling, and parameter optimization.
Initialize GPIO pins for motor control and sensor input.
Implement edge detection via encoder signal arrays to count wheel rotations.
Calculate RPM from encoder counts using rolling averages to smooth data.
Log data (time, power, RPM, trial, and error) to CSV for analysis.
Implement PID control using FOPDT-derived tuning parameters and methods such as ITAE, PI-only, and Ziegler-Nichols.
The control loop compared measured RPM to the 80 RPM setpoint, adjusting motor PWM duty cycles to minimize error.
The PID (Proportional-Integral-Derivative) controller was implemented to dynamically adjust the power supplied to each motor in response to real-time differences between the actual wheel speed and the target speed (setpoint). The purpose of this control logic was to minimize the drift observed in the open-loop configuration, ensuring that both wheels moved in synchrony and the car maintained a straight path.
The proportional term corrected the immediate error between the setpoint and actual RPM. A larger proportional gain resulted in a faster system response but could also introduce overshoot and oscillations if not tuned properly.
The integral term helped eliminate long-term bias by accumulating small errors over time. This was particularly useful in addressing persistent mismatches between the motor outputs—such as when one motor was slightly weaker than the other. By accounting for historical error, the integral action gradually pushed the system toward eliminating steady-state offset.
The derivative term predicted how the error was changing, effectively dampening the system and reducing oscillations. It responded to the rate at which the error was growing or shrinking and acted preemptively to stabilize the output. While useful, excessive derivative action could amplify sensor noise, so it required careful tuning.
Multiple methods were used to tune the PID controller gains:
ITAE (Integral of Time-Weighted Absolute Error) Method: This method aimed to reduce the total accumulated error over time, giving priority to quick and smooth stabilization. The tuning was based on values derived from earlier step response experiments, where system characteristics like time delay and time constant were identified for each wheel.
PI (Proportional-Integral) Controller: A simpler version of the full PID controller that omits the derivative term. This was useful in scenarios where derivative action introduced instability or was unnecessary due to low levels of oscillation.
Ziegler-Nichols Method: A heuristic tuning method that increased proportional gain until sustained oscillations occurred. Based on the resulting oscillation period and gain, standard formulas were used to determine the final controller parameters. This method typically produced a faster, more aggressive response but came with a trade-off in steady-state accuracy.
Each control strategy was tested in a 40-second closed-loop trial where the motors attempted to reach and maintain 80 RPM. Performance was evaluated based on several metrics, including:
Steady-state error (how close the motor speed stayed to the setpoint)
Overshoot (how far the speed exceeded the target before stabilizing)
Settling time (how long it took to stabilize)
Steady-state deviation (variability during stable operation)
Integral of Absolute Error (cumulative deviation from the setpoint)
The PID controller tuned via the ITAE method consistently outperformed the others. It achieved the lowest steady-state error, fast response time, and minimal oscillation. The Ziegler-Nichols method had the fastest stabilization but introduced more error at steady state. The PI controller was a middle ground, performing adequately but with slower settling behavior.
Overall, the PID approach proved to be the most effective in balancing speed, precision, and stability in motor control.