Project Report: Optimizing Line Following
Robot
1. Introduction
The primary objective of this project was to design and implement an autonomous line-following
robot capable of tracking a path with high stability and precision. The project involved hardware
assembly, data collection, and the implementation of a control system to translate sensor inputs
into smooth motor movements.
2. Hardware Design
The robot is built upon a differential drive chassis, utilizing a microcontroller for processing and
an H-Bridge driver for motor control.
[INSERT HARDWARE DESIGN SKETCH HERE]
● Microcontroller: Arduino (Uno/Nano)
● Motor Driver: L298N Dual H-Bridge
● Sensors: 3 TCRT5000 IR Sensors
● Actuators: 4x DC Gear Motors
● Power Supply: Lithium-Ion Battery Pack
3. Data Acquisition & Processing
The data was acquired by coping the outputs from the serial monitor and inserting into a
spreadsheet to get a .csv file so be prepared by a python script.
To understand the physical dynamics of the robot, we logged real-time telemetry data during
operation. The robot transmitted timestamps, motor PWM values, and raw sensor readings to a
serial logger.
Data Cleaning Tool:
Due to the unavailability of MATLAB, Python (Pandas & NumPy) was used for all data
processing tasks.
● Challenge: High-speed serial communication caused buffer overflows, resulting in
corrupted data streams (missing delimiters).
● Solution: A custom Python script was written to parse the raw text, repairing broken
lines and structuring the valid data into a clean CSV format for analysis.
4. System Modeling & Transfer Function
Instead of relying on manual trial-and-error, we used System Identification to mathematically
model the robot’s behavior. Using Python's scikit-learn library, we analyzed the relationship
between the steering commands and the sensor error response.
Derived Transfer Function:
By performing linear regression on the time-series data, we extracted the robot's discrete
transfer function:
G(s) = -0.009 / (z - 0.9426)
5. Initial Control Strategy
Initially, the robot operated using a basic logic-based controller. The system used simple
conditional statements (If Sensor Left -> Turn Left) to navigate.
● Observation: While functional, this approach resulted in "jerky" motion. The robot would
frequently overshoot the line, turning sharply left and right in a zigzag pattern rather than
following a smooth curve.
● Analysis: The lack of variable speed control meant the motors were always operating at
fixed power levels, unable to adjust for the severity of a turn.
6. Optimization: The PID Controller
To address the oscillation and stability issues of the initial strategy, we implemented a
Proportional-Integral-Derivative (PID) Controller. This algorithm allows the robot to adjust its
motor speeds continuously based on the precise position of the line.
Why Python for Tuning?
Since MATLAB's PID Tuner app was unavailable, we developed a Python Simulation script. This
script used the Transfer Function derived in Section 4 to virtually simulate the robot's movement.
We performed a "grid search" optimization to test thousands of combinations of K_p, K_i, and
K_d values, finding the optimal parameters mathematically before testing them on the real
hardware.
Final Implementation:
The PID controller calculates the correction value using the formula:
u(t) = K_p e(t) + K_i \int e(t) dt + K_d \frac{de(t)}{dt}
● Proportional (K_p): Reacts immediately to the current error.
● Integral (K_i): Corrects small, accumulated errors over time.
● Derivative (K_d): Predicts future error and dampens the oscillation (crucial for
overcoming the system inertia identified in Section 4).
7. Conclusion
By shifting from simple logic to a control-theory approach, the robot's performance was
significantly improved. The use of Python for System Identification allowed us to derive an
accurate Transfer Function without proprietary software like MATLAB. The final PID
implementation resulted in smoother trajectory tracking, higher average speeds, and reduced
mechanical stress on the motors.