You are on page 1of 6

Proceedings of the 29th International Conference

2018 Cybernetics & Informatics (K&I)


Jan. 31 - Feb. 3, 2018, Lazy pod Makytou, Slovakia

MPC Controller As a Service in IoT Architecture


Štefan Kozák Anton Pytel
Institute of Applied Informatics MAKERS s.r.o
FI, Pan-European University Bratislava, Slovakia
Bratislava, Slovakia Email: anton.pytel@makers.sk
Email: stefan.kozak@paneurouni.com

Abstract—These days a term Internet of Things (IoT) is often CaaS is special kind of SaaS. As it was mentioned SaaS is
mentioned in commercial and academic sphere so it can some- usually accessed by user in browser. In CaaS case, controller
times sound as a buzzword. Nevertheless the IoT idea moving service is accessed by a device that is able to communicate
the world further in terms of almost unlimited connectivity
of fog components, meaning sensors, actuators, gateways, with with server, process response and do the actuation. How this
cloud components meaning high cpu power and memory capacity can be done is explained later after IoT architecture definition.
computers in data centers with all kind of software services Before that a terms fog and cloud, mentioned before, is needed
connectable, that can add value to data coming from fog to cloud to explain. Fog computing, also known as fog networking, is
and from cloud to fog. By this approach of connecting fog with a decentralized computing infrastructure in which computing
cloud it is possible to do cpu and memory power demanding
operation in cloud and so sophistically affecting actuators in the resources and application services are distributed in the most
field. This papers is inspired by the IoT architecture and proposes logical, efficient place at any point along the continuum from
an idea of Controller as a Service approach in automation. the data source to the cloud. The goal of fog computing is
MPC online method was chosen as demanding controller and is to improve efficiency and reduce the amount of data that
exposed as a service for use of everyone or better every internet needs to be transported to the cloud for data processing,
thing. The complicated computation is done in the cloud, only
communication with cloud is needed in fog area. analysis and storage. This is often done for efficiency reasons,
Index Terms—Computer and Control Systems, Controller but it may also be carried out for security and compliance
Hardware/Software, Controller as a Service, Model predictive reasons. [2] In other words, fog components are devices with
and optimization-based control the ability to interconnect themselves and that are placed
in the environment e.g. power plant - indoor example or
I. I NTRODUCTION city - outdoor example. Devices are sensors, actuators and
This paper describes the principle of controller as a service gateways. Through gateways or also denoted as edge devices
approach. For better understanding a prototype application or aggregators, fog is connecting to cloud. In the simplest
was created and is described here. Then it describes IoT terms, cloud computing means storing and accessing data
architecture, fog and cloud components and an advantage of and programs over the Internet instead of your computer’s
IoT architecture in controller as a service bringing into reality. hard drive. The cloud is just a metaphor for the Internet. It
This paper outlines future possible extensions of controller as goes back to the days of flowcharts and presentations that
a service idea. Mathematical background of model predictive would represent the gigantic server-farm infrastructure of the
controller is described in this paper, what makes it that compu- Internet as nothing but a puffy, white cumulus cloud, accepting
tational demanding and why online form of this algorithm was connections and doling out information as it floats. [3]
chosen. At the end an application prototype with experiment
A. IoT definition
is described.
It can be said that IoT architecture bringing CaaS into the
II. C ONTROLLER AS A S ERVICE - C AA S life. There are many definition what IoT is and IEEE even cre-
These days terms SaaS, PaaS, IaaS are used very often. ated a 86 pages long document with title Toward a definition
They are abbreviation of software, platform, infrastructure as a of the Internet of Things (IoT) [4]. Main characteristics, that
service. What means that user does not need to install software, are common in the most of the definitions of IoT in general
platform or buy hardware infrastructure, but can take advan- are summarized in this chapter and after that there is IoT
tage of installed software or platform by service provider also architecture specification.
with provider’s responsibility of service availability. Software • First common feature of all definition is that IoT consists
as a Service (SaaS), represent the largest cloud market and are of objects that can sense environment, sensors’s state
still growing quickly. SaaS uses the web to deliver applications and objects that can actuate. In other words, it contains
that are managed by a third-party vendor and whose interface sensors and actuators. [5]
is accessed on the clients’ side. Most SaaS applications can • Second common feature is interconnection between them.
be run directly from a web browser without any downloads So If there are sensors and actuators without access
or installations required, although some require plugins. [1] interface they cannot be found as a part of IoT system. In

978-1-5386-4421-8/18/$31.00 ©2018 European Union


Responsibility of gateways is to interconnect IoT devices with
IoT backend. But some lower level automation rules can be
distributed from IoT backend to IoT gateways. Graphic user
interfaces with layered architecture are provided also at this
level. At IoT device level a specialized firmware is running in
the devices. So IoT architecture is mixture of multiple system
architectures and application types taking advantages of each
of them at different level.
C. CaaS prototype
Prototype of CaaS application consists of two parts residing
at two different levels of IoT architecture. MPC online algo-
rithm computation is at IoT backend level exposed as service
using REST architectural style. REST is an architectural style,
and an approach to communications that is often used in
Fig. 1. IoT architecture components [7] the development of Web services. The use of REST is often
preferred over the more heavyweight SOAP (Simple Object
Access Protocol) style because REST does not leverage as
contrary if there are sensors and actuators with communi- much bandwidth, which makes it a better fit for use over
cation interface it is important sign of IoT system. In real the Internet. The SOAP approach requires writing or using a
life examples the interconnection is done via gateways. provided server program (to serve data) and a client program
[5] (to request data). [8] The key abstraction of information in
• Next feature is creation of intelligent environment. When REST is a resource. Any information that can be named
common objects are able to sense physical quantities can be a resource: a document or image, a temporal service
and their states. With interconnection, they are able to (e.g. today’s weather in Los Angeles), a collection of other
send measured data to edge device and edge device resources, a non-virtual object (e.g. a person), and so on. In
to data center. Values are analyzed and statistics are other words, any concept that might be the target of an author’s
prepared in data center. According to prepared statistics hypertext reference must fit within the definition of a resource.
and computations it is possible to do actuation back to A resource is a conceptual mapping to a set of entities, not the
physical object level in real time or quasi real time. In entity that corresponds to the mapping at any particular point
large scale, this can create a smart environment. [6] in time. [9] The REST resources that are provided to users in
CaaS service are:
B. IoT architecture • POST c-a-a-s/rest/mpccontrollers - Resource that cre-
Common components of IoT architecture are shown in the ates MPC controller in server. System model, controller
Fig. 1. constraints, tuning parameters can be set at input. Result
• IoT device. Sensors and actuators with communication is ID of the controller.
interface are considered as IoT device. IoT devices can • GET c-a-a-s/rest/mpccontrollers/id - Resource returns
have their certain computational power for basic automa- all parameters of the controller according to input id.
tion processes, but it is not necessary. • POST c-a-a-s/rest/mpccontrollers/id/steps - Resource
• IoT Gateway. Their role is to aggregate measurements to ask server for next step of actuation. Current system
form IoT devices and actuate commands to them. These state and reference signal can be set at input. The output
edge devices aggregate that kind of IoT devices that are of calling these resource with POST operation is actuation
not able to connect to IoT Backend directly. value that has to be performed.
• Last component is IoT Backend. It resides in data • GET c-a-a-s/rest/mpccontrollers/id/steps/id - If it is
center with scalable CPU power and memory capacity. needed to see previous steps, then this resource is used.
Its responsibility is to do high level analysis, statistics, Second part of CaaS application is CaaS client a piece of
actuation, data provision and data interface for end user software. In the experiment it is placed at IoT gateway level,
applications. but it could be placed at IoT device level. Requirements for
The core of the IoT system is based on microservice archi- CaaS client are regularly create a POST HTTP request to CaaS
tecture with use of service applications. IoT backend is usually server at specified URI, process JSON message format and
set of services, that it can provide. Example of common IoT execute the actuation. JSON is a lightweight data-interchange
backend services are data provision, data analysis. Another format. It is easy for humans to read and write. It is easy for
type of application can be used when creating visualization. machines to parse and generate. It is based on a subset of
With grow of Javascript language and HTML standardization the JavaScript Programming Language, Standard ECMA-262
the actual trend is to create web applications. At IoT gateway 3rd Edition - December 1999. [10] So when the requirements
level an event-driven or microkernel architecture is used. are met then it is possible to control almost any process.
while x is state of the system, y is output of the system and
u is input or actuation at step t.
n – number of states
p – number of outputs
m – number of inputs
Quadratic criteria for optimal control in finite horizon of a
length N is:

J(x(t), u(t), . . . , u(N − 1)) =


N −1
1  T 1 (2)
[xk Qxk + uTk Ruk ] + xTN QN xN
2 2
k=0

with constraints

Fig. 2. Receding Horizon Control [12] x( k + 1) = Axk + Buk


x0 = x(t),
Q = QT  0, QN = QTN  0, R = RT  0 (3)
Creation of new controller is matter of creating a new instance n×n
QN ∈ R
in server and passing id of controller to client. Creation of
new instance of MPC controller consists of setting process R ∈ Rm×m
model, constraints and MPC tuning parameters to server so
next chapter defines MPC controller. Matrices, Q, QN and R are called weighting matrices and
together with prediction horizon N are called parameters for
III. O NLINE MPC tuning of predictive controller. Finding the optimal actuation,
which would minimize criteria is dynamic optimization and
Model Predictive Control is, at the most basic level, a
its analytical solution is: [13]
method of controlling dynamic systems using the tools of
mathematical optimization. The common feature of all Model
Predictive Control approaches is to solve on-line, at each k−1
sampling instant, a finite horizon optimal control problem 
xt+k = Ak x0 + Ai Buk−1−i
based on a dynamic model of the plant, where the current (4)
i=0
state is the initial state. Only the first element of the computed
ut,N = [uTt , . . . , uTt+N −1 ]
sequence of predicted optimal control actions is then applied to
the plant. At the next sampling instant, the prediction horizon
is shifted, and the finite horizon optimal control problem is Predicted state is then expressed as:
solved again for newly obtained state measurements. This idea
is not new, already in Lee and Markus (1967) one can find the [xTt+1 , . . . , xTt+N ]T = V x0 + T ut,N (5)
following statement: “One technique for obtaining a feedback
controller synthesis from knowledge of open-loop controllers
is to measure the current control process state and then This is the first most important part of online MPC algo-
compute very rapidly for the open-loop control function. The rithm. Second important part is adding constrains. Having the
first portion of this function is then used during a short time same system as in 1 and same criteria as in 2 adding this
interval, after which a new measurement of the process state conditions to the system:
is made and a new open-loop control function is computed for
this new measurement. The procedure is then repeated.” The xk+1 = Axk + Buk ,
technique described by Lee and Markus (1967) is commonly x0 = x (t) ,
referred to as “Receding Horizon Control” (RHC), and is today (6)
Ec xk + Gc uk ≤ mc , k = 1 . . . N
used more or less synonymously to the term Model Predictive
Q = QT  0, QN = QTN  0, R = RT  0
Control [11].
If a discrete state space is defined:
Then criteria function is:
x(t + 1) = Ax(t) + Bu(t),
1 1
y(t) = Cx(t) + Du(t), J (x (t) , Ut ) = ut,N T Hut,N + xT (t) F Ut + xT (t) Yx (t) ,
(1) 2 2
x(t) ∈ Rn , y(t) ∈ RP , u(t) ∈ Rm , Gut,N ≤ w + Ex(t)
A ∈ R(n×n) , B ∈ R(n×m) , C ∈ R(p×n) (7)
Where matrices G, E and vector w are defined in this way: Raspberry Pi creates a REST interface to expose values. Cus-
⎡ ⎤ ⎡ ⎤ tom plugin to read REST interface is created in VeraLite, so
−I N 0
⎢ ⎥ ⎢ ⎥ value about light intensity is delivered to IoT Gateway. As
⎢ I
N ⎥ ⎢ 0 ⎥
⎢−(IN ⎥ ⎢ ⎥ IoT Backend a simple Debian server with Tomcat 8 application
G=⎢  CT )⎥ , E = ⎢−(IN CV )⎥ , server, MongoDB database and Octave computation core is
⎢ (IN ⎥
CT ) ⎦ ⎢ CV ) ⎥
⎣ ⎣ (IN ⎦ chosen.
.. ..
. . Measured data for system identification are showed in the
⎡  ⎤ (8) graph 3.
−(1N umin )
⎢ (1N ⎥
⎢ umax ) ⎥
⎢ −(1N y ) ⎥
w=⎢  min ⎥
⎢ (1N y ) ⎥
⎣ max ⎦
..
.
The actuation value is obtained from the following equation:
u∗t,N (x (t)) = arg min {J(x (t) , ut,N } = −H −1 F T x(t)
ut ,N
(9)
Together with equation 8 it is base for quadratic programming
problem. As matrices can grow with prediction horizon and
system complexity, the matrix inversion and other matrix Fig. 3. Light level intensity to dimmer percentage dependency
operations can become that cpu and memory demanding, that
it is not possible to do computation at embedded devices. It is obvious that system is not linear. Because in first part
Another drawback of MPC is that it needs a mathematical from 20 to 60% at x axes, the lux intensity rises 25 lux at y
model of controlled process, therefore system identification is axes. While in second part from 60% to 100% again 40% rise
needed. Here is the point of future extension of CaaS idea at x axes, causes now 40 lux increase at y axes. Part from 0
so that CaaS application would come with identification as a to 10% can be third linear part, but is now ignored, therefore
service so that according to measured data it would compute two working points are chosen at 30% and at 80%. Measured
system model. It is not trivial task, therefore at first feasibility data at these points and moved to zero level are showed at
of prototype of CaaS is being confirmed. With these set of two graphs 4, 5 and 6.
tool an adaptive mechanism of system change can be applied.
This is the reason of choosing online form of MPC so that
in certain periods whole controlled system can be changed
during process runtime. The CaaS application is prepared
for this way of online system model changing, because new
controller is matter of calling controller object constructor
in exposed server application. In next chapter experiment
execution follows.

IV. E XPERIMENT
Experiment consists of description of real testing IoT system
and control of desired light intensity by CaaS application, Fig. 4. Step responses at 30% working point
where online MPC algorithm is provided by the service.
It is needed to mention that value provided by photoresistor
A. IoT system components is 0 - 255 and it is converted to lux intensity according to
For the experiment these devices are used at different level. reference lux meter. 255 represents the darkest point and 0 the
It is an intelligent household IoT system. lightest. Above 140 lux the measurement has almost 40 lux
For IoT Gateway, VeraLite device is chosen, because of noise level as the conversion has exponential characteristic. For
its abilities to handle Z-Wave and other application protocols identification at 80% level a filtration with moving average is
above TCP/IP protocol and possibilities of custom develop- done, so it is possible to obtain better result with Matlab’s ident
ment in Lua and UPnP combined together in framework called toolbox. Best transfer functions results for these two measured
Luup. datasets are
IoT Device to actuate light intensity is FIBARO FGD 211 14.71 ∗ s + 0.0291
connected directly to VeraLight. G1 = 2 (10)
s + 11.17 ∗ s + 0.0232
IoT Device to measure light intensity is photoresistor con- 8.074 ∗ s + 57.6
nected via PCF8591 converter to Raspberry Pi’s GPIO port. G2 = 2 (11)
s + 7.645 ∗ s + 18.4
120 lux. Above 120 lux, noise of measured light intensity is
higher and because of that noise a quality of control is lower.
But later in the step to 50 and 100 again the quality is much
higher. Sample period of MpcMaster device was set to 15
seconds not to overload the VeraLite device as it responsible
for management of all Z-Wave nodes. Because of this period
an input delay can be seen. Finally there is an obvious control
error at 20 lux set point that is most probable caused by the
first not linear part of the graph 4, that was ignored during
identification. It is not visualized here that it was combination
of two separate controllers, but the decision rule is simple so
Fig. 5. Step responses at 80% working point
all set points above 75 lux are handled by second MPC and
below by first.

Fig. 6. Step responses at 80% working point - filtered


Fig. 7. Desired values and measured values.

Now having two transfer functions for one process, it is needed


to create two instances of MPC client. They are developed
in LuuP framerwork in VeraLite device. Each of them is
responsible for different part of process. According to graph
3 a boundary lux level was set to 75 lux. Equation 10 is set
to first MPC client and it is responsible for set point lower
than 75 lux and equation 11 is set to second MPC client
and is responsible for setpoint value greater than 75 lux. For
deciding which MPC client should be called a special plugin is
developed in Luup framework called MpcMaster. MpcMaster
plugin has these inputs:
• IDs of MpcClients,
• boundary level, Fig. 8. Measured value and dimmer level value.
• set point value,
• sample period.
V. C ONCLUSION
Usually MPC client is responsible for setting regular server
call with setpoint value and request for next step. In a case Based on the results of control quality, it can be definitely
of multiple controllers, setpoint and sample period of MPC said that CaaS approach is feasible. Restriction that this
clients are ignored because a MpcMaster plugins override solution is bound to is connectivity dependency. If network
their values because now MpcMaster is responsible for whole is down, then there is not control loop, because client is
process. Now after process identification and all software not able to call server. Now many ISP can guarantee 24/7
components identified a control loop can be executed. connection and it is first most important CaaS dependency.
The bad control quality above 120 lux is drawback of low cost
B. Process control results sensors, that can be point when thinking over IoT solution to
Measured data of experiment on real devices can be seen choose sensors with proper measurement quality in the whole
in the picture 7 and 8. Steps started from zero to 200 lux with range. Finally the minimal sample period and server response
step of 20 lux. Afterwards step to 50 lux, 100 lux, 20 lux time is matter of criticality of a process that is going to be
and back to zero respectively. It can be seen from graph 7 controlled. Minimal sample times, that can be achieved by this
that measured values and output values are equal until almost approach is subject of further experiments, the estimate is tens
of milliseconds. But the server side has to be still optimized.
The concept of CaaS was developed and tested for the
purpose of controlling such systems, that needs to control
many subsystems and adding new subsystem can be only
matter of configuration. It also can lead to process control
standardization, that will be probably needed with oncoming
grow of IoT system implementations and possible demand for
controlling processes that are similar and often reproduced,
so one provider of controller service will provide the same
algorithm implementation for many consumers.
ACKNOWLEDGMENT
This paper is supported by the Slovak Research and De-
velopment Agency (VEGA 1/0819/17), and the Cultural and
Educational Grant Agency of the Ministry of Education,
Science, Research and Sport of the Slovak Republic (KEGA
030STU-4/2017).
R EFERENCES
[1] Apprenda, “Iaas, paas, saas (explained and compared) - apprenda,”
https://apprenda.com/library/paas/ iaas-paas-saas-explained-compared/,
2015, (Accessed on 04-11-2016).
[2] M. Rouse, “What is fog computing (fog networking)? - defi-
nition from whatis.com,” http://internetofthingsagenda.techtarget.com/
definition/fog-computing-fogging, 2016, (Accessed on 04-11-2016).
[3] E. Griffith, “What is cloud computing? — pcmag.com,”
http://www.pcmag.com/article2/ 0,2817,2372163,00.asp, 2016,
(Accessed on 05-11-2016).
[4] D. R. R. Minerva, A. Biru, “Towards definition
internet of things,” http://iot.ieee.org/images/files/pdf/
IEEE IoT Towards Definition Internet of Things
Revision1 27MAY15.pdf, 2015, (Accessed on 04-11-2016).
[5] A. Pytel, “Dissertation thesis,” https://github.com/anton-pytel/caas/
blob/master/text/MPC IOT/dizertacna praca.pdf, 2016, (Accessed on
05-11-2016).
[6] Techopedia, “What is the internet of things (iot)? - definition from
techopedia,” https://www.techopedia.com/definition/ 28247/internet-of-
things-iot, 2015, (Accessed on 04-11-2016).
[7] B. Kithion, “Simple steps to learn iot architecture — brucelin kithion —
pulse — linkedin,” https://www.linkedin.com/pulse/ simple-steps-learn-
iot-architecture -brucelin-kithion, 2016, (Accessed on 05-11-2016).
[8] M. Rouse, “What is rest (representational state transfer)? - defini-
tion from whatis.com,” http://searchsoa.techtarget.com/definition/ REST,
2014, (Accessed on 05-11-2016).
[9] P. Subramaniam, “Rest api design - resource modeling — thought-
works,” https://www.thoughtworks.com/insights/ blog/rest-api-design-
resource-modeling, 2014, (Accessed on 05-11-2016).
[10] JSON, “Json,” http://www.json.org/, 2016, (Accessed on 05-11-2016).
[11] M. Balandat, “Constrained robust optimal trajectory tracking: Model
predictive control approaches,” 2010.
[12] M. M. A. Bemporad, “Robust model predictive control: A survey,” 1999.
[13] J. Řehoř, “Návrh explicitnı́ho prediktivnı́ho regulátoru
s využitı́m Multi-Parametric Toolboxu pro Matlab,”
http://www2.humusoft.cz/www/papers/tcp07/rehor.pdf, 2008, (Accessed
on 12-02-2014).

You might also like