You are on page 1of 50

AUTO-TUNING OF PID PARAMETERS

USING ARTIFICIAL NEURAL NETWORKS


A Project Submitted
in Partial Fulfillment of the Requirement
for the Degree of

BACHELOR OF TECHNOLOGY
in
Electrical Engineering
by

PRATIKSHA KUMARI (1705220032)

SAMEEKSHA SINGH (1705220042)


VIKRAM SINGH (1805220911)

Under the Supervision of


Prof. KULDEEP SAHAY
Professor, Electrical Engineering Department

to the
Department of Electrical Engineering

INSTITUTE OF ENGINEERING &


TECHNOLOGY LUCKNOW-226021, INDIA
August, 2021

I
CERTIFICATE

Certified that PRATIKSHA KUMARI (1705220032), SAMEEKSHA SINGH


(1705220042), VIKRAM SINGH (1805220911) have carried out the project work
presented in this project entitled “AUTO-TUNING OF PID PARAMETERS USING
ARTIFICIAL NEURAL NETWORKS” for the award of Bachelor of Technology in
Electrical Engineering at Institute of Engineering & Technology, Lucknow under my
supervision. The project embodies results of original work, and studies are carried out by
the students themselves and the contents of the project do not form the basis for the
award of any other degree to the candidates or to anybody else from this or any other
University/Institution.

Place: Lucknow Prof. Kuldeep Sahay


Date: August 3, 2021 (Professor)
Electrical Engineering Department
IET, Lucknow

II
ABSTRACT

This project presents an autotuning method of the PID controller by using the
artificial neural network for the Brushless Direct Current (BLDC) motor drives. The
BLDC motor has some advantages compared to other types of motors. However, the
nonlinearity of this motor drive characteristics makes it difficult to handle using manual
tuning method of proportional-integral-differential (PID) controllers. In order to
overcome this main problem, an autotuning method of PID controller is introduced. The
controller result obtained is used to train an artificial neural network. This makes the
system to learn and keep getting better with time. This enhances the automaticity and
reliability of the system. The system is first operated using a PID controller to check its
efficiency. It is then operated under a PID controller with variations in operating
conditions. It is done through simulation models and comparison is done between these
two methods. The effectiveness of the proposed method is verified by the simulation
model in MATLAB-Simulink software. The simulation results show that the proposed
Artificial Neural Network, autotune the used PID controller and will provide better
speed control than the speed control by the manual tuning of the PID controller by an
individual.

III
ACKNOWLEDGEMENT

We wish to extend our thanks to teammates for their insightful comments and
constructive suggestions to improve the quality of this work. First and foremost our
utmost gratitude to my supervisor Prof. Kuldeep Sahay for his constant guidance
throughout B. Tech Major Project undertaken during B. Tech Final Year and I am also
thankful to Prof. Seethalakshmi K. Head of Department, Department of Electrical
Engineering, IET Lucknow for their constant support and guidance throughout the
course of my work. His sincerity, thoroughness and perseverance have been a constant
source of inspiration for me. It is only his cognizant efforts that my endeavour has seen
the light of the day. I also want to thank Dr. Shewta for her valuable support. I also do
not like to miss the opportunity to acknowledge the contribution of all faculty members
of the department for their kind assistance and cooperation during the development of
my project. Last but not the least, I acknowledge my friends for their cooperation in
completion of the project.

(Pratiksha Kumari) (Sameeksha Singh) (Vikram Singh)


1705220032 1705220042 1805220911

IV
Table of Content
Topic Page No.

Certificate II

Abstract III

Acknowledgement IV

CHAPTER 1: INTRODUCTION 1-2

1.1. Introduction 1

1.2. Aim 1-2

1.3. Scope 2

CHAPTER 2: CONTROLLER 3-6

2.1. PID Controller 3

2.1.1. Proportional 3

2.1.2. Integral 3

2.1.3. Derivative 4

2.1.4. Proportional Term 4

2.1.5. Steady State Error 4

2.1.6. Integral Term 4

2.1.7. Derivative Term 5

2.1.8. Loop Tuning 5

2.1.9. Stability 6

CHAPTER 3: SPEED CONTROL OF BLDC MOTOR 7-12

3.1. BLDC Motor 7

3.2. Comparison between BLDC and other motors 7

V
3.3. Speed control of BLDC Motor 8

3.3.1. Open Loop Method 8

3.3.2. Closed Loop Method 9

3.4. Algorithms used for speed control 10

3.5. Autotuning of PID 11

CHAPTER 4: ARTIFICIAL NEURAL NETWORK 13-14

4.1. Artificial Neural Network 13

4.2. Types 14

4.3. Component of ANN 14

4.3.1. Neurons 14

4.3.2. Connections and weights 14

4.3.3. Propagation function 14

CHAPTER 5: HARDWARE 15-21

5.1. Hardware Connection 15

5.2. BLDC Motor 15

5.3. Arduino 16

5.3.1. Arduino Mega 16

5.4. Microcontroller 17

5.4.1. Raspberry Pi 17

5.5. IR Tachometer 18

5.6. Electronic Speed Controller (ESC) 19

5.7. Battery (LiPo) 20

CHAPTER 6: SOFTWARE 22-23

6.1. MATLAB / SIMULINK 22

6.2. Python 22

VI
CHAPTER 7: IMPLEMENTATION 24-30

7.1. Architecture (Manual Tuning) 24

7.2. Simulation Result (Manual Tuning) 26

7.3. Proposed Architecture (Auto Tuning) 27

7.4. Simulation Result (Auto Tuning) 29

7.5 Hardware Implementation 31

7.6 Simulation Result 33

CONCLUSION 34

BIBLIOGRAPHY 35

VII
LIST OF FIGURES

VIII
PAGE
FIGURE NO. Description
NO.
Fig 1.1 Structure of PIDNN 2

Fig 2.1 PID controller block loop diagram 6

Fig 3.1 Process without feedback 8

Fig 3.2 Process with feedback 9

Fig 3.3 Algorithms used for speed control 10

Fig 4.1 Neural network 13

Fig 5.1 Proposed hardware structure 15

Fig 5.2 BLDC Motor 16

Fig 5.3 Arduino Mega 17

Fig 5.4 Raspberry Pi 18

Fig 5.5 IR Tachometer 19

Fig 5.6 Electronic Speed Controller (ESC) 20

Fig 5.7 LiPo Battery 21

Fig 7.1 Architecture of manual tuning 24

Fig 7.2 Manual tuning simulation 26

Fig 7.3 Architecture for autotuning using neural network 27

Fig 7.4 Autotuning simulation 29

Fig 7.5 Auto Tuning ANN (hardware implementation) 31

Fig 7.6 Hardware Result 33

List of Tables

IX
Page.
Table No. Table
No.
Table 3.1 Comparison between BLDC and other motors 7

Table 7.1 Result 34

LIST OF ABBREVIATION

X
BLDC Brushless Direct Current

DC Direct Current

PID Proportional-Integral-Derivative

FLC Fuzzy- Logic Controller

P Proportional

PI Proportional-Integral

DSP Digital Signal Processing

EMF Electromotive Force

RPM Revolution per Minute

ANN Artificial Neural Network

LiPo Lithium Polymer

XI
CHAPTER 1

1.1. INTRODUCTION

The PID controller is by far the most common control algorithm. Today, PID
controllers can be found in virtually all control systems, with applications
ranging from process conditions regulation to precision motion control for
assembly and process automation. The importance of PID controllers cannot be
undermined as they provide the engines to millions of control systems operating
around the world.
Since the number of PID controllers that can be found in industry is so
overwhelming, the tuning of such devices is an important issue. Indeed, this issue
has received significant attention in the literature. Several methods have been
proposed for PID auto-tuning.

PID has wide application in industries due to their versatility and tuning
capabilities. They can be used in many ways: as stand-alone regulators or as a
distributed component of control systems. However tuning the parameter poorly
will deteriorate the performance of PID. We can tune the PID manually but it
may not give promising results every time. The current microprocessor
technology has powerful computation capabilities which provides an alternative
for autotuning of PID controllers. In this project we used auto tuning of PID
controllers using Neural Network. We have used BLDC motors as our plant and
will control the speed of the plant using PID.

1.2. AIM

The project has two parts simulation and hardware implementation.

For simulation, we will use MATLAB 2019b. Our approach is to develop a


neural network which will take two inputs: error and output. The neural network

1
will have hidden layers and their weights will modify until the error reaches
minimum threshold or zero.

The inputs in neural network are:

1. Difference between reference speed and actual speed of BLDC motor


(error).

2. The output of PID (PWM value).

The neural network will give the proportional (K p), integral (Ki) and
differential (Kd) constant as output. We will train our model online till the error
becomes zero. When error reaches zero, the output of the neural network will
give the tuned parameter of PID.

Fig 1.1 Structure of PIDNN

For hardware implementation we will take a BLDC motor of 1000 kV. The
motor will be given supply by Poly Lithium battery. We will use 30A ESC to
connect the motor and our microcontroller. The ESC will control the frequency
which in turn controls the speed of the motor. We will use raspberry pi 4 to
implement the neural network and PID. The Pi 4 will take the input as speed
error from the arduino and give the required PWM as output. To measure the

2
speed we will use a tachometer. We will design a tachometer using IR sensors
and an arduino. This measured speed (v) will be the output speed of the plant
which will be used to find the error. (e = V r-v). To adjust the reference speed we
will use 10 kΩ Potentiometer. 

1.3. SCOPE

The future scope of this work is automatic speed control of closed loop systems
using Artificial Neural Network. Its scope also includes application of using
BLDC motors in electric vehicles and quadcopters.

3
CHAPTER 2

Controller

2.1. PID controller

A PID controller is an instrument used in industrial control applications to


regulate temperature, flow, pressure, speed and other process variables. PID
(proportional integral derivative) controllers use a control loop feedback
mechanism to control process variables and are the most accurate and stable
controller.
PID control is a well-established way of driving a system towards a target
position or level. It's a practically ubiquitous as a means of controlling
temperature and finds application in myriad chemical and scientific processes as
well as automation. PID control uses closed-loop control feedback to keep the
actual output from a process as close to the target or setpoint output as possible.
 A PID controller continuously calculates an error value as the difference
between a desired setpoint (SP) and a measured process variable (PV) and
applies a correction based on proportional, integral, and derivative terms
(denoted P, I, and D respectively), hence the name.

Mathematical form

4
The overall control function can be expressed mathematically as:

t
de(t )
u ( t )=K p e ( t )+ K i∫ e ( t ) dt + K d
0 dt

where Kp , Ki , and Kd , all non-negative, denote the coefficients for the


proportional, integral, and derivative terms respectively (sometimes denoted P, I,
and D).

By measuring the position (PV), and subtracting it from the setpoint (SP), the
error (e) is found, and from it the controller calculates how much electric current
to supply to the motor (MV).

2.1.1. Proportional

The obvious method is proportional control; the motor current is set in


proportion to the existing error. However, if this method fails, for instance, the
arm has to lift different weights: a greater weight needs a greater force applied
for the same error on the down side, but a smaller force if the error is on the
upside. That's where the integral and derivative terms play their part.

2.1.2. Integral

An integral term increases action in relation not only to the error but also the
time for which it has persisted. So, if the applied force is not enough to bring the
error to zero, this force will be increased as time passes. A pure "I" controller
could bring the error to zero, but it would be both slow reacting at the start
(because the action would be small at the beginning, needing time to get
significant) and brutal (the action increases as long as the error is positive, even if
the error has started to approach zero).

2.1.3. Derivative

A derivative term does not consider the error (meaning it cannot bring it to
zero: a pure D controller cannot bring the system to its setpoint), but the rate of

5
change of error, trying to bring this rate to zero. It aims at flattening the error
trajectory into a horizontal line, damping the force applied, and so reduces
overshoot (error on the other side because of too great applied force). Applying
too much impetus when the error is small and decreasing will lead to overshoot.
After overshooting, if the controller were to apply a large correction in the
opposite direction and repeatedly overshoot the desired position, the output
would oscillate around the setpoint in either a constant, growing, or decaying
sinusoid. If the amplitude of the oscillations increases with time, the system is
unstable. If they decrease, the system is stable. If the oscillations remain at a
constant magnitude, the system is marginally stable.

2.1.4. Proportional term

The proportional term produces an output value that is proportional to the


current error value. The proportional response can be adjusted by multiplying the
error by a constant Kp, called the proportional gain constant.
The proportional term is given by
Pout = K p e(t )
A high proportional gain results in a large change in the output for a given
change in the error. If the proportional gain is too high, the system can become
unstable. In contrast, a small gain results in a small output response to a large
input error, and a less responsive or less sensitive controller. If the proportional
gain is too low, the control action may be too small when responding to system
disturbances. Tuning theory and industrial practice indicate that the proportional
term should contribute the bulk of the output change.

2.1.5. Steady-state error

The steady-state error is the difference between the desired final output and
the actual one. Because a non-zero error is required to drive it, a proportional
controller generally operates with a steady-state error. Steady-state error (SSE) is
proportional to the process gain and inversely proportional to proportional gain.

6
SSE may be mitigated by adding a compensating bias term to the setpoint and
output or corrected dynamically by adding an integral term.

2.1.6. Integral term

The contribution from the integral term is proportional to both the magnitude
of the error and the duration of the error. The integral in a PID controller is the
sum of the instantaneous error over time and gives the accumulated offset that
should have been corrected previously. The accumulated error is then multiplied
by the integral gain (Ki) and added to the controller output.
The integral term is given by
t
I out =K i∫ e ( t ) dt
0

The integral term accelerates the movement of the process towards setpoint
and eliminates the residual steady-state error that occurs with a pure proportional
controller. However, since the integral term responds to accumulated errors from
the past, it can cause the present value to overshoot the setpoint value.

 
2.1.7. Derivative term

The derivative of the process error is calculated by determining the slope of


the error over time and multiplying this rate of change by the derivative gain K d.
The magnitude of the contribution of the derivative term to the overall control
action is termed the derivative gain, Kd.
de(t )
Dout =K d
dt
Derivative action predicts system behaviour and thus improves settling time
and stability of the system. An ideal derivative is not causal, so that
implementations of PID controllers include an additional low-pass filtering for
the derivative term to limit the high-frequency gain and noise. Derivative action
is seldom used in practice though – by one estimate in only 25% of deployed

7
controllers– because of its variable impact on system stability in real-world
application.
 
2.1.8. LOOP TUNING

Tuning a control loop is the adjustment of its control parameters (proportional


band/gain, integral gain/reset, derivative gain/rate) to the optimum values for the
desired control response. Stability (no unbounded oscillation) is a basic
requirement, but beyond that, different systems have different behaviour,
different applications have different requirements, and requirements may conflict
with one another.
PID tuning is a difficult problem, even though there are only three parameters
and in principle is simple to describe, because it must satisfy complex criteria
within the limitations of PID control. There are accordingly various methods for
loop tuning, and more sophisticated techniques are the subject of patents; this
section describes some traditional manual methods for loop tuning.
Designing and tuning a PID controller appears to be conceptually intuitive, but
can be hard in practice, if multiple (and often conflicting) objectives such as short
transient and high stability are to be achieved. PID controllers often provide
acceptable control using default tunings, but performance can generally be
improved by careful tuning, and performance may be unacceptable with poor
tuning. Usually, initial designs need to be adjusted repeatedly through computer
simulations until the closed-loop system performs or compromises as desired.
Some processes have a degree of nonlinearity and so parameters that work
well at full-load conditions don't work when the process is starting up from no-
load; this can be corrected by gain scheduling (using different parameters in
different operating regions).

2.1.9. Stability

8
If the PID controller parameters (the gains of the proportional, integral and
derivative terms) are chosen incorrectly, the controlled process input can be
unstable, i.e., its output diverges, with or without oscillation, and is limited only
by saturation or mechanical breakage. Instability is caused by excess gain,
particularly in the presence of significant lag.
Generally, stabilization of response is required and the process must not
oscillate for any combination of process conditions and setpoints, though
sometimes marginal stability (bounded oscillation) is acceptable or desired.
Mathematically, the origins of instability can be seen in the Laplace domain.
The total loop transfer function is:

K ( s ) G(s )
H (s)=
1+ K ( s ) G( s)

Fig 2.1 PID Controller Block Loop Diagram

9
CHAPTER 3
Speed Control of BLDC Motor

3.1. BLDC Motor

Brushless DC (BLDC) motors are synchronous motors with permanent


magnets on the rotor and armature windings on the stator. It has no brushes. As
there are no windings on the rotor, electrical losses on the rotor is minimal.
BLDC motor do not use brushes for commutation; instead of this they are
electronically commutated. BLDC motor have many advantages over brushed
DC motor and induction motor. A few of these are:
1. Better speed vs torque characteristics
2. High efficiency.
3. Long operating life.

10
4. Higher speed ranges
5. Noiseless operation.

3.2. Comparison between BLDC and other motors


Inverter + Three Brushless Motor Servo Motor
Phase Motor
Composition Three Phase Sensor mounted to Encoder is
Induction Motor + magnet motor + mounted to
General Inverter Dedicated drive magnet motor
Open Loop Closed Loop Control
Control
Control Speed Control Speed control Speed Control,
Function with accuracy not (Torque control is position control,
required partly possible) torque control
RPM 100-2400 rpm 80-4000 rpm Up to 5500 rpm
Efficiency Low Highly Efficiency due to permanent
magnet
Responsiveness Low High High
Overrun Yes, Large Yes, Large Highly Accurate
variation Variation
Suitable Used at fixed  When speed  High-
Operation speed changes, torque responsive and
Where speed and speed are kept high precision,
needs to be stable. positioning,
changed quickly  Multi-speed speed control
operation and torque
control

Table 3.1 Comparison between BLDC and other motors

11
3.3. Speed Control of BLDC Motor

Speed control of BLDC motor is necessary to operate the motor work at


desired or required speed. We can control speed of brushless dc motor by
controlling its input voltage or input current. As the voltage increases the speed
also increases and as the voltage decreases the speed decreases. We can conclude
that the speed of BLDC motor is directly proportional to input voltage and
inversely proportional to input current.
There are many different control algorithms used to provide control of BLDC
motors. The input voltage of the motor can be controlled using a power
transistors like MOSFET, GTO etc; operating as a linear voltage regulator but
this method can be practically used for low-power motor or small size motor. For
high-power motors we must use PWM control and a microcontroller is required
along with it to provide starting and control functions of the BLDC Motor
Any algorithm used for speed control of BLDC motor must provide following
essential three things:
● PWM voltage to control the motor speed
● Mechanism to commutate the motor
● Method to estimate the rotor position using the back-EMF or Hall
Sensors or IR Tachometer
A Pulse-width modulator is required to get a variable voltage. This voltage is
given to the motor windings. PWM duty cycle controls the effective voltage
given to motor and it is also proportional to duty cycle. When properly
commutated, the torque-speed characteristics of the BLDC motor are identical to
a dc motor. The variable voltage can be used to control the speed of the motor
and the available torque. The proper commutation of the power transistors is
necessary to energizes the appropriate windings in the stator in order to get
optimum torque generation depending on the rotor position.
For speed control of BLDC motor and for achieving required torque, the
MCU must be provided correct position of the rotor and the current running

12
speed. This helps motor to commutate at appropriate time. Motor speed can be
controlled by either open loop method or closed loop method.

3.3.1. Open Loop Method

In this method, the actual motor speed does not affect the current speed of
motor. Hence, there is no feed-back mechanism. PWM duty cycle is changed in
order to change the speed of the motor. The advantages of this method is
simplified control algorithm and lower cost of implementation. The disadvantage
of this method is accuracy cannot be maintained and there is no way to track the
actual motor speed.

Fig 3.1 Process without Feedback

3.3.2. Closed Loop Method:

In this method, the motor speed is continuously measured and tracked and hence
the feed-back mechanism becomes important for speed control. Here both the
reference speed and the actual speed are used to control the motor speed by

changing the PWM duty cycle. The advantages of this method are the minimal
disturbances, system stability as compared with open-loop control and reduced
sensitivity for dynamic load variations.

13
Fig 3.2 Process with Feedback

P controller, PI controller, PD controller and PID controller are the basic


controllers and combined controllers are also used in feedback or feedforward
systems as per the system requirements. In speed control of BLDC motor PID
controller is widely used in feedback path. P and PD controller is directly
proportional to incoming error and hence little change in error can cause system
instability.

3.4. Algorithms used for speed control

Fig 3.3
Algorithms used for speed control

14
An algorithm is a set of well-defined instructions in sequence to solve a
problem. It must have following properties:

1. Input and output should be defined precisely.


2. Each step in the algorithm should be clear and unambiguous.
3. Algorithms should be most effective among many different ways to solve
a problem.
4. An algorithm shouldn't include computer code. Instead, the algorithm
should be written in such a way that it can be used in different
programming languages.

For the speed control of BLDC Motor following algorithms can be used:

1. Ziegler–Nichols method

2. Cohen–Coon parameters
3. Relay method
4. Genetic Algorithm
5. FUZZY LOGIC
6. Neural Network

3.5. Autotuning of PID

An autotuner is a device that automatically computes the parameters of a


controller. Its goal is to achieve the best control possible given the tuning
objectives. In the field many PID controllers are manually tuned. But badly tuned
controllers results in less efficiency and it can lead to unpredictable and
undesirable system behaviour. An autotuner improves the result and finishes any
case of unpredictable result. An autotuner follows the same approach that a
control engineer would when tuning a controller:

1. Process Model - Choose a model for the process

2. Process Identification - Collect process data and fit it to the model

15
3. Design Method - Compute the new parameters

In this project, PID controller is autotuned by using artificial neural network


using MATLAB. A general overview of the workflow for PID autotuning is as
below

1. Incorporate a PID autotuner block into your system, as shown in the


schematic diagram.
2. Configure the start/stop signal that controls when the tuning experiment
begins and ends. You can use this signal to initiate the PID autotuning
process at any time. When you stop the experiment, the block returns tuned
PID gains.
3. Specify controller parameters such as controller type and the target
bandwidth for tuning.
4. Configure experiment parameters such as the amplitudes of the
perturbations injected during the frequency-response experiment. 
5. Start the autotuning process using the start/stop signal, and allow it to run
long enough to complete the frequency-response estimation experiment.
6. Stop the autotuning process. When the experiment stops, the autotuner
computes and returns tuned PID gains.
7. Transfer the tuned gains from the block to your PID controller. You can
then validate the performance of the tuned controller in Simulink or in real
time.

16
CHAPTER 4

4.1. ARTIFICIAL NEURAL NETWORK

An artificial neural network (ANN) is the piece of a computing system


designed to simulate the way the human brain analyses and processes
information. It is the foundation of artificial intelligence (AI) and solves
problems that would prove impossible or difficult by human or statistical
standards. ANNs have self-learning capabilities that enable them to produce
better results as more data becomes available.
Artificial neural networks are built like the human brain, with neuron nodes
interconnected like a web. The human brain has hundreds of billions of cells
called neurons. Each neuron is made up of a cell body that is responsible for
processing information by carrying information towards (inputs) and away
(outputs) from the brain.
An ANN has hundreds or thousands of artificial neurons called processing
units, which are interconnected by nodes. These processing units are made up of
input and output units. The input units receive various forms and structures of
information based on an internal weighting system, and the neural network
attempts to learn about the information presented to produce one output report.
Just like humans need rules and guidelines to come up with a result or output,
ANNs also use a set of learning rules called backpropagation, an abbreviation for
backward propagation of error, to perfect their output results.

17
An ANN initially goes through a training phase where it learns to recognize
patterns in data, whether visually, aurally, or textually. During this supervised
phase, the network compares its actual output produced with what it was meant
to produce—the desired output. The difference between both outcomes is
adjusted using backpropagation. This means that the network works backward,
going from the output unit to the input units to adjust the weight of its
connections between the units until the difference between the actual and desired
outcome produces the lowest possible error.

Fig 4.1 Neural Network

4.2. TYPES

ANNs have evolved into a broad family of techniques that have advanced
the state of the art across multiple domains. The simplest types have one or more
static components, including number of units, number of layers, unit weights and
topology. Dynamic types allow one or more of these to evolve via learning. The
latter are much more complicated, but can shorten learning periods and produce

18
better results. Some types allow/require learning to be "supervised" by the
operator, while others operate independently. Some types operate purely in
hardware, while others are purely software and run on general purpose
computers.
Some of the main breakthroughs include: convolutional neural networks
that have proven particularly successful in processing visual and other two-
dimensional data; long short-term memory avoid the vanishing gradient problem
and can handle signals that have a mix of low and high frequency components
aiding large-vocabulary speech recognition, text-to-speech synthesis, and photo-
real talking heads;] competitive networks such as generative adversarial networks
in which multiple networks (of varying structure) compete with each other, on
tasks such as winning a game or on deceiving the opponent about the authenticity
of an input.

4.3. Components of ANNs

4.3.1. Neurons

ANNs are composed of artificial neurons which are conceptually derived


from biological neurons. Each artificial neuron has inputs and produce a single
output which can be sent to multiple other neurons. The inputs can be the feature
values of a sample of external data, such as images or documents, or they can be
the outputs of other neurons. The outputs of the final output neurons of the neural
net accomplish the task, such as recognizing an object in an image.
To find the output of the neuron, first we take the weighted sum of all the
inputs, weighted by the weights of the connections from the inputs to the neuron.
We add a bias term to this sum. This weighted sum is sometimes called the
activation. This weighted sum is then passed through a (usually nonlinear)
activation function to produce the output. The initial inputs are external data,
such as images and documents. The ultimate outputs accomplish the task, such as
recognizing an object in an image.

19
4.3.2. Connections and weights

The network consists of connections, each connection providing the output


of one neuron as an input to another neuron. Each connection is assigned a
weight that represents its relative importance. A given neuron can have multiple
input and output connections.

4.3.3. Propagation function

The propagation function computes the input to a neuron from the outputs
of its predecessor neurons and their connections as a weighted sum. A bias term
can be added to the result of the propagation.

CHAPTER 5

Hardware

5.1. Hardware Connection

20
Fig 5.1 Proposed Hardware Structure
As per the circuit mentioned above, the major component used in the
project are Arduino, ESC (Electronic Speed Controller), BLDC (Brushless DC)
motor, IR Tachometer, Battery and connecting wires.
LiPo (Lithium Polymer) batter is used to supply power to the whole project,
which is directly connected to the ESC unit. Here ESC unit is taking control
signal form the Arduino and varying the voltage level given to the BLDC motor
in order to control the speed of the BLDC motor.
Neural network has been uploaded in the Raspberry Pi microcontroller. All
the data and feedback is given to it which calcite the value of Kp, Ki, Kd and
generate signal which reaches ESC and works as control signal for it.
IR Tachometer is connected with the BLDC motor and it tells neural
network the current position of the motor this helps neural network to decide
which winding is to energised and for what time.

5.2. BLDC Motor

Brushless DC (BLDC) motors are synchronous motors with permanent


magnets on the rotor and armature windings on the stator. It has no brushes. As
there are no windings on the rotor, electrical losses on the rotor is minimal.
BLDC motor do not use brushes for commutation; instead of this they are
electronically commutated. BLDC motor have many advantages over brushed
DC motor and induction motor. A few of these are:
1. Better speed vs torque characteristics
2. High efficiency.
3. Long operating life.
4. Higher speed ranges
5. Noiseless operation.

21
In our project BLDC motor is acting like a plant for our PID controller. The
output values will of ANN will give the PID parameters and these parameters
will be used to control the speed of motor.

Fig 5.2 BLDC Motor

5.3. Arduino

Arduino is an open-source platform used for building electronics projects.


Arduino consists of both a physical programmable circuit board (often referred to
as a microcontroller) and a piece of software, or IDE (Integrated Development
Environment) that runs on your computer, used to write and upload computer
code to the physical board. In this project two Arduino Nano is being used.

5.3.1 Arduino Mega

In our project we use the Arduino Mega as an interface between the python
and ESC. The output of our ANN is PWM which needs to be given to ESC for
speed control. This output is given to arduino mega through serial
communication and which is further given to ESC using servo library.

Fig 5.3 Arduino Mega

5.4. Microcontroller

22
A microcontroller is a small computer on a single metal-oxide-
semiconductor (MOS) integrated circuit (IC) chip. Microcontrollers are used
in automatically controlled products and devices, such as automobile engine
control systems, implantable medical devices, remote controls, office machines,
appliances, power tools, toys and other embedded systems. By reducing the size
and cost compared to a design that uses a separate microprocessor, memory, and
input/output devices, microcontrollers make it economical to digitally control
even more devices and processes.  Mixed signal microcontrollers are common,
integrating analog components needed to control non-digital electronic systems.
In the context of the internet of things, microcontrollers are an economical and
popular means of data collection, sensing and actuating the physical world
as edge devices. In this Raspberry pi microcontroller is being used

5.4.1 Raspberry Pi

Raspberry Pi is a series of small single-board computers developed in


the United Kingdom by the Raspberry Pi Foundation in association
with Broadcom. The Raspberry Pi project originally leaned towards the
promotion of teaching basic computer science in schools and in developing
countries. The original model became more popular than anticipated, selling
outside its target market for uses such as robotics. It is widely used in many
areas, such as for weather monitoring, because of its low cost, modularity, and
open design. It is typically used by computer and electronic hobbyists, due to its
adoption of HDMI and USB devices.
The purpose of raspberry pi is to run the ANN in python. It takes the speed
from the tachometer and sends the output of ANN to the ESC through an
arduino.

23
Fig 5.4 Raspberry Pi

5.4. IR Tachometer

A Digital Tachometer is a measuring instrument which can measure the


rotational speed of a rotary machine that indicate instantaneous values of speed in
revolutions per minute (RPM) digitally.  Tachometer is a RPM counter which
counts the no. of rotations per minute. There are two types of tachometer - one is
mechanical and the other one is digital. Here we are going to design an Arduino
based digital tachometer using IR sensor module to detect object for count
rotation of any rotating body and the programming is given by the Programmers
logic.
In this project the IR tachometer is placed near the shaft of the motor. The
shaft is painted black a white strip is made on it. When the shaft of the motor
rotates and white strip comes in front of the IR sensor, the IR light gets reflected
(generating a low signal) and when it encounters a black shaft the light gets
absorbed (generating a high signal). As white strip comes in front of the
tachometer, the IR sensor sends the interrupt to the arduino. Arduino calculates
the time between two interrupts and hence we get frequency. We can find the

24
speed in rpm using this frequency. The calculated speed is send to python
through serial communication for input to ANN.

Fig 5.5 IR
Tachometer

5.5. ESC ( Electronic Speed Controller)

The term ESC stands for “electronic speed control is an electronic


circuit used to change the speed of an electric motor, its route, and also to
perform as a dynamic brake. These are frequently used on radio-controlled
models which are electrically powered, with the change most frequently used for
brushless motors providing an electronically produced 3-phase electric
power low voltage source of energy for the motor. An ESC can be a separate unit
that lumps into the throttle receiver control channel or united into the receiver
itself, as is the situation in most toy-grade R/C vehicles.
An electronic speed controller can be designed with three essential components
like a voltage regulator/ BEC (Battery Eliminator Circuit)), a Processer & the

25
switching includes FETs. The BEC is a separation of the electronic speed control
that will transmit power back to your receiver after that to servos.
In our project ESC is providing variable voltage to the BLDC motor used
in the project. ESC gets a pulse signal from the Raspberry Pi through arduino
mega. ESC has MOSFET which also works as a voltage chopper in the project. It
reduces and increases the voltage level by changing the firing angle.

Fig 5.6 Electronic Speed Controller (ESC)

5.6. LiPo Battery

A lithium polymer battery, or more correctly lithium-ion polymer battery


(abbreviated as LiPo, LIP, Li-poly, lithium-poly and others), is a rechargeable
battery of lithium-ion technology using a polymer electrolyte instead of a liquid
electrolyte. High conductivity semisolid (gel) polymers form this electrolyte.
These batteries provide higher specific energy than other lithium battery types
and are used in applications where weight is a critical feature, such as mobile
devices, radio-controlled aircraft and some electric vehicles.

26
LiPo is used to power the whole set up of experiment. We are using 3S type
batteries each of which has 3.7 volts. It current rating is 2200mAh

Fig 5.7 LiPo Battery

CHAPTER 6

Software

6.1 MATLAB / SIMULINK

MATLAB (matrix laboratory) is a fourth-generation high-level programming


language and interactive environment for numerical computation, visualization

27
and programming. It combines a desktop environment tuned for iterative
analysis and design processes with a programming language that expresses
matrix and array mathematics directly. It includes the Live Editor for creating
scripts that combine code, output, and formatted text in an executable notebook.
It is a high-level language for numerical computation, visualization and
application development and it also provides an interactive environment for
iterative exploration, design and problem solving.

For simulation, we will use MATLAB 2019b. Our approach is to develop a


neural network which will take two inputs: error and output. The neural network
will have hidden layers and their weights will modify until the error reaches
minimum threshold or zero.

Simulink, an add-on product to MATLAB, provides an interactive, graphical


environment for modelling, simulating, and analysing of dynamic systems. It
enables rapid construction of virtual prototypes to explore design concepts at any
level of detail with minimal effort. For modelling, Simulink provides a graphical
user interface (GUI) for building models as block diagrams. It includes a
comprehensive library of predefined blocks to be used to construct graphical
models of systems using drag-and-drop mouse operations. The user is able to
produce an “up-and-running” model that would otherwise require hours to build
in the laboratory environment. It supports linear and nonlinear systems, modelled
in continuous-time, sampled time, or hybrid of the two. Since students learn
efficiently with frequent feedback, the interactive nature of Simulink encourages
you to try things out, you can change parameters “on the fly” and immediately
see what happens, for “what if” exploration. Lastly, and not the least, Simulink is
integrated with MATLAB and data can be easily shared between the programs.
In our project, we first simulate the model of a BLDC motor and cascade it
with a PID block to control its speed through voltage. Later we add an artificial
neural network to auto-tune the system. The ANN is added through the function
block in Simulink of MATLAB.

28
6.2 Python

Python is one of those rare languages which can claim to be


both simple and powerful. You will find yourself pleasantly surprised to see how
easy it is to concentrate on the solution to the problem rather than the syntax and
structure of the language you are programming in.
Python is an easy to learn, powerful programming language. It has
efficient high-level data structures and a simple but effective approach to object-
oriented programming. Python's elegant syntax and dynamic typing, together
with its interpreted nature, make it an ideal language for scripting and rapid
application development in many areas on most platforms.
In our project we have used python to interface our microcontrollers and
IR tachometer with ANN. For hardware implementation we use python in
Raspberry Pi to implement ANN.

CHAPTER 7

Implementation

29
7.1. Architecture (Manual Tuning)

Fig 7.1 Architecture for Manual Tuning

In the above Simulink model manual tuning of BLDC motor is done. For
this manually tuned PID Block is used which takes difference of reference speed
and current speed as input and generate a pulse in order to control the controlled
voltage source. This controlled voltage is given to the 3 phase inverter. The firing
angle of MOSFET is controlled by the gate signal given by decoder which is
detecting the position of rotor using Hall Effect Transducer. In this way the
correct winding is energized at correct time to get required speed and torque.

PID controller: This block is only used for manual tuning. We set the values of PID
parameters and input them along with error in reference speed and actual speed. The
output of this block is controlled voltage which is given to control voltage source block.

PMSM Block: A Permanent Magnet Synchronous Motor block is used as a BLDC


Motor. It takes 3-phase current and mechanical load torque as input. The output is

30
bundled and contains the Hall sensor output, stator current, rotor speed in rad/s, and
torque produced by the motor.

3-Phase Inverter Block: The 3-phase supply for the motor is provided by a 3-phase
inverter. It takes DC voltage and gate pulses as input. The block models a standard two-
leg, three-level inverter model.

Controlled Voltage Source Block: The controlled voltage block produces a DC


output voltage which is equal to the input signal. This block is used to vary the DC
voltage which in turn will change the speed of our BLDC Motor.

The values of PID parameters using manual tuning are-


Kp = .018
Ki = 30
Kd = 0.0005

7.2 Simulation Result

Fig 7.2 Manual Tuning Simulation Results

31
7.3 Architecture (Auto-Tuning using ANN)

Fig 7.3 Architecture for Auto-Tuning using ANN

In the above Simulink model auto-tuning of BLDC motor is done. For this
Neural Network Block is used which takes current speed (present and last 2
values), reference speed, previous pulse given to voltage source, difference of
reference speed and current speed (present and last 2 values) as input and
generate a pulse in order to control the PID Block. This PID Block generate pulse
signal given to the controlled voltage source. This controlled voltage is given to
the 3 phase inverter. The firing angle of MOSFET is controlled by the gate signal
given by decoder which is detecting the position of rotor using Hall Effect
Transducer. In this way the correct winding is energized at correct time to get
required speed and torque.

ANN Algorithm Block: A MATLAB Function block is used to perform the


ANN algorithm. This block is used only for autotuning. The Inputs are x which is

32
reference speed and errors (along with delayed values up to two time cycles) The
delayed values of errors are used in backpropagation algorithm. Initial random
weights are also given to the block. The output is the kp ki and kd which is then
fed to the varying PID controller. The block also outputs the updated weights to
measure the adaptation of the controller on varied operating conditions.

PID controller: This block is only used for manual tuning. We set the values of
PID parameters and input them along with error in reference speed and actual
speed. The output of this block is controlled voltage which is given to control
voltage source block.

PMSM Block: A Permanent Magnet Synchronous Motor block is used as a


BLDC Motor. It takes 3-phase current and mechanical load torque as input. The
output is bundled and contains the Hall sensor output, stator current, rotor speed
in rad/s, and torque produced by the motor.

3-Phase Inverter Block: The 3-phase supply for the motor is provided by a 3-
phase inverter. It takes DC voltage and gate pulses as input. The block models a
standard two-leg, three-level inverter model.

Controlled Voltage Source Block: The controlled voltage block produces a DC


output voltage which is equal to the input signal. This block is used to vary the
DC voltage which in turn will change the speed of our BLDC Motor.

The difference between manual tuning and auto tuning is:

 In manual tuning, we have to tune the PID Controller for every time for
different values of Reference Speed and Load Torque whereas in auto-tuning
the Neural Network is trained it itself changes the value of PID Controller for
different value of Reference Speed and Load Torque.
 Manual tuning takes more time in tuning whereas auto-tuning does it
quickly.

33
 Accuracy in Manual tuning reduces but accuracy of auto-tuning is high.
 Manual tuning is used where constant performance by motor is needed and
less precision required whereas auto-tuning is used where variable
performance and precise speed is required.

7.4. Simulation Result

Fig 7.4 Auto-Tuning using ANN Simulation Results

The values of PID parameters using manual tuning are-


Kp = 0.033829

34
Ki = 5.0893
Kd = 0.038472e-2

In above graph the motor is running from 0 RPM to 2000 RPM (Reference
Speed). When motor reaches its minimum running speed, a peak is generated
at 1000 RPM and then again the speed increases and motor reaches the 99%
speed within 0.25 seconds.

7.4 Hardware Implementation

35
Fig 7.5 Auto-Tuning using ANN (hardware implementation)

For hardware implementation we will take a BLDC motor of 1000KV. The


motor will be given supply by Poly Lithium battery. We will use 30A ESC to
connect the motor and our microcontroller. The ESC will control the frequency
which in turn controls the speed of the motor.

BLDC (Brushless DC) Motor: We use a 1000KV BLDC motor. The motor is
powered by a Poly-Lithium battery through ESC.

ESC (Electronic Speed Controller): ESC module (30A ESC) is providing the
variable voltage to the Motor. The input of ESC is given by computer through
Arduino Mega.

Arduino: One arduino is used for interfacing the motor with a computer
(Arduino Mega). The other one is used for measuring the speed of motor
(Arduino Uno).

IR Tachometer: To measure the speed of the motor we design our own


tachometer using IR sensor and Arduino Uno.
A cap is mounted on the motor's shaft. The cap is coloured black with a
white strip. The sensor will generate high signal when it encounters the white
strip otherwise it generates low signal. The arduino uno calculate the time for
high and low signal and give the speed as output

Li-Po Battery: A 3S type battery, each cell with 3.7 volts rating is used to power
the whole setup. The current rating of this battery is 2200mAh.

Neural Network: To run a neural network we need raspberry pi, a mini


computer. However we replaced pi with our laptop in actual implementation of
the project. This not only decreases the cost of the project but also increases the
speed and computational power.

36
7.5 Simulation Result

Fig 7.4 Hardware Results

The mean of output speed in the above graph is 7117 rpm. (Ref speed =
7000rpm)
The values of PID parameters are-
Kp = .47783
Ki = 1.3656
Kd = 1.7949

37
CONCLUSION
Artificial Neural Network has its own advantages and disadvantages, but
its disadvantages like unexplained behaviour of the network, determination of
proper network structure etc are getting eliminated one by one, and their
advantages are increasing day by day. It means that ANN has become an
indispensable part of our lives increasingly important. Here we used the
autotuning of PID controllers using Artificial Neural Networks and then used the
same PID controller to control the speed of the BLDC motor.
The PID controller has only three parameters to adjust. In this we have done the
two parts- simulation and hardware implementation. In the simulation part, we
have trained the model online in such a way so that the error becomes nearly
zero, and the output of the neural network will give the tune parameter of PID.
For hardware purposes we tried to train ANN with real time data. We acquire and
send data using microcontrollers. Microcontrollers act as an interface between
our plant (motor) and ANN (in python). We also built our own tachometer for
speed measurements
For a more robust control of the BLDC motor and to fine tune the desired
output, an agent is used to achieve this goal in an uncertain potentially complex
environment. This mechanism of reinforcement learning can be done through
artificial neural networks.

Reference PID Parameter


S.No. Condition
Speed Kp Ki Kd

Manual
1. 5000 RPM 0.018 30 0.0005
Tuning

2. Auto - Tuning 2000 RPM 0.033829 5.0893 0.038472e-2

3. Hardware 7000 RPM 0.47783 1.3656 1.7949

38
Table 7.1 Result

BIBLIOGRAPHY
[1] S. Skogestad, 2000. Probably the Best Simple PID Tuning Rules in the World,
Journal of Process Control, September 2000, pp. 1-28.
[2] Laurene Fausett, 2004. Fundamentals of Neural Networks.
[3] C. Sheeba Joice, P. Nivedhitha, 2014. Simulation of Speed Control of Brushless
DC Motor,, International Journal of Electrical, Electronics and Data
Communication, ISSN: 2320-2084, Vol. 2, Issue 4, pp. 24-29, April 2014.
[4] J. Wang and B. Malakooti, “On training of artificial neural networks,” in Proc.
1989 Int. Joint Conk Neural Networks, vol. 2, 1989.
[5] A. Noregia Ponce, A. Aguado Behar, A. Ordaz Hernandez, V. Rauch Sitar.
”Neural Networks for Self-tuning Control Systems”, Acta Polytechnica
Vol.44,2004.
[6] Tayfun Gundogdu and Guven Komurgoz,” Self-Tuning PID Control of a
Brushless DC Motor by Adaptive Interaction”. IEEJ Transactions on Electrical
and Electronic Engineering,2014.
[7] Jagganathan Sarangapani, 2016. Neural Network Control of Nonlinear Discrete-
Time Systems, CRC Press.
[8] I E. Levin, R. Gewirtzman, and G. F. Inbar, “Neural network architecture for
adaptive system modeling and control,” in Proc. 1989 lnt. Joint Conk NeuraI
Networks, vol. 2.
[9] J. Kang, W. Meng , A. Abraham and H. Liu, An adaptive PID neural network
for complex nonlinear system control, Neuro computing.
[10] Changliang Xia, Zhiqiang Li, and Tingna Shi, ”A Control Strategy for Four-
Switch Three-Phase Brushless DC Motor Using Single Current Sensor”, IEEE
Transactions On Industrial Electronics, Vol. 56, No. 6, June 2009.
[11] Cui X., Shin K. G.: “Direct Control and Coordination Using Neural Networks.”
IEEE Transactions on Systems, Man and Cybernetics, Vol.23(1992).
[12] Bhat N., McAvoy T.J.: “Use of Neural Nets for Dynamic Modelling and Control
of Chemical Process Systems.” Computers on Chem. Engineering.

39

You might also like