You are on page 1of 6

Teaching Model-Based Design and Rapid Prototyping to Undergraduate Students

Krisada Sangpetchsong
Marine Engineering Department, The Academic Branch, Royal Thai Naval Academy
204 Sukhumwit Road Paknam, Samutprakan 10270, Thailand, Tel. 0-2475-3864 Email: krisada.s@navy.mi.th

Abstract
An increasing number of engineered systems are
relying more on electronics digital controllers. This
creates a challenge when teaching students following
traditional mechanical engineering curriculum,
lacking basic knowledge in digital electronics and
microprocessors. This paper presents a project-based
learning at Marine Engineering Department, Royal
Thai Naval Academy, to provide marine engineering
students with a cheap and comprehensive set of
experiments, to design a conventional DC motor
speed controller in under 6 hours with Model-Based
Design and Rapid Prototyping techniques. During the
experiments, students must identify and validate the
system model, apply Root Locus technique to
controller design, compare controller performances
between pure simulations and an actual discrete-time
controller with Hardware in the Loop tests, and
lastly, implement a stand-alone controller with a
microcontroller. The approach eliminates the needs
for students to have in-depth basic knowledge that
most marine engineering students lack. Yet, it
presents students the whole design process including
such common real-world issues as non-linearity and
system noises. It is believed that the same approach
can benefit even electrical engineering students
taking control theory courses, since it focuses on
pertinent design techniques, control system analysis,
and concisely shows relationships between theories
and real-world implementation issues.
Keywords:

Model-Based Design, Rapid Prototyping,


Control System, Project Based Learning

1. Whats Wrong?
An increasing number of engineered systems,
including a large array of mechanical systems, are being
controlled by electronic digital controllers. Although this
technological advancement makes control system design
and implementation easier and more powerful, it
presents a challenge when teaching feedback control
theory to students major in mechanical engineering such
as naval cadets in Marine Engineering Department,
Royal Thai Naval Academy (RTNA). By nature, these
students have very limited knowledge about
analog/digital electronics circuit analysis, embedded
systems, and C programming. Furthermore, time and
curriculum prevent them from taking basic classes
necessary to understand modern control theory such as
digital
electronics,
discrete-time
system,
and
microprocessors. Nonetheless, after graduation, these
The 36th Electrical Engineering Conference : EECON- 36

students have to operate and maintain a range of highcost hi-tech systems in warships that may rely on either
classical or modern control theories. This situation raises
a question about how to best find the balance and
prepare these students for their future responsibilities.
The followings are immediate requirements for
designing learning experiments in automatic control
system course at the department:

Concisely and thoroughly enforce understanding


of control system fundamentals both classical
and modern.
Easy to follow and can be completed in a short
time (no more than 6 hours).
Low-cost to acquire, repair and replace. Students
are encouraged to think outside the box,
experiment and make mistakes.
Small in size, allowing students to take back to
experiment in their dormitory in their own time.
Illustrate relationships between theory and realworld implementation issues such as system
identification, non-linearity, system noises and
discrete-time implementation.
What was taught can be built-up or applied to
their final year projects.
Prepare them with necessary knowledge for 1)
further studies in related graduate courses, 2) to
perform
more
advanced
research
and
development, 3) and to implement real systems
with industrial standard tools and techniques
(whatever path they wish to pursue).

Conventional feedback control LAB sets are usually


very expensive to acquire and maintain. Most
importantly, they cannot meet all of the requirements
above simultaneously.
This paper presents a project-based learning
experiment to teaching automatic control system that
accomplishes all of the above requirements.

2. Model-Based Design and Rapid Prototyping


In this paper, Model-Based Design refers to a
technique where it is assumed that the mathematical
model of a system to be controlled has been made
available somehow. Control engineers can then design
and verify an appropriate controller from analytical
solutions and/or computer simulation experiments, based
on that mathematical model.
Most control system students and researchers may be
familiar with designing and analyzing systems, and the
enormous benefits of, using computer simulation with

Matlab and Simulink (Block diagram model for dynamic


system simulation.). To implement a real-world standalone system without a PC, however, most of them end
up manually rewriting another set of C code for specific
controllers to use. This process is error prone and time
consuming. Common input / output interface boards that
can work with Matlab and Simulink are generally
expensive and are not the best choice where end
applications require embedded standalone systems.
In this paper, Rapid Prototyping refers to a collection
of techniques that help shorten design and development
time. Few users know that it is possible to automatically
generate C code directly from Simulink models. This
capability can shorten development time enormously,
allowing researchers to more easily explore advanced
algorithm designs the primary benefits of Rapid
Prototyping (prove that it works sooner, optimize later
philosophy). Hardware in the Loop (HIL) test refers to
any simulation scenarios where actual target hardware is
a part of a computer simulation loop.
In 2010, the Thailand Research Funds (TRF) granted
a research team at RTNA to develop a set of Simulink
Blockset that facilitates code generation from Simulink
together with other Rapid Prototyping tools such as realtime data acquisition and other hardware device drivers
for ARM Cortex M3 Core microcontrollers. That R&D
effort resulted in what is commonly known as
RapidSTM32 Blockset as well as the founding of
Aimagin Co.,Ltd., the company that licenses and
commercializes the technology from TRF. In 2012,
Aimagin released Waijung, the next generation Blockset
for STM32F4 microcontrollers, which is based on ARM
Cortex M4 Core with hardware Floating Point Unit
and other more advanced peripherals such as Ethernet
and Camera Interface. This project-based learning
experiment is based on Waijung Blockset and the
following tools and assumptions.
The experiment takes place after all of the following
topics have been taught (some topics are taught during
the automatic control class, some are taught prior to the
class in other subjects.).

Basic Matlab m-file Programming


System Model and Simulation with Simulink
1st Order System Characteristics
Mathematical Model for Motor Speed Control
Linearization of Non-Linear System Model
Root Locus Design Method
Discrete-Time Model and Controller
sisotool (Matlab Control System toolbox) and
Root Locus Design

The following software is used:

Matlab
Simulink
Simulink Coder
Embedded Coder
Control System Toolbox
System Identification Toolbox
Waijung Blockset

The hardware shown in Fig 1 is used.

aMG LAB Kit - F4S as the controller module


aMG Motor Driver Module
Lego NXT DC Motor with built-in encoder
Motor Driver Module

Controller Module
Fig. 1 Hardware Setup

3. The Experiments
The goal of the experiment is to design a digital
controller to control angular speed of a DC motor. The
experiment is divided into 5 phases as follows.
1.
2.
3.
4.
5.

Introduction to encoder and motor driver


DC motor system model identification
Controller design via Root Locus
Hardware in the Loop tests
Standalone control system implementation

3.1 Introduction to Encoder and Motor Driver


This phase of the experiment aims at introducing
how an incremental quadrature encoder is used to
measure motor shaft angular positions. The controller
module (aMG LAB Kit F4S) is programmed and used
as a generic data acquisition board that acquires and
sends encoder signals, direction and position (counts), to
a PC for plotting in a Simulink scope in real-time.
Students can monitor the encoder signals while manually
rotating the motor. Example Simulink models for target
controller board, the host PC are shown in Fig 2. Fig 3.
Sample encoder outputs are shown in Fig 4.
Next, students are introduced to an actuator for
driving a DC motor. They are asked how they may
control direction and speed of a DC motor, especially, in
absence of a large variable analog driving source, with
only small control signals from a microcontroller.
Concepts about Pulse Width Modulation (PWM) signals
and a driver circuit that can control both speed and
direction are introduced.
The controller module is now programed as a generic
input / output board that allows students to vary the duty
cycle of the PWM control signal, while simultaneously
monitor the shaft positions from Simulink environment
in realtime.
Students are asked to experiment by varying duty
cycles of the PWM control signal. They are asked to
explain what may be reasons that the motor does not

move when duty cycle of the PWM signal is below a


certain level and how this may affect controller design
and performance. These questions aim at stimulating
their thought about viscous friction and non-linearity.

Fig. 4 Sampled encoder signals.


Duty cycle of driving PWM signal

Duty cycle (%)

25
20
15
10
5
99

100

101

Fig. 2 Target Simulink model for reading encoder.

102

103

104

105

103

104

105

103

104

105

Motor shaft position

Position (deg)

1000

500

0
99

100

101

102

Speed (deg /sec)

Motor shaft speed


800
600
400
200
99

100

101

102
Time (sec)

Fig. 5 Angular positions and speed for 20% duty cycle PWM
control signal.

800

Fig. 3 Simulink model for host PC to monitor encoder signals.

Having sufficiently experimented with driving the


motor and sensing its positions, students are asked how
they may identify the mathematical model of the motor
for speed control. At this point, they are reminded about
the mathematical model of a DC motor and the
characteristics of a 1st order system. (Students are taught
in previous classes how to derive a 1st order system
model from step response experiments.)
Students are asked how they may compute angular
speed from encoder position (counts). Fig 5. shows
sample of PWM control signal (20msec period) duty
cycles and output shaft speed. Concepts about
measurement noises and lowpass filtering are
introduced as a means to lower the noises as shown in
Fig 6 and Fig 7.

Measured Speed (deg / sec)

700

3.2 DC Motor System Model Identification

600

500

No low-pass filtering
With low-pass filtering

400

300

200
99

100

101

102
Time (sec)

103

104

105

Fig. 6 Comparison of angular speed when measurements are


made with and without lowpass filtering.

continuous-time controller using sisotool and Root


Locus technique to satisfy the following specifications.

Fig. 7 Angular speed computation with a 1st order low-pass


filter to lower measurement noises

Students are asked to obtain step responses for a few


test cases by varying duty cycles of the driving PWM
signal, e.g. step from 0% to 100%, from 10% to 20%,
and from 80% to 90%, and analyze the results. They are
advised to notice the discrepancies in step response due
to non-linearity. Next, an input profile of PWM signals
with varying duty cycle in 10% step at every 5 seconds
interval from 0% to 100% and back to 0% are used to
drive the motor, while recording its speed. Students are
asked to produce another set of step responses using the
same input profile for a linear system. The transfer
function of this linear system is determined a priori at a
specific operating point (in this case at around 700
degrees/sec). Students are asked to compare step
responses of the two simulation runs. Students are firmly
introduced to the non-linear effects of the motor as
shown in Fig 8. Students are also introduced to another
non-linear effect, namely, PWM signal saturation at
100% duty cycle.

Settling Time < 1 sec


Overshoot < 10 %
Steady State Errors = 0

Students are asked to justify their choice of controller


(number and location of poles and zeros). They are asked
to create and compare the output from Simulink
simulation model and the output from sisotool.
First thing students should be aware from the transfer
function, which is also confirmed by simulation results,
is that the steady state error is not zero as shown in Fig
10. Students are reminded how to eliminate steady state
errors with a pure integrator.

Driving PWM signal profile (Duty Cycle - %)

Duty Cycle (%)

100
80
60
40
20
0
0

20

40

60

80

Output speed profile

Fig. 9 Root Locus of an uncompensated system.

120

Actual (Non-Linear Plant)


Ideal Linear Plant (G(s)=67.5/[1 1.85])

4000
Speed (deg/sec)

100

3000
2000
1000

Operating Region
0

20

40

60
Time (sec)

80

100

120

Fig. 8 Linear / non-linear system input / output relationship.

Having learned about the non-linear nature of the


plant model, students are reminded about linearization
and asked how they may apply linearization technique to
the present case.
Students are given an operating point for
linearization as shown in Fig 5 and Fig 8. They are asked
to determine a mathematical model from 1st principle
and compared with a model derived using System
Identification Toolbox. In this example, the operating
point was selected to be in the region 400 700
degrees/sec. The transfer function is determined to be:

( )

(1)

3.3 Controller Design via Root Locus


At this point, students have already derived a
linearized plant model. They are asked to design a

Fig. 10 Time-domain step response of an uncompensated


system. (Gain = 0.1)

Students are left to design their controllers. Fig 11.


and Fig 12. show examples Root Locus design and step
response of one controller.
Having graphically designed a continuous time
controller that satisfies the design specifications,
students are asked to manually convert the continuous
time controller to a discrete time controller and
compare their results when using Matlab c2d command.
[2] and [3] show examples of the dereived controller.

( )
( )

(2)
(3)

Fig. 13 Simulation of continuous time and discrete time


controllers.
1.4
1.2

Fig. 11 Root Locus of the resultant control system.

Output

1
0.8
0.6
0.4

Continuous-time response
Discrete-time response

0.2
0

0.5

1.5

2
2.5
Time (sec)

3.5

Fig. 14 Continuous time and discrete time controller


simulation results.

Outputs
from
Simulation
Test
Input
Signals
Fig. 12 Time-domain step response of the resultant system.

Next, students are asked to simulate and compare


performances between the continuous time and the
discrete time controllers as shown in Fig 13.,
Simulations should result in similar responses as shown
in Fig 14. (Notice that the simulation model includes
PWM control signal saturation.) At this point students
are also advised about issues relating to control efforts.

Outputs
from
Real Hardware

Fig. 15 HIL test concept to verify continuous time and


discrete time controller performances.

3.4 Hardware in the Loop Tests


Having successfully verified controller performances
under pure software simulation environments, students
are introduced to the most appealing aspect of Rapid
Prototyping techniques. They are asked to implement the
controller using a microcontroller and HIL tests to
compare outputs between computer simulation and the
actual hardware simultaneously, as shown conceptually
in Fig 15. and Fig 16. This can be done entirely in
Simulink environment, without writing a single line of C
code.

Fig. 16 Simulink model for target controller for HIL tests.

4. What do students have to say?

900

This project-based learning experiment, especially


the Rapid Prototyping techniques, has not only been
taught to naval cadets at RTNA but also to engineers,
researchers, lecturers and students in other universities
and institutes in Thailand and abroad. A few universities
have already adopted such approach as part of their
control system laboratories. In addition to fulfilling the
objectives stated previously, common feedbacks are as
follows:

Angular Speed (deg/sec)

800
700
600
500
400
Command Input
Simulated discrete-time response
Real hardware response

300
200
100

10

15

20
Time (sec)

25

30

35

40

Fig. 17 HIL test results.

Fig 17. shows that performances of the actual


hardware controller closely match the simulated ideal
discrete-time controller, which is what we are aiming
for. Students are then asked to discuss possible causes
for the discrepancies.

3.5 Standalone control system implementation


A final task for students is to implement an actual
standalone control system. This can be accomplished
with Simulink and minimum efforts as shown in Fig 18.
and Fig 19.

1. The experiment bridges the gap between theory


and practices. Learners grasp fundamental concepts in
control system design and analysis much more easily and
in-time, while considerable topics are covered. Most
lecturers reported running out of time when trying to get
students to design, analyze and implement controllers
based on traditional C or other text-based programming
methods.
2. The low-cost nature means that more students can
have access to such experiments.
3. A few fundamental non Rapid Prototyping
techniques such as derivation of Root Locus theory and
basic C programming are still crucial and should still be
taught as appropriate.

5. Conclusions

Fig. 18 Simulink model for a standalone target system.

This paper presents a minimumresources approach


to apply ModelBased Design and Rapid Prototyping
techniques to thoroughly enforce understanding of
control system fundamentals, and to introduce modern
control theory to nonelectrical / nonelectronics
engineering students. Although the approach does not
involve any advanced control algorithms, it has proved
valuable, especially, when students lack solid
background knowledge in digital electronics and
microprocessors. Like any tools and methodologies, the
necessity and suitability of a tool depends largely on
specific problems and requirements at hands.
Nonetheless, it is hope that any advancement in teaching
methodology at university level will focus on getting
learners ready with high level of proficiency and
creativity, whatever fields they are in.

Dr. Krisada Sangpetchsong received


the BEng. degree in Aeronautical
Engineering from Royal Naval
Engineering College (Manadon), U.K.
in 1996 and the Ph.D. degree in
Avionics from Cranfiled University,
U.K., in 2000. Currently, he serves as
a lecturer at the Royal Thai Naval
Academy. His current research
interests include visual programming
for embedded system development.

Fig. 19 Standalone controller.

You might also like