You are on page 1of 27

HANOI UNIVERSITY OF SCIENCE AND

TECHNOLOGY
School of Electrical and Electronic Engineering
Control and Automation Department

PROJECT REPORT
LINEAR CONTROL THEORY
THREE – WHEELED LINE FOLLOWER ROBOT MODELING

Instructor: Vu Thi Thuy Nga


Group 9:
Tran Huong Giang 20192200
Pham Quoc Huy 20192214
Nguyen Thi My 20192236
Ngo Xuan Thai 20192248

Hanoi, 2022

1
Contents
I. Introduction ......................................................................................................................................... 3
1.1. Wheeled Mobile Robot .................................................................................................................... 3
1.2. Wheeled Mobile Robot Types ......................................................................................................... 3
1.2.1. Differential Wheeled Robot...................................................................................................... 3
1.2.2. Bicycle Drive Robot .................................................................................................................. 3
1.2.3. Tricycle Robot ........................................................................................................................... 3
1.2.4. Car Drive Robot .................................................................................................................. 4
1.2.5. Omni Wheeled Robot................................................................................................................ 4
1.3. Differential Wheeled Robot............................................................................................................. 5
II. Main Components ........................................................................................................................... 5
2.1. IR Sensor........................................................................................................................................... 5
2.2. Wheel................................................................................................................................................. 7
2.3. DC Motor .......................................................................................................................................... 8
2.4. Battery............................................................................................................................................... 9
2.5. Microcontroller Arduino Uno R3 ................................................................................................. 10
2.5. Motor Drive L298N........................................................................................................................ 11
III. Modeling ........................................................................................................................................ 13
3.1. State Space Model .......................................................................................................................... 13
3.2. Controller........................................................................................................................................ 13
3.3. Voltage Regulator .......................................................................................................................... 16
3.4. Deviation Calculation .................................................................................................................... 17
IV. Realistic Simulation: ..................................................................................................................... 19
4.1. Build programs and algorithms .................................................................................................... 19
4.2. Flow chart ....................................................................................................................................... 21
4.3. Run simulation ............................................................................................................................... 21
4.4. Code Arduino ................................................................................................................................. 22
V. Results: ............................................................................................................................................... 27
VI. References:..................................................................................................................................... 27

2
I. Introduction
1.1. Wheeled Mobile Robot
- Wheeled Mobile Robot (WMR) have the capability to move around in their
environment and are not fixed to one physical location. Wheeled Mobile
Robot can be "autonomous" which means they are capable of navigating an
uncontrolled environment without the need for physical or electro-
mechanical guidance devices.
- Mobile robots have become more commonplace in commercial and
industrial settings. Mobile robots are also found in industrial, military and
security settings.
- The components of a mobile robot are a controller, sensors, actuators and
power system.
1.2. Wheeled Mobile Robot Types
1.2.1. Differential Wheeled Robot
- A differential wheeled robot is
a mobile robot whose movement is
based on two separately
driven wheels placed on either side of
the robot body. It can thus change its
direction by varying the relative rate of
rotation of its wheels and hence does
not require an additional steering
motion. Robots with such a drive
typically have one or more castor wheels to prevent the vehicle from tilting.
1.2.2. Bicycle Drive Robot
- Unlike Differential Dive, Bicycle
Drive also has 2 wheels, but its 2
wheels are arranged in a straight line,
and usually, only one wheel is active
and one wheel can control the steering
angle, similar in structure. like a
bicycle. This type of robot is sporadic
due to its low practical application.
1.2.3. Tricycle Robot
- Tricycle Drive is a combination of the 2 types of WMR mentioned above, it
has 3 wheels and in which 2 rear wheels are arranged coaxially, and one
front wheel acts as a steering wheel; 2 of the 3 wheels will be attached to the

3
actuator for control and the other wheel to be free, or the actuator can also be
used to control only one front rudder at the desired speed and steering angle.
1.2.4. Car Drive Robot

- This type of WMR has a structure similar to a car with 2 front wheels that
can change the steering angle.
1.2.5. Omni Wheeled Robot

- Omni Wheels are another option for wheeled robots, an Omni wheel has an
axis perpendicular to the axis of the core wheel. This allows the wheels to
move in two directions, Omni-wheeled robots can move at any angle in any
direction, without rotating beforehand.

4
1.3. Differential Wheeled Robot
- For this project, our team chooses Differential Wheeled Robot model which
has three – wheel. We have developed a Line Follower Robot based on
differential drive mechanism.

- A differential drive robot contains two wheels each of which is equipped


with a separate DC motor that controls its rotation.
- This robot is called differential drive because the steering of this system is
based on difference in the turning rates of the two wheels.

II. Main Components


2.1. IR Sensor
- An infrared sensor is an electronic device that measures and detects infrared
radiation in its surrounding environment. There are two types of infrared sensors:
active and passive. Active IR sensors have two parts: a light emitting diode (LED)
and a receiver. Passive IR sensors only detect infrared radiation and do not emit it
from an LED.
- The working principle of phototransistor is based on reflected light signal from
source to generate a voltage signal. For a race track where the line color with the
color with the color of the background has high contrast (example black line on
white background), infrared LED has higher sensitivity but need to shield against
interference.
➔ Choose sensor module is a pair that transmit and receives infrared rays.

5
- Specifications:
• Use 1 LED emit infrared.
• 1 led infrared receiver.
• Main IC LM358 SMD.
• LED indicator light.
• 10K square VR adjustment rheostat.
• Pins AO – DO – GND – VCC
• Operating voltage: 3.3 – 5 VDC
• VCC= 3 – 5 VDC
• GND = 0V.
• DO = Output signal 0/1
- Signal Processing Algorithm: Comparative Method
• Use the comparator to determine the on/off status of the sensors, then infer
the vehicle position according to a predefined table of states. With this
method, the line detection error will depend on the number of states of the
system, or the distance between sensors and this method has fast processing
speed.

6
- We will use PID method to adjust position of wheel mobile robot. We set value for
middle point of sensor array. Then, using PID method to make error value
between middle point and other point is minimum. From that, the wheel mobile
robot can track the predetermine line.
2.2. Wheel
- Fixed wheels: Because the vehicle moves on flat terrain at high speed, we choose
ordinary rubber wheels that have a large tank and no spikes.

➔ We use 2 yellow wheels: diameter 66mm. They are attached at the behind of mobile
robot.
- Free wheel: Wheel has the ability to change direction easily, small friction.

- This wheel can move in all directions, when changing direction does not slip and
change the vehicle’s center of gravity of robot when moving.

7
2.3. DC Motor
- DC motor is any kind of rotary electrical motors that converts direct current (DC)
electrical energy into mechanical energy. The output wire of this motor usually
consists of two wires (power wire - VCC and ground wire - GND).

- Input parameters:
Load and vehicle mass 2.7 Kg
Diameter of fix wheel 66mm
Max of velocity 1 m/s
Acceleration 0.5 𝑚/𝑠 2
Fraction coefficient 0.6
Safe coefficient 3
- We consider that:
• I: moment of inertia (kg.𝑚2 )
• T: Torque (N.m)
• R: Radius of wheel (m)
• 𝐹𝑓 : Friction force (N)
• 𝛾: Angular acceleration (rad/𝑠 2 )
• Ω: Angular velocity (rad/s)
• a: Acceleration (𝑚/𝑠 2 )
• M: Mobile robot mass
• m: Wheel mass
- Inertia moment of fixed wheel:
1
𝐼 = 𝑚𝑅2 = 0.18 × 10−3 (𝑘𝑔. 𝑚2 )
2
- Friction force at 1 wheel:
𝐹𝑓 = (0.5𝑀 + 𝑚)𝑎 = 0.65 (𝑁)
- Equation:

8
𝑇 − 𝐹𝑓 . 𝑅 = 𝐼𝛾
𝑎
⇒ T = 𝐹𝑓 . 𝑅 + 𝐼𝛾 = 𝐹𝑓 . 𝑅 + 𝐼. = 23.89 (𝑁. 𝑚𝑚)
𝑅
 Power of motor need:
𝑣
𝑃 = 𝑐. 𝑇. 𝜔 = 3 × 23.89 × = 2.2 (𝑊)
𝑅
➔ Choose Yellow DC motor

- Specification:
• Voltage: 3 – 12V
• Load current: 70 mA (at 3V)
• Torque: 800 gfcm = 0.08 Nm
• Gear ratio: 1:48
• Speed: 300 rpm (at 10V)
𝑇.𝑛
• Power: 𝑃 = = 2.5 𝑊
9.55

2.4. Battery
- An 18650 is a lithium ion rechargeable battery. Their proper name is “18650 cell”.
The 18650 cell has voltage of 3.7V and has between 1800mAh and 5000mAh

9
- Specification:
• Quantity: 3 pins
• Voltage: 3.7V
• Capacity: 5000mAh
- 3 pins are connected in series, so total Voltage is approximately 12V. This voltage
is suitable for requirement of robot
2.5. Microcontroller Arduino Uno R3
- The Arduino Uno is an open-source microcontroller board which is developed
by Arduino.cc based on the Microchip ATmega328P microcontroller. It is
programmable with the Arduino IDE (Integrated Development Environment) via a
type B USB cable.
- The board is equipped with sets of digital and analog input/output (I/O) pins that
may be interfaced to various expansion boards (shields) and other circuits. It can
be powered by the USB cable or by an external 9-volt battery, though it accepts
voltages between 7 and 20 volts.

- Specification:

10
• It is an Atmega328P based Microcontroller
• The operating voltage of the Arduino is 5V
• The recommended input voltage ranges from 7V to 12V
• The i/p voltage (limit) is 6V to 20V
• Digital input and output pins – 14
• Digital input & output pins (PWM) – 6
• Analog i/p pins are 6
• DC current for each I/O Pin is 20mA
• DC current used for 3.3V Pin is 50mA
• Flash Memory – 32KB, and 0.5 KB memory is used by the boot loader
• SRAM is 2 KB
• EEPROM is 1 KB
• The speed of the CLK is 16 MHz
• Built-in LED
• Length and width of the Arduino are 68.6mm X 53.4mm
• The weight of the Arduino board is 25g
2.5. Motor Drive L298N
- This L298N Motor Driver Module is high power motor driver module for driving
DC and Stepper Motors. This module consists of an L298 motor driver IC and a
78M05 5V regulator. L298N Module can control up to 4 DC motors, or 2 DC motors
with directional and speed control.

- Specification:
• Driver Model: L298N 2A
• Driver Chip: Double H Bridge L298N
• Motor Supply Voltage (Maximum): 46V
• Motor Supply Current (Maximum): 2A
• Logic Voltage: 5V
• Driver Voltage: 5 – 35V

11
• Driver Current: 2A
• Logical Current: 0 – 36mA
• Maximum Power (W): 25W
• Current Sensor for each motor
• Heatsink for better performance
• Power – on LED indicator
- Configuration Pinout:
• IN1 & IN2: Motor A input pins. Used to control the spinning direction of
Motor A
• IN3 & IN4: Motor B input pins. Used to control the spinning direction of
Motor B
• ENA: Enables PWM signal for Motor A
• ENB: Enables PWM signal for Motor B
• OUT1 & OUT2: Output pins of Motor A
• OUT3 & OUT4: Output pins of Motor B
• 2V: 12V input from DC power Source
• 5V: Supplies power for the switching logic circuitry inside L298N IC
• GND: GND pin
- The L298N Motor Driver module consists of an L298 Motor Driver IC, 78M05
Voltage Regulator, resistors, capacitor, Power LED, 5V jumper in an integrated
circuit
- ENA & ENB pins are speed control pins for Motor A and Motor B while IN1 & IN2
and IN3 & IN4 are direction control pins for Motor A and Motor B.

12
III. Modeling

Figure: Block Diagram of Wheeled Mobile Robot


3.1. State Space Model
- The state space model of Line Follower Robot can be written briefly as:
𝒙̇ = 𝑨𝒙 + 𝑩𝒖 + 𝒅(𝒕)
, where 𝒙 is the state variables of the Line Follower Robot, 𝒖 is the control signal, 𝑨
is the system matrix and 𝒅(𝒕) is the disturbances and uncertainties of this robot.
- The state space model of Line Follower Robot can be written as
0 0
𝜑̇ 0 0 1 𝜑 1 1
𝜏𝑟
[ 𝑣̇ ] = [0 0 0] [ 𝑣 ] + 𝑚𝑟 𝑚𝑟 [ 𝜏 ] + 𝑑(𝑡)
1 1 𝑙
𝜔̇ 0 0 0 𝜔 −
[2𝐽𝑟 2𝐽𝑟]
𝝋 𝝉𝒓 𝟎 𝟎 𝟏
, where 𝒙 = [ 𝒗 ], 𝒖 = [ 𝝉 ], 𝑨 = [𝟎 𝟎 𝟎]
𝒍
𝝎 𝟎 𝟎 𝟎
3.2. Controller
- The dynamic model written in matrix form based on Euler – Lagrange equation:
𝑴(𝒒)𝒒̈ + 𝑪(𝒒, 𝒒̇ )𝒒̇ + 𝑭(𝒒̇ ) + 𝑮(𝒒) = 𝑬(𝒒)𝒖 − 𝑨𝑻 (𝒒)𝝀
, where
• 𝑴(𝒒) 𝑖𝑠 𝑎 𝑠𝑦𝑚𝑚𝑒𝑡𝑟𝑖𝑐 𝑝𝑜𝑠𝑖𝑡𝑖𝑣𝑒 𝑑𝑒𝑓𝑖𝑛𝑖𝑡𝑒 𝑖𝑛𝑒𝑟𝑡𝑖𝑎 𝑚𝑎𝑡𝑟𝑖𝑥 𝑜𝑓 𝑡ℎ𝑒 𝑠𝑦𝑠𝑡𝑒𝑚
• 𝑪(𝒒, 𝒒̇ ) 𝑖𝑠 𝑎 𝑐𝑒𝑛𝑡𝑟𝑖𝑝𝑒𝑡𝑎𝑙 𝐶𝑜𝑟𝑖𝑜𝑙𝑖𝑠 𝑚𝑎𝑡𝑟𝑖𝑥

13
• 𝑭(𝒒̇ ) 𝑖𝑠 𝑡ℎ𝑒 𝑓𝑟𝑎𝑐𝑡𝑖𝑜𝑛 𝑣𝑒𝑐𝑡𝑜𝑟
• 𝑮(𝒒) 𝑖𝑠 𝑡ℎ𝑒 𝑔𝑟𝑎𝑣𝑖𝑡𝑎𝑡𝑖𝑜𝑛𝑎𝑙 𝑣𝑒𝑐𝑡𝑜𝑟
• 𝑬(𝒒) 𝑖𝑠 𝑡ℎ𝑒 𝑖𝑛𝑝𝑢𝑡 𝑡𝑟𝑎𝑛𝑠𝑓𝑜𝑟𝑚𝑎𝑡𝑖𝑜𝑛 𝑚𝑎𝑡𝑟𝑖𝑥
• 𝒖 𝑖𝑠 𝑎 𝑐𝑜𝑛𝑡𝑟𝑜𝑙 𝑖𝑛𝑝𝑢𝑡 𝑣𝑒𝑐𝑡𝑜𝑟
• 𝑨(𝒒) 𝑖𝑠 𝑎 𝑚𝑎𝑡𝑟𝑖𝑥 𝑎𝑠𝑠𝑜𝑐𝑖𝑎𝑡𝑒𝑑 𝑤𝑖𝑡ℎ 𝑛𝑜𝑛ℎ𝑜𝑙𝑜𝑛𝑜𝑚𝑖𝑐 𝑐𝑜𝑛𝑠𝑡𝑟𝑎𝑖𝑛𝑡𝑠
• 𝝀 𝑖𝑠 𝑡ℎ𝑒 𝑣𝑒𝑐𝑡𝑜𝑟 𝑜𝑓 𝐿𝑎𝑔𝑟𝑎𝑛𝑔𝑒 𝑚𝑢𝑙𝑡𝑖𝑝𝑙𝑖𝑒𝑟𝑠
• 𝒒̇ 𝑎𝑛𝑑 𝒒̈ 𝑑𝑒𝑛𝑜𝑡𝑒 𝑣𝑒𝑙𝑜𝑐𝑖𝑡𝑦 𝑎𝑛𝑑 𝑎𝑐𝑐𝑒𝑙𝑒𝑟𝑎𝑡𝑖𝑜𝑛 𝑣𝑒𝑐𝑡𝑜𝑟𝑠
- As we consider the Wheeled Mobile Robot running in ideal environment and on a
flat ground, the fraction vector and the gravitational vector are eliminated. This
means 𝑭(𝒒̇ ) = 𝟎 and 𝑮(𝒒) = 𝟎. Suppose that the centripetal Coriolis matrix equals
zero – 𝑪(𝒒, 𝒒̇ ) = 𝟎.
- After considering Kinematic and Dynamic Model of WMR, we have
𝑴(𝒒)𝒒̈ = 𝑬(𝒒)𝒖 − 𝑨𝑻 (𝒒)𝝀
, where
𝑚 0 0
𝑴 = [ 0 𝑚 0]
0 0 𝐽
cos 𝜑 cos 𝜑
1 sin 𝜑 sin 𝜑
𝑬= [ 𝐿 −𝐿 ]
𝑟
2 2
𝜏𝑅
𝒖 = [𝜏 ]
𝐿

− sin 𝜑 cos 𝜑 0
𝑨=[ ]
− sin(𝛼 + 𝜑) cos(𝛼 + 𝜑) 𝑑 cos 𝛼
𝜆
𝝀 = [ 1]
𝜆2
- Matrix S contains two columns presenting the possible moving direction of WMR:
cos 𝜑 0 −𝜑̇ sin 𝜑 0
𝑺 = [ sin 𝜑 0] 𝑎𝑛𝑑 𝑺̇ = [ 𝜑̇ sin 𝜑 0]
0 1 0 0
- Moreover, we have the relationship between 𝑨, 𝑺, 𝒒̇ and 𝒗:
𝑨. 𝑺 = 𝟎
𝒒̇ = 𝑺. 𝒗

14
- To simplify the Dynamic Equation, we temporarily eliminate the dependence in 𝒒
of matrix vectors
𝑴. 𝒒̈ = 𝑬. 𝒖 − 𝑨𝑻 . 𝝀
- Take the derivative of 𝒒̇ , we have 𝒒̈ = 𝑺̇. 𝒗 + 𝑺. 𝒗̇
𝑴. 𝑺̇. 𝒗 + 𝑴. 𝑺. 𝒗̇ = 𝑬. 𝒖 − 𝑨𝑻 . 𝝀
- Multiply both sides by 𝑺𝑻
𝑺𝑻 . 𝑴. 𝑺̇. 𝒗 + 𝑺𝑻 . 𝑴. 𝑺. 𝒗̇ = 𝑺𝑻 . 𝑬. 𝒖
- Denote
𝑺𝑻 . 𝑴. 𝑺̇ = 𝑽 ̃
{𝑺𝑻 . 𝑴. 𝑺 = 𝑴 ̃
𝑺𝑻 . 𝑬 = 𝑬 ̃
𝑚 0 0 −𝜑̇ sin 𝜑 0
̃=[ cos 𝜑 sin 𝜑 0 0 0
𝑽 ] [ 0 𝑚 0] [ 𝜑̇ sin 𝜑 0] = [ ]
0 0 1 0 0 𝐽 0 0
0 0
𝑚 0 0 cos 𝜑 0
̃ = [cos 𝜑 sin 𝜑 0] [ 0 𝑚 0] [ sin 𝜑 0] = [𝑚 0]
𝑴
⇒ 0 0 1 0 0 𝐽 0 𝐽
0 1
cos 𝜑 cos 𝜑
cos 𝜑 sin 𝜑 0 1 sin 𝜑 sin 𝜑 1 1 1
̃
𝑬=[ ]. .[ 𝐿 𝐿 −𝐿]
0 0 1 𝑟 −𝐿 ] = 𝑟 . [
{ 2 2
2 2
𝑣 ̃ −𝟏 . 𝑬
̃. 𝒖
⇒ 𝒗̇ = [ ] = 𝑴
𝜔
- The difference between practical velocity and reference velocity:
𝑣 𝑣𝒓
𝒗𝒆 = 𝒗 − 𝒗𝒓 = [ ] − [𝜔 ]
𝜔 𝒓

- Take the derivative of 𝒗𝒆 :


̃ −𝟏 . 𝑬
𝒗̇ 𝒆 = 𝒗̇ − 𝒗̇ 𝒓 = 𝑴 ̃ . 𝒖 − 𝒗̇ 𝒓
- Choose the control law:
̃ −𝟏 . 𝑴
𝒖=𝑬 ̃ (𝒗̇ 𝒆 + 𝒗̇ 𝒓 )
̃ −𝟏 . 𝑴
𝒖=𝑬 ̃ (−𝑲. 𝒗𝒆 + 𝒗̇ 𝒓 )
, where
• Matrix 𝑲 is the positivity – determining control matrix 2x2

15
• lim 𝒗𝒆 = 𝟎
𝑡→∞

3.3. Voltage Regulator

Figure: DC motor circuit diagram


- Kirchhoff’s Voltage Law:
𝑑𝑖
𝑉𝑎 = 𝐼𝑎 𝑅𝑎 + 𝐿𝑎 + 𝐸𝑏
𝑑𝑡
- The motor electric generated torque:
𝑑𝜔𝑚
𝑇𝑚 = 𝑇𝐿 + 𝐵𝜔𝑚 + 𝐽
𝑑𝑡
- Laplace Transform:
𝑉𝑎 = 𝐼𝑎 𝑅𝑎 + 𝐿𝑎 𝐼𝑎 𝑠 + 𝐸𝑏
𝑉𝑎 − 𝐸𝑏
𝐼𝑎 =
𝑅𝑎 + 𝑠𝐿𝑎

𝑇𝑚 = 𝑇𝐿 + 𝐵𝜔𝑚 + 𝑠𝐽𝜔𝑚 = 𝑇𝐿 + (𝐵 + 𝑠𝐽)𝜔𝑚

Figure: Block diagram of DC motor

16
- From the block diagram of DC motor, we have:
1 1
(𝑉𝑎 − 𝐾𝜔𝑚 ) . 𝐾. = 𝜔𝑚
𝑅𝑎 + 𝑠𝐿𝑎 𝐵 + 𝑠𝐽
𝐾 2 + (𝑅𝑎 + 𝑠𝐿𝑎 )(𝐵 + 𝑠𝐽) 𝑉𝑎 𝐾
⇒ 𝜔𝑚 =
(𝑅𝑎 + 𝑠𝐿𝑎 )(𝐵 + 𝑠𝐽) (𝑅𝑎 + 𝑠𝐿𝑎 )(𝐵 + 𝑠𝐽)
𝐾
⇒ 𝜔𝑚 = 𝑉𝑎 .
𝐾 2 + (𝑅𝑎 + 𝑠𝐿𝑎 )(𝐵 + 𝑠𝐽)
, where:
• 𝑉𝑎 : 𝑎𝑟𝑚𝑎𝑡𝑢𝑟𝑒 𝑖𝑛𝑝𝑢𝑡 𝑣𝑜𝑙𝑡𝑎𝑔𝑒
• 𝐼𝑎 : 𝑎𝑟𝑚𝑎𝑡𝑢𝑟𝑒 𝑐𝑢𝑟𝑟𝑒𝑛𝑡
• 𝐸𝑏 : 𝑏𝑎𝑐𝑘 𝑔𝑒𝑛𝑒𝑟𝑎𝑡𝑒𝑑 𝐸𝑀𝐹 (𝐸𝑏 = 𝑅. 𝜔𝑚 )
• 𝑅𝑎 : 𝑎𝑟𝑚𝑎𝑡𝑢𝑟𝑒 𝑟𝑒𝑠𝑖𝑠𝑡𝑎𝑛𝑐𝑒
• 𝐿𝑎 : 𝑎𝑟𝑚𝑎𝑡𝑢𝑟𝑒 𝑖𝑛𝑑𝑢𝑐𝑡𝑎𝑛𝑐𝑒
• 𝐵: 𝑑𝑎𝑚𝑝𝑖𝑛𝑔 𝑐𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡
• 𝐽: 𝑚𝑜𝑡𝑜𝑟 𝑏𝑜𝑑𝑦 𝑖𝑛𝑒𝑟𝑡𝑖𝑎
• 𝑇𝐿 : 𝑙𝑜𝑎𝑑 𝑡𝑜𝑟𝑞𝑢𝑒
• 𝑇𝑚 : 𝑚𝑜𝑡𝑜𝑟 𝑒𝑙𝑒𝑐𝑡𝑟𝑖𝑐 𝑔𝑒𝑛𝑒𝑟𝑎𝑡𝑒𝑑 𝑡𝑜𝑟𝑞𝑢𝑒
• 𝜔𝑚 : 𝑎𝑛𝑔𝑢𝑙𝑎𝑟 𝑠𝑝𝑒𝑒𝑑
- The relationship between linear velocity and angular velocity of DC motor:
𝑣 = 𝑅. 𝜔𝑚
3.4. Deviation Calculation

Figure: Line Follower Robot algorithm


17
- A weight is given to each sensor, with higher values to the extreme ones providing
higher control signals when higher deviation is detected. The weighted current
deviation is calculated from the below equation:
∑20 𝑠𝑒𝑛𝑠𝑜𝑟 𝑟𝑒𝑎𝑑𝑖𝑛𝑔 (0⁄1) ∗ 𝑐𝑜𝑟𝑟𝑒𝑠𝑝𝑜𝑛𝑑𝑖𝑛𝑔 𝑤𝑒𝑖𝑔ℎ𝑡
𝐶𝑢𝑟𝑟𝑒𝑛𝑡 𝑑𝑒𝑣𝑖𝑎𝑡𝑖𝑜𝑛 =
2
- The Desired deviation when the robot is centered on a thin black line is set to a
constant value of 0. In this case, when the Current deviation is 0, the Error is 0 and
the robot can move straight
𝐸𝑟𝑟𝑜𝑟 = 𝐷𝑒𝑠𝑖𝑟𝑒𝑑 𝑑𝑒𝑣𝑖𝑎𝑡𝑖𝑜𝑛 − 𝐶𝑢𝑟𝑟𝑒𝑛𝑡 𝑑𝑒𝑣𝑖𝑎𝑡𝑖𝑜𝑛
- A summarized list of all possible errors is shown in the below table:

IR sensor Deviation Current Error Move


reading calculation deviation
00100 0/0 0 0 Straight
10000 −4/2 -2 2 Right
01000 −2/2 -1 1 Right
00001 4/2 2 -2 Left
00010 2/2 1 -1 Left

- From the Error, we can find the deviation angel 𝜑


1.4 × 𝐸𝑟𝑟𝑜𝑟
𝜑 = tan−1
14
, where 1.4 (𝑐𝑚) is the distance between two sensors and 14 (𝑐𝑚) is the distance
between the row of sensors and DC motors.

18
IV. Realistic Simulation:
- After choosing main components, we have the circuit design on Proteus and the
practical one of Wheeled Mobile Robot

Figure: Circuit design of Line Follower Robot


4.1. Build programs and algorithms
- Use the comparator to determine the on/off status of the sensors, then infer the
vehicle position according to a predefined table of states. With this method, the
line detection error will depend on the number of states of the system, or the
distance between sensors and this method has fast processing speed.
- When one of 5 sensors detect lines, the result of its is 1. So there are 5 cases
indicate the position of Mobile Robot

Sensor value Position of Mobile Robot


00100 Line in middle of the robot
10000 Line is on the left of the robot
01000 Line is on the left of the robot

19
00010 Line is on the right of the robot
00001 Line is on the right of the robot

- We will use PID method to adjust position of wheel mobile robot. We set value for
middle point of sensor array. Then, using PID method to make error value
between middle point and other point is minimum. From that, the wheel mobile
robot can track the predetermine line. So we have table transformation between
sensor value and PID variables.
Sensor value PID values
00100 0
10000 2
01000 1
00010 -2
00001 -1

Figure: Line Follower Robot

20
4.2. Flow chart
- After having signal from sensor, we check one by one case and calculate PID
variables to control motor.

Figure: Flow chart of Line Follower Robot


4.3. Run simulation
- If we put the robot at any positon, we can know the address of robot by the sensor
values and the velocity of 2 wheels.
- The signal from sensor will present the positon of the Robot.

21
- We change PID variables and calculate the velocity of each wheels.

Figure: Sensors for detecting line

4.4. Code Arduino


// IR Sensors
int sensor1 = 2; // Left most sensor
22
int sensor2 = 3;
int sensor3 = 4;
int sensor4 = 12;
int sensor5 = 13; // Right most sensor

// Initial Values of Sensors


int sensor[] = {0, 0, 0, 0, 0};
int x1, x2, x3,x4,x5;

// Motor Variables
int ENA = 6;
int motorInput1 = 11;
int motorInput2 = 10;
int motorInput3 = 9;
int motorInput4 = 8;
int ENB = 5;

// Output Pins for Led


int ledPin1 = A0;
int ledPin2 = A1;
int ledPin3 = A2;
int ledPin4 = A3;
int ledPin5 = A4;

// PID Constants
float Kp = 4;
float Ki = 0.1;
float Kd = 0;
int deltaV;
int Vl;
int Vr;
const int V0 = 45;
float error = 0, P = 0, I = 0, D = 0;
float previous_error = 0, previous_I = 0;

int flag = 0;

void setup()
{
pinMode(sensor1, INPUT);
pinMode(sensor2, INPUT);
pinMode(sensor3, INPUT);

23
pinMode(sensor4, INPUT);
pinMode(sensor5, INPUT);

pinMode(motorInput1, OUTPUT);
pinMode(motorInput2, OUTPUT);
pinMode(motorInput3, OUTPUT);
pinMode(motorInput4, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);

pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);

digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);

Serial.begin(9600); //setting serial monitor at a default baund


rate of 9600
}

void loop()
{
/*x1 = digitalRead(sensor1);
x2 = digitalRead(sensor1);
x3 = digitalRead(sensor1);
x4 = digitalRead(sensor1);
x5 = digitalRead(sensor1);
Serial.print(x1);
Serial.print(x2);
Serial.print(x3);
Serial.print(x4);
Serial.println(x5);
delay(500);*/
/*read_sensor_values();
Serial.print(sensor[0]);
Serial.print(sensor[1]);
Serial.print(sensor[2]);

24
Serial.print(sensor[3]);
Serial.println(sensor[4]);
delay(500);*/
//dieu_khien_robot(90, 90);
read_sensor_values();
calculate_pid();
calculate_velocity(deltaV);
dieu_khien_robot(Vl, Vr);
Serial.println(Vl);
Serial.println(Vr);

delay(500);
}

void read_sensor_values()
{
sensor[0] = digitalRead(sensor1);
sensor[1] = digitalRead(sensor2);
sensor[2] = digitalRead(sensor3);
sensor[3] = digitalRead(sensor4);
sensor[4] = digitalRead(sensor5);

if ((sensor[0] == 1) && (sensor[2] == 0) && (sensor[3] == 0) &&


(sensor[4] == 0))
error = 2;
else if ((sensor[1] == 1) && (sensor[3] == 0) && (sensor[4] == 0))
error = 1;
else if ((sensor[0] == 0) && (sensor[2] == 1) && (sensor[4] == 0))
error = 0;
else if ((sensor[0] == 0) && (sensor[1] == 0) && (sensor[3] == 1))
error = -1;
else if ((sensor[0] == 0) && (sensor[1] == 0) && (sensor[2] == 0) &&
(sensor[4] == 1))
error = -2;
}

void calculate_pid()
{
P = error;
I = I + previous_I;
D = error - previous_error;

deltaV = (Kp * P) + (Ki * I) + (Kd * D);

25
previous_I = I;
previous_error = error;
}
void calculate_velocity(int dv)
{
Vl = V0 - dv;
Vr = V0 + dv;
}
void dieu_khien_robot(int vl, int vr)
{
motor_control(1, vl);
motor_control(0, vr);

}
void motor_control(int motor, int v) // 0 is right, 1 is left
{
int en;
int input1;
int input2;
if(motor == 0)
{
input1 = motorInput1;
input2 = motorInput2;
en = ENA;
}else{
en = ENB;
input1 = motorInput3;
input2 = motorInput4;
}
if( v >= 0)
{
digitalWrite(input1, LOW);
digitalWrite(input2, HIGH);
analogWrite(en,v);
}
else{
digitalWrite(input1, HIGH);
digitalWrite(input2, LOW);
analogWrite(en,-v);
}
}

26
V. Results:
- Our team has builts the mathematical model and control algorithms for the
Line Follower Mobile Robot
- The Mobile Robot is able to follow the line on flat ground. Sometimes, the
Mobile Robot fluctuates due to the delayed response time and the error of
hardware components
VI. References:
[1] https://www.mathworks.com/help/supportpkg/arduino/ref/arduino-robot-
line-follower-application.html
[2] https://quartzcomponents.com/blogs/electronics-projects/line-follower-
robot-using-arduino

27

You might also like