Hello everyone in this video tutorial
we will look into another type of controller
that is model reference controller
how these controller will be developed is shown on the screen
so as the name suggest in this case we will have our
reference model and then we will design controller that will
control our plant to follow that  reference model
so in this case will also have 2 steps
the first step will be the plant identification
and 2nd step will be the designing the controller
so as you can see in the figure
first we have a plant for which we will create a neural network plant model
then we have nm controller block
it has 3 inputs
one is the delay reference input, second is the delayed controller output
and the third is the delayed plant output
so in this case we will have 2 neural network
first will be the plant and second will be for
controller the figure on the screen shows
how are controller will look like when build on simulink
 
so type
in the matlab command window
and this will open simulink model that may use the
model predictive controller so first let's look
plant we are using so this is the figure
this is the single link robot arm
and equation governing its motion is shown on the screen
and the equation at the bottom represent the
reference equation of the reference model
like our robot arm to follow
double click on the plant and
as you can see these are the same equation governing the motion of the robot arm
right click on the controller click on open in new tab
 
this is how our controller will be build
so we have our nm plant
right click on it and click on open in new tab
so this is the basic time series model of our plant
right click on nm controller and click on open in new tab
as already said it has 3 inputs
and then we have neural network structure
for this controller that will eventually output of the control signal
double click on it, it will open this window
so as the first step
we required to identify the plant
plant identification
and this is the same window as discussed for the other controller
click on generate training data
the data will be generated is input and target
for creating a neural network plant model will be generated
after the data is generated click on except data
 
here you can specify the size of the hidden layer
the number of delays for the plant input
the plant output
here i am using the training function
and the number of epoch that are 300 click on train network
the network is trained using the lm algorithm
the plant output and the
output graph should be identical
if they are so the network is trained good
you should click on ok or apply now we train our controller
so in this case also
we can specify the number of hidden layer neurons , number of delays
reference input and the controller output
as well as the number of delays plant output
i will be generating 6000 training samples
for training the controller
and this is just the setting the maximum and minimum value that is the
random reference signal
so click on generate training data
and weight till the data is generated
after the data generation is completed
click on except data
and click on train controller
 
as you would have seen the training has taken place
in segments this is because the controller
network is recurring neural network
and it will involve dynamic back propagation
which is very slow so what we do is
to create a segment of the hall training data
and train them individually you can also click on
before clicking on train controller
if we want to add each segment to the training data
after the training is complete click on ok
and apply and then click on run
after the simulation is complete
we will see 2 signals with our reference signal
output of our plant
so as we can see the blue line
is trying to follow the red line
now we can also create the
controller in the matlab script
so what we will do that we will create
the neural network figure which will top of the screen
using simple neural network matlab command
so this is the matlab script for creating a model predictive neural network
controller
first we will import the robot arm data set
and then will creating input delays and feedback delays
for creating plant neural network model
we also give the number of hidden layer neuron
equal to 5 now
so we use the command
in this case we will use all the data set
so we keep dividing function
and also we do not need to processing for this example
then we prepare our network by supplying with the input
and the target
after that we train the network and then close the network
that we have created so before going another further
let's run this code and see what happens
so first we have created neural network
for the plant model which is shown by the
neural network at the bottom of the window
so we supply with the one input
give it number of neuron 5 and obtain 1 output
then in the above figure we have created a recurrent neural network
so third hidden layer and the output
layer together are equivalent to our plant neural network model
you can also see the
third hidden layer and the output
looks similar to bottom figure
and the 1st hidden layer and the 2nd hidden layer together represent our controller
so let's see how it is done
now we have discussed till creating the neural network model
of out plant after that we will create a neural network
for our controller
so make use of feed forward net command  in this which we supply
the number of layers represented by
number of elements in the matrix and number of neurons
in each of those layer so we are creating
515 matrix
it will represent 3 layer 1st layer contain 5 neuron
2nd will contain 1 and 3rd will contain 5 neuron
then we are using the command
dot layer
this command is responsible for creating the connection between the different layers
so for reading this
select any of the elements from this matrix
let's say i select 2nd row and the 1st column
it is 1 it means there is a connection
to 2nd layer from the first layer
and it can also be seen control neural network diagram
so there is a connection 2nd layer from the 1st layer
and it is represent by this arrow
let's say another example
let me select the 3rd and 2nd column
it is also 1 so it make there a connection
to the 3rd layer to 2nd layer which is also true
you can also read other connection
by using this concept then we have our network as
close neural network
we provide the transfer function
for our controller then we would specify delays as 2
make sure that these are same as
that specified for the plant
then these command make sure the training of the neural network
does not take place again because we have already trained it
then we do the same thing
to the controller model as we done with plant network
we are not dividing the data that we are using
nor we are processing it
we supply with the delays of 2
then we import our reference model
and configure our controller model
with that model then we importing the weights of our train plant model
to the controller that we have created
so represent the close neural network
of our plant
and we are getting input weight
so this will represent the weight from this arrow
and we are supplying these weight to the layer
weight going to the third hidden layer from 2nd hidden layer
which will be represented by this arrow
similarly we supply all the weight from the plants
model to our controller model
and similarly the bias or also supplied
initially we will set the weights going from the 1st layer
to the 2nd layer as the row
this will ensure that the 1st output our controller
will be zero and then we are viewing our controller network
and then we train network
after that we prepare our controller network
and train it using the train command
after that we will test our network
test data input and then we convert the data input
into a sequence a time series network
and obtain a output as supplying
the data to the controller network
and then finally plotting the result
the plotted result are shown in figure
so this figure represent the blue is our
reference test input and red line is trying to follow that
reference single
more accuracy can be obtain by
is the increasing the data point
or by changing the number of hidden layer  or the number of hidden layer neuron
so that's it everyone this is it for this video
hope you like it and
please like subscribe and share and thanks for watching
