0% found this document useful (0 votes)
41 views8 pages

Line Follower Robot Design

Uploaded by

Ilyas Mhammedi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views8 pages

Line Follower Robot Design

Uploaded by

Ilyas Mhammedi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/377666058

Line Follower Robot with PID Control

Article · January 2024

CITATIONS READS

0 1,856

3 authors:

Onur Erbay Abdullah Burhan Doğan


Abdullah Gul University Abdullah Gul University
5 PUBLICATIONS 0 CITATIONS 7 PUBLICATIONS 0 CITATIONS

SEE PROFILE SEE PROFILE

Enes Devecioğlu
Abdullah Gul University
5 PUBLICATIONS 0 CITATIONS

SEE PROFILE

All content following this page was uploaded by Onur Erbay on 25 January 2024.

The user has requested enhancement of the downloaded file.


Line Follower Robot with PID Control

Onur Erbay Abdullah Burhan Doğan Enes Devecioğlu


Department of Electrical and Depeartment of Electrical and Depeartment of Electrical and
Electronic Engineering, Electronic Engineering, Electronic Engineering,
Abdullah Gül University Abdullah Gül University Abdullah Gül University
Kayseri, Turkiye Kayseri, Turkiye Kayseri, Turkiye
[email protected] [email protected] [email protected]

Abstract— This paper aims to improve autonomous navigation control leads to a faster system response to disturbances.
in mobile robotics by developing and implementing a line- However, beyond a certain point, raising the proportional
following robot that utilizes the Proportional-Integral- gain can result in unstable oscillatory behavior. The integral
Derivative (PID) control algorithm and register-level ARM C control in the PID controller helps eliminate steady-state error
code. The primary objectives include successfully traversing the
track and minimizing the time required to complete the task.
by keeping track of past errors in the system. However,
The focus is on overcoming the challenges associated with increasing the integral gain can cause overshooting, which
guiding the robot along a predetermined path in a controlled can lead to unstable behavior. The derivative control plays a
environment. To deploy the algorithm, a basic system has been role in minimizing overshooting and speeding up the transient
constructed using low-cost and off-the-shelf components response. It acts as a mechanism to anticipate future errors in
including a microcontroller, reflectance sensor, and motor the system. By using derivative control to reduce
driver. This paper describes the heuristic approach used in the overshooting, the robustness of the system can be improved.
identification of the system specifications as well as the Nevertheless, in the presence of noise, a derivative controller
optimization of the controller. The PID controller is analyzed in can introduce instability due to the amplification of high-
detail and the effect of each term is explained in the context of
stability. Lastly, the challenges encountered during the
frequency signals.
development of controller and robot are discussed.
By adjusting the parameters based on sensor readings, the
Keywords — Line follower robot, Microcontroller robot becomes better at navigating complex paths. By
(STM32F103C8), Reflectance Sensor, PID controller combining traditional line tracking with PID control, this
project improves precision and deepens our understanding of
I. INTRODUCTION closed-loop control strategies in autonomous robotic
navigation. The study focuses on fulfilling two primary
The purpose this study is to design and implement a line- requirements. Firstly, the robot must successfully traverse the
following robot utilizing the Proportional-Integral-Derivative entire track. Secondly, the completion time of the task should
(PID) control algorithm and register level arm C code. The be minimized to the greatest extent possible.
development of a Line Follower Robot equipped with PID
control represents a significant advancement in autonomous In this study, a PID controller was utilized to design a line
navigation. This project focuses on mobile robotics and tracking controller that achieves both high speed and high
addresses the challenge of guiding the robot along a accuracy. The DC motors of the robot was controlled via a
predetermined path in a controlled environment reliably and microcontroller and the microcontroller was coded in ARM
efficiently. Line tracking is an essential behavior in mobile C language at the register level. The PID controller computes
robotics where robots use identifiable markers like magnetic errors based on data obtained from the reflectance sensor
tape, surface voids, or reflective tape to navigate. They rely array. The primary purpose of incorporating PID control in
on sensors like Hall-Effect sensors or Photo-interrupters, the development of the line tracking controller is to mitigate
using infrared or visible light technology, to detect and follow overshooting, reduce steady-state error, and prevent system
these paths [1]. Traditionally, line tracking has been done oscillations.
digitally. Digital sensors send their signals to a
microcontroller, which adjusts the robot's motor speeds based
II. MATERIALS
on its position relative to the center of the line. Finding the
right motor speed involves trial and error to ensure accurate In this chapter, the mechanical and electronic components
line tracking. which utilized in the robot system will be described.
A. Mechanical Components
This project takes a step further by using PID control, a
more advanced method that fine-tunes motor responses. PID
control uses three components - Proportional, Integral, and In figure 2.1, it can be observed the line follower robots
Derivative - to achieve smoother and more precise line utilized as the test platform in this project. This robot is
tracking. The PID controller is a widely used closed-loop equipped with affordable DC gear motors. The motors have
control system in various industries. Its purpose is to drive built-in gearboxes, which enables them to deliver adequate
the system towards a desired state by calculating the error, torque for rapid responses. An advantage of these motors is
which is obtained by comparing the reference input with the their cost-effectiveness, and if necessary, a higher input
system's output. Increasing the proportional gain in the PID voltage can be applied to achieve higher speeds for shorter
durations. The mounting of the DC motors to the frame was 2) Motor Driver(L298N): To control the two DC motors,
achieved using two plastic components and two screws for a motor driver module with an L298N dual full-bridge driver
each motor. Another important point is that the stability of was utilized. This motor driver module operates on a 12V (3
the robot is directly influenced by the position of its center of batteries with 4.2V) DC voltage supply. It also includes a 5V
mass. Manipulating the location of the battery on the chassis DC voltage regulator that powers the STM32
allows for control over the center of mass, as the battery is microcontroller. . It has two input pins for controlling the
the heaviest component. When the center of mass is closer to speed of each motor (IN1, IN2 for Motor A and IN3, IN4 for
the front of the robot, there is an increased risk of slipping. Motor B) and two output pins for controlling the direction of
Conversely, when the center of mass is closer to the rear, the each motor (OUT1 and OUT2 for Motor A and OUT3 and
front side of the robot experiences more pronounced up and OUT4 for Motor B). The motor driver module features four
down movements during sharp turns. Therefore, to maintain
input pins where PWM signals are applied to control the
stability, the center of mass has been aligned with the center
direction and speed of the motors. The output pins of the
of the frame. Additionally, keeping an optimum distance (7
module are specifically designed for DC motors and can
mm) between the ground and QTR-8 reflectance sensor
contributes to stability, particularly during sharp turns. The deliver a maximum current of 2 A for each motor.
distance of the sensor from the ground is so crucial that if the
sensor is too far or too close to the ground, the robot fails to
track the line at all.

B. Electronic Components
1) Microcontroller (STM32F103C8): To read sensor
values and drive the DC motors accordingly, a
microcontroller was utilized. A microcontroller is a compact
integrated circuit that incorporates a processor, memory, and
input/output (I/O) peripherals. STMicroelectronics produces
the STM32F103C8 microcontroller, which belongs to the
STM32 family. These microcontrollers are based on the
ARM Cortex-M3 processor core. The STM32F103C8
microcontroller is equipped with a 32-bit ARM Cortex-M3
processor that can operate at a maximum clock speed of 72 (Figure 2.3 – Motor Driver (L298N))
MHz. It offers various I/O peripherals, including 12-bit
analog-to-digital converters, UARTs, and general-purpose 3) Batteries: Three rechargeble 4.2V Li-ion batteries was
input/output (GPIO) pins. Additionally, it includes a built-in used to power the robot system. The system utilizes a 13 V
RTC (Real Time Clock) and a low-power mode to minimize DC input voltage (from the batteries), with the positive
power consumption. Notably, the STM32F103C8 terminal of the battery connected to the 12 V input pin of the
microcontroller supports the ARM Cortex-M3's memory motor driver. It has been determined that a minimum input
protection unit (MPU), enhancing security and reliability in voltage of 7 V is necessary to ensure a stable 5 V output
operation. The STM32F103C8 microcontroller finds wide- voltage from the motor driver's internal regulator. This
ranging applications in consumer electronics, industrial voltage level is crucial for the efficient operation of both the
control systems, and automotive systems. It is also a popular STM32 microcontroller and the QTR-8 reflectance sensor.
choice among hobbyists and educational projects due to its
affordability, widespread availability, and extensive 4) Reflectance Sensor (QTR-8RC): The QTR-8 sensor
documentation and support provided by the manufacturer. module is employed to enable the robot to track the line. This
Also, it is important to have an original STM32F103C8 card module consists of eight reflectance sensors (see in fig. 2.4)
to operate the system properly. that comprise infrared light emitters, MOSFETs that switch
in response to infrared light, and capacitors. The MOSFETs
control the grounding of the capacitors. Each of the eight pins
corresponding to a sensor is connected to the GPIO pins of
the STM32 microcontroller, as depicted in Figure 2.5 , for
performing read and write operations. When the MOSFETs
are exposed to infrared light, the capacitors are connected to
ground and discharged. After a brief period of a few
milliseconds, the GPIO pins are switched to input mode. If a
specific sensor reads a logic 0, it indicates the presence of a
reflective surface. Conversely, if the reading is logic 1, it
signifies a non-reflective surface, typically dark in color. This
mechanism enables the microcontroller to determine the
position of the line that needs to be followed. It is essential to
note that the distance between the sensors and the track must
(Figure 2.2 – Microcontroller (STM32F103C8)) not exceed 7 mm.
(Figure 2.4 – Reflectance Sensor (QTR-8RC)

Furthermore, a voltage regulator was used to provide 3.3V


for the microcontroller by using 5V coming from the motor
driver. In other words, the voltage regulator converts the 5V
which is coming from motor driver into 3.3V to prevent the
microcontroller. If the microcontroller is supplied with 5V,
there is a risk of the microcontroller facing the danger of
overheating.

5) Final Block Diagram and Line Follower Design

The whole circuit diagram was given in figure 2.5. By


examining the circuit diagram, the connections between the (Figure 2.6 – Line follower robot design)
motor driver (L298N), microcontroller (STM32F103C8), and
reflectance sensor (QTR-8RC) can be easily understood and
implemented. However, in the block diagram given below,
the timers (PWM signals) are connected to the PA8, PA9,
PA10 and PA11 microcontroller pins. In the final version of
the line follower robot, PWM signals are connected to the
PB0, PB1, PB10 and PB11. The final version of line tracking
robot can be seen in figure given below.

(Figure 2.7 – Line follower robot design)

III. PID CONTROLLER DESIGN


PID (Proportional-Integral-Derivative) control is a
commonly utilized control algorithm in various control
systems. It operates on the principle of employing feedback
(Figure 2.5 – Circuit diagram of the line follower) to continuously regulate the system's output in order to reach
a desired setpoint. (Open loop systems are not controllable.)
The implementation of PID control involves establishing the
setpoint for the system and measuring its actual output. The
difference, or error, between the setpoint and actual output is
computed and utilized to adjust the system's output.
The fundamental components of a PID controller consist of
three distinct control terms: Proportional, Integral, and
Derivative. The Proportional term is determined by
multiplying the error with a constant factor, while the Integral
term is derived from the accumulated error over time. The
Derivative term is calculated based on the rate of change of
the error. These three terms are combined to generate the
control output of the controller.
The Proportional term initiates the correction process by is positive, the left motor's speed is increased while the right
driving the error towards zero. It provides an initial motor's speed is decreased. This adjustment causes the robot
adjustment to the system's output. The Integral term is to veer towards the right, ultimately eliminating the error.
responsible for addressing steady-state errors, ensuring that
the system reaches the desired setpoint accurately. On the In short, when the error value is negative, it indicates that
other hand, the Derivative term promotes stability by the robot needs to veer towards the left. To achieve this
anticipating and mitigating future errors. correction, the speed of the left motor should be decreased
while the speed of the right motor should be increased. To
The PID constants, also known as coefficients, play a implement this adjustment, the PID value is calculated by
crucial role in determining the behavior and performance of using given formula below and added or subtracted from the
the controller. These constants are selected based on the motor speeds accordingly. This modification of the motor
specific characteristics of the system and the desired speeds is accomplished by adjusting the duty cycle of the
performance criteria. Generally, the process of tuning the PID PWM signal sent to the two DC motors.
constants involves a trial-and-error approach to achieve
optimal control. PID value = 𝐾𝑝 e(n) + 𝐾𝑖 ∑9𝑛=1 𝑒(𝑛) + 𝐾𝑑 [𝑒(𝑛) − 𝑒(𝑛 − 1)]

(Modified PID Controller)

The decision-making mechanism of the sensor is realized


by the assessment of sensor’s conditions. Possible conditions
of the sensor and the motor movements are given below [2].

(Figure 3.1 – Closed loop PID controller)

A) Calculation of Positional Error

The error is determined by analyzing the data obtained


from the sensors. Each sensor reading provides positional
information, which is calculated using formula (1). The
reference position value, representing the center of the sensor,
is set at 4500. Formula (2) is used to calculate the error based
on this positional information.

∑9𝑛=1 1000 ∙ 𝑆𝑛
𝑥= (1)
∑9𝑛=1 𝑆𝑛
(Figure 3.2 - Location of the right sensors)
∑9𝑛=1 1000 ∙ 𝑆𝑛
𝑒 = 4500 − (2)
∑9𝑛=1 𝑆𝑛

The reference value of 4500 was chosen because it


corresponds to the desired tracking of two sensors positioned
in the middle. Sensor 4 and sensor 5 should ideally be on the
black line during tracking. To calculate the position, each
sensor's digital output is multiplied by 1000, resulting in the
average of sensor 4 and sensor 5 being equal to 4500.

When the error value is negative, it indicates that the robot


is veering towards the left. Conversely, a positive error value
signifies that the robot has deviated from the line towards the
right. The PID controller adjusts the motor speeds to correct
(Figure 3.3 - Location of the left sensor)
the robot's trajectory. If the calculated error is negative, the
left motor's speed is reduced while the right motor's speed is
increased. This correction causes the robot to steer towards
the left and eliminate the error. Conversely, if the error value
The Integral term continuously adds up the accumulated
error over time until the error is reduced to zero. It serves as
a refinement process that aids in eliminating steady-state
errors by gradually driving the error towards zero. When the
system reaches a steady-state and the error is non-zero, the
integral term continues to accumulate the error until it reaches
zero. It is important to note that if the integral term is not reset
at the appropriate time, it will keep accumulating the error
(Figure 3.4 – Motor movements) even when it is already zero. This phenomenon is known as
integral windup, and it can cause instability in the controller.
To mitigate this issue, techniques such as anti-windup are
B) Proportional Term (𝐾𝑝 ) utilized.

The Proportional term, denoted as P, is a crucial When using proportional control alone, it has been noticed
component of the Proportional-Integral-Derivative (PID) that a steady-state error persists. The mathematical
control algorithm. It plays a primary role in correcting the representation of integral control is given by equation (5).
system's output and reducing the error towards zero. The The integral term involves the accumulation of past errors.
Proportional term is calculated by multiplying the error by a By combining the integral term with the integral gain (𝑘𝑖 ),
constant factor called the proportional gain (𝐾𝑝 ). The value integral feedback is introduced, which effectively reduces
steady-state tracking error by introducing a pole at the origin
of the proportional gain can be adjusted to control the
[3].
controller's responsiveness to changes in the error. A higher
proportional gain leads to a larger control output for a given 𝑡
error, resulting in a faster response. However, a high 𝑢(𝑡) = 𝑘𝑖 ∫ 𝑒(𝜏)𝑑(𝜏) (5)
proportional gain can also lead to overshooting and 𝑡0
instability, so it's important to select an appropriate value
based on the system's characteristics. The Proportional term
primarily drives the correction process for the system's D) Derivative Term (𝐾𝑑 )
output. It is responsible for a significant portion of the
correction when the error is relatively large. As the error The Derivative term in a control system serves two
approaches zero, the Proportional term's influence purposes: providing stability and anticipating future errors. It
diminishes. At this point, the integral and derivative terms is determined by calculating the rate of change of the error
come into play to fine-tune the controller's output and and multiplying it by a constant known as the derivative gain
eliminate steady-state errors. ( 𝐾𝑑 ). The derivative gain is an adjustable parameter that
governs how responsive the controller is to changes in the
Formula (4) represents the mathematical representation of error rate. A higher derivative gain leads to a larger control
proportional control. It has been noticed that when employing output for a given change in the error rate, resulting in a faster
only proportional control, the robot exhibits a faster response response to those changes. However, using a higher
to errors encountered during line tracking. However, if the derivative gain can also lead to overshoot and instability, so
value of the proportional gain ( 𝐾𝑝 ) exceeds a certain it is crucial to select an appropriate value based on the
threshold, the robot experiences significant oscillations. system's characteristics.
Decreasing the proportional gain reduces oscillations, but at
the expense of slower error response. To address this, The Derivative term enhances stability by anticipating
derivative control has been incorporated into the system. future errors. It is computed based on the error's rate of
change, allowing the controller to predict and address errors
𝑢(𝑡) = 𝑘𝑝 𝑒(𝑡) (4) before they occur. This helps to mitigate overshoot and
oscillations that may arise when using only the proportional
and integral terms. It is worth noting that the derivative term
C) Integral Term (𝐾𝑖 ) is sensitive to noise, which can lead to erratic and unstable
control outputs. To mitigate this issue, techniques such as
The Integral term in a control system plays a crucial role in filtering or using a derivative of the measurement instead of
eradicating steady-state errors by progressively driving the the error can be employed.
error towards zero over time. It is computed by multiplying
the accumulated error by a constant known as the integral Equation (6) is the mathematical expression for the
gain (𝐾𝑖 ). The integral gain is an adjustable parameter that classical derivative control. Derivative control has been
governs the rate at which the accumulated error is reduced. A added to eliminate oscillation and overshooting caused by
higher integral gain leads to a larger control output for a given proportional and integral terms.
accumulated error, resulting in a faster reduction of the error.
However, using a larger integral gain can also lead to 𝑑𝑒(𝑡)
𝑢(𝑡) = 𝑘𝑑 (6)
overshoot and instability, so it is essential to select an 𝑑𝑡
appropriate value based on the system's characteristics.
selected to produce outputs on PB10 and PB11 for the first
The derivative (D) control plays a role in preventing two channels without any remapping. By employing the PID
overshooting in the system and enhancing the transient controller and the calculated PID value, the duty cycle (i.e.,
response. However, it is important to acknowledge that the D speed) of the two motors was controlled.
control is sensitive to noise. The reason for this sensitivity is
that the D control acts as a high-pass filter, amplifying sudden After completing all the necessary configurations, the line
changes in the error signal. Throughout the development of follower robot was ready to navigate along the track. It can
the robot, the impact of noise has not been extensively be found the codes of line follower with detailed explanation
observed [3]. and demonstration video in the following links.
Link for the codes:
As a result, during the final design phase, the values of 𝐾𝑝 , https://drive.google.com/drive/folders/1KFhX2eJ4PyPlXyp
𝐾𝑖 , and 𝐾𝑑 were determined to be 0.015, 0.003, and 10, _5h_219WkmtiNEEo2?usp=sharing
respectively, using a trial-and-error approach on the track. It
was observed that setting 𝐾𝑑 too low caused significant Link for the video:
oscillations in the robot's movements. Similarly, 𝐾𝑝 was https://drive.google.com/file/d/1y-DiEAl0--
adjusted to ensure smooth and stable movement. Lastly, 𝐾𝑖 TdewfIteiGaYC-k6pkNZDZ/view?usp=sharing
was fine-tuned to improve line tracking and reduce steady-
state error. These PID control coefficients was determined V. CONCLUSION
based on test track given in figure 3.5.

In this project, it was gained practical knowledge about the


configuration and application of essential software
components such as timers and PWM signals for controlling
motors at the register level in real-world scenarios.
Additionally, PID controllers was successfully integrated into
embedded systems as a crucial software element. Moreover,
it was developed a comprehensive understanding of the
effects of the individual components of PID control,
including the Proportional term, Integral term, and Derivative
term, within an actual system.

One of the major difficulties encountered during the


system design was the absence of original microcontrollers.
The clone microcontrollers could solely control the motors by
(Figure 3.5 – Test track) delivering PWM signals, without the capability to influence
the motor's movement based on sensor data. Also, it was
difficult to find original microcontroller (STM32F103C8)
IV. SOFTWARE PART from the internet.

Another challenge faced during the system design was the


On the software part of the project, all the peripheral iterative process of determining the optimal values for the
configuration is done in register level. No HAL libraries or PID controllers. Through numerous trial and error attempts,
automatic configuration tools such as STM32CubeIDE are it was aimed to find the most suitable parameters.
used for configuration. Several functions are written in Keil Unfortunately, this extensive testing resulted in the
C to robot to follow the line according to the input data of the malfunctioning of some motors in the line follower,
QTR-8 sensor. necessitating multiple replacements of the DC motors.
To read the data from the QTR8RC sensor, the GPIOA 0- Furthermore, it was encountered inconsistencies in
7 pins were utilized as input data registers (IDR). The uploading the code onto the microcontrollers, as certain
position of the robot was determined based on the data computers were unsuccessful in this process. Unfortunately,
received from these pins. For precise delays, such as when the cause of this issue could not be identified or resolved.
reading the QTR8RC sensor, a small delay of approximately
12 microseconds was required. Timer2 was employed to In summary, we successfully implemented and utilized key
generate accurate delays based on the system clock, which software components, explored the effects of PID control
operated at a frequency of 72MHz. components, and overcame challenges related to
microcontroller availability, PID parameter tuning, and code
To control the speeds of two DC motors, two PWM signals uploading.
needed to be generated. Timers were once again utilized as
efficient software components to generate these PWM
signals. For controlling the speed of the left motor, TIM2 was
used, which produced outputs on PB0 and PB1 for the first
two channels without any remapping. Similarly, TIM3 was
REFERENCES
[1] Balaji, V., Balaji, M., Chandrasekaran, M., & Elamvazuthi, I. (2015).
Optimization of PID control for high speed line tracking robots. Procedia
Computer Science, 76, 147-154.
https://www.sciencedirect.com/science/article/pii/S1877050915038302

[2] Kose, O., & KARAS, I. R. (2014). PID controlled line follower robot
design on indoor 3D networks. In IAES Intern. Conf. on Electrical
Engineering, Computer Science and Informatics (EECSI-2014). –
Yogyakarta, Indonesia (pp. 20-21).
https://core.ac.uk/download/pdf/296975585.pdf

[3] Oguten, S., & Kabas, B. (2021). PID Controller Optimization for Low-
cost Line Follower Robots. arXiv preprint arXiv:2111.04149.
https://arxiv.org/pdf/2111.04149.pdf

View publication stats

You might also like