You are on page 1of 7

1 Copyright 2013 by ASME

Proceedings of IMECE2013
ASME 2013 International Mechanical Engineering Congress & Exposition
November 15-21, 2013, San Diego, California, USA
IMECE2013-65568
TEACHING NEURAL NETWORK CONTROL SYSTEM DESIGN USING A LOW-COST
RAPID CONTROL PROTOTYPING PLATFORM

Francisco Franquiz
Graduate Student
M.S. Aerospace Engineering
Embry-Riddle Aeronautical University
Daytona Beach, Florida, 32114
Email: franquif@my.erau.edu
Alecia Hurst
Graduate Student
M.S. Mechanical Engineering
Embry-Riddle Aeronautical University
Daytona Beach, Florida, 32114
Email: hursta@my.erau.edu


Yan Tang
Assistant Professor
Mechanical Engineering
Embry-Riddle Aeronautical University
Daytona Beach, Florida, 32114
Email: yan.tang@erau.edu



ABSTRACT

This paper presents the use of a low-cost rapid control
prototyping platform, HILINK, in teaching a graduate course
on neural network control system design for mechanical
engineering students. The HILINK platform offers a seamless
interface between physical plants and Simulink for
implementation of hardware-in-the-loop real-time control
systems. With HILINK, student can quickly build a neural
network controller for applications using Neural Network
Toolbox in Simulink. As a result, students can use one single
environment for both computer simulation and hardware
implementation to understand theories and tackle practical
issues in a limited time frame. The paper presents the
experimental setup and implementation process of the
NARMA-L2 controller for DC motor speed control, and
demonstrates the convenience and effectiveness of using
HILINK in developing a neural network controller.


INTRODUCTION

In advanced control courses, students may often lose
interests if the contents heavily focus on theories. Students
want to see how theories work through both computer
simulations and hardware implementation [1-3]. Therefore,
instructors need to include both simulation assignments and
hands-on activities in curricula to keep students motivated and
engaged. Choosing the right tool for simulation and
implementation will speed up the design process significantly.
Simulink has been the most popular choice for control system
simulations as it has a block diagram based graphical editor and
students can quickly build computer models of a control
system.by using simple drag-and-drop operations to copy the
block diagram of the control system [4]. On the contrary,
hardware implementation often creates a steep learning curve
for students who do not have working knowledge of
mechatronics and programming if they need to hand code the
target microcontroller. These students might not be able to
finish the hands-on activities successfully due to the time
constraints and their low tolerance of frustrations. As a matter
of fact, such situations can be avoided by using the code
generation capability, named Simulink Coder, in Simulink.
Simulink Coder (formerly Real-Time Workshop

) enables
students to automatically generate C and C++ codes for the
target microcontroller directly from their Simulink models,
therefore it eliminates the need to hand code microcontrollers.
This practice has been widely used in industry though it has not
received much attention in classroom. One possible reason is
that instructors might intend to avoid using code generation as
students are expected to have basic programming skills.
Although code generation will speed up controller
implementation, tuning controllers might seem to be time
consuming and painful for students if they cannot evaluate the
effects of changing control parameters in real time. If that is the
2 Copyright 2013 by ASME
case, the Real-time Windows Target could enhance the
learning experience as it enables students to observe the
plants immediate response when parameters are changed.
With the aforementioned benefits (i.e. a single
environment for simulation and implementation and real-time
turning) in mind, we naturally chose Simulink instead of
Matlab for the intelligent control course ME 595F which
covers neural networks and fuzzy logic. However, the
microcontroller selection encountered a dilemma as we
intended to choose a platform compatible with the Student
Version of Simulink while providing both benefits.
Unfortunately, Real-time Windows Target is not available
on the Student Version, so the choice of microcontrollers is
very limited because very few microcontrollers can
implement real-time tuning in Simulink without Real-time
Windows Target. HILINK (Figure 1) became our final
selection because it uses Simulink as the single environment
for both simulation and implementation and does not require
Real-time Windows Target for real-time tuning. HILINK,
developed by Zeltom, LLC, is a low cost, real-time control
board designed for implementation of hardware-in-the-loop
real-time control systems. It provides a variety of I/Os and
includes Simulink library blocks (see Figure 2) associated
with each input and output. Students can simply drag-and-
drop these blocks to create connections between the Simulink
model and external hardware.

Figure 1: HILINK Hardware

Figure 2: HILINK SIMULINK Library Input and Output
Blocks

We intend to share our experience of using HILINK as a
hardware platform in teaching advanced control courses
through this paper. We will present how HILINK is used in
developing and implementing a neural network controller for
the DC motor speed control. The paper is organized as follows:
we first describe the experimental setup for the DC motor speed
control. Then we explain the NARMA-L2 controller design
process using the neural network toolbox, followed by results.
The paper concludes with the summary of experiences in using
HILINK and our recommendations for interested instructors in
control engineering education.

EXPERIMENTAL SETUP DESCRIPTION

As a typical control problem, speed control of a DC motor
was also used in ME595 so students can compare the neural
network control design with the PID control they are familiar
with. The DC motor speed control system consists of a PC
running Simulink, a DC motor with encoder, and HILINK
which transfers the control signal and the sensor measure
between the PC and the DC motor through a serial port, as
shown in Figure 3 without PC.

Figure 3: HILINK board (right) and DC motor (left) setup.

HILINK has a broad range of inputs and outputs including
eight analog inputs, two capture inputs, two encoder inputs, one
digital input, two analog outputs, two frequency outputs, two
pulse outputs, and one digital output. , some of which are
multiplexed. For the DC motor speed control application, only
the encoder input and one pulse output for the sensor
measurement and the control signal, respectively (see Figure 3).
The board interfaces via a serial port with a host computer
running Matlab/Simulink. A HILINK library to allow for
accessing HILINK hardware inputs and outputs is included for
integrating with Matlab/Simulink in a real-time Windows
environment (Figure 2). The real-time operation for the
HILINK platform operates to a maximum 3.8 kHz sampling
rate.
The DC Motor is a 12V brushed permanent magnet motor
with a 12 bit encoder with 1024 pules per revolution (the angle
resolution of 2 / 4096 rad). The computer used in this project
is Dell Precision T3600 running 64bit Windows 7 and has 2G
RAM. The suite of required software includes Simulink 7.9,
Neural Network Toolbox 7.0.3, and HILINK software 1.5.
Serial Connection
Power Supply
H-Bridge
Connection
Encoder
Connection
3 Copyright 2013 by ASME
The information exchange between the host computer and
the DC motor is executed by a simple Simulink model shown
in Figure 4. The blocks E0 and H0 represent the encoder input
and the H-bridge PWM output, respectively. The transfer
function, 1/ (0.09 1) s , is a low pass filter to smooth out the
captured encoder signal, and Gain2 is used for unit conversion
so users can choose speed output either in rad/s or rpm. As the
power supply voltage is 12V, Gain3 takes the value of 1/ 12
to represent the duty cycle of the output PWM signal. The
Out1 and In1 in Figure 4 represent the encoder output velocity
and the controller input of the masked model shown in Figure
5.

Figure 3: DC motor plant HILINK interface sub-blocks.


Figure 5: DC motor plant block diagram.
It can be easily seen from the above description that
programming HILINK can be done within minutes by simple
drag-and-drop operations as the I/Os have been represented
by Simulink library blocks.
Next, we will present the neural network controller design
and implementation.

CONTROLLER DESIGN AND IMPLEMENTATION

The Neural Network Toolbox is used for controller
design as it provides three popular neural network
architectures for control including model predictive control,
NARMA-L2 control, and model reference control [7].
NARMA-L2 was chosen as the controller requires the least
computation of these three architectures [7].
The design of NARMA-L2 controller goes through two
stages: system identification and control design. First, a neural
network model of the plant is developed and trained offline in
batch form. Then the controller is simply a rearrangement of
the neural network plant model.
A Simulink model for NARMA-L2 control of DC motor
speed control is created as shown in Figure 6. The blue
block represents the NARMA-L2 provided by Neural
Network Toolbox. As described in the previous section, the
masked block, named DC Motor Plant, handles the control
and measurement signal transfer between the computer and the
DC motor. The signal generator provides the reference signal
for the DC motor.

Figure 6: Block diagram of entire control system model.

NARMA-L2 Controller

The Nonlinear Autoregressive-Moving Average (NARMA)
model represents general discrete-time nonlinear systems.
NARMA-L2 control linearizes non-linear system dynamics by
transforming the nonlinearities. For this case, the plant model
and the training model are the same form, so the control is
referred to as NARMA-L2 rather than feedback linearization
(Figure 5). The NARMA-L2 uses an approximate model
(companion form) to represent the system:
(k + d)= f[y(k), y(k 1),, y(k n + 1), u(k 1),, u(k m +
1)]+
g[y(k), y(k 1), , y(k n + 1), u(k 1),, u(k m + 1)] u(k)
where y(k) is the system output, u(k) is the system input, and
the format y(k+d)= yr(k+d) indicates the system output follows
a reference trajectory. To avoid realization problems, the
NARMA-L2 model typically used is
y(k + d) =f[y(k), y(k 1), , y(k n + 1), u(k), u(k 1), , u(k
n + 1)]
+ g[y(k),, y(k n + 1), u(k),, u(k n + 1)] u(k + 1)
where d 2. As a result, the controller becomes
( +1) =

( + ) [(), , ( + 1), (), , ( + 1)]


[(), , ( + 1), (), , ( + 1)]

, which is realizable for d 2.
For this setup, however, the training model used is the DC
Motor plant model discussed in the previous section. The
NARMA-L2 block used in Figure 6 is illustrated in Figure 7
where TDL stands for tapped delay line which represents the
delayed signals in the controller.

System Identification

The NARMA-L2 controller block (Figure 7) is used to train
the output of the plant to match the reference signal, and the
system identification window is shown in Figure 8.

4 Copyright 2013 by ASME

Figure 7: NARMA-L2 algorithm controller block representation.
This shows the workings inside the library block included in the
MATLAB neural network toolbox.

Figure 8: NARMA-L2 controller block GUI plant identificationn
stage.
Through trial-and-error, the size of 20 neurons was
decided for the hidden layer, and 1,000 training samples were
used for system identification. As the H-bridge works in a
shifted mode which indicates a voltage between 0V and 6V
will result in a clockwise rotation while a voltage between 6V
and 12V will result in a counter clockwise rotation. For
simplicity, we only consider the counter clockwise rotation.
Therefore, the input signals are limited to 6.2V and 10.8V so
the motor will rotate in a moderate speed to ensure reliable
encoder readings. The behavior of the motor compared to the
reference signal should match the range and therefore the
plant should output between 325 and 175 radians per second.
These input and output values should be sent with a minimum
interval of 0.01 seconds and a maximum interval of 1 second.
Training Data for the control block is generated by using the
Generate Training Data operation.
The Generate Training Data Operation sends 10,001 test
inputs between the set minimum and maximum values into the
DC motor plant. The corresponding plant output velocity values
are then compared with the plant input values. The operation
then adjusts the weights using the user specified learning
algorithm (see Bias and Weight Setting section). In this
simulation, a comparison of the 10,0001 input and output data
samples collected over a period of 1000 seconds reveals a
proportionality between their rates of change (Figure 9). This
translates into corresponding input based velocity changes in
the DC Motor rotations. Using this collected data that can be
exported for saving and imported for later use.


Figure 9: Plant training data results collected over 1000 seconds at
a 0.1s sampling rate for a total of 10,000 data samples.
The learning algorithm used in the training of the Narma-L2
controller was the Levenberg-Marquardt Algorithm (LMA) [7].
The training results for our plant are portrayed below in Figures
10-16. As can bee seen in Figure 10, the neural network model
never matches the plant output perfectly modeling never
reaches a zero error state. Yet because the performance of the
controller is based on the total sum of the point squared errors
this number will tend to be higher for training data with a large
amount of samples. Increasing the number of neurons in the
network produced small improvements in its performance but
at the cost of a significant increase in training duration. In
addition, regardless of the number of neurons utilized in the
training, and because we utilized validation data in the training,
the maximum number of epochs was never reached without
encountering a validation check stop condition. That is, a point
at which the mean squared error of only the points used for
validation increased for 6 consecutive iterations. Figures 11-13
compare the plant input, plant output, neural network output,
and the total system error based only on training, validation,
and testing data respectively.
5 Copyright 2013 by ASME


Figure 10: LMA neural network training tool results.


Figure 11: Model performance based on training data.




Figure 42: Model performance based on validation data.
The overall performance of the system identification
progress is based on four different criteria: MSE, Gradient, m,
and validation. Once those conditions are met, the system
reverts to those weight and bias values providing the lowest
validation MSE.
The other three parameters are plotted as part of the final
series of outputs for the users beneft as shown in Figure 15.
The gradient value represents the derivative of the network
error based on the change of the current weights and biases.
The mu parameter represents an internal paramanter of the
LMA calculation and serves to determine how the method will
approximate the Hessian matrix in each particular time step[7].
Finally, the validation plot shows all failed validation checks
through the duration of training.
In reference to the training parameters, the regression plots
(Figure16) indicate the resulting data points deviation from the
best fit, providing a measure of their linearity.

Figure 53: Model performance based on testing data.
0 100 200 300
0
100
200
300
400
Input
0 100 200 300
0
200
400
600
Plant Output
0 100 200 300
-200
0
200
400
600
Error
time (s)
0 100 200 300
0
200
400
600
NN Output
time (s)
0 50 100 150
0
100
200
300
400
Input
0 50 100 150
0
100
200
300
400
500
Plant Output
0 50 100 150
-150
-100
-50
0
50
100
Error
time (s)
0 50 100 150
0
100
200
300
400
500
NN Output
time (s)
0 50 100 150
0
100
200
300
400
Input
0 50 100 150
0
100
200
300
400
500
Plant Output
0 50 100 150
-150
-100
-50
0
50
100
Error
time (s)
0 50 100 150
0
100
200
300
400
500
NN Output
time (s)
6 Copyright 2013 by ASME



Figure 65: Other training states and parameter of final
controller training.

Figure 76: Regression of all three data point types separately
and combined.

The simulation of the entire control system as shown in
Figure 15 consists of a single feedback loop, the components
of which can be arranged to follow a typical input- controller-
plant diagram. Out plant and controller are the HILINK and
NARMA-L2 subsystems as dicussed in previous sections and
the input is a simple signal generator allowing for different
wave configurations.

Control Design

As NARMA-L2 is simply a rearragement of the neural
network model, the control design is completed by running
the Simulink model shown in Figure 6.
The reference signal sent into the NARMA-L2 control
block originates the signal generator. The signal generator
consists of a square wave with a simulation time T, a 50 rad/s
amplitude and a 5 Hz frequency. To vertically translate the
square wave to be entirely in the positive y-axis sector, a
constant value of 250 rad/s is added with a sample time T. This
also ensures the signal does not reach speed values that are too
low for the encoder to measure accurately. After shifting, the
square wave is sent through a signal specification block (Figure
17) where the minimum parameter allowed is 0 and the
maximum value is 350 rad/s, with automatically inherited data
and a sample time T.


Figure 8: Reference signal input block diagram.

RESULTS AND ANALYSIS

The overall results of the simulation refer only to the
tracking error of the reference signal. Through this response it
is possible to assess the final performance of the system
including the average settling time, steady state error, and the
systems robustness over time. Figure18 shows the response of
the system for the first 10 s of simulation time. From this plot it
is possible to observe the output changes little over time, this
remains true even after extensive run times (10 min).


Figure 9: Error Between Reference Signal (Blue) and Encoder
Output Velocity (Green)
Taking this previous observation into account, it is
acceptable to say the average performance parameters can be
determined from a single step response. From further analysis
of the data plotted in Figure 18, we can determine the steady
state error to be 6.5 rad/s (2.1%) and the average settling time is
0.35 s. As the neural network model cannot match the plant
output perfectly, the steady state error cannot be eliminated.
The delay in the response is partly due to HILINKs
7 Copyright 2013 by ASME
performance degrades in Normal Mode. If Real-time
Windows Target is used, HILINK can be used in External
Mode to support higher real-time performance, and the delay
cannot be reduced.
All points of interest for this model can be determined
from its response to a square wave as shown in Figure 19 but
in order to assess the controllers flexibility other input wave
forms were tested as well. Figures 20-21 show the systems
overall response to a saw tooth wave and a sine wave. The
controller exhibits an average peak to peak error of 1.9 rad/s
relative to the saw tooth (Figure 20) and 2.1 rad/s relative to
the sine wave (Figure 21). This performance is comparable to
that of the case shown in Figure 19 and shows the error
remains consistent regardless of the input signals shape as
long as the frequency of the input does not exceed the
physical response time of the DC motor.


Figure 10: Single Square Wave: Error Between Reference Signal
(Blue) and Encoder Output Velocity (Green)

Figure 11: Saw Wave: Error Between Reference Signal (Blue)
and Encoder Output Velocity (Green)

CONCLUSION

This paper presents how the rapid control prototyping
platform HILINK facilitates neural network design. With
HILINK, students can quickly design and implement a
NARMA-L2 controller for DC motor speed control by simple
drag-and-drop operations. Therefore, they can focus on the
control parameter selection without developing low-level
code to program the microcontroller. The control performance
can be improved if Real-time Windows Target is used so
HILINK can be used in External Mode.


Figure 12: Sine Wave: Error Between Reference Signal (Blue) and
Encoder Output Velocity (Green)
ACKNOWLEDGMENTS
The authors acknowledge the financial support of IEEE
Control Systems Society Outreach Fund and technical support
from Zeltom LLC.
REFERENCES
[1] P. S. Shiakolas, S. R. Van Schenck, D. Piyabongkarn and I.
Frangeskou. Magnetic levitation hardware-in-the-loop and
MATLAB-based experiments for reinforcement of neural
network control concepts. Education, IEEE Transactions On
47(1), pp. 33-41. 2004.
[2] Woon-Seng Gan, Yong-Kim Chong, W. Gong and Wei-
Tong Tan. Rapid prototyping system for teaching real-time
digital signal processing. Education, IEEE Transactions On
43(1), pp. 19-24. 2000.
[3] P. S. Shiakolas and D. Piyabongkarn. Development of a
real-time digital control system with a hardware-in-the-loop
magnetic levitation device for reinforcement of controls
education. Education, IEEE Transactions On 46(1), pp. 79-87.
2003.
[4] James B. Dabney and Thomas L. Harman, "Mastering
SIMULINK," Prentice Hall, 2004.
[6] L. Zeltom, "HILINK Real-Time Hardware-In-The-Loop
Control Platform For MATLAB/SIMULINK User
Manual," vol. 2013, pp. 35, May 1, 2011, 2011.
[7] H. B. Demuth, M. Beale and M. T. Hagan. "Levenberg-
marquardt (trainlm)," in Neural Network Toolbox 6 User's
Guide Mathworks 2012, .

You might also like