Embedded Digital Control With Microcontrollers Implementation With C and Python
Embedded Digital Control With Microcontrollers Implementation With C and Python
Cover
Title Page
Copyright
Dedication
Preface
About the Companion Website
1 Introduction
1.1 What is a System?
1.2 What is a Control System?
1.3 About the Book
2 Hardware to be Used in the Book
2.1 The STM32 Board
2.2 The STM32 Microcontroller
2.3 System and Sensors to be Used Throughout the Book
2.4 Systems and Sensors to be Used in Advanced
Applications
2.5 Summary
Problems
3 Software to be Used in the Book
3.1 Python on PC
3.2 MicroPython on the STM32 Microcontroller
3.3 C on the STM32 Microcontroller
3.4 Application: Running the DC Motor
3.5 Summary
Problems
4 Fundamentals of Digital Control
4.1 Digital Signals
4.2 Digital Systems
4.3 Linear and Time-Invariant Systems
4.4 The -Transform and Its Inverse
4.5 The -Transform and LTI Systems
4.6 Application I: Acquiring Digital Signals from the
Microcontroller, Processing Offline Data
4.7 Application II: Acquiring Digital Signals from the
Microcontroller, Processing Real-Time Data
4.8 Summary
Problems
5 Conversion Between Analog and Digital Forms
5.1 Converting an Analog Signal to Digital Form
5.2 Converting a Digital Signal to Analog Form
5.3 Representing an Analog System in Digital Form
5.4 Application: Exciting and Simulating the RC Filter
5.5 Summary
Problems
6 Constructing Transfer Function of a System
6.1 Transfer Function from Mathematical Modeling
6.2 Transfer Function from System Identification in Time
Domain
6.3 Transfer Function from System Identification in
Frequency Domain
6.4 Application: Obtaining Transfer Function of the DC
Motor
6.5 Summary
Problems
7 Transfer Function Based Control System Analysis
7.1 Analyzing System Performance
7.2 The Effect of Open-Loop Control on System
Performance
7.3 The Effect of Closed-Loop Control on System
Performance
7.4 Application: Adding Open-Loop Digital Controller to the
DC Motor
7.5 Summary
Problems
8 Transfer Function Based Controller Design
8.1 PID Controller Structure
8.2 PID Controller Design in Python
8.3 Lag–Lead Controller Structure
8.4 Lag–Lead Controller Design in MATLAB
8.5 Application: Adding Closed-Loop Digital Controller to
the DC Motor
8.6 Summary
Problems
9 State-space Based Control System Analysis
9.1 State-space Approach
9.2 State-space Equations Representing an LTI System
9.3 Conversion Between State-space and Transfer Function
Representations
9.4 Properties of the System from its State-space
Representation
9.5 Application: Observing States of the DC Motor in Time
9.6 Summary
Problems
10 State-space Based Controller Design
10.1 General Layout
10.2 Regulator and Controller Design via Pole Placement
10.3 Regulator and Controller Design in Python
10.4 State Observer Design
10.5 Regulator and Controller Design in Python using
Observers
10.6 Application: State-space based Control of the DC
Motor
10.7 Summary
Problems
11 Adaptive Control
11.1 What is Adaptive Control?
11.2 Parameter Estimation
11.3 Indirect Self-Tuning Regulator
11.4 Model-Reference Adaptive Control
11.5 Application: Real-Time Parameter Estimation of the
DC Motor
11.6 Summary
Problems
12 Advanced Applications
12.1 Nonlinear Control
12.2 Optimal Control
12.3 Robust Control
12.4 Distributed Control
12.5 Auto Dimmer
12.6 Constructing a Servo Motor from DC Motor
12.7 Visual Servoing
12.8 Smart Balance Hoverboard
12.9 Line Following Robot
12.10 Active Noise Cancellation
12.11 Sun Tracking Solar Panel
12.12 System Identification of a Speaker
12.13 Peltier Based Water Cooler
12.14 Controlling a Permanent Magnet Synchronous Motor
Appendix A: STM32 Board Pin Usage Tables
Bibliography
Index
End User License Agreement
List of Tables
Chapter 2
Table 2.1 Pin usage table for the DC motor.
Table 2.2 Systems to be used in advanced applications.
Table 2.3 Sensors to be used in advanced applications.
Chapter 3
Table 3.1 UART pins for ID numbers.
Chapter 6
Table 6.1 Fundamental electrical components.
Table 6.2 Fundamental mechanical components.
Table 6.3 Comparison of estimated transfer functions.
Chapter 7
Table 7.1 The effect of open-loop control in time domain.
Table 7.2 The effect of open-loop control in frequency
domain.
Table 7.3 The effect of closed-loop control in time domain.
Table 7.4 The effect of closed-loop control in frequency
domain.
Table 7.5 Time domain performance criteria for the DC
motor.
Chapter 8
Table 8.1 PID gain parameters according to the Ziegler–
Nichols method.
Table 8.2 Auxiliary parameters for the Cohen–Coon
method.
Table 8.3 PID gain parameters according to the Cohen–
Coon method.
Table 8.4 Auxiliary parameters for the Chien–Hrones–
Reswick method.
Table 8.5 PID gain parameters according to the Chien–
Hrones–Reswick method.
Table 8.6 Comparison of the P, PI, and PID controllers by
the time domain per...
Table 8.7 Comparison of the P, PI, and PID controllers by
the frequency domai...
Table 8.8 Comparison of the lag, lead, and lag–lead
controllers by the time d...
Table 8.9 Comparison of the lag, lead, and lag–lead
controllers by the freque...
Table 8.10 The effect of lag, lead, and lag–lead controllers
on system parame...
Table 8.11 The time domain performance criteria
comparison for the DC motor w...
Chapter 11
Table 11.1 Time domain performance criteria for the RLS
estimated and system ...
Appendix A
Table A.1 Pin usage table for the STM32 board, connector
CN7-left.
Table A.2 Pin usage table for the STM32 board, connector
CN7-right.
Table A.3 Pin usage table for the STM32 board, connector
CN8-left.
Table A.4 Pin usage table for the STM32 board, connector
CN8-right.
Table A.5 Pin usage table for the STM32 board, connector
CN9-left.
Table A.6 Pin usage table for the STM32 board, connector
CN9-right.
Table A.7 Pin usage table for the STM32 board, connector
CN10-left.
Table A.8 Pin usage table for the STM32 board, connector
CN10-right.
List of Illustrations
Chapter 1
Figure 1.1 PololuZumo robot.
Figure 1.2 General setup for a digital control system.
Chapter 2
Figure 2.1 The STM32 board.
Figure 2.2 Pin layout of the STM32 board.
Figure 2.3 Functional block diagram of the STM32
microcontroller.
Figure 2.4 Pololu DC motor.
Figure 2.5 DC motor drive expansion board.
Figure 2.6 General settings of the DC motor drive expansion
board.
Figure 2.7 Connection between the DC motor drive
expansion board and DC moto...
Figure 2.8 Quadrature encoder outputs.
Figure 2.9 FT232 UART to USB converter module.
Figure 2.10 Baud rate setting of the FT232 module.
Chapter 3
Figure 3.1 Available dfu devices window.
Figure 3.2 Selecting the related dfu file.
Figure 3.3 Browsing the related .hex file.
Figure 3.4 Tera Term opening window.
Figure 3.5 REPL in the rshell command window.
Figure 3.6 Mbed Studio welcome window.
Figure 3.7 Forming the new program.
Figure 3.8 General layout to control a system with
microcontroller.
Figure 3.9 Hardware setup for the application.
Chapter 4
Figure 4.1 The unit pulse signal.
Figure 4.2 The unit step signal.
Figure 4.3 The unit ramp signal.
Figure 4.4 The parabolic signal.
Figure 4.5 The exponential signal.
Figure 4.6 The sinusoidal signal.
Figure 4.7 The damped sinusoidal signal.
Figure 4.8 The rectangular signal.
Figure 4.9 The sum of sinusoids signal.
Figure 4.10 The sweep signal.
Figure 4.11 The random signal.
Figure 4.12 Representation of a digital system.
Figure 4.13 Representation of an LTI system with impulse
response .
Figure 4.14 Unit step response of the DC motor.
Figure 4.15 Series connection of two LTI systems.
Figure 4.16 Parallel connection of two LTI systems.
Figure 4.17 Feedback connection of two LTI systems.
Figure 4.18 Hardware setup for the first application.
Figure 4.19 Parabolic signal obtained by the C code.
Figure 4.20 Step input signal and simulated system output
obtained by the C ...
Figure 4.21 General system setup for real-time data
processing.
Figure 4.22 Hardware setup for the second application.
Figure 4.23 Input signal and actual DC motor speed signal
obtained by C code...
Chapter 5
Figure 5.1 Simple RC filter as the analog system.
Figure 5.2 Hardware setup for the application.
Figure 5.3 Unit step response of the RC filter, simulation
and actual measur...
Chapter 6
Figure 6.1 Simple RC filter.
Figure 6.2 Schematic representation of system
identification. (a) Unknown sy...
Figure 6.3 Block diagram of the general setup for system
identification in t...
Figure 6.4 MATLAB system identification toolbox GUI.
Figure 6.5 Import data window.
Figure 6.6 Transfer function window.
Figure 6.7 Data/model info window.
Figure 6.8 Representing the DC motor.
Figure 6.9 Block diagram of the DC motor.
Figure 6.10 Block diagram of the general setup for the DC
motor by system id...
Chapter 7
Figure 7.1 Step response of the DC motor.
Figure 7.2 Bode plot of the DC motor.
Figure 7.3 Root-locus plot of the DC motor with a controller
added to it.
Figure 7.4 Nyquist plot of the DC motor.
Figure 7.5 General structure of the open-loop control
system.
Figure 7.6 Unit step response of the DC motor with open-
loop controller appl...
Figure 7.7 Bode plot of the DC motor after applying open-
loop controller to ...
Figure 7.8 General structure of the closed-loop control
system.
Figure 7.9 Unit step response of the DC motor with closed-
loop controller ap...
Figure 7.10 Bode plot of the DC motor after applying closed-
loop controller ...
Figure 7.11 System setup for the application.
Figure 7.12 Actual and simulated output signals obtained
from the DC motor....
Figure 7.13 The continuous-time system in Problem 7.6.
Figure 7.14 The system in Problem 7.8.
Chapter 8
Figure 8.1 Closed-loop control with the P controller.
Figure 8.2 Closed-loop control with the PI controller.
Figure 8.3 Closed-loop control with the PID controller.
Figure 8.4 Unit step response of the closed-loop system
formed by the P cont...
Figure 8.5 Bode plot of the DC motor after applying the P
controller to it. ...
Figure 8.6 Unit step response of the closed-loop system
formed by the PI con...
Figure 8.7 Bode plot of the DC motor after applying the PI
controller to it....
Figure 8.8 Unit step response of the closed-loop system
formed by the PID co...
Figure 8.9 Bode plot of the DC motor after applying the PID
controller to it...
Figure 8.10 Lag controller setup.
Figure 8.11 Lead controller setup.
Figure 8.12 Lag–lead controller setup.
Figure 8.13 The controller structure in the CSD tool.
Figure 8.14 The CSD tool interactive window.
Figure 8.15 Step response system parameters selection
window.
Figure 8.16 Root-locus editor in the CSD tool.
Figure 8.17 Possible pole locations in the root-locus editor
for our control...
Figure 8.18 Unit step response of the closed-loop system
formed by the lag c...
Figure 8.19 Unit step response of the closed-loop system
formed by the lead ...
Figure 8.20 Unit step response of the closed-loop system
formed by the lag–l...
Figure 8.21 Bode plot editor in the CSD tool.
Figure 8.22 Bode plot of the DC motor after applying the lag
controller to i...
Figure 8.23 Bode plot of the DC motor after applying the
lead controller to ...
Figure 8.24 Bode plot of the DC motor after applying the
lag–lead controller...
Figure 8.25 Actual (a) and simulated (b) output signals
obtained from the DC...
Figure 8.26 Actual (a) and simulated (b) output signals
obtained from the DC...
Chapter 9
Figure 9.1 State-space representation of the selected system.
(a) Output. (b...
Figure 9.2 State-space and output plots of the DC motor
obtained by the C co...
Chapter 10
Figure 10.1 State-spaceform of an LTI system.
Figure 10.2 The controllable canonical state-space form of
an LTI system.
Figure 10.3 The regulator structure.
Figure 10.4 The controller structure.
Figure 10.5 Observer-based regulator structure.
Figure 10.6 Observer-based controller structure.
Figure 10.7 State-space and output plots of the DC motor
with regulator appl...
Figure 10.8 State-space and output plots of DC motor with
controller applied...
Figure 10.9 State-space and output plots of DC motor with
observer and regul...
Figure 10.10 State-space and output plots of DC motor with
observer and cont...
Figure 10.11 Actual signals obtained by the C code and
simulated signals obt...
Chapter 11
Figure 11.1 General layout of the adaptive control scheme.
Figure 11.2 Estimation of the two system parameters in
time. (a) wrt . (b...
Figure 11.3 General block diagram of ISTR.
Figure 11.4 Unit step response of the DC motor with
feedback controller in I...
Figure 11.5 Unit step response of the DC motor with
feedback and feedforward...
Figure 11.6 MRAC setup for gain adjustment.
Figure 11.7 value in time with MRAC setup.
Figure 11.8 Output comparison of estimated and identified
systems. (a) Outpu...
Figure 11.9 Output comparison of the estimated and
identified systems. (a) O...
Figure 11.10 Bode plot comparison of the estimated and
identified systems. (...
Chapter 12
Figure 12.1 Nonlinear model properties window.
Figure 12.2 Hammerstein–Wiener model of the DC motor.
(a) Input nonlinearity...
Figure 12.3 Phase portrait of the inverted pendulum.
Figure 12.4 Comparison of the regulators designed by pole
placement and LQR....
Figure 12.5 Hardware and software setup for the distributed
control applicat...
Figure 12.6 Hardware setup for the auto dimmer
application.
Figure 12.7 Hardware setup for the servo motor from DC
motor application usi...
Figure 12.8 Hardware setup for the servo motor from DC
motor application usi...
Figure 12.9 Hardware setup for the visual servoing
application.
Figure 12.10 Hardware setup for the smart balance
hoverboard application.
Figure 12.11 Hardware setup for the line following robot
application.
Figure 12.12 Hardware setup for the active noise
cancellation application.
Figure 12.13 General representation of the ANC system.
Figure 12.14 Block diagram of LMS based ANC operation.
Figure 12.15 Hardware setup for the sun tracking solar
panel application usi...
Figure 12.16 Hardwaresetup for the sun tracking solar panel
application usin...
Figure 12.17 Hardware setup for the system identification of
a speaker appli...
Figure 12.18 Mechanical and electrical parts of the speaker.
Figure 12.19 Hardware setup for the peltier based water
cooler application....
Figure 12.20 Hardware setup for controlling the PMSM.
Figure 12.21 STM32 motor control workbench program,
main window.
Figure 12.22 Motor profiler window.
Figure 12.23 New project window.
Figure 12.24 STM32 motor control workbench GUI.
(Source: STMicroelectronics....
Figure 12.25 STM32 motor control workbench monitor
window.
Embedded Digital Control with
Microcontrollers
Implementation with C and Python
Cem Ünsalan
Marmara University
Duygun E. Barkana
Yeditepe University
H. Deniz Gürhan
Yeditepe University
Copyright © 2021 by The Institute of Electrical and Electronics Engineers, Inc.
IEEE Standards designations are trademarks of The Institute of Electrical and Electronics
Engineers, Incorporated (www.ieee.org/).
Non-IEEE trademarks are the respective property of their owners.
Published by John Wiley & Sons, Inc., Hoboken, New Jersey. All rights reserved.
Published simultaneously in Canada.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted
in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or
otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright
Act, without either the prior written permission of the Publisher, or authorization through
payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222
Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4470, or on the web at
www.copyright.com. Requests to the Publisher for permission should be addressed to the
Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030,
(201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permission.
Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their
best efforts in preparing this book, they make no representations or warranties with respect
to the accuracy or completeness of the contents of this book and specifically disclaim any
implied warranties of merchantability or fitness for a particular purpose. No warranty may
be created or extended by sales representatives or written sales materials. The advice and
strategies contained herein may not be suitable for your situation. You should consult with a
professional where appropriate. Neither the publisher nor author shall be liable for any loss
of profit or any other commercial damages, including but not limited to special, incidental,
consequential, or other damages.
For general information on our other products and services or for technical support, please
contact our Customer Care Department within the United States at (800) 762-2974, outside
the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears
in print may not be available in electronic formats. For more information about Wiley
products, visit our web site at www.wiley.com.
Library of Congress Cataloging-in-Publication Data applied for:
ISBN: 9781119576525
Cover design by Wiley
Cover image: businessman/depositphotos
To our families.
Preface
We are surrounded by systems performing specific tasks for us.
There are also control systems designed to improve existing system
characteristics. To do so, an input signal (possibly originating from a
sensor) is acquired. The control system generates a control signal for
this input. Hence, the desired system output is obtained.
The designed control system can be either in analog or digital form.
Analog control systems are constructed by either electrical or
mechanical elements. With the arrival of embedded systems, digital
control became the new standard. Recent microcontrollers provide a
cheap and powerful platform for this purpose. This book aims to
introduce implementation methods and theory of digital control
systems on microcontrollers via focusing on real-life issues.
Python, MicroPython (the modified form of Python to be used in
embedded systems), and C will serve as the programming languages
throughout the book. Python will be extensively used in explaining
theoretical digital control concepts. MicroPython and C languages
will be the main mediums for microcontroller based implementation.
Hence, the reader will develop and implement a digital controller for
a given problem.
We took an undergraduate engineering student and hobbyist as
benchmark in explaining digital control concepts. Therefore, a
professional engineer may also benefit from the book. We pick the
STM32 board with an Arm Cortex-M microcontroller on it. Hence,
the reader may find a wide variety of applications besides the ones
considered in this book. As a result, we expect the reader to become
familiar with the basic and advanced digital control concepts in
action.
Istanbul, Turkey
June 2020
Cem Ünsalan
Duygun E. Barkana
H. Deniz Gürhan
About the Companion Website
This book is accompanied by a companion website:
www.wiley.com/go/Unsalan/Embedded_Digital_Control_
with_Microcontrollers
The website includes:
2.2.2 Memory
The microcontroller needs a medium to keep the code to be executed
and variables to be operated on. The relevant medium in the
microcontroller is called memory. Unless the microcontroller is
using an additional external memory, the core memory is always on
the microcontroller chip.
There are two memory regions on the microcontroller as flash and
RAM. Codes to be executed are kept in the flash. As power of the
microcontroller is turned down, codes remain there. Therefore, flash
resembles the solid-state drive (SSD) on PC. Although the recent
SSD storage size for a PC is reasonable, memory space in flash of a
microcontroller is very limited. For the STM32 microcontroller, this
is 2 MB. Therefore, the user should prepare his or her digital control
code such that it does not exceed this limit. Fortunately, most digital
control algorithms fit into this space.
The medium for temporary storage in the microcontroller is called
RAM. Hence, variables to be executed in the code are kept there.
This is similar to the RAM on PC with one difference. The RAM on
the microcontroller is very limited in storage size. For the STM32
microcontroller, the RAM size is 512 kB. Therefore, the reader should
use this space with care.
2.2.3 Input and Output Ports
A port in the microcontroller mean is a group of pins (or wires).
These are used to input data to the microcontroller or output data
from the microcontroller. Hence, the microcontroller can interact
with the outside world through its input and output ports. Here, the
processed data can be analog or digital. The STM32 microcontroller
has 114 pins (arranged in eight ports called A, B, C, D, E, F, G, and
H). All these pins can be used as input or output. They can also be
used for other operations as well. Therefore, they are called general
purpose input and output (GPIO). We summarized the usage area of
each pin in Appendix A.
Digital input and output values are processed in voltage levels as 0 V
and (supply voltage). Within the microcontroller code, these
correspond to logic level zero and one, respectively. Therefore, the
reader should always remember that when the logic level one is fed
to output from a pin of the microcontroller, the voltage there is .
Similarly, when the logic level zero is fed to output from a pin of the
microcontroller, the voltage there is 0 V.
2.3.3 Encoder
The selected DC motor has an integrated encoder as mentioned in
the previous section. This is used to measure speed of the motor. The
encoder we are using is of type quadrature encoder with 48 counts
per revolution (cpr).
Figure 2.7 Connection between the DC motor drive expansion
board and DC motor.
(Source: (STM, 2015). Used with permission of STMicroelectronics.)
2.4.1 Systems
There are wide variety of modules which can be used as a system. We
tabulate the most suitable ones for digital control applications in
Table 2.2. In the same table, we also provide a brief explanation of
the sample usage area of each system. While picking these, we paid
attention to their general availability. Please use these systems with
care since some of them (such as heater or drone motor with
propeller) may be harmful when used without caution. Besides,
usage of these possible dangerous systems are not mandatory to
understand the concepts explained throughout the book.
Figure 2.10 Baud rate setting of the FT232 module.
(Source: Used with permission from Microsoft.)
2.4.2 Sensors
We also have candidate sensors to be used in control applications.
We tabulate them in Table 2.3. These sensors are also picked such
that they can be purchased easily. To note here, usage area of each
sensor is not limited to the one tabulated in Table 2.3. They can be
used in other applications as well.
2.5 Summary
This book aims to blend theory with practice for digital control
concepts. Therefore, we focused on the hardware to be used
throughout the book in this chapter. To do so, we started with
properties of the STM32 microcontroller and STM32 board which
will be embedded hardware environments for implementation. Then,
we explored the DC motor and its driver board as basic systems to be
used. Related to these, we introduced systems and sensors which can
be used in advanced applications. We will be extensively using the
hardware introduced in this chapter. Therefore, the reader can
consult this chapter whenever needed.
Problems
2.1 Why do we need a development board instead of the
microcontroller alone?
2.2 Provide pin names of the STM32 microcontroller.
2.3 Can a pin of the STM32 microcontroller be used for more
than one purpose? If this is the case, give one such example.
2.4 What is the voltage range the STM32 microcontroller can
operate?
2.5 How are the supply and ground voltages named within the
STM32 microcontroller?
2.6 What is the method to program the STM32
microcontroller?
2.7 Which methods can be used to power the STM32 board?
2.8 Which architecture is the STM32 microcontroller based on?
2.9 Why do we need a clock signal for the CPU and peripheral
units within the microcontroller?
2.10 What is the difference between the flash and RAM?
Provide the size of these two modules within the STM32
microcontroller.
2.11 How many timer modules does the STM32 microcontroller
has? What is the reason for having different timer modules
within the microcontroller?
2.12 What does ADC and DAC stand for?
2.13 What is the difference between the DAC and PWM
signals?
2.14 Which digital communication modules are available
within the STM32 microcontroller?
2.15 Summarize physical characteristics of the DC motor to be
used throughout the book.
2.16 Why do we need a DC motor expansion board for?
2.17 Explain working principles of the encoder on the DC
motor.
2.18 Why will we need the FT232 module throughout the book?
2.19 Give names of at least three systems those can be used in
advanced applications. Summarize their sample usage.
2.20 Give names of at least three sensors those can be used in
advanced applications. Summarize their sample usage.
3
Software to be Used in the Book
We will approach digital control algorithm implementation in three
levels as high, middle, and low. Python running on PC will be the
medium for high-level implementation. It will allow the reader to
implement and test the desired control algorithm offline. Besides, it
will help the reader to visualize the system and signal of interest.
Hence, they can be analyzed easily. MicroPython (Python for
microcontrollers) will be the medium to be used in middle-level
implementation. We can think of MicroPython as the intermediate
step between PC and STM32 microcontroller implementations. Here,
we will benefit from properties of the Python programming language
on the microcontroller. However, this implementation will not be
optimal in terms of microcontroller resource usage. Therefore, low-
level implementation of digital control algorithms will be done by C
language on the STM32 microcontroller. To do so, we will benefit
from Arm Mbed Studio to program and debug the C code on the
microcontroller. Neither MicroPython nor Mbed Studio is specific to
the STM32 microcontroller. Hence, the reader can migrate the codes
given in this book to another hardware platform that support
MicroPython or Mbed Studio. Therefore, the book content has a wide
range of implementation options.
In the following sections, we will cover Python, MicroPython, and C-
based implementation steps in detail. We expect the reader to master
them. Hence, methods introduced in this chapter can be used in the
following chapters for digital control algorithm implementation. As
the end-of-chapter application, we will introduce how a DC motor
can be run by the STM32 microcontroller via Python and C codes.
This will be the backbone of applications to be covered in the
following chapters.
3.1 Python on PC
Python is a prototyping language used in scientific and engineering
applications. We will be using Python 3 on PC throughout the book.
We leave the Python installation and downloading steps to the
reader. To note here, a text editor will be needed to modify Python
files on PC.
Python has several add-on libraries provided by the user community
free of charge. Although these libraries simplify life for the user, we
will avoid them whenever possible since they are not available in
MicroPython. Hence, we will only use the mandatory Python
libraries on the PC side. For all other operations, we will use the
basic Python commands which are available for both PC and
microcontroller implementations.
There are excellent books on Python programming language. Here,
our aim is not to cover Python as they did. We will only focus on
fundamental topics of interest for our book. Therefore, let us
introduce them next.
When the reader clicks “Extract” in Figure 3.2, a hex file will be
created in the same directory. Then, the reader should open the
STM32 ST-LINK Utility program and select “Target, Program &
Verify.” In the opening window, he or she should browse the related
hex file as in Figure 3.3. Here, the reader should use the provided hex
file in the book website. Finally, the reader should click “Start” and
wait until the loading process is finished.
Before explaining how to program the STM32 microcontroller using
MicroPython, there is a good online simulator at
https://micropython.org/unicorn/. The simulator uses the PyBoard
instead of the STM32 board, but it can be useful to learn basic
concepts of MicroPython. Also, detailed documentation on
MicroPython can be found at
http://docs.micropython.org/en/latest/.
Figure 3.3 Browsing the related .hex file.
(Source: Used with permission from Microsoft.)
When the main.py file is corrupted, the reader needs to reset the
STM32 microcontroller to its initial settings. To do so, MicroPython's
“factory reset the file system property” can be used. Internal flash of
the microcontroller is returned to its initial state in this mode. To
start MicroPython in this mode, press both the user and reset
buttons. Then, release the reset button. LEDs are turned on in a cycle
as only blue LED, only red LED, and both blue and red LEDs. When
both LEDs are turned on, release the user button. The blue and red
LEDs should flash quickly four times. Then the green, red, and blue
LEDs should be turned on. Wait until all LEDs are turned off and
MicroPython starts in factory reset mode.
We can test whether all the above steps have been implemented
correctly by adding the print(‘‘Hello world!’’) command in the
main.py file. As the code is executed, we expect to see the string Hello
world! in the REPL window. The reader should check all the above
steps when the string cannot be observed. From this point on, we will
assume that MicroPython works without any problem on the STM32
microcontroller.
3.2.3.2 Timers
The timer of the STM32 microcontroller can be accessed from the
pyb module using the object Timer . To use the timer, first it should be
initialized using the function pyb.Timer(TimerID,
freq=TimerFrequency, mode=TimerMode) . Here, TimerID is the number
of the desired timer. TimerFrequency is the desired frequency value,
and all timer registers are arranged automatically to create this
frequency. The TimerMode can be selected as Timer.UP , Timer.DOWN , or
Timer.CENTER . These define the counting order whether it will be
from zero to AutoReload Register (ARR) value, or from ARR to
minimum value or counting up then down. The ARR value is
calculated automatically according to the selected timer frequency.
Also, the Timer.callback() function can be used to define what will
happen when the timer counts to the desired value. A sample code
using timer functions can be found in Listing 3.9. Here, the onboard
red LED connected to pin PB14 is toggled every two seconds using
the Timer2 interrupt.
3.2.3.3 ADC
We will extensively use analog to digital conversion (ADC) operation
throughout the book. We will also introduce theoretical aspects of
this operation in Chapter 5. We can use ADC module of the STM32
microcontroller via MicroPython. To do so, we should initialize the
ADC module using the function pyb.ADC(pin=pyb.Pin('PinName')) .
Here, pin is the microcontroller pin with analog input capability. The
PinName can be entered as Pxy with x being the port name and y being
the pin number. Then, analog value from this pin can be read using
the function ADC.read() in 12-bit resolution. Whenever this function
is called in the code, it performs single read. ADC input voltage can
be calculated using
(3.1)
3.2.3.4 DAC
We will also extensively use digital to analog conversion (DAC)
operation as with ADC throughout the book. We will introduce
theoretical aspects of this operation in Chapter 5. We can use DAC
module of the STM32 microcontroller via MicroPython. To do so, we
should initialize the DAC module using the function pyb.DAC(port,
bits=DACbits, buffering=DACbuffer) . Here, port is the predefined
DAC output pin and can be selected as 1 or 2 . Based on the selection,
pin PA4 or PA5 can be used for DAC output, respectively. DACbits is
used for selecting resolution of the DAC module. This value can be 8
or 12 for the related resolution. DACbuffer is used to enable or disable
the output buffer. It can be enabled using True or disabled using
False . After the DAC module is initialized, the function
DAC.write(value) can be used to feed the desired value to DAC
output. Here, value can be selected between 0 and . The
DAC output voltage can be calculated using
(3.2)
3.2.3.5 UART
Universal asynchronous receiver/transmitter (UART) module of the
STM32 microcontroller can be accessed by the pyb module using the
object UART . To use this module, first it should be initialized by the
function pyb.UART(UARTID, BaudRate) . Here, UARTID is the number of
the desired UART pin which can take values between 1 and 5. These
ID numbers and corresponding UART pins are tabulated in Table
3.1.
The desired text can be sent using the command UART.write('TEXT')
. Also, the function UART.writechar() can be used to send one
character. To read data, UART.read() function can be used. If input of
the function is set null, all available characters are read. If input of
the function is an integer value, then number of characters defined
by this integer are read. Also, UART.readchar() function can be used
to read one character.
Sample codes using UART functions can be found in Listings 3.16
and 3.17. The string “Hello world!” is sent to PC from the
microcontroller via UART every second in Listing 3.16. The onboard
green LED turns on and off in Listing 3.17 by button presses “h” and
“l” on the PC keyboard.
Table 3.1 UART pins for ID numbers.
ID TX pin RX pin
2 PD5 PD6
3 PD8 PD9
5 PB6 PB12
6 PC6 PC7
3.2.4 MicroPython Control Systems Library
Inspired by the Python control systems library introduced in Section
3.1.7, we constructed a new library to be used under both PC and
MicroPython for microcontrollers. We call this as MicroPython
control systems library. We should emphasize that Python and
MicroPython control systems libraries do not compete. They
complete each other. We will also see that there are functions in our
library to form a bridge between both libraries. Hence, they can be
used together.
Due to memory size constraints on the STM32 microcontroller, we
partitioned our MicroPython control systems library into two parts.
The first part, called mpcontrolPC.py , can only be used on PC. The
second part, called mpcontrol.py , can be used both on PC and
STM32 microcontroller. We provided both files in the accompanying
book website. These files should be added to the working Python
directory on PC. Then, we should import them to our Python code by
the commands import mpcontrolPC and import mpcontrol . We
should add the file mpcontrol.py to flash folder using rshell to run on
the microcontroller. Then, we should import it to the main.py file by
using the command import mpcontrol .
3.3.3.2 Timers
We can modify and use timers via Mbed Studio. In the first example,
we turn on and off the red LED on the STM32 board at two seconds
intervals using the timer interrupt. We provide the corresponding C
code in Listing 3.20. Here, we define the timer by Ticker
timer_ticker . Our timer interrupt function in this example is
toggle_LD3() . We call this function every two seconds using the code
timer_ticker.attach(&toggle_LD3,2) .
3.3.3.4 DAC
We can also modify and use the DAC module via Mbed Studio. In the
first example, we feed analog voltage to output from pin PA4. We
provide the corresponding C code in Listing 3.25. Here, we define the
analog output pin by AnalogOut dac(PA_4) . The analog voltage to be
fed to this pin is set by the function dac.write . This output can be
observed by connecting a multimeter to pin PA4.
3.3.3.5 UART
We can modify and use UART module via Mbed Studio. In the first
example, we send the “Hello World!” string from the STM32
microcontroller to PC every second. We can benefit from the
function printf for this purpose. This option is viable for directly
displaying some variables to the terminal window. Besides, we can
also adjust all properties of UART communication to transfer data to
PC. We provide such C code in Listing 3.27. Here, we first set TX and
RX pins of the microcontroller to be used in UART communication
via the setup Serial pc(USBTX, USBRX) . Then, we adjust the
communication speed by the function pc.baud() . Finally, we transfer
data from the microcontroller to PC by the function pc.printf() .
In the second example, we turn on and off the onboard green LED on
the STM32 board by transmitting data from PC. If the incoming
character is “h,” the green LED turns on. If the incoming character is
“l,” the green LED turns off. We provide the C code for this operation
in Listing 3.28. The only difference of this code from the previous
one is that, we receive data from PC by the function pc.getc() . In
order to transmit characters from PC, the terminal window in Mbed
Studio should be opened with necessary settings.
3.3.4 C Control Systems Library
Since we will be using C language in digital control applications
throughout the book, we introduce the corresponding C control
systems library here. This is the C version of our MicroPython
control systems library introduced in Section 3.2.4. Function names
and entries are the same in both libraries. Hence, the reader can use
both with minor modifications. To note here, C implementation will
be slightly harder to use. More importantly, the C control systems
library can only be used on the microcontroller.
We can include the C control systems library to our Mbed Studio
project as follows. We should add the Ccontrol.cpp and Ccontrol.h
files to our project. These files will be provided in the accompanying
book website. Afterward, we should include the Ccontrol.h to our
main.cpp file by the code snippet #include "Ccontrol.h" .
3.4.2 Procedure
As the reader forms the setup, the DC motor can be run either by the
C or Python code given in the following section. Here, the DC motor
input should be selected as 0, 3, 6, 9, or 12 and speed of the motor
should be observed. Afterward, the motor input should be set as 18
and 18. The observed speed values corresponding to these inputs
should be compared with the inputs 12 and 0, respectively. Finally,
the reader should alter the direction of rotation for the DC motor by
the menu for the C code and via its corresponding input value in the
MicroPython code.
After the input signal is selected with desired parameters, the system
waits for the user to push the button to start the process. As the user
button is pressed, the motor starts running. The green LED on the
STM32 board also turns on to indicate this. There is also a
notification on the terminal program telling that the motor is
running, and the user button should be pressed to stop it. If the user
presses the button again, the motor stops. The green LED on the
STM32 board turns off. There is also a notification on the terminal
program telling that the motor has stopped running and the user
button should pressed to start running it again.
3.5 Summary
Software is the most important element in digital control
applications. We handled it in three steps as high, middle, and low in
this chapter. As for high-level implementation, we picked the Python
programming language. This language offers a user friendly
environment on PC. As for the middle-level implementation, we
picked MicroPython which is the modified form of Python for
microcontrollers. Finally, we picked the C language for the low-level
operation. We provided sample codes on the usage of all three
languages for various applications. To note here, these sample codes
can be ported to other microcontrollers different than STM32. This is
due to the abstraction property of MicroPython and Mbed Studio.
However, the selected microcontroller should support these
programming environments. Besides, it should handle the code size
for the application. We also introduced Python, MicroPython, and C
control systems libraries developed specifically for digital control
applications. We will use them extensively in the following chapters.
Finally, we provided an end of chapter application on running our
DC motor by the STM32 microcontroller via C and Python codes.
This will be the backbone of applications to be covered in the
following chapters.
Problems
3.1 Provide a brief history of Python and analyze its recent
popularity.
3.2 Download and install Python on your computer with all
required libraries to be used throughout the book.
3.3 Write a program in Python language on PC
a. to calculate the first 10 elements of the function
for to 9. Store your results in an array.
b. Restructure your code such that the calculation is done
within a function.
c. Add a code snippet to save your results to a file.
3.4 Write a program in Python language on PC
a. to calculate the first 10 elements of the Fibonacci series and
store them in an array.
b. Restructure your code such that the calculation is done
within a function.
c. Add a function to your code which takes the two calculated
values in array form as input. If the array entry is even, it is
replaced by one. Otherwise, it is replaced by zero. Return
the calculated array as the output of your function.
3.5 What is the difference between Python and MicroPython?
3.6 Download and install MicroPython on your
microcontroller. Make sure it works.
3.7 Repeat Problem 3.3 in MicroPython except part c. Observe
the results on the command window.
3.8 Repeat Problem 3.4 in MicroPython. Observe the results on
the command window.
3.9 Write a code in MicroPython such that the onboard red
LED toggles every 0.1 second.
3.10 Expand Problem 3.9 such that the toggling operation
starts when the “s” button is pressed on the PC keyboard. The
toggling stops when the “d” button is pressed on the PC
keyboard.
3.11 Open an account in http://mbed.org. Import and compile
an example project related to the STM32 board we will be using
throughout the book. Embed and execute the generated code on
your board. Observe the results.
3.12 Download and install Mbed Studio on your computer.
Compile, embed, and execute the available sample code there on
the STM32 microcontroller to make sure that everything works
as expected.
3.13 Repeat Problem 3.3 in C language except part c on Mbed
Studio. Observe the results on the terminal window.
3.14 Repeat Problem 3.4 in C language on Mbed Studio.
Observe the results on the terminal window.
3.15 Repeat Problem 3.9 in C language on Mbed Studio.
3.16 Repeat Problem 3.10 in C language on Mbed Studio.
4
Fundamentals of Digital Control
Digital control systems to be considered in the following chapters
depend on digital signal representation. Therefore, this chapter
starts with an introduction to digital signals both from theoretical
and practical perspectives. Next, we will evaluate digital systems and
their properties. Here, we will focus on linear and time-invariant
(LTI) systems which form the fundamental structure in the following
chapters. We will also explore -transform and how it can be used in
analyzing digital systems. We will follow a more practical approach
throughout the chapter since our aim is applying the concepts
introduced here to practical digital control problems. Therefore, we
will provide Python and C codes whenever possible. We will direct
the reader to references for in depth theoretical evaluation of digital
control topics introduced here. As the end of chapter applications, we
will first provide methods on handling offline signals on the STM32
microcontroller. Then, we will take the DC motor as the system and
apply basic operations on it.
The unit pulse signal is defined within the C control systems library
by the function void unit_pulse_signal(int N, float signal[]) .
Here, N represents the total number of array elements to be returned.
signal[] is the array keeping unit pulse signal.
(4.2)
(4.4)
4.2.2.2 Representation in C
We can also use the C language to represent a digital system in code
form. As in Python, we suggest using the function definition for this
purpose. Let us reconsider the sample system introduced in the
previous section and form its C function representation next.
4.2.3.1 Stability
A system is stable if its output does not diverge to infinity for any
given bounded input. To note here, bounded input means that input
does not diverge to infinity. Hence, this stability definition is called
bounded input bounded output (BIBO). There are also other stability
definitions which we will not consider in this book. For more
information on these, please see Ogata (1995). Next, we provide
examples on stable and unstable systems.
Example 4.3 (A stable system)
The digital system is stable since its output is obtained
by multiplying the input signal by a constant. Therefore, if the input
signal is bounded, then there is no way the output can be
unbounded.
4.2.3.2 Linearity
A system is called linear if it satisfies the homogeneity and additivity
conditions. Let us say the input–output relationship of a system is
represented by . The homogeneity condition can be
represented as , where is constant. This
condition indicates that when input of the linear system is multiplied
by a constant, then the obtained output from the system should also
be multiplied by the same value. The additivity condition can be
represented as
, where and are constants. The additivity condition indicates
that a linear system can process an input signal as a whole or by
parts such that the output will be the same for both cases. If a system
satisfies both homogeneity and additivity conditions, then it is called
linear. Otherwise, it is called nonlinear. Next, we provide examples
on linear and nonlinear systems.
Example 4.5 (A linear system)
The digital system is linear since we can check the
homogeneity and additivity conditions are satisfied for any and
values.
(4.6)
One way to see this result is feeding a unit-step signal to the system
and feeding a step signal with amplitude four. Output obtained from
both inputs will be different besides their amplitude values. Hence,
we can deduce that the system of interest is nonlinear.
4.2.3.3 Time-Invariance
Time-invariance property tells us that the system characteristics do
not change with time. Hence, the system does not have different
responses to the same input applied in different times. This
definition also leads to a method to test the time-invariance property
of a given system.
Let us assume that we feed an input signal to a digital system
and obtain its output as . If this system is time-invariant, then a
time shift in the input signal should be observed in output as well. In
other words, when we feed a shifted input signal as , we
should get for a time-invariant digital system. On the
other hand, if a time shift in the input signal does not produce the
same amount of shift in the output signal, then the system is time-
varying. Next, we provide examples on time-invariant and time-
varying systems.
Example 4.7 (A time-invariant system)
The digital system is time-invariant. As in the
definition of time-invariance, a shift in the input signal such as
leads to the same shift in the output as .
Therefore, it is time-invariant.
(4.8)
(4.9)
There are two sum terms in Eq. (4.9). The first one only takes
current and past input signal values. This sum is called the
feedforward term. The second sum only takes past output signal
values. This sum is called the feedback term.
We can plot the obtained output signal using the matplotlib library.
As a result, we will obtain the output signal in Figure 4.14.
Figure 4.14 Unit step response of the DC motor.
Likewise, we can use the Python control systems library to obtain the
equivalent impulse response of serially connected systems. The
function series(sys1,*sysn) within the library can be used to
construct the series connection of systems represented by their
transfer function. The reader can check the usage of this function
through the Python control systems library website.
4.3.4.2 Parallel Connection
There may be cases in which a signal is fed to two systems at once
and their outputs are summed. Such a connection between the two
systems is called parallel. We provide schematic representation of
this setup in Figure 4.16. The equivalent impulse response between
input and output for this connection will be as
, where and are the impulse
response of the first and second systems, respectively.
We can use the MicroPython control systems library to obtain the
equivalent transfer function of two LTI systems connected in parallel
form using the function parallel(tf1, tf2) . Here, tf1 and tf2
represent the two transfer functions to be connected in parallel form.
Let us provide an example to this connection.
We can also use the Python control systems library to obtain the
equivalent transfer function of parallel connected systems. The
function parallel(sys1,*sysn) can be used for this purpose. The
reader can check the usage of this function through the Python
control systems library website.
(4.10)
(4.12)
(4.13)
We know that the same LTI system can also be represented by its
constant-coefficient difference equation from Eq. (4.8). Taking the
-transform of this equation, we will have
(4.14)
(4.15)
(4.16)
Rearranging the terms in Eq. (4.16), we can obtain the corresponding
transfer function as
(4.17)
.
-Transform can also be used to construct the constant-coefficient
difference equation of an LTI system from its impulse response. To
do so, the first step is taking the -transform of to obtain
. Then, can be used in Eq. (4.15) such that an algebraic
equation can be formed between the and terms as in Eq.
(4.13). Finally, applying the inverse -transform to this equation
leads to the constant-coefficient difference equation representation
of the LTI system in time domain.
(4.18)
4.6.2 Procedure
As the reader forms the hardware setup, the C or Python code given
in the next section can be executed. In the first part of this
application, a parabolic input signal with 50 elements is sent to PC
from the STM32 microcontroller. On the PC side, the received data is
saved by the Python code and it can be plotted afterward. In the
second part of this application, a step signal with 500 elements is
constructed on the STM32 microcontroller. Then, this signal is
applied to the LTI system given in Example 4.9. Afterward, both the
input and output signals obtained from the STM32 microcontroller
are sent to PC. As in the first part of the application, these data are
saved and can be plotted afterward.
4.8 Summary
Digital signals and systems form the basis of this book. Therefore,
understanding them is extremely important. We introduced digital
signals and systems in this chapter. Then, we evaluated digital
system properties. We focused on LTI systems since they will be
extensively used in this book. We also reviewed the - and inverse
-transform in this chapter. We provided Python based - and
inverse -transform calculation methods on PC. We also analyzed
the properties of digital LTI systems via -transform. As end of
chapter applications, we provided two cases of data acquisition from
the STM32 microcontroller. The first application focuses on offline
data processing. The second application provides methods of
acquiring real-time data from the microcontroller. We will frequently
use both applications in the following chapters.
Problems
4.1 Generate the following digital signals, with parameters of
your choice, for their first 20 elements in Python on PC. Plot
them using the matplotlib library.
a. Pulse.
b. Step.
c. Ramp.
d. Parabolic.
e. Exponential.
f. Sinusoidal.
g. Damped sinusoidal.
h. Rectangular
i. Sum of sinusoids.
j. Sweep.
k. Random.
4.2 Repeat Problem 4.1 in C language on the STM32
microcontroller. Transfer the generated signals to PC via UART
communication. Plot them using the matplotlib library in
Python.
4.3 Represent the below LTI systems by the Python control
systems library.
a.
b.
c.
4.4 Obtain and plot the unit step response of LTI systems in
Problem 4.3 in Python.
4.5 Repeat Problem 4.3 via
a. MicroPython control systems library.
b. C control systems library on the STM32 microcontroller.
4.6 Repeat Problem 4.4 via
a. MicroPython control systems library.
b. C control systems library on the STM32 microcontroller.
4.7 Obtain the constant-coefficient difference equation of the
LTI systems with transfer function in Problem 4.3.
4.8 Use the MicroPython and Python control systems libraries
separately, to connect LTI systems in Problem 4.3 with below
setups.
a. is serially connected to .
b. and is connected in parallel.
c. and form a negative feedback loop.
4.9 Obtain the inverse -transform of , , and
in Problem 4.3 using Python functions.
4.10 Check stability of LTI systems in Problem 4.3 using
MicroPython control systems library.
5
Conversion Between Analog and Digital
Forms
This book is on digital control. However, actual control signals are in
analog form most of the times. These should be represented in digital
form so that they can be processed by the STM32 microcontroller. As
the digital signal is processed or desired control signal is generated
by the microcontroller, it should be converted to analog form. Hence,
it can be applied to the analog system to be controlled. For both
cases, we need methods for converting analog and digital signals
from one to other. There are solid mathematical theories explaining
how these conversions can be done. We will start with explaining
them in this chapter. Besides theory, one needs practical methods to
convert analog and digital signals. Modern microcontrollers (as
candidate digital control system platforms) have dedicated hardware
for this purpose. We introduced such hardware on the STM32
microcontroller in Chapter 2. We will focus on how this hardware
can be used both in Python and C languages in this chapter. Hence,
the reader will be able to process an analog signal on the
microcontroller and feed the processed signal to outside world in
analog form.
The user may have an analog controller working as desired which has
been designed beforehand. We may want to represent it in digital
form as code. Hence, we can duplicate the existing analog controller
in digital form such that no analog parts are needed for its
implementation. This way, we can benefit from the advantages of
digital domain. In a similar manner, most existing systems to be
controlled are also in analog form. We may need their digital
representations for control operations. Therefore, it becomes a
necessity to bridge analog and digital domains. To do so, we will
focus on methods to represent an analog system in digital form in
this chapter. At the end of chapter, we will also provide a practical
application emphasizing all the methods considered here.
5.1 Converting an Analog Signal to Digital
Form
Analog to digital conversion (ADC)operation should first be
understood by mathematical derivations. Then, the reader should
learn how to realize the ADC operation in practice. Therefore, we
start with the mathematical derivation of ADC followed by its
implementation via Python and C languages in this section.
(5.1)
where stands for the floor function. Please note that we will have
an integer value between 0 and after quantization. We can
use this value in two different ways. First, we can convert it to float
representation by normalizing it (by and an appropriate
multiplier) and perform floating-point operations as we have been
doing till now. Second, we can convert the integer value to a fixed-
point representation and use it accordingly (Ünsalan et al. 2018).
The difference (in terms of the analog value) between two successive
quantization levels is called resolution. Naturally, higher the
quantization level, better the resolution. However, as the number of
bits assigned to each sample increases, memory space required to
save them becomes problematic. Moreover, the CPU clock speed
should be increased to process more samples in a given time slot.
Therefore, balance needs to be established between the resolution
and data size that can be stored and processed. For more
information on these topics, please see the book by Proakis and
Manolakis (1995).
Sampling andquantization operations are jointly called ADC. Next,
we will consider this operation from a practical perspective both in
Python and C languages.
(5.2)
(5.3)
(5.4)
(5.5)
(5.6)
(5.7)
(5.8)
(5.9)
(5.10)
(5.11)
5.5 Summary
Digital processing of continuous-time signals opens up a way to
replace any analog system with its digital counterpart. This leads to
digitalization of existing analog systems. The first step here is
obtaining digital version of the analog signal to be processed. The
next step is obtaining analog version of the processed digital signal.
In this chapter, we considered these steps through ADC and DAC
modules. The remaining part to be considered is representing the
continuous-time system in digital form. We also focused on this issue
in this chapter. Therefore, we introduced three methods to convert a
continuous-time system to digital form. These topics help the reader
to replace an analog system with its digital counterpart.
Problems
5.1 Consider the continuous-time system with transfer function
Using the Python control systems library
a. obtain digital version of the system using pole-zero
matching, zero order hold equivalent, and bilinear
transformation. Set seconds for transformations.
b. plot unit step response of the obtained discrete systems.
5.2 Repeat Problem 5.1 when seconds. What has
changed?
5.3 Apply a sinusoidal signal to PA6 pin of the STM32
microcontroller using MicroPython. The sinusoidal signal
should be between 1 and 2 V with frequency 10 Hz.
a. Implement the ADC operation by setting the sampling
frequency to 500, 100, 20, and 5 Hz. Store 500 samples in
an array. The quantization level for the operation should be
12 bits. Transfer the acquired data to PC and analyze the
results.
b. Repeat the steps in part (a) by setting the quantization level
to 8 bits. For this case, use the sampling frequency as
500 Hz. Comment on the effect of quantization level in the
ADC operation.
5.4 Generate a sawtooth signal on the STM32 microcontroller
and feed it through PA4 pin using MicroPython. The period of
the signal should be 10 Hz. The amplitude of the signal should
be between 1 and 2 V.
a. Implement the DAC operation by setting the sampling
frequency to 100, 250, and 1000 Hz. Feed the generated
data to output and observe it by an oscilloscope and analyze
the results.
b. Repeat the steps in part (a) by setting the quantization level
to 8 bits. For this case, use the sampling frequency as
1000 Hz. Comment on the effect of quantization level in the
DAC operation.
5.5 Repeat Problem 5.3 using C language on Mbed Studio.
5.6 Repeat Problem 5.4 using C language on Mbed Studio.
6
Constructing Transfer Function of a System
The first step in controlling a system is to know how it behaves for
different input signals. The input output relation obtained for this
purpose is called transfer function of the system as explained in
detail in Chapter 4. Afterward, control methods can be applied on it.
This chapter focuses on constructing the transfer function of a
system. To do so, we will use two fundamental methods as
mathematical modeling and system identification. Mathematical
modeling is a theoretical approach in which the system structure
should be known in advance. On the other hand, system
identification is a more general approach which can be applied to any
system. Through these two approaches, we will obtain both the
continuous- and discrete-time transfer functions for the system of
interest. Here, we pick the simple RC filter as an electrical system to
explain the concepts in the following sections. Besides, we pick the
DC motor as a more advanced electro-mechanical system at the end
of chapter application. We will benefit from the extracted transfer
functions here throughout the book. The reader can also apply the
methods introduced in this chapter to his or her system to
understand its characteristics. Hence, suitable controllers can be
designed for it as will be practiced in the following chapters.
(6.1)
(6.3)
(6.4)
After all data objects are imported, we are ready for system
identification. To do so, drag one dataset to the “Working Data” box
and one dataset to the “Validation Data” box. The dataset selected for
working data is used for identifying the transfer function. To perform
identification, click on the “Estimate ” dropdown menu and select
“Transfer Function Models ” The opening window will be as in
Figure 6.6.
In Figure 6.6, the transfer function can be identified either in
continuous- or discrete-time by selecting the related checkbox. Also,
number of poles and zeros of the transfer function should be entered
to the related boxes before the identification process. For our simple
RC filter, please enter the number of poles as 1, number of zeros as 0,
and select continuous-time transfer function from the related
checkboxes. Finally, click on the “Estimate” button to start the
identification process. As the process finalizes, the created transfer
function object is placed in one of the 12 boxes at the right as data
icon. The obtained transfer function and its properties can also be
seen in the “Data/model Info” window by double-clicking on it as in
Figure 6.7.
After the estimation process finishes, dataset selected for validation
data can be applied to the estimated transfer function. Here, input of
the validation dataset is fed to the transfer function, and output of
this process is compared with output of validation dataset. This
comparison can be also observed on a plot by clicking “Model
output” checkbox. Also residual analysis can be performed by
clicking “Model resids” checkbox.
After identifying the system, its transient response and pole-zero
locations can be observed. To do so, please click on the estimated
transfer function and make it bold. Then, click on “Transient resp” or
“Zeros and Poles” box to obtain the related plots.
Figure 6.7 Data/model info window.
(Source: The MathWorks, Inc.)
For our simple RC filter, the obtained transfer functions and their fit
percentages to validation data (output of random input signal) are
tabulated in Table 6.3. As can be seen in this table, the fit percentage
for all estimations are fairly high. This is because the RC filter is a
first-order system. Moreover, the highest fit percentage is obtained
when the input is selected as random signal as expected. The sum of
sinusoids input signal also has a fairly good fit percentage. Both
transfer functions are close to the one calculated by mathematical
modeling given in Eq. (6.3). The time domain system identification
results obtained by the rectangular and unit-step input signals are
also acceptable.
(6.5)
(6.6)
(6.8)
(6.9)
(6.10)
Substituting Eqs. (6.8) and (6.9) into Eqs. (6.7) and (6.10), we obtain
(6.11)
(6.12)
When Eqs. (6.11) and (6.12) are merged, transfer function of the DC
motor can be obtained as
(6.13)
(6.14)
For our motor, we applied the above procedure and obtained the
parameter values as = 3.2 , = 8.2 mH, = 0.85 Vs/rad,
= 0.85 Nm/A, = 0.016 Nms/rad, and = 0.0059 Nms /rad.
Based on these parameters, we can obtain the transfer function in
Eq. (6.14) as
(6.15)
(6.16)
Figure 6.10 Block diagram of the general setup for the DC motor by
system identification.
We already know that the system to be identified should have two
poles and no zero from mathematical modeling. Hence, the system
identification toolbox under MATLAB is executed for the created
time domain data object to obtain second-order transfer function
with no zero. The obtained transfer function is
(6.17)
where the fit to the validation data is 88% in time domain system
identification. As we compare the transfer function obtained by
mathematical modeling, given in Eq. (6.15), and the transfer function
in Eq. (6.17), we can see that they have similar coefficients. Hence,
system identification in time domain is justified for this case.
We can represent the transfer function in Eq. (6.17) in digital form
using bilinear transformation and obtain
(6.18)
(6.20)
6.5 Summary
Representing a physical system by its transfer function is mandatory
while designing a controller for it. Therefore, this chapter introduced
three methods for extracting the transfer function of a system.
During operation, we assumed an LTI system and acted accordingly.
The first method we considered in the transfer function extraction
operation was based on mathematical modeling. If building blocks of
a physical system and differential equation representing the overall
system is at hand, this method can be used with confidence. Besides,
it does not require any measurements on the system. The second and
third transfer function extraction methods depend on system
identification in time and frequency domains, respectively. These
assume the system to be a black box. They obtain transfer function of
the system based on its input and output signals. The STM32
microcontroller is a perfect candidate for obtaining the input and
output signals from the actual system. We applied all three methods
on the simple RC filter and DC motor throughout the chapter. The
reader can apply the same setup to his or her physical system by
following the procedures given in this chapter. Therefore, the
physical system can be represented by its transfer function. This
leads to digital controller design to be considered in the following
chapters.
Problems
6.1 What is system identification, why is it used, and what are
its types?
6.2 Reconsider the simple RC filter given in Figure 6.1, with
and F,
a. apply system identification in time domain with the
sampling frequency set to 50 Hz and 100 Hz.
b. apply system identification in frequency domain with the
sampling frequency set to 50 and 100 Hz.
c. what has changed in the characteristics of identified
systems?
6.3 Reconsider the simple RC filter given in Figure 6.1, now
with and F,
a. construct transfer function of this new system by
mathematical modeling.
b. pick an appropriate sampling frequency for operation.
Apply system identification in time domain with the
selected sampling frequency.
c. apply system identification in frequency domain with the
selected sampling frequency.
d. compare the obtained results.
7
Transfer Function Based Control System
Analysis
A system has its inherent characteristics. These may not satisfy the
required target performance criteria. We can make sure that these
are satisfied by adding a controller to the system. Hence, we should
first understand what are the possible performance criteria. To do so,
we will introduce methods to analyze the system in time domain,
frequency domain, and complex plane. These three domains are
related. However, they provide valuable information on the same
system from different perspectives. We will next explore open- and
closed-loop controllers as well as their effects on system
performance. Although controller design via transfer functions will
be covered in Chapter 8, we believe the system analysis should be
understood first. Therefore, we will cover fundamental concepts in
control system analysis by transfer functions in this chapter. To be
more specific, we will analyze digital systems constructed by open-
and closed-loop control methods. We will also provide the
corresponding Python functions for analysis methods. We will
provide performance analysis of the actual DC motor as the end of
chapter application.
(7.1)
We can then plot the obtained output signal using the matplotlib
library. The plot will be as in Figure 7.1. As can be seen in this figure,
the response cannot reach the desired output value (as unit step).
Although it is possible to plot the step response of a given system and
analyze the result visually, this is not feasible. Besides, it may not be
possible to set controller design criteria (to be explored in the next
chapter) just by the step response plot. Hence, we should summarize
transient response of the system by some parameters or measures.
Damping ratio, , and natural frequency, , are the first two
candidate parameters for this purpose.
If poles of a second-order system are complex as , then
and can be calculated as
(7.2)
(7.3)
(7.4)
(7.6)
Figure 7.7 Bode plot of the DC motor after applying open-loop
controller to it.
(7.7)
(7.8)
7.4.2 Procedure
In this application, we pick the open-loop control strategy by
selecting the controller transfer function as . We
apply a constant amplitude input to the DC motor as 60 rpm. Then,
we observe speed of the DC motor from its quadrature encoder and
send the observed data to PC in real-time for one second. Next, we
use transfer function of the DC motor obtained in Chapter 6. Hence,
we simulate the system with open-loop controller by applying the
same input signal. Finally, we compare the simulated and actual
output signals as plots and transient response measures.
7.4.3 C Code for the System
We can form a new Mbed Studio project in C language to apply the
open-loop controller to the DC motor. The software setup here will
be the same as in Section 3.4.3.
As we check the system_controller.cpp file, there are two functions
of interest. These are explained briefly as follows: The
controller_tf_init(float *num, float *den, int nbr_num_coeffs,
int nbr_den_coeffs, int select) function is used to create discrete-
time controller and select between open-loop or closed-loop control
by the select input. If select is 0, then open-loop controller is
realized. If select is 1, then closed-loop controller is realized. The
obtain_controller_output(float input, float output, int
cnt_signal) function is used to generate controller output for a given
input, and output if feedback is used.
We should add the function controller_tf_init to the main function
to create and add a controller to the system. For this application, we
set select as 0 since we will apply the open-loop control strategy. We
choose a controller with constant gain 0.0923. This represents the
relation between motor voltage and speed. This value is obtained
from the DC motor datasheet as 12V/130 rpm. Here, the controller
input will be the desired speed value. Hence, it will be entered as
constant amplitude in the terminal interface. The modified main file
will be as in Listing 7.13.
In order to compare the real system output and simulation results,
the reader should run the Python code in Listing 7.14. Then, the user
button on the STM32 board should be pressed. Afterward, the DC
motor starts running and data transfer to PC begins.
In Listing 7.14, we should set get_data_from_MC(NoElements,
com_port, selection) for real-time data transfer for two signals.
Then, the function save_to_file() is used to save the received data to
files. Afterward, we construct digital transfer function of the DC
motor. Then, we obtain time domain performance criteria for both
simulation and actual output data using the function
compare_stepinfo(Real_Time_Output, Transfer_Function,
Step_Gain) .
7.5 Summary
We focused on transfer function-based control systems in this
chapter. We introduced definitions for both open- and closed-loop
control systems based on transfer functions. We also introduced
performance criteria based on transfer functions. As the end of
chapter application, we applied open-loop control strategy to the DC
motor both in Python and C languages. We observed the actual and
simulated system output. This application forms the backbone for all
digital open- and closed-loop controller implementations. Besides,
the setup introduced here is not specific to the DC motor. The reader
can use it to control his or her system. The part to be added here is
the digital controller. We will introduce controller design techniques
based on transfer functions in the next chapter.
Figure 7.12 Actual and simulated output signals obtained from the
DC motor.
Table 7.5 Time domain performance criteria for the DC motor.
Measure Actual Simulation
Rise Time ( ), sec 0.0460 0.0485
Settling Time ( ), sec 0.1010 0.0880
Peak Time ( ), sec 0.4570 0.4345
Overshoot ( ), % 0 0
Undershoot, % 0 0
Settling min. 51.0395 52.2299
Settling max. 57.1000 58.0259
Peak 57.1000 58.0259
Problems
7.1 Consider a system with transfer function
and , sec.
Use Python and MicroPython control systems libraries to
a. find the digital transfer function ( ) of the system
for values 10, 20, and 40.
b. plot unit-step response of the systems obtained in part (a).
c. determine , , , , and of the systems in
part (a). Comment on the results for each value.
7.9 The feedforward transfer function of a unity feedback
closed loop system is
(8.2)
(8.3)
(8.4)
where , , and stand for gain parameters to be set for the
design criteria at hand. To note here, one or two of these gains can be
set to zero to obtain the PI and P controllers, respectively.
The transfer function in Eq. (8.1) can be converted to digital form by
using one of the conversion methods, preferably bilinear
transformation, discussed in Section 5.3. Hence, the PID controller
can be used in digital domain.
We will introduce the PID controller design strategy in this section.
To do so, we will first focus on the P, PI, and PID controllers
separately. Then, we will introduce three parameter tuning methods
for these controllers.
8.2.2.2 PI Controller
Designing the PI controller is the same as in the P controller. We can
obtain the controller gain parameters using the Python code in
Listing 8.5 for this purpose. Here, we use the Ziegler–Nichols
method to obtain the and parameters of the controller. Then,
we form the controller in continuous-time and convert it to digital
form using bilinear transformation.
Figure 8.5 Bode plot of the DC motor after applying the P controller
to it. (a) Magnitude plot. (b) Phase plot.
(8.5)
(8.6)
(8.8)
To note here, the reader can obtain a different controller from the
CSD tool when a different point is selected in the interactive plot.
Therefore, the lag controller in Eq. (8.8) is not unique.
We can implement the designed lag controller in Eq. (8.8) in Python.
Afterward, we can obtain unit-step response of the closed-loop
system using the Python code in Listing 8.2. To do so, we should
modify the transfer function of the controller as num2 = [0.6514,
-0.6514*0.9950] and den2 = [1, -1] . We plot the obtained response
in Figure 8.18. We can have some key observations from this figure.
However, the better way is tabulating the system performance
criteria in time domain. To do so, we should modify the Python code
in Listing 8.3 by replacing num2 = [0.6514, -0.6514*0.9950] and
den2 = [1, -1] . We will analyze the time domain performance
criteria in a comparative way in Section 8.4.2.4.
(8.9)
To note here, the reader can obtain a different controller from the
CSD tool when a different point is selected in the interactive plot.
Therefore, the lead controller in Eq. (8.9) is not unique.
We can implement the designed lead controller in Eq. (8.9) in
Python. Afterward, we can obtain unit-step response of the closed-
loop system using the Python code in Listing 8.2. To do so, we should
modify transfer function of the controller as num2 = [2.6613,
-2.6613*0.9] and den2 = [1, -0.7339] . We plot the unit step
response in Figure 8.19. By updating the Python code in Listing 8.3
as num2 = [2.6613, -2.6613*0.9] and den2 = [1, -0.7339] , we can
obtain the time domain performance criteria for the closed-loop
system formed by the lead controller. We will analyze these in a
comparative way in Section 8.4.2.4.
Figure 8.19 Unit step response of the closed-loop system formed by
the lead controller designed in MATLAB.
We can also analyze the closed-loop system formed by the lead
controller in frequency domain. To do so, we should modify the
transfer function of the controller in Listing 8.4 as num2 = [2.6613,
-2.6613*0.9] and den2 = [1, -0.7339] . As we obtain the frequency
domain performance criteria, we will analyze the effect of the lag
controller in frequency domain in a comparative way in Section
8.4.2.4.
(8.11)
To note here, the reader can obtain a different controller from the
CSD tool when a different point is selected in the interactive plot.
Therefore, the lag controller in Eq. (8.11) is not unique.
We can implement the designed lag controller in Eq. (8.11) in
Python. Afterward, we can analyze the closed-loop system formed by
this controller in frequency domain. To do so, we should modify
transfer function of the controller in Listing 8.4 as num2 = [0.4352,
-0.4352*0.9909] and den2 = [1, -0.996] . As we execute this code,
we obtain Bode plot of the system both in magnitude and phase
terms for 1000 elements as in Figures 8.22(a) and 8.22(b),
respectively.
Although Figure 8.22 is helpful in understanding the effect of the lag
controller on the DC motor, it is better to obtain frequency domain
performance criteria to quantify this effect. Therefore, we can add
the function margin() to the Python code in Listing 8.4. As we obtain
the frequency domain performance criteria, we will analyze the effect
of the lag controller in frequency domain in a comparative way in
Section 8.4.3.4.
(8.12)
To note here, the reader can obtain a different controller from the
CSD tool when a different point is selected in the interactive plot.
Therefore, the lead controller in Eq. (8.12) is not unique.
In order to analyze the effect of the designed lead controller in the
closed-loop system, we should modify the transfer function of the
controller in Listing 8.4 as num2 = [3.1574, -3.1574*0.8668] and
den2 = [1, -0.5793] . As we execute this code, we obtain Bode plot
of the system both in magnitude and phase terms for 1000 elements
as in Figures 8.23(a) and 8.23(b), respectively. We will also analyze
the effect of lead controller in frequency domain in a comparative
way in Section 8.4.3.4.
8.6 Summary
This chapter focused on digital controller design methods based on
transfer functions. Therefore, we first considered the PID controller
and its design methodology. We provided functions in the
MicroPython control systems library to design and construct the P,
PI, or PID controller for a given system. We applied these controllers
to the DC motor and compared the resultant systems in terms of
their time and frequency domain performance criteria. We followed
the same strategy to the lag, lead, and lag–lead controller design.
However, we used the CSD tool under MATLAB for this purpose. As
the end of chapter application, we applied the designed PI and PID
controllers to the DC motor via the STM32 microcontroller and
observed their working principles. The reader can benefit from the
methods introduced in this chapter to design and implement transfer
function based controllers to the system at hand.
Problems
8.1 Consider the DC motor with transfer function
a. design P, PI, and PID controllers for the DC motor using the
Cohen–Coon method. Form a separate closed-loop system
for each controller separately.
b. Plot the unit step response for the closed-loop systems.
c. Compare the closed-loop systems in terms of time domain
performance criteria.
d. Obtain Bode plots for the closed-loop systems.
e. Compare the closed-loop systems in terms of frequency
domain performance criteria.
8.2 Repeat Problem 8.1 now using the Chien–Hrones–Reswick
method in the controller design.
8.3 Consider the DC motor in Problem 8.1,
a. Convert it to digital form by the bilinear transformation
method.
b. Design lag, lead, and lag–lead controllers (in closed-loop
form) for the digital system in time domain that improves
by at least 50% and by at least 10%.
c. Plot unit step response for the closed-loop systems formed
by the designed controllers.
d. Compare the closed-loop systems formed by the designed
controllers in terms of time domain performance criteria.
e. Obtain Bode plots for the closed-loop systems formed by
the designed controllers.
f. Compare closed-loop systems formed by the designed
controllers in terms of frequency domain performance
criteria.
8.4 Consider the DC motor in Problem 8.1,
a. Convert it to digital form by the bilinear transformation
method.
b. Design lag, lead, and lag–lead controllers (in closed-loop
form) for the digital system in frequency domain such that
the overall system has GM 40 dB.
c. Plot the unit step response for the closed-loop systems
formed by the designed controllers.
d. Compare the closed-loop systems formed by the designed
controllers in terms of time domain performance criteria.
e. Obtain Bode plots for the closed-loop systems formed by
the designed controllers.
f. Compare the closed-loop systems formed by the designed
controllers in terms of frequency domain performance
criteria.
9
State-space Based Control System Analysis
State-space provides another option to analyze and design digital
controllers besides transfer function based methods. Therefore, we
will explore the state-space approach in detail here. To do so, we will
start with the definition of state and emphasize its difference from
the transfer function approach. Then, we will show how state-space
representation of an LTI system can be constructed from its
differential or difference equation in continuous- and discrete-time,
respectively. We know that differential equations lead to transfer
function representation in continuous-time from Chapter 6.
Likewise, difference equations lead to transfer function
representation in discrete-time as mentioned in Chapter 4. Hence,
we will cover methods on converting state-space and transfer
function representations. Finally, we will look at properties of a
system from its state-space representation. While performing all
these, we will benefit from MicroPython and Python control systems
libraries. As the end of chapter application, we will simulate state-
space representation of the DC motor.
(9.1)
(9.2)
where .
We can represent these equations in matrix form, Ogata (2009), as
(9.3)
(9.4)
(9.5)
(9.7)
where is the dimensional state vector, is the input
signal, and is the output signal. , , , and are the
state (system), input, output, and feedforward matrices, respectively.
For completeness, we can represent these matrices as
(9.8)
(9.9)
where,
(9.10)
(9.11)
(9.12)
(9.13)
As a result, we obtain the discrete-time state-space representation
starting from continuous-time differential equation. We can follow a
more straightforward methodology as well. To do so, we will consider
conversion between state-space and transfer function
representations in Section 9.3.
(9.14)
(9.15)
(9.16)
(9.17)
(9.18)
(9.19)
(9.20)
(9.21)
where is the initial state of the system. To note here, initial
states are assumed to be zero to find the transfer function of a
system. The system transfer function is the ratio of output, , to
input, as mentioned in Section 4.5. Therefore, transfer
function of the system represented by its state-space equations
becomes
(9.22)
We can also use the Python control systems library to find transfer
function of the system if its state-space equations are known. To do
so, we can use the function ss2tf() within the library. Let us take
state-space representation of the DC motor given in Eqs. (9.14) and
(9.15). We can use the Python code given in Listing 9.4 to obtain
transfer function of the DC motor.
As we execute the Python code Listing 9.4, we obtain transfer
function of the DC motor as
(9.23)
9.4.2 Stability
We can check stability of a system from its state-space
representation using two different methods. We can use the pole()
function within the Python control systems library as the first and
straightforward method. Then, we can check whether any system
pole is outside the unit-circle or not.
Let us take the state-space representation of the DC motor obtained
from its continuous-time transfer function in Listing 9.2. We can
extend this code to obtain poles of the system directly from its state-
space representation. To do so, we form the extended Python code as
in Listing 9.6.
As we execute the Python code Listing 9.6, we obtain poles of the DC
motor as 0.9775 and 0.8417. These values are the same as in Chapter
6. Besides, they are in the unit circle. Hence, we can deduce that the
DC motor is stable.
As the second method, we can benefit from the state matrix . Poles
of the system can be obtained using the equation (for
, no direct feedforward path). Hence, roots of this equation
are in fact eigenvalues of the matrix . We can use the numpy library
under Python for this purpose.
Let us take state-space representation of the DC motor obtained
from its continuous-time transfer function in Listing 9.2. We can
extend this code to obtain poles of the system directly from its state-
space representation. To do so, we form the extended Python code as
in Listing 9.7. As we execute the code, we obtain the eigenvalues as
0.9775 and 0.8417. These are the actual poles of the system. Besides,
they are within the unit circle. Again, we can deduce that the DC
motor is stable.
9.4.3 Controllability
A discrete-time system is said to be completely controllable if an
input sequence can be determined that will take the system to
any desired state in finite number of time steps. Here, we
assume that the system model and its state are known at the
specific time step . Controllability is checked by looking at rank of
the matrix . If the rank of this
matrix is not equal to zero, then the system is controllable.
We can benefit from the Python control systems library to check
controllability using state-space equations of the system. To do so,
we can use the function ctrb() within the library to find the
controllability matrix. The controllability property of the DC motor
can be checked using the Python code given in Listing 9.8 on PC. As
we execute this code, we obtain the controllability matrix and its
rank. Since rank of the controllability matrix is two, we can deduce
that the DC motor is controllable.
9.4.4 Observability
A discrete-time system is said to be completely observable if its state
at any specific step can be determined from the system
model, input, and output values for a finite number of steps.
Observability refers to the ability to estimate a state variable.
Observability is checked by looking at the rank of the matrix
. If the rank of this matrix is not
equal to zero, then the system is observable.
We can benefit from the Python control systems library to find the
observability using state-space equations of the system. To do so, we
can use the function obsv() within the library to find the
observability matrix. The observability property of the DC motor can
be checked using the Python code given in Listing 9.9 on PC. As we
execute this code, we obtain the observability matrix and its rank.
Since rank of the observability matrix is two, we can deduce that the
DC motor is observable.
The controllability and observability concepts are introduced by
Kalman (1960, 1963). They will be useful when designing state
feedback controller and state estimator to be explained in state-space
method based controller design in Chapter 10. There, we will see that
if the system is controllable and observable, then we can accomplish
the design objective of placing the poles precisely at desired locations
to meet performance criteria (such as less and ).
We can also relate controllability and observability with the transfer
function of a system. If transfer function of the system does not have
pole-zero cancellation (some poles and zeros of the transfer function
are same and they are cancelled), then the system can be represented
in controllable and observable forms. If transfer function of the
system has pole-zero cancellation, then the system will be either
uncontrollable or unobservable.
9.5.2 Procedure
We will use state-space representation of the DC motor introduced in
Section 9.3.1 within this application. Afterward, a step input with 8 V
amplitude and 500 elements will be applied to the system and
simulation results will be obtained. We will transfer state values in
time and output of the system to PC as we did in Section 4.6. As the
final part of the application, we will plot the obtained results on PC
via Python.
9.6 Summary
We focused on discrete system analysis by state-space representation
in this chapter. To do so, we started with the definition of state and
how it can be represented in code form. Afterward, we explored how
transfer function of an LTI system can be represented in state-space
form. We also considered how a state-space representation can be
transformed to transfer function form. We also explored system
properties based on its state-space representation. We finally
provided an end of chapter application based on C and Python.
Although this application is a simulation running on the STM32
microcontroller, it forms the setup for the state-space system control
to be introduced in the next chapter.
Problems
9.1 Consider a system represented by
(9.24)
(9.25)
(9.26)
(9.27)
(10.2)
(10.3)
We can take the -transform of Eqs. (10.2) and (10.3) and form the
denominator polynomial of the (closed-loop) system as
. We know that poles of the closed-loop system
are determined by the roots of this equation. Assume that, we want
to set the roots of the equation as . The pole placement
method determines the state feedback (regulator) gain based on
these values. To do so, the straightforward method is using
Ackermann's formula, to be explored next.
(10.5)
(10.6)
where
(10.7)
(10.9)
(10.10)
(10.11)
(10.13)
(10.14)
where is the observer gain matrix that is determined as part of the
observer design procedure. The state estimator error is
defined as
(10.15)
As can be seen in Eq. (10.15), the state observer error equation has
the same structure with the one we obtained in the regulator design.
Hence, the error dynamics are obtained from .
The main idea here is to make the state estimates, , to converge
to the actual state values, . To do so, we can follow the pole
placement method to obtain . As in the regulator design, we should
define desired poles of the observer such that the observation
operation is performed as expected. Ackermann's formula can be
used in the observer design as well.
10.4.2 Ackermann's Formula for the Observer Gain
Assume that the solution of is the set
. Hence, we can write
. It is possible to place the poles of
the observer anywhere as long as the system is observable through
the output by selecting . Then, Ackermann's formula for the
observer gain matrix becomes
(10.16)
Using the calculated value in Eq. (10.13), we can estimate the state
values for the LTI system at hand. This leads to the regulator and
controller design based on the observed state values. We will
introduce these next in code form.
10.6.2 Procedure
Here, we control the DC motor using observer-based state-space
controller. We will use the and matrices obtained in Listing
10.8 for this purpose. We apply a constant amplitude input with
60 rpm to the DC motor. Then, we obtain the output and estimate of
the first state variable. We send these to PC in real-time for one
second. Afterward, we use the discrete-time state-space equations of
the DC motor obtained in Chapter 9. We simulate the system using
these equations with the same input signal. Finally, we compare the
actual system and simulation results.
Problems
10.1 Consider the DC motor with transfer function
(10.17)
(10.18)
(11.2)
(11.3)
(11.4)
(11.5)
where
(11.6)
(11.7)
(11.8)
where
There are two functions in the MicroPython control systems library
for parameter estimation via RLS. The first function RLS_Sim(x, y,
Nnum, Nden, Ts, gp) provides the estimated parameters as well as
their evolution in time. We should provide a known input signal and
output obtained from it in array form as x and y . We should also feed
the order of numerator and denominator polynomials to the function
as Nnum and Nden , respectively. Finally, we should enter the sampling
period Ts and gain value gp to the function. This gain value is used as
a multiplier for the matrix just for the first step in iteration. There
is also the real-time version of the parameter estimation method by
RLS in C language. We will introduce it in Section 11.5. While
forming these functions, we are inspired by the MATLAB code by
Attya at
https://www.mathworks.com/matlabcentral/fileexchange/58121-
recursive-least-square. Besides the RLS method, Attya also provides
other adaptive control algorithms originated from the book by
Åström and Wittenmark (2013). Therefore, we strongly suggest the
reader to visit the mentioned web site.
The function RLS_Sim returns a class keeping all necessary
information on system parameters as the estimation runs. Let us
show how the function works on the DC motor with the next
example.
As we compare Eqs. (6.18) and (11.9), we can see that the RLS
method estimated the actual numerator and denominator
coefficients fairly well. We can observe the iterative convergence of
these parameters to their final value. To do so, we should use the
command rls_simulation.num[ ] and rls_simulation.den[ ] . We
picked the coefficients and in Listing 11.1 for demonstration
purposes. We plot the evolution of these two parameters in time in
Figure 11.2. As can be seen in this figure, the two parameters
converge to their final and true value fairly fast.
(11.11)
(11.12)
(11.13)
(11.14)
(11.15)
(11.16)
(11.17)
(11.18)
where is the gain parameter for iteration, is the sampling
period. is the difference between the actual output and
reference model output. is the reference model output.
MicroPython control systems library has the function MRAC_Sim(x,
ym, g, Ts, gamma) which provides the gain parameter in Figure
11.6 and its evolution in time. We should provide a known input
signal and output obtained from the reference model in array form as
x and ym to the function. We should also feed the actual system model
as g . Finally, we should enter the sampling period Ts and gain value
gamma to the function. We explain working principles of the function
MRAC_Sim on the DC motor by an example next.
We can use the Python code in Listing 11.4, to obtain the value
for the DC motor via MRAC setup in Figure 11.6. Here, we set
and ask the adjustment mechanism in MRAC to
adjust to reach the final value 0.5.
11.6 Summary
This chapter focused on adaptive control schemes. We started with
parameter estimation with RLS method. Then, we introduced ISTR
and MRAC methods as indirect and direct controller design
strategies. Finally, we applied the RLS method on estimating the
parameters of the DC motor in real-time as the end of chapter
application. Since we are using microcontrollers in implementation,
adaptive control methods can be implemented on them easily.
Therefore, the reader can benefit from them in solving real-life
problems.
Problems
11.1 Consider the simple RC filter with transfer function
(11.19)
(12.2)
(12.3)
We can use this gain value in the regulator structure given in Section
10.1.2. Hence, the LQR is formed.
12.4.2 Procedure
The first step in the application is to set up the HC-05 module via
UART communication. To do so, we should use the FT232 module.
Initially, we should connect the RXD, TXD, GND, and VCC pins of
HC-05 to TX, RX, GND, and VCC pins of FT232, in the same order.
Then, we should connect the FT232 module to PC and open a
terminal program (such as Tera Term). Baud rate in the terminal
program should be set as 9600 bps since this is the default value for
the HC-05 module. Afterward, we should use AT commands on the
terminal for setting up the module. For more information on AT
commands, please see Ünsalan et al. (2017).
In order to setup the HC-05 module, let's start with entering the first
command AT through the terminal program. If the hardware is set
correctly, the module should return OK to the terminal. Next, we
should assign a name to the HC-05 module. This will allow us to
reach it from smart phone. To do so, the command
AT+NAME=DesiredName should be entered through the terminal. The
HC-05 module should return OK . Finally, we should set the baud rate
for UART communication. Therefore, we should use the command
AT+UART=921600,0,0 on the terminal. This command has the setup
such that 921600 stands for the baud rate, first 0 represents the stop
bit, and second 0 represents the parity bit in UART communication.
Again, the HC-05 module should return OK to the terminal.
Afterward, the HC-05 module will be ready to be used. To note here,
the HC-05 module will have its baud rate set as 921600 bps from this
point on. This value should be used for all UART communication
operations between the module and another device. The reader can
reach more information on this module and other wireless
communication modules from our book (Ünsalan et al. 2017).
The next step in the procedure is to form the application on smart
phone. The application should be set up such that it should locate
nearby bluetooth devices. It should allow connecting to a selected
device. As the connection is established, speed of the DC motor
should be modified, between 0 and maximum allowed value, by a
slider in the application. There should also be another button to
change rotation direction of the motor. Finally, there should be a
window in the application continuously displaying speed of the DC
motor. To note here, the speed value will be read from encoder of the
motor and transmitted back to smart phone from the STM32 board.
There should also be a button in the application to stop bluetooth
connection.
We should have all necessary software running on the STM32
microcontroller to control the DC motor. Here, we suggest forming a
closed-loop controller to set speed of the microcontroller. All these
mentioned steps provide insight on the basics of distributed control.
Moreover, the methodology introduced in this application can be
used to form more complex distributed control applications such as
connecting more than one controller or system via bluetooth
communication.
12.5.2 Procedure
The first step in the procedure of the application is to calibrate the
overall system. Hence, we will set the minimum and maximum
ambient light levels to turn on and off the LED. Within these two
levels, LED brightness will change linearly based on measured
voltage from the LDR. This way, we form an open-loop controller
with gain parameter (or a proportional controller). In fact, the
formed system can also be taken as nonlinear since we set minimum
and maximum voltage levels in operation. Finally, we can replace the
LED with an adjustable light bulb to implement a more general
dimmer.
Figure 12.7 Hardware setup for the servo motor from DC motor
application using potentiometer feedback.
12.6.2 Procedure
In the first part of the application, resistance of the potentiometer for
0 and 180 is obtained. Resistance of the potentiometer changes
linearly with its rotation angle. Hence, it becomes possible to obtain
angle of the motor shaft from resistance of the attached
potentiometer. To do so, we should form a voltage divider circuit by
the potentiometer and read the voltage from the ADC module of the
STM32 microcontroller. This voltage value can be used as the
feedback signal to form a closed-loop control action. Since the overall
system is formed by the DC motor and potentiometer, we can form
the transfer function between the required angle (as reference signal)
and motor rotation angle (as output signal). This way, the reader can
design a controller for this setup.
In the second part of the application, we should know how to get
feedback signal from the accelerometer attached to shaft of the DC
motor. To do so, we will use the and axis of the accelerometer.
Assume that the accelerometer attached to the motor shaft is parallel
to ground. For this case, the accelerometer will give (gravity) and
0 values from its and axis, respectively. As we rotate the
accelerometer through 90 with the motor shaft, the value read from
the axis will be close to 0. Meanwhile, the value read from the
axis will approach . At exactly 90 , these values will be 0 and ,
respectively. From 90 to 180 , the axis values will approach .
Meanwhile, the axis value will approach 0. At exactly 180 , these
values will be and 0, respectively. By looking at the sign of the
axis data, we can decide whether the motor rotation angle is between
0 and 90 or 90 and 180 . Then, we can use axis data to
calculate the actual angle. Based on these and required rotation
angle, we can form an closed-loop controller. Hence, we can rotate
the DC motor based on the reference input and feedback signal from
the accelerometer.
Figure 12.8 Hardware setup for the servo motor from DC motor
application using accelerometer feedback.
12.7.2 Procedure
A green ball is moved within camera's point of view in the
application. First, we acquire image from the camera and locate the
ball by simple image processing techniques. Then, we rotate the DC
motor accordingly. If the ball is at the center of the image, then we
set the DC motor rotation angle to 0 . If the ball is at the leftmost or
rightmost location, then the rotation angle becomes and 90 ,
respectively. For the ball location between these two values, we set
the rotation angle linearly. In order to measure rotation angle of the
motor, we use the ADXL-345 accelerometer as in the servomotor
application.
Figure 12.9 Hardware setup for the visual servoing application.
12.10.2 Procedure
General setup for ANC is given in Figure 12.13. As can be seen here,
the noise term is obtained by a sensor. The ANC actuator is used to
generate the signal to eliminate unwanted noise. The error sensor
forms a feedback loop to control whether the noise is eliminated or
not. Noise cancellation operation is performed in the ANC algorithm
module. In this application, we will use the most popular method in
literature called LMS within the module.
Block diagram of the ANC operation by the LMS algorithm is as in
Figure 12.14. Here, represents the original signal not affected by
noise. We will generate this signal from the signal generator.
represents the noise detected by the sensor. We will generate this
signal by the STM32 board. represents the actual noise term
affecting the original signal. Therefore, we will cancel this noise
signal. This signal will be generated within the STM32 board by
filtering with the filter . In other words, the filter
represents the path affecting the noise from its source to reaching the
original signal. In this application, we will represent it by an FIR
filter. In Figure 12.14, is the adaptive FIR filter which will
generate the noise cancellation signal. Coefficients of this filter will
be obtained by the LMS algorithm. represents the original
signal with noise added on it. Finally, is the feedback signal to
be sent to the LMS algorithm. This signal is obtained by the
difference of signals and .
Figure 12.13 General representation of the ANC system.
12.11.2 Procedure
As can be seen in Figures 12.15 and 12.16, there are two LDRs in the
system. These should be placed on far ends of the solar panel. Hence,
the light intensity received by these two LDRs can guide the system.
When the sun is on top, we expect the two LDRs receive the same
light intensity. If one LDR receives more light compared to the other,
this means that the solar panel is not directly looking at the sun.
Therefore, it should be rotated to have the same reading from two
LDRs. This way, it is assured that the panel gets the maximum
sunlight. When the stepper motor is used, the rotation angle to be
moved to is converted to the corresponding step number. Then, the
open-loop control action moves the panel to that angle. For the DC
motor case, angle of the motor is measured by the ADXL-345
accelerometer attached to shaft of the motor. This way, we can form
a feedback loop such that the motor rotating the solar panel
performs the closed-loop control action.
Figure 12.15 Hardware setup for the sun tracking solar panel
application using stepper motor.
12.12 System Identification of a Speaker
This application aims to obtain transfer function of a speaker. To do
so, we will use the system identification tools introduced in Chapter
6.
12.12.2 Procedure
When a voltage is applied across terminals of the speaker the cone
inside the speaker moves in and out causing pressure waves
perceived as sound. There are two parts inside the speaker as
mechanical and electrical. These are shown in Figure 12.18.
As can be seen in Figure 12.18, the speaker consists of a fixed magnet
that produces uniform magnetic field of strength (the power
factor). The speaker has a cone with mass ( ) that moves in
direction. The cone can be modeled by a spring ( ) and friction (
) element. There is a coil of wire with radius within the
magnetic field and it is attached to the cone. The wire has resistance
( ) and inductance ( ). The coil consists of turns and it moves
along with the cone. A force is generated that moves the cone when
current passes through the coil. Back emf voltage is also generated in
the coil when the cone moves. and are the back emf and
input voltages, respectively. Speed and displacement of the cone is
represented as and , respectively. Based on these definitions,
transfer function of the speaker between the input, , and
output, is obtained by Palm (2013) as
Figure 12.17 Hardware setup for the system identification of a
speaker application.
12.13.2 Procedure
In this application, we will use the peltier and the temperature
sensor to cool down the water in a metal container to a desired level.
The DS18B20 temperature sensor forms the feedback signal. We will
use this signal and a PI controller to construct a closed-loop
controller for the peltier module. The reader should apply a step
signal and store temperature values till the peltier temperature
stabilizes. Then, these values should be used in the system
identification framework introduced in Chapter 6 to form the
transfer function of the peltier. Here, a first-order system will be
sufficient to model the peltier. Then, the obtained transfer function
can be used to design the PI controller in the closed-loop operation.
12.14 Controlling a Permanent Magnet
Synchronous Motor
The permanent magnet synchronous motor (PMSM) has the
characteristics of both brushless DC and induction motors. It has a
permanent magnet rotor as in the brushless DC motor and stator
structure generating sinusoidal back emf as in the induction motor.
The PMSM needs full torque control at zero speed, instant speeding
and stopping, and smooth rotation at high speed. To achieve these
goals, field-oriented control (FOC) is used. This method can be
explained in simple terms as dividing the stator current into two
parts as magnetic field and torque producing. Then, these parts can
be controlled separately.
ST Microelectronics has a firmware called X-CUBE-MCSDK to
control PMSM. This firmware consists of the STM32 motor control
workbench program and FOC library. The reader can download this
firmware from https://www.st.com/en/embedded-software/x-cube-
mcsdk.html.
12.14.2 Procedure
As we start the STM32 motor control workbench program, its main
window will be as in Figure 12.21. The FOC library needs model of
the PMSM to generate necessary control parameters. To do so, we
will need the motor profiler program which can be reached from the
top right of the main window.
The opened motor profiler window will be as in Figure 12.22. Here,
we should first select the development board and motor driver pair
to be used through the “Select Boards” section. Then, we should
press “Connect” to connect the boards to the motor profiler.
Afterward, we should enter the PMSM pole pair number, maximum
speed, maximum current, and applied voltage to “Pole Pairs,” “Max
Speed,” “Max Current,” and “VBus” boxes, respectively. Finally, we
should select the PMSM type as either “SM-PMSM” or “I-PMSM.”
Afterward, we can start the PMSM modeling operation by pressing
“Start Profile.” The motor profiler applies different input signals to
the PMSM and identifies its parameters. As the modeling finalizes,
we should save the result by pressing on “Save” and exit the motor
profiler window.
Next, we should open a new project under STM32 motor control
workbench by pressing on “New Project.” A new window should
open up as in Figure 12.23. Here, we should select the development
board from the “Control” drop-down menu; motor driver from the
“Power” menu; and saved motor model from the “Motor” menu.
Figure 12.21 STM32 motor control workbench program, main
window.
(Source: STMicroelectronics.)
Figure 12.22 Motor profiler window.
(Source: STMicroelectronics.)
Figure 12.23 New project window.
(Source: STMicroelectronics.)
Table A.3 Pin usage table for the STM32 board, connector CN8-left.
Pin Port name Usage area
1 NC –
2 IOREF I/O reference
3 RESET External reset
4 +3V3 3.3 V input/output
5 +5V 5 V output
6 GND Ground voltage
7 GND Ground voltage
8 VIN External 7–12 V input
Table A.4 Pin usage table for the STM32 board, connector CN8-
right.
Pin Port name Usage area
1 PC8 Digital I/O, Interrupt, Timer, UART
2 PC9 Digital I/O, Interrupt, Timer, UART, I2C
3 PC10 Digital I/O, Interrupt, UART, SPI
4 PC11 Digital I/O, Interrupt, UART, SPI
5 PC12 Digital I/O, Interrupt, UART, SPI
6 PD2 Digital I/O, Interrupt, Timer, UART
7 PG2 Digital I/O, Interrupt
8 PG3 Digital I/O, Interrupt
Table A.5 Pin usage table for the STM32 board, connector CN9-left.
Pin Port name Usage area
1 PA3 Digital I/O, Interrupt, Timer, UART, ADC
2 PC0 Digital I/O, Interrupt, ADC
3 PC3 Digital I/O, Interrupt, SPI, ADC
4 PF3 Digital I/O, Interrupt, ADC
5 PF5 Digital I/O, Interrupt, ADC
6 PF10 Digital I/O, Interrupt, ADC
7 NC —
8 PA7 Digital I/O, Interrupt, Timer, SPI, ADC
9 PF2 Digital I/O, Interrupt, I2C
10 PH1 Digital I/O, Interrupt
11 PH0 Digital I/O, Interrupt
12 GND Ground voltage
13 PD0 Digital I/O, Interrupt, UART
14 PD1 Digital I/O, Interrupt, UART
15 PG0 Digital I/O, Interrupt
Table A.6 Pin usage table for the STM32 board, connector CN9-
right.
Pin Port name Usage area
1 PD7 Digital I/O, Interrupt, UART, SPI
2 PD6 Digital I/O, Interrupt, UART
3 PD5 Digital I/O, Interrupt, UART
4 PD4 Digital I/O, Interrupt, UART, SPI
5 PD3 Digital I/O, Interrupt, UART, SPI
6 GND Ground voltage
7 PE2 Digital I/O, Interrupt, SPI
8 PE4 Digital I/O, Interrupt, SPI
9 PE5 Digital I/O, Interrupt, Timer, SPI
10 PE6 Digital I/O, Interrupt, Timer, SPI
11 PE3 Digital I/O, Interrupt
12 PF8 Digital I/O, Interrupt, Timer, UART, SPI
13 PF7 Digital I/O, Interrupt, Timer, UART, SPI
14 PF9 Digital I/O, Interrupt, Timer, UART, SPI
15 PG1 Digital I/O, Interrupt
Table A.7 Pin usage table for the STM32 board, connector CN10-
left.
Pin Port name Usage area
1 AVDD External analog voltage/voltage reference pin
2 AGND Analog ground voltage
3 GND Ground voltage
4 PB1 Digital I/O, Interrupt, Timer, ADC
5 PC2 Digital I/O, Interrupt, SPI, ADC
6 PF4 Digital I/O, Interrupt, ADC
7 PB6 Digital I/O, Interrupt, Timer, UART, I2C
8 PB2 Digital I/O, Interrupt, SPI
9 GND Ground voltage
10 PD13 Digital I/O, Interrupt, Timer, UART, I2C
11 PD12 Digital I/O, Interrupt, Timer, UART, I2C
12 PD11 Digital I/O, Interrupt, UART, I2C
13 PE2 Digital I/O, Interrupt, SPI
14 GND Ground voltage
15 PA0 Digital I/O, Interrupt, Timer, UART, ADC
16 PB0 Digital I/O, Interrupt, Timer, UART, ADC
17 PE0 Digital I/O, Interrupt, Timer, UART
Table A.8 Pin usage table for the STM32 board, connector CN10-
right.
Pin Port name Usage area
1 PF13 Digital I/O, Interrupt, I2C
2 PE9 Digital I/O, Interrupt, Timer, UART
3 PE11 Digital I/O, Interrupt, Timer, UART, SPI
4 PF14 Digital I/O, Interrupt, I2C
5 PE13 Digital I/O, Interrupt, Timer, SPI
6 PF15 Digital I/O, Interrupt, I2C
7 PG14 Digital I/O, Interrupt, Timer, UART, SPI
8 PG9 Digital I/O, Interrupt, UART, SPI
9 PE8 Digital I/O, Interrupt, Timer, UART
10 PE7 Digital I/O, Interrupt, Timer, UART
11 GND Ground voltage
12 PE10 Digital I/O, Interrupt, Timer, UART
13 PE12 Digital I/O, Interrupt, Timer, SPI
14 PE14 Digital I/O, Interrupt, Timer, SPI
15 PE15 Digital I/O, Interrupt, Timer
16 PB10 Digital I/O, Interrupt, Timer, UART, SPI, I2C
17 PB11 Digital I/O, Interrupt, Timer, UART, I2C
Bibliography
Åström, J.K. and Murray, R.M. (2008). Feedback Systems: An
Introduction for Scientists and Engineers. Princeton University
Press.
Åström, J.K. and Wittenmark, B. (2013). Adaptive Control, 2e.
Dover Publications.
Bertsekas, D.P. (2012). Dynamic Programming and Optimal
Control, vol. 1, 4e. Athena Scientific.
Braunl, T. (2006). Embedded Robotics Mobile Robot Design and
Applications with Embedded Systems, 2e. Springer-Verlag.
Burns, R.S. (2001). Advanced Control Engineering. Butterworth-
Heinemann.
Chen, C.T. (2006). Analog and Digital Control System Design:
Transfer-Function, State-Space and Algebraic Methods. Oxford
University Press.
Chien, K.L., Hrones, J.A., and Reswick, J.B. (1952). On the automatic
control of generalized passive systems. Transactions of the ASME
74: 175–185.
Cohen, G.H. and Coon, G.A. (1953). Theoretical consideration of
retarded control. Transactions of the ASME 75: 827–834.
Corke, P. (2017). Robotics, Vision and Control Fundamental
Algorithms in MATLAB, 2e. Springer.
Dorf, R.C. and Bishop, R.H. (2010). Modern Control Systems, 12e.
Prentice Hall.
Fliess, M., Levine, J., Martin, P., and Rouchon, P. (1992). On
differentially flat nonlinear systems. IFAC Proceedings Volumes
25: 159–163.
Forrai, A. (2013). Embedded Control System Design A Model Based
Approach. Springer.
Franklin, G.F., Powell, J.D., and Workman, M.L. (2006). Digital
Control of Dynamic Systems, 3e. Ellis-Kagle Press.
Ghosh, S. (2004). Control Systems: Theory and Applications.
Pearson.
Golnaraghi, F. and Kuo, B.C. (2010). Automatic Control Systems, 9e.
Wiley.
Goodwin, G.C., Graebe, S.F., and Salgado, M.E. (2000). Control
System Design. Pearson.
Gopal, M. (2003). Digital Control and State Variable Methods:
Conventional and Neuro-Fuzzy Control Systems, 2e. McGraw-
Hill.
Hristu-Varsakelis, D. and Levine, W.S. (2005). Handbook of
Networked and Embedded Control Systems. Birkhauser.
Ibrahim, D. (2006). Microcontroller Based Applied Digital Control.
Wiley.
Jordan, D.W. and Smith, P. (2007). Nonlinear Ordinary Differential
Equations, 4e. Oxford University Press.
Kalman, R.E. (1960). A new approach to linear filtering and
prediction problems. Journal of Basic Engineering 82 (1): 35–45.
Kalman, R.E. (1963). Mathematical description of linear dynamical
systems. Journal of the Society for Industrial and Applied
Mathematics, Series A: Control 1 (2): 152–192.
Kuo, S.M. and Morgan, D.R. (1996). Active Noise Control Systems:
Algorithms and DSP Implementations. Wiley-Interscience.
Ledin, J. (2004). Embedded Control Systems in C/C++: An
Introduction for Software Developers Using MATLAB. CMP
Books.
Leith, D.J. and Leithead, W.E. (2010). Survey of gain-scheduling
analysis and design. International Journal of Control 73: 1001–
1025.
Ljung, L. (1999). System Identification: Theory for the User, 2e.
Prentice Hall.
Mandal, A.K. (2010). Introduction to Control Engineering:
Modeling, Analysis and Design, 2e. New Age International Pvt.
Ltd.
Moudgalya, K.M. (2008). Digital Control. Wiley.
Ogata, K. (1995). Discrete-Time Control Systems, 2e. Pearson.
Ogata, K. (2009). Modern Control Engineering, 5e. Pearson.
Oppenheim, A.W. and Schafer, R.W. (2009). Discrete-Time Signal
Processing, 3e. Prentice Hall.
Oppenheim, A.W., Willsky, A.S., and Nawab, S.H. (1997). Signals
and Systems, 2e. Prentice Hall.
Palm, W. (2013). System Dynamics, 3e. McGraw-Hill.
Phillips, C.L., Nagle, H.T., and Chakrabortty, A. (2015). Digital
Control System Analysis and Design, 4e. Pearson.
Pintelon, R. and Schoukens, J. (2001). System Identification. A
Frequency Domain Approach. Wiley-IEEE Press.
Proakis, J.G. and Manolakis, D.K. (1995). Digital Signal Processing:
Principles, Algorithms and Applications, 3e. Prentice Hall.
Skogestad, S. and Postlethwaite, I. (1996). Multivariable Feedback
Control: Analysis and Design. Wiley.
Söderström, T. and Stoica, P. (1989). System Identification. Prentice
Hall.
Starr, G.P. (2006). Introduction to Applied Digital Control. Draft.
STMicroelectronics (2015). UM1925 User Manual, docid028121 rev 1
edition.
Tewari, A. (2002). Modern Control Design with MATLAB and
Simulink. Wiley.
Ünsalan, C. and Gürhan, H.D. (2013). Programmable
Microcontrollers with Applications: MSP430 LaunchPad with
CCS and Grace. McGraw-Hill.
Ünsalan, C., Gürhan, H.D., and Yücel, M.E. (2017). Programmable
Microcontrollers: Applications on the MSP432 LaunchPad.
McGraw-Hill.
Ünsalan, C., Yücel, M.E., and Gürhan, H.D. (2018). Digital Signal
Processing using Arm Cortex-M based Microcontrollers: Theory
and Practice. Arm Education Media.
Wescott, T. (2006). Applied Control Theory for Embedded Systems.
Newnes.
Xue, D., Chen, Y.C., and Atherton, D.P. (2007). Linear Feedback
Control Analysis and Design with MATLAB. SIAM.
Yiu, J. (2013). The Definitive Guide to ARM® Cortex®-M3 and
Cortex®-M4 Processors, 3e. Newness.
Yu, W., Wen, G., Chen, G., and Cao, J. (2016). Distributed
Cooperative Control of Multiagent Systems. Wiley.
Zhou, K. and Doyle, J.C. (1997). Essentials of Robust Control.
Pearson.
Ziegler, J.G. and Nichols, N.B. (1942). Optimum settings for
automatic controllers. Transactions of the ASME 64: 759–768.
Index
a
Ackermann's formula 251, 253, 262
adaptive control 279, 280
analog 2, 10, 111
analog to digital converter (ADC) 11, 37, 48, 112, 114, 124, 126, 136
analog signal 64, 112
analog system 120, 123
anti-aliasing filter 118
Arduino 6, 14
ARM Cortex-M7 architecture 9
array 25
b
bandwidth 157, 211
baud rate 18, 31
bilinear transformation 120, 123, 134, 184
Bode plot 156, 191, 202, 211, 293
bounded input bounded output (BIBO) 79
c
central processing unit (CPU) 8
Chien–Hrones–Reswick method 186
C language 23, 111, 136
clock 9
closed-loop 151, 167
closed-loop control 167, 170, 183, 217
closed-loop system 160, 161
Cohen–Coon method 186
complex plane 151, 159
conditional statements 26
constant-coefficient difference equation 82
continuous-time signal 64, 112
continuous-time system 82
controllability 238
controllable canonical form 230
controllable system 248
controller area network (CAN) 11
convolution sum 82
Control System Designer (CSD) tool 201, 202
d
damped sinusoidal signal 71
damping ratio 154
DC gain 157
DC motor 53
DC motor drive 54
decibel 156
desired output 153, 163
dfu 29
DFU file manager 30
DfuSeDemo 29
difference equation 81, 120
differential equation 132, 133
differentiator 67
digital 10, 11
digital communication 11
digital control 174
digital signal 25, 63
digital system 77
digital to analog converter (DAC) 11, 39, 50, 117
Diophantine equation 285, 287
discrete-time signal 64, 112
distributed control 306
disturbance 163, 249
e
embedded 5
encoder 12
error signal 167, 249
exponential signal 69
f
fast Fourier transform 142
feedback 82, 89
feedforward 82
file usage 28
fixed-point 113
flash 10
floating-point 113
frequency domain 156, 159, 211
g
gain crossover frequency 159
gain margin (GM) 159
gain matrix 251
gain scheduling 280
gearbox 12
general purpose input and output (GPIO) 10, 34
h
hall effect sensor 16
i
inter integrated circuit (I2C) 11
impulse response 82
impulse signal 82
impulse train 112
indirect self tuning regulator 283
input and output 6
integrator 67, 184, 249
inverse z-transform 92
k
Kirchhoff current law (KCL) 133
Kirchhoff voltage law (KVL) 133
l
lag controller 199, 204, 211
lag–lead controller 200, 207, 213
Laplace transform 131
lead controller 200, 206, 213
linear system 80
logic level 10
loop operations 26
linear and time-invariant (LTI) system 63, 81
m
magnitude 156
magnitude plot 156
matplotlib library 25
matrix 25
Mbed Studio 23, 43
memory 9
micro USB 32
MicroPython 29, 31, 42
MIT rule 289
model-reference adaptive control 288
motor driver 12, 54
multi-input multi-output (MIMO) 78
n
natural frequency 154
nonlinear control 299
nonlinear system 80
Numpy library 26
Nyquist plot 160
o
observability 239
observable canonical form 230
observable system 250
observer 250
observer gain matrix 262
open-loop control 163
open-loop system 161
optimal control 302
oscillator 6
overdamped 154
overshoot 152, 155
p
parabolic signal 68
parameter estimation 280
P controller 184, 188, 197
peak time 155
peak value 155
percent overshoot 155
percent undershoot 155
phase 156
phase crossover frequency 159
phase margin (PM) 159
phase plot 157
pin layout 5, 6, 13
pole placement 230, 251
poles 95
pole-zero matching 121
Pololu metal gearmotor 12
port 10
proportional controller 289
proportional integral derivative (PID) controller 185, 187, 194, 197
proportional integral (PI) controller 184, 191, 197
pulse width modulation (PWM) 11, 36, 73
Python 24, 28
q
quadrature encoder 15
quantization 113
r
RAM 10
ramp signal 68
random signal 76, 136
read evaluate print loop (REPL) 31
rectangular signal 72, 137
recursive least squares (RLS) 280
region of convergence (ROC) 91
regulator 249
regulator gain matrix 251
resolution 113
rise time 155
robust control 305
root-locus plot 160
rshell 32
s
sampling frequency 37
sampling period 83
sampling theorem 112
second order system 154
sensor 12
serial peripheral interface (SPI) 11
settling time 155
sinc function 117
single input single output (SISO) 78
sinusoidal signal 71
ST-LINK debugger 6, 8
stability 79, 157, 160, 237
stable system 79, 95
state 227
state feedback 251
state feedback gain 251
state observer 260
state-space 227, 228, 247
steady-state error 156
step signal 67, 151
STM32 board 5, 29
STM32 microcontroller 5, 8, 23, 29
STM32 ST-LINK 29
sum of sinusoids signal 73
sweep signal 75, 142
system identification 134, 142
t
Tera Term 31, 307
time domain 134, 151
time-invariance 81
time-invariant system 81
timers 35, 47
time-varying system 81
transfer function 82, 131, 134, 142
transient response 152
Tustin's approximation 120
u
underdamped 154
undershoot 152
unit pulse signal 66
unit ramp signal 68
unit step signal 67
universal asynchronous receiver/transmitter (UART) 11, 41
universal synchronous/asynchronous receiver/transmitter
(USART) 11
unstable system 79
z
zero-order hold equivalent 120
zeros 95
Ziegler–Nichols method 186
WILEY END USER LICENSE AGREEMENT
Go to www.wiley.com/go/eula to access Wiley’s ebook EULA.