Next Article in Journal
Attenuation of Lightning-Induced Effects on Overhead Distribution Systems in Urban Areas
Next Article in Special Issue
Adaptive Control of Flapping-Wing Micro Aerial Vehicle with Coupled Dynamics and Unknown Model Parameters
Previous Article in Journal
Characterization of Sorghum Processed through Dry Heat Treatment and Milling
Previous Article in Special Issue
Multi-Robot Formation Control Based on CVT Algorithm and Health Optimization Management
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Temperature Control Unit—Modeling and Implementation of a Particle Filter on a Microcontroller

Faculty of Control, Robotics and Electrical Engineering, Institute of Robotics and Machine Intelligence, Poznan University of Technology, 60-965 Poznan, Poland
*
Authors to whom correspondence should be addressed.
Appl. Sci. 2022, 12(15), 7631; https://doi.org/10.3390/app12157631
Submission received: 26 June 2022 / Revised: 19 July 2022 / Accepted: 27 July 2022 / Published: 28 July 2022
(This article belongs to the Collection Advances in Automation and Robotics)

Abstract

:
The paper discusses the possibilities of using particle filter estimation algorithms in embedded systems. For this purpose, the dedicated testing platform was built, which allowed for the determination of the estimation quality of a particle filter on a real system, and the microcontroller performance in that scenario. Tests were performed using the obsolete and not very efficient, although energy-saving, STM32F4 Discovery board—it has allowed for an in-depth analysis, and the results can be easily improved by switching to a modern platform. The quality of operations in open- and closed-loop systems was investigated based on the analysis of time simulations conducted for various mathematical models. These analyses made it possible to establish a correlation between the number of particles and the required calculation power. They have shown that it is possible to successfully implement and run a particle filter algorithm on an older and computationally limited device, as well as in real-time scenarios.

1. Introduction

Autonomous and stand-alone solutions that can work together are becoming increasingly popular in automation and robotics [1,2]. This makes it possible to build a fault-tolerant unit, which can act independently of a powerful main server and allows for reducing the amount of data transmitted over the network. The goal can be achieved by putting some data processing mechanisms in peripheral units [3], such as microcontrollers. The advantages of this approach are (1) the insensitivity to server malfunction and (2) the high availability rate. Unfortunately, it may result in poor output quality, e.g., of sensor value estimations, because of the generally lower performance of a unit, and the limited hardware resources. The situation may be even more difficult if a sophisticated algorithm, such as a particle filter (PF) [4], is used, which produces a high-quality output but requires a more powerful processing unit compared to other estimation algorithms [5]. Higher output quality means a better match to the real-life signal value, which is desirable.
In a case where the measurement data needs to be improved, or it is necessary to determine the values of non-measurable variables, state estimation is desirable. Formerly, thanks to the low computational complexity, static estimation, such as weighted least squares (WLS) [6], was mainly used in automation. Unfortunately, low computational complexity was accompanied by low estimation quality. With the development and increased capabilities of computing devices, dynamic state estimation approaches have become widely used. One of the most popular methods for linear systems was the Kalman filter (KF) [7,8], proposed by Rudolf Kalman in 1960 [9]. Later, many variants of Kalman filters for estimating a state of nonlinear systems were proposed. The most common modifications are: based on static linearization, the extended Kalman filter (EKF) [10], and, based on the unscented transformation, the unscented Kalman filter (UKF) [11]. Other interesting modifications can be found in [12,13,14,15]. A more complex algorithm, but also of better output quality for highly nonlinear objects, is the particle filter (PF), proposed in 1993 by Gordon, Salmond, and Smith [4]. It is based on the randomization of particles and the calculation of their weights best matching the system’s actual output. Over the years, various types of particle filters have been developed, such as an auxiliary particle filter (APF) [16] or a likelihood particle filter (LPF) [17]. The main differences involve selecting the transition function from which the particles are drawn. The particle filter is extremely useful in scenarios where enough processing power is available. In previous works, the authors proposed a modification relating to the parallelization of the basic particle filter, dividing it into smaller parts—the sub-filters. The code can be efficiently parallelized [18], resulting in a reduction of processing time without a negative impact on the output quality (except for the resampling step, which is very important in PF methods and, unfortunately, cannot be parallelized).
Problems of applying the efficient use of microcontrollers and PF together have been analyzed in several works [19,20,21]. The researchers used a variety of platforms, ranging from hardware to software. The researchers used different types of platforms, which varied at the hardware and software levels. Some of them were built on commercial hardware platforms offered by, e.g., LEGO Mindstorms. The common parts of the above-mentioned platforms are a high-performance processor and a large amount of RAM memory. The platforms based on low-cost boards such as Nucleo and Discovery boards from ST, Arduino family boards, or just ESP8266 are rare. That was the motivation to test one of the mentioned platforms and check its performance. In our case, we decided to get an older platform—the results can be easily improved by simply replacing the board with its newer equivalent.
The main subject of research in this publication is the state estimation in the temperature control system. The object was prepared as a dedicated platform for this research. In the literature, there are examples of the use of state estimation of thermal processes. For example, in [22], a particle filter was used to regulate the temperature, with the proposed adjustment of particle weights to improve the operation of the algorithm. The authors rely on a complex non-linear process model. In [23], the authors experimentally determined the parameters of the temperature control model, both in an open- and closed-loop system. However, the model was based only on measurement information—the development of the research may be the use of state estimation to improve this information. One can find many sources on the use of temperature estimation for various devices. In works [24,25], the new temperature estimation technique in a permanent magnet using Kalman filtering is proposed. The article [26] presents a review of various methods of state estimation in battery modeling tasks, using the state of temperature too.
In this paper, emphasis is put on the implementation of PF on a computationally weak device; therefore, a simplified (linear) model is adopted concerning [22]. Such an approach provides better implementation options and the opportunity to increase the number of particles. Various versions of the mathematical model that have been proposed can be successfully used for state estimation.
The structure of the work is as follows. Section 2 describes the particle filter algorithm. Section 3 contains the description of the computing platform. Section 4 describes the control object and the procedure of how to identify it. Section 5 describes the results of the experiments. Section 6 and Section 7 contain the discussion and summary, respectively.

2. Particle Filter

The particle filter is a state estimation algorithm that can be used on linear or nonlinear discrete-time systems, including systems with non-Gaussian noises. The system is represented by the following equations:
x ( k + 1 ) = f ( x ( k ) , u ( k ) ; k ) + v ( k ) y ( k ) = g ( x ( k ) ) + n ( k ) ,
where k denotes the time step number, x ( k ) is the state vector, u ( k ) is the control inputs vector, y ( k ) is the vector of measurement outputs, f ( · ) is the transition functions vector, and g ( · ) is the measurement functions vector, v ( k ) and n ( k ) are the process and measurement noises, respectively. The transition and measurement model can be linear or nonlinear. In the latter case, the equations of state cannot be written in a matrix form [27].
The main purpose of the state estimation is to obtain internal variables x ( k ) that cannot be directly measured and to filter out measurement noise from the signals y ( k ) .
The basis of the particle filter is the recursive Bayesian filter algorithm [28,29]
p x ( k ) | Y ( k ) = p y ( k ) | x ( k ) p x ( k ) | Y ( k 1 ) p y ( k ) | Y ( k 1 ) ,
where:
  • Y ( k ) = { y ( 1 ) , , y ( k ) } —the set of output vectors,
  • p x ( k ) | Y ( k ) —the posterior Probability Density Function (PDF);
  • p y ( k ) | x ( k ) —the likelihood;
  • p x ( k ) | Y ( k 1 ) —the prior PDF;
  • p y ( k ) | Y ( k 1 ) —the evidence which is given by equation
p y ( k ) | Y ( k 1 ) = p y ( k ) | x ( k ) p x ( k ) | Y ( k 1 ) d x ( k ) .
The posterior PDF in the particle filter is represented by a set of particles, and its weights are given by { x i , q i } , where each particle x i has a weight q i , for  i = { 1 , , N p } . The approximation of posterior PDF for a large number of particles can be written as
p x ( k ) | Y ( k ) = N p p ^ x ( k ) | Y ( k ) = i = 1 N p q i , ( k ) δ x ( k ) x i , ( k ) ,
where δ ( · ) denotes a Dirac Delta function.
The first proposed particle filter algorithm is the bootstrap algorithm [4,28] presented in Algorithm 1 and in Figure 1.
Algorithm 1: Bootstrap Particle Filter (BPF)
1. Initialization. Draw N p initial values from the posterior PDF x i , ( 0 ) p ( x ( 0 ) ) . Set time step k : = 1 . Do this step only once.
2. Prediction. Draw the new particles x i , ( k ) p ( x ( k ) | x i , ( k 1 ) ) , where i = { 1 , , N p } from the transition model.
3. Update. Determine the weights of the N p particles based on the measurement model
q i , ( k ) = p ( y ( k ) | x i , ( k ) ) .
4. Normalization. Scale values of the weights in such a way that their sum equals 1.
5. Resampling. Draw N p particles from among those that already exist. The PDF for drawing is defined by the set of normalized weights (the systematic resampling is applied [30]).
6. End of the iteration. Estimate the state vector at k-th time step, increase the time step k = k + 1 . Jump to the 2nd step.

3. The Platform

Our tests were carried out on a temperature control system, prepared as a dedicated platform built of commercially available elements. The platform consists of three related parts:
  • A case—made of steel, plexiglass, printable elements;
  • Hardware—microcontroller, sensors, H-bridge, and others;
  • Software—code written in the C programming language.
The case (Figure 2) was designed in the Autodesk Inventor and was printed using ABS material. The general idea was to build a chamber that would be partially independent of the external environment and relatively small. As air volume has a great impact on the heating and cooling time of the air inside the chamber; only a small amount of free space was left for additional new measurement instruments. Besides the aspects of functionality, we decided to consider a visual aspect and used plexiglass windows, which enabled us to look inside the case. The dimensions of the box are shown in Figure 3. The total outer case size is 120 × 80 × 70 mm.
For measurement and control purposes, we decided to use the STM32F4 Discovery evaluation board, which is quite old and nowadays does not offer a great performance compared to other boards. We decided that if the solution works fine on this microcontroller, it can work even better on modern embedded platforms. Besides the board, we used two DS18B20 thermometers using a 1-wire interface, one L298N H-bridge controlled by PWM (pulse width modulation), one 40 × 40 × 10 12 V PC fan, one 10 W light-emitting diode (LED), and a PL2303HX converter, which allowed us to communicate with the board through the USART interface. One thermometer and one LED were put inside the chamber. The fan was placed on one side of the case. It allowed two goals to be reached: at low speed, it forced the airflow inside the case to equalize the temperature in the case, whereas at high speed, it cooled down the chamber. The microcontroller, H-bridge, and second thermometer were placed outside the case. We decided to use the led diode as a heater because it produces a large amount of heat and does not need a powerful power supply, which was confirmed in our internal tests in the past. The output power of the diode can be programmed to work between 0 % and 100 % . The power of the diode was reduced by a resistor, as suggested by the manufacturer. The fan can also be controlled, but in the range of 30 % to 100 % percent. The whole system is shown in Figure 4. The peripherals, which are an integral part of the case, are shown in the Figure 2.
An algorithm written in the C programming language controls the system. We used the STM32CubeIDE environment for board programming and Hercules software for communication over the USART interface. The code was divided into several parts that work together. The PF algorithm was rewritten from our original code in C# language [18] and modified to work with the object.
For the purpose of the estimation algorithm, the system was modelled by several mathematical models explained in the next section. The experiment can be in one of three states: heating, normal (keeping), and cooling down, according to the control inputs. Different models are used when the temperature decreases or when it increases. The switch of the models is based on the indoor temperature, the user-expected temperature, and the tolerance range: ± 0.26 (the value results from the highest resolution of DS18B20, which is 0.065 ). The measured temperature has an accuracy of 0.065 . The second thermometer was not used directly in the system during the main tests, it was only used to perform comparison measurements.

4. Research Objects—The Mathematical Models

4.1. Simulation Object

The microcontroller was used in simulated tests and under real-world conditions. For simulation purposes, we used common particle filters examination [4]. According to [31], this object was first proposed in 1978 by Netto, Gimeno, and Mendes. The object is one-dimensional and has no external inputs; it is autonomous. The state change is only due to the presence of process noise. It is given by the discrete-time state-space equations
x ( k + 1 ) = 0.5 x ( k ) + 25 x ( k ) 1 + x ( k ) 2 + 8 cos ( 1.2 k ) + v ( k ) y ( k ) = x ( k ) 2 20 + n ( k ) .
Simulation parameters: v ( k ) N ( 0 ; 10 ) , n ( k ) N ( 0 ; 1 ) , x ( 0 ) = 0.1 .

4.2. Real Object—Heating and Cooling System

To implement the particle filter algorithm for the real system, it was necessary to define a mathematical model of the tested object. In the literature, many examples involve the modeling and testing of the heating system [32,33,34], but in this study, two-inertial objects were established. The detailed course of the thermal process identification experiment in different versions can be found in [23]. The selected type of system is universal and is often used in the synthesis of a controller [35]; it is given by a transfer function,
G ( s ) = K ( 1 + s T 1 ) ( 1 + s T 2 ) ,
and the differential equation
y ¨ ( t ) = 1 T 1 + 1 T 2 y ˙ ( t ) 1 T 1 T 2 y ( t ) + K T 1 T 2 u ( t ) ,
where t denotes continuous time, K is the gain of the object, and T 1 and T 2 are the time constants. The notation y ˙ and y ¨ stand for d y d t and d 2 y d t 2 , respectively. Noises that affect the object have been ignored in the continuous-time model.
To identify the parameters of the object, tests with various amplitude step controls were carried out, during which the gain and time constant for the experiments were adjusted. Separate tests were carried out for the heating and cooling processes as different dynamic properties were then demonstrated by the models. Constant parameters were selected for the heating process (denoted by subscript h), while in the case of cooling (subscript c), the gain depends on the initial temperature y ( 0 ) that at the beginning of the experiment should be ideally equal to the temperature measured outside. The resulting parameters in the two modes are as follows:
  • heating: K h = 0.0526 , T h , 1 = 36.32 , T h , 2 = 508.48 ;
  • cooling: K c = 0.2069 y ( 0 ) 100 , T c , 1 = 25.00 , T c , 2 = 148.00 .
Only two modes are assumed, namely, heating or cooling, in which the controls u 1 (diode power—for heating) and u 2 (fan power—for cooling) work, respectively. The built model can be considered as a jump system [36,37].
Continuous state-space equations, including phase variables, are given by
x ˙ 1 ( t ) x ˙ 2 ( t ) = 0 1 1 T 1 T 2 1 T 1 + 1 T 2 x 1 ( t ) x 2 ( t ) + 0 K T 1 T 2 u ( t ) y ( t ) = 1 0 x ( t ) .
The system (9) is then discretized with sample time T s = 1 second using the Euler extrapolation method, and the obtained discrete state-space equations (dependent on the model parameters), including the modeling errors (1), are shown below
x 1 ( k + 1 ) x 2 ( k + 1 ) = 1 T s T s T 1 T 2 1 T s 1 T 1 + 1 T 2 x 1 ( k ) x 2 ( k ) + 0 K T s T 1 T 2 u ( k ) + v 1 ( k ) v 2 ( k ) y ( k ) = 1 0 x ( k ) + n ( k ) .
It is worth noting that particle filters are applied in the heating process as well—an example such a process can be found in [22]. In this paper, the complexity of the object has been limited to two state variables and one control signal due to implementation on a computationally weaker device. The noise of the process included in the PF (1) compensates for the nonlinearity omitted in the model. To simplify the above considerations, the process noise in the transition function and the related disturbance transfer function were omitted. The PF algorithm takes into account the initial condition, namely, the temperature y ( 0 ) , read in the first step of each experiment. Tests were performed for various noise variances.

4.3. Real Object—Estimation Using the Outdoor Temperature

A system given by the transfer function (7) can be extended by using not just the measured temperature as an output but the difference between internal and external temperatures y = T i n T o u t . The parameters of this object were matched to the dynamics of changes in the new defined signal y.
As it turns out in the test example, such a model will be very sensitive to disturbances in the form of, for example, changes in the outside temperature. Ultimately, when only T i n was used in the transition model and when the initial value only depended on the outside temperature, the model performed better.

4.4. Real Object—Estimation without Using a Physical Model

In this model, the state-space equations are based not only on the dynamics of the system model under consideration but on the speed of temperature changes in the previous step. This approach allows for effective state estimation without knowing the exact dynamics of the process.
The discrete-time state variable x 1 ( k ) is the estimated temperature and accounts for the rate of change in the output of the previous step, as shown below:
x 1 ( k + 1 ) = x 1 ( k ) + Δ y ( k ) = x 1 ( k ) + x 1 ( k ) x 1 ( k 1 ) = 2 x 1 ( k ) x 2 ( k ) .
The variable x 2 ( k ) is used to store the history, representing the state variable from the previous step. Therefore, noise with zero error variance is added to it to obtain x 2 ( k + 1 ) x 1 ( k ) .
The matrix expression of the state-space equations, taking into account the process noises and based on (11), is given by
x 1 ( k + 1 ) x 2 ( k + 1 ) = 2 1 1 0 x 1 ( k ) x 2 ( k ) + v 1 ( k ) v 2 ( k ) y ( k ) = 1 0 x ( k ) + n ( k ) .
It should be noted that the proposed system is autonomous. The change of state is caused only by the presence of system noise, and the parameters to be adjusted are the variances of the noises. The best estimation (based on the graphs) was observed for the parameters σ v 1 2 = 10 6 , σ v 2 2 = 0 , and σ n 2 = 0.0225 .
This approach can be associated with dynamic linearization, which is used, among others, in the ADRC control algorithm [38]. The result of this linearization is a model in the form of a double integrator. Therefore, the discrete-time characteristic polynomial for (12) is M ( z ) = ( z 1 ) 2 .

5. Experiments Results

The results of the performed tests show that particle filters can be used successfully in low-performance embedded systems. We prepared three different scenarios:
  • A test of the platform performance, including a comparison with the original C# implementation,
  • A heating and cooling test,
  • A heating and normal test.
From among all the conducted tests, only several are chosen to be presented in this section. The remaining test results are shown in Appendix A.

5.1. PF Performance Comparison

The performance is a very important part of data processing, especially in embedded systems. In this part of the tests, we compare the results from four different platforms, including solutions in which processing is done on an outside computer unit or on an embedded board (the details are given in Table 1). The original C# code, expressing the particle filter algorithm and prepared for platforms A, B, and C, was rewritten to the C language because of the board (platform D) requirements. We also decided to prepare two different versions of the code—a standard version without any platform optimization (S), and a highly optimized code (O). The optimized version includes several specified improvements listed below:
1.
Using only float variable types instead of double (in the entire code);
2.
Changing all numbers by adding f postfix (e.g., 3.0f instead of 3.0);
3.
Using float-specific arithmetic functions such as cosf, powf, and sqrtf;
4.
Enabling FPU (floating point unit);
5.
Selecting—Ofast optimization level in the compiler settings.
After applying the improvements, we used the STM32F4 evaluation board to recheck the performance. As STM32F4 has a limited amount of memory, we decided to reduce the maximum number of iterations and particles (additional changes made for optimizing the C code are given later in the text). Platform tests (Table 1) were repeated with the same parameters to achieve reliable results for comparison.
The one-dimensional object described by Equation (6) was used for these simulation tests. The experiment data (noises and state variables) were regenerated during each experiment. Initial tests showing a comparison of the particle filter operation for the considered platforms are given in [18].
Three tests were carried out with the following number of iterations and number of particles (accordingly) used: N p = 1000 , M = 500 ; N p = 1000 , M = 500 ; and N p = 500 . The results of the tests are shown in Figure 5.
The performance of the microcontroller with the algorithm in the standard version (S) is much worse than on the other compared platforms. The simulation of the object and the particle filter algorithm on the STM32F4 is from 57 to 360 times slower (without any platform-specific optimizations). It is a huge difference that cannot be compensated for by the simulation scenario. In this case, the microcontroller cannot be used in scenarios when a high number of iterations, a high number of particles, and real-time processing are required. The highly optimized version (O) is much more efficient and can compete with other platforms. The differences are related to clock speed, IPC (instructions per cycle), and the hardware architecture of the platform. The comparison of the standard and optimized version is additionally shown in Table 2.
As embedded systems are called energy-saving, it is obvious that boards such as STM32F4 consume less energy than a powerful PC in general and offer less computational power. However, the question arises of what is the result of power consumption per task. We performed additional tests based on M = 1000 and N p = 1000 to determine it (Table 3). We used a commercially available current clamp meter to measure the electric current and a commercially available multimeter to measure the voltage. The computation time was measured at the code level by a dedicated function. The results obtained are not particularly clear. The powerful platforms calculate the results much faster and during this time can consume less energy. If we compare Platform D (S) with Platform C, we can see that the second platform consumes about 2.3 times less energy per task. It is important to note that in this case, the low-energy platform consumed more energy. The situation is different if the highly optimized code is used (Platform D (O)). STM32F4 consumes over 10 times less energy than Platform C, which confirms its usability in different tasks. The most important thing for embedded systems is to prepare the code that can be compiled as fast as possible on a used board. It is also worth noting that the energy consumption of platforms A, B, and C contains the energy consumed by the operating systems, which did not occur in the platform D cases.

5.2. Heating and Cooling Test

In the second part of the experiments, the heating and cooling test was performed. We prepared a scenario in which the air in the case was heated to the desired temperature. After reaching the temperature, the air was immediately cooled down to the base temperature ( 19.875   ° C ). The information collected online was the indoor temperature and the estimated temperature. The quality of the estimation of the data models was tested and compared to the models given by Equations (10) and (12). The results obtained are shown in Figure 6, Figure 7 and Figure 8 and are denoted as y ^ m 1 and y ^ m 2 for the systems (10) and (12), respectively. Figure A1 from Appendix A shows experiments obtained only with the use of the model (10) because these experiments were used to verify the operation of the estimation for various parameters of the particle filter—for different values of set temperatures and different noise variances. For better visibility of the range and approximations, some fragments of the charts are zoomed in on; they are marked with rectangles in the main picture.
The u 2 value is never set to zero as it is a signal related to the fan where the minimal PWM duty cycle is 30% due to below the value the fan is not working correctly. WMuch more importantly, we observed that the fan is very useful to mix up the air in the chamber. In cases when the fan is off, the hot air accumulates itself around the heater and above it. In other places of the chamber, the air stays colder. Further, when u 2 was changed to 100% and u 1 was changed to 0%, we observed air mixing at the beginning of the experiment. This resulted in a sudden increase in the air temperature around the thermometer. When the air became a semi-homogeneous mixture, the temperature drop was similar to the one described in the article. Using values below 30% for u 2 would have had a negative impact on the quality of the experiments. Hence the nominal value of the “off” state of the fan was taken as 30%.
Results obtained for various configurations of particle filter parameters were compared—for the noise variances, the number of particles, and for the different temperature values (see Appendix A, Table A1 and Table A2). The results show that the estimates fit the measured values despite slight differences in the initial values. This is due to the use of measurement information in the filtration step. With correct PF settings (such as the number of particles, variances, etc.), the initial errors are quickly compensated for, and the estimate begins to follow the measured temperature. When the assumed temperature was reached, the heater was turned off and the model parameters (10) were switched on in PF.
In the case of model (10), a sufficiently large number of particles is needed for a correct estimation. For Equation (12), the estimation also works correctly when the number of particles is reduced. This may be due to the estimation following a mathematical model, which did not keep the history of the previous sample, as was the case with the second one. The dynamics of the system and the impact of external controls can be treated here (in model (12)) as a disturbance in the estimation task. On the other hand, the model based on an inertial object (model (10)) always adjusts the response to the assumed dynamics, primarily following the measured signal and being more sensitive to external noise. Such a phenomenon may be undesirable, for example, when we want to use the estimate to improve the resolution of the measuring device. The model is based on the rate of change averages of the estimates, assuming values other than the resolution of the thermometer. The estimated value increases slowly in this case, as expected for the temperature.
There is also a visible difference in the operation of the system for different values of the outside temperature. As one can see in Figure 6, the system was warming up to the assumed temperature longer than for Figure 7 and Figure 8. In the first case, the ambient temperature was slightly lower than in the others, which increased the time constant in the facility (value of y o u t approx 19.3 vs. 19.6).
Ultimately, the mathematical model did not to take into account the outside temperature in this research. As one can read in Section 4.3, the model turned out to be very sensitive to even slight disturbances in this temperature. It is possible to effectively estimate the state for the proposed simplified models using only indoor temperature as the measurement.
In addition, the results of estimation errors (13) for the above-mentioned experiments are presented below. One can confirm the conclusions drawn regarding the reduced errors for the y m 2 chart —see Figure 9.
ϵ ( k ) = y ( k ) y ^ ( k )
It is worth noting that the PF calculations were performed in discrete time. The timeline on the presented waveforms has been scaled in such a way that it is possible to read the continuous time from it.

5.3. Heating and Normal Test

The next main test with the temperature control system was the heating and normal test. We take into account the scenario where the control u 1 takes one of two values, 90 % or 10 % . The desired temperature was 21.5   ° C . The tests were carried out in about 20 min. The results are shown in Figure 10.
The two-position temperature control (with hysteresis) was implemented. The algorithm of the particle filter takes into account the changes in the operating mode at each switch to ensure that the estimate would follow the measured value. Particle filter settings were selected based on previous observations for the heating and cooling test and separately for the heating and the cooling process. The width of the hysteresis was 0.52   ° C (which is a multiple of the thermometer resolution). Switching between models takes place more often than before, but it is still possible to observe the accurate tracking of the measurement signal by the estimate. The use of the particle filter can improve sensory information and thus the quality of control in a closed-loop system as well.

6. Discussion

Due to the simplicity of the assumed models, some features have been ignored, such as the nonlinearities of the system, the presence of two input signals at the same time, or the impact of the external temperature. This allowed for an effective implementation of an algorithm that operates with a real object on a device with low computing power. The mentioned features were effectively compensated for by the process noise generated in the particle sampling step. The heating process appeared to be more predictable, and the selection of parameters was unproblematic. The cooling process is also more complex to model.
The results were also obtained for various variances and temperatures (see Appendix A). They show that the assumed values of the process and measurement noise variance have a critical impact on the quality of the PF performance. If the value of σ v 2 is too high, the results affect the significant deviations of the mathematical model from the real object—in the particle sampling process, significant variance noise is added and later particles may not be able to match the actual measurements. For this research, better results were obtained in the case with lower variance values of the process noise (see Figure A1d,e, for example), which proves that the model is well fitted, despite its simplification. It is also shown by the correct operation of the algorithm and the good adjustment of the estimate to the measurements in the case of different temperature values (operating points), as one can see in Figure A1a,j.
The variance of the measurement noise is responsible for the inaccuracies of the sensor. In each test case, the best effects were observed for the σ n 2 value set comparable to the resolution of the measuring device. An overly high value of the setting resulted in the limiting of the confidence in the measurement in favor of the mathematical model. Ultimately, a compromise must always be made between trusting the model and the measurements. This allows us to compensate for any inaccuracies by the particle filter.
With correctly selected PF settings, a sufficiently large number of particles is needed for an effective state estimation. The number of particles must also be well suited to the computing power of the microcontroller to its capabilities.
In the case of precise process control, the use of feedback from the estimated value may improve the algorithm’s performance. Estimated values are commonly used in control, for example, in the active disturbance rejection control (ADRC) method [39]. Improving the sensory information may be necessary, for example, if the resolution of the measuring device is too low.

7. Conclusions

In the article, an analysis of the possibilities of using the particle filter algorithm in an embedded system was carried out on real-time tasks. For the experiments, a special platform was built. It provided opportunities to perform tests on a real physical object. The main goal was to determine whether a relatively old platform, such as the STM32F4 Discovery board, is capable of performing calculations using particle filters, known for their high hardware requirements. Research has shown that it is possible, even in real-time scenarios. Our current research is focused on the real-time scenario with a much shorter sampling time, especially in tasks associated with drones. It is planned to also extend the research to uncontrolled environmental conditions. In the future, it is planned to carry out tests under various environmental conditions, for example, at very low or very high outdoor temperatures, e.g., by placing the box in an oven or fridge. We also plan to improve the quality of the measurements performed by the UAV on-board sensors. The work presented in this article is preparation for this.

Author Contributions

Conceptualization, J.M.; Data curation, M.R. and P.K.; Funding acquisition, J.M.; Investigation, J.M.; Methodology, J.Z.; Project administration, P.K.; Resources, M.R.; Software, M.R.; Supervision, P.K. and J.Z.; Visualization, J.Z.; Writing—original draft, J.M. and M.R.; Writing—review & editing, P.K. and J.Z. All authors have read and agreed to the published version of the manuscript.

Funding

This research was financially supported as a statutory work of Poznan University of Technology (No. 0214/SBAD/0237).

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

Not applicable.

Conflicts of Interest

The authors declare no conflict of interest.

Symbols

knumber of a time step
x ( k ) state vector at the k-th step
x ^ j ( k ) estimated j-th state variable at the k-th time step
x j + ( k ) real value of the j-th state variable at the k-th step
x i , ( k ) i-th particle vector at the k-th step
q i , ( k ) weight of the i-th particle at the k-th step
u ( k ) input vector (control signals)
y ( k ) output vector (measurement signals)
Y ( k ) set of all measurement vectors, from the first to the k-th step
v ( k ) internal noises vector
n ( k ) measurement noises vector
f ( · ) vector of transition functions (linear or nonlinear)
g ( · ) vector of measurement functions (linear or nonlinear)
p ( · ) probability density function
N p number of particles
Mnumber of iterations
N ( μ , σ 2 ) normal distribution with the mean value μ and the variance σ 2

Abbreviations

The following abbreviations are used in this manuscript:
BPFbootstrap particle filter
FPUfloating point unit
IPCinstructions per cycle
PFparticle filter
PWMpulse width modulation
USARTUniversal Synchronous and Asynchronous serial Receiver and Transmitter

Appendix A

The additional section contains the results of the tests, which were briefly described in the main part of the document. Table A1 and Table A2 represent the names of the graphs and are correlated with their temperature and parameters (such as σ v 2 , σ n 2 or the number of particles N p ). The tests were aggregated into three groups with the following prefixes:
  • A—for tests performed at 22.0 °C;
  • B—for tests performed at 22.5 °C;
  • C—for tests performed at 23.0 °C.
This Appendix shows the results using Equation (10) because for (12) the quality is comparable regardless of the above factors.
Table A1. Details of the tests performed ( N p = 1000 ).
Table A1. Details of the tests performed ( N p = 1000 ).
σ v 2 σ n 2 Temperature
22.0 ° C 22.5 ° C 23.0 ° C
0.0100.005A-1B-1C-1
0.0050.005A-2B-2C-2
0.0010.010A-3B-3C-3
0.0010.001A-4B-4C-4
1.0000.100A-5
0.1001.000A-6
Table A2. Details of the performed tests ( σ v 2 = 0.010 , σ n 2 = 0.005 ).
Table A2. Details of the performed tests ( σ v 2 = 0.010 , σ n 2 = 0.005 ).
N p Temperature
22.0 ° C 22.5 ° C 23.0 ° C
100A3-1B3-1C3-1
500A2-1B2-1C2-1
1000A-1B-1C-1
Figure A1. Results from the various tests.
Figure A1. Results from the various tests.
Applsci 12 07631 g0a1aApplsci 12 07631 g0a1bApplsci 12 07631 g0a1c

References

  1. Vermesan, O.; Bahr, R.; Ottella, M.; Serrano, M.; Karlsen, T.; Wahlstrøm, T.; Sand, H.E.; Ashwathnarayan, M.; Gamba, M.T. Internet of Robotic Things Intelligent Connectivity and Platforms. Front. Robot. AI 2020, 7, 104. [Google Scholar] [CrossRef] [PubMed]
  2. Afanasyev, I.; Kolotov, A.; Rezin, R.; Danilov, K.; Kashevnik, A.; Jotsov, V. Blockchain Solutions for Multi-Agent Robotic Systems: Related Work and Open Questions. arXiv 2019, arXiv:1903.11041. [Google Scholar] [CrossRef]
  3. Villa, D.; Song, X.; Heim, M.; Li, L. Internet of Robotic Things: Current Technologies, Applications, Challenges and Future Directions. arXiv 2021, arXiv:2101.06256. [Google Scholar] [CrossRef]
  4. Gordon, N.; Salmond, D.; Smith, A. Novel approach to nonlinear/non-Gaussian Bayesian state estimation. IEE Proc. F Radar Signal Process. 1993, 140, 107. [Google Scholar] [CrossRef] [Green Version]
  5. Hendeby, G.; Karlsson, R.; Gustafsson, F. Particle Filtering: The Need for Speed. EURASIP J. Adv. Signal Process. 2010, 2010, 181403. [Google Scholar] [CrossRef] [Green Version]
  6. Asparouhov, T.; Muthén, B. Weighted least squares estimation with missing data. Mplus Tech. Append. 2010, 2010, 1–10. [Google Scholar]
  7. Dutra, B.; Silveira, A.; Pereira, A. Grasping force estimation using state-space model and Kalman Filter. Biomed. Signal Process. Control 2021, 70, 103036. [Google Scholar] [CrossRef]
  8. Wang, Z.; Gladwin, D.T.; Smith, M.J.; Haass, S. Practical state estimation using Kalman filter methods for large-scale battery systems. Appl. Energy 2021, 294, 117022. [Google Scholar] [CrossRef]
  9. Kalman, R.E. A New Approach to Linear Filtering and Prediction Problems. J. Basic Eng. 1960, 82, 35–45. [Google Scholar] [CrossRef] [Green Version]
  10. Kluge, S.; Reif, K.; Brokate, M. Stochastic Stability of the Extended Kalman Filter With Intermittent Observations. IEEE Trans. Autom. Control 2010, 55, 514–518. [Google Scholar] [CrossRef]
  11. Impraimakis, M.; Smyth, A.W. An unscented Kalman filter method for real time input-parameter-state estimation. Mech. Syst. Signal Process. 2022, 162, 108026. [Google Scholar] [CrossRef]
  12. Jiang, C.; Wang, S.; Wu, B.; Fernandez, C.; Xiong, X.; Coffie-Ken, J. A state-of-charge estimation method of the power lithium-ion battery in complex conditions based on adaptive square root extended Kalman filter. Energy 2021, 219, 119603. [Google Scholar] [CrossRef]
  13. Yang, S.; Zhou, S.; Hua, Y.; Zhou, X.; Liu, X.; Pan, Y.; Ling, H.; Wu, B. A parameter adaptive method for state of charge estimation of lithium-ion batteries with an improved extended Kalman filter. Sci. Rep. 2021, 11, 5805. [Google Scholar] [CrossRef]
  14. Peng, N.; Zhang, S.; Guo, X.; Zhang, X. Online parameters identification and state of charge estimation for lithium-ion batteries using improved adaptive dual unscented Kalman filter. Int. J. Energy Res. 2020, 45, 975–990. [Google Scholar] [CrossRef]
  15. Li, D.; Zhou, J.; Liu, Y. Recurrent-neural-network-based unscented Kalman filter for estimating and compensating the random drift of MEMS gyroscopes in real time. Mech. Syst. Signal Process. 2021, 147, 107057. [Google Scholar] [CrossRef]
  16. Elvira, V.; Martino, L.; Bugallo, M.F.; Djuric, P.M. Elucidating the Auxiliary Particle Filter via Multiple Importance Sampling [Lecture Notes]. IEEE Signal Process. Mag. 2019, 36, 145–152. [Google Scholar] [CrossRef]
  17. Arulampalam, M.; Maskell, S.; Gordon, N.; Clapp, T. A tutorial on particle filters for online nonlinear/non-Gaussian Bayesian tracking. IEEE Trans. Signal Process. 2002, 50, 174–188. [Google Scholar] [CrossRef] [Green Version]
  18. Michalski, J.; Kozierski, P.; Giernacki, W.; Zietkiewicz, J.; Retinger, M. MultiPDF particle filtering in state estimation of nonlinear objects. Nonlinear Dyn. 2021, 106, 2165–2182. [Google Scholar] [CrossRef]
  19. Llofriu, M.; Andrade, F.; Benavides, F.; Weitzenfeld, A.; Tejera, G. An embedded particle filter SLAM implementation using an affordable platform. In Proceedings of the 2013 16th International Conference on Advanced Robotics (ICAR), Montevideo, Uruguay, 25–29 November 2013. [Google Scholar] [CrossRef]
  20. Truong, M.T.N.; Kim, S. Parallel implementation of color-based particle filter for object tracking in embedded systems. Hum. Centric Comput. Inf. Sci. 2017, 7, 2. [Google Scholar] [CrossRef] [Green Version]
  21. Fortes, L.L.; Ayres, L.M.; Rocha, E.M.; Cuadros, M.A.; da Silva, J.R.; Freitas, R. Implementation of the Particle Filter in an embedded system for the localization of a differential mobile robot. In Proceedings of the 2018 13th IEEE International Conference on Industry Applications (INDUSCON), Sao Paulo, Brazil, 12–14 November 2018. [Google Scholar] [CrossRef]
  22. Xu, Y.; Deng, M. Particle Filter Design for Robust Nonlinear Control System of Uncertain Heat Exchange Process with Sensor Noise and Communication Time Delay. Appl. Sci. 2022, 12, 2495. [Google Scholar] [CrossRef]
  23. Patil, N.; Datar, R.G.; Patil, D.R. System Identification of a Temperature Control Process using Open Loop and Closed Loop methods. In Proceedings of the 2018 Second International Conference on Computing Methodologies and Communication (ICCMC), Erode, India, 15–16 February 2018. [Google Scholar] [CrossRef]
  24. Erazo, D.E.G.; Wallscheid, O.; Böcker, J. Improved fusion of permanent magnet temperature estimation techniques for synchronous motors using a Kalman filter. IEEE Trans. Ind. Electron. 2019, 67, 1708–1717. [Google Scholar] [CrossRef]
  25. Feng, G.; Lai, C.; Tjong, J.; Kar, N.C. Noninvasive Kalman filter based permanent magnet temperature estimation for permanent magnet synchronous machines. IEEE Trans. Power Electron. 2018, 33, 10673–10682. [Google Scholar] [CrossRef]
  26. Wang, Y.; Tian, J.; Sun, Z.; Wang, L.; Xu, R.; Li, M.; Chen, Z. A comprehensive review of battery modeling and state estimation approaches for advanced battery management systems. Renew. Sustain. Energy Rev. 2020, 131, 110015. [Google Scholar] [CrossRef]
  27. Simon, D. Kalman filtering with state constraints: A survey of linear and nonlinear algorithms. IET Control Theory Appl. 2010, 4, 1303–1318. [Google Scholar] [CrossRef] [Green Version]
  28. Candy, J.V. Adaptive and Cognitive Dynamic Systems: Signal Processing, Learning, Communications and Control. In Bayesian Signal Processing, 2nd ed.; John Wiley & Sons: Nashville, TN, USA, 2016. [Google Scholar]
  29. Kurz, G.; Gilitschenski, I.; Hanebeck, U.D. Recursive Bayesian filtering in circular state spaces. IEEE Aerosp. Electron. Syst. Mag. 2016, 31, 70–87. [Google Scholar] [CrossRef] [Green Version]
  30. Kozierski, P.; Lis, M.; Zietkiewicz, J. Resampling in Particle Filtering-Comparison; Poznanskie Towarzystwo Przyjaciol Nauk: Poznań, Poland, 2013. [Google Scholar]
  31. Kitagawa, G. Monte Carlo Filter and Smoother for Non-Gaussian Nonlinear State Space Models. J. Comput. Graph. Stat. 1996, 5, 1. [Google Scholar] [CrossRef]
  32. Zuo, X.; Dong, M.; Gao, F.; Tian, S. The Modeling of the Electric Heating and Cooling System of the Integrated Energy System in the Coastal Area. J. Coast. Res. 2020, 103, 1022. [Google Scholar] [CrossRef]
  33. Van der Heijde, B.; Fuchs, M.; Tugores, C.R.; Schweiger, G.; Sartor, K.; Basciotti, D.; Müller, D.; Nytsch-Geusen, C.; Wetter, M.; Helsen, L. Dynamic equation-based thermo-hydraulic pipe model for district heating and cooling systems. Energy Convers. Manag. 2017, 151, 158–169. [Google Scholar] [CrossRef] [Green Version]
  34. Wang, Z.; Luo, M.; Geng, Y.; Lin, B.; Zhu, Y. A model to compare convective and radiant heating systems for intermittent space heating. Appl. Energy 2018, 215, 211–226. [Google Scholar] [CrossRef]
  35. Kuznetsov, S.S.; Ryzhkova, E.A. On the Selection of a Control Law for Multiply Connected Inertial Objects. Fibre Chem. 2017, 49, 284–287. [Google Scholar] [CrossRef]
  36. Smith, S.; Seiler, P. Estimation with lossy measurements: Jump estimators for jump systems. IEEE Trans. Autom. Control 2003, 48, 2163–2171. [Google Scholar] [CrossRef] [Green Version]
  37. Li, X.; Ahn, C.K.; Lu, D.; Guo, S. Robust Simultaneous Fault Estimation and Nonfragile Output Feedback Fault-Tolerant Control for Markovian Jump Systems. IEEE Trans. Syst. Man Cybern. Syst. 2019, 49, 1769–1776. [Google Scholar] [CrossRef]
  38. Wu, Z.; Gao, Z.; Li, D.; Chen, Y.; Liu, Y. On transitioning from PID to ADRC in thermal power plants. Control Theory Technol. 2021, 19, 3–18. [Google Scholar] [CrossRef]
  39. Sun, C.; Liu, M.; Liu, C.; Feng, X.; Wu, H. An Industrial Quadrotor UAV Control Method Based on Fuzzy Adaptive Linear Active Disturbance Rejection Control. Electronics 2021, 10, 376. [Google Scholar] [CrossRef]
Figure 1. Flow chart of the Bootstrap particle filter algorithm with systematic resampling.
Figure 1. Flow chart of the Bootstrap particle filter algorithm with systematic resampling.
Applsci 12 07631 g001
Figure 2. The figure shows fully the built case. One can see internal peripherals (light-emitting diode (LED), thermometer) and an external thermometer placed on the top of the case.
Figure 2. The figure shows fully the built case. One can see internal peripherals (light-emitting diode (LED), thermometer) and an external thermometer placed on the top of the case.
Applsci 12 07631 g002
Figure 3. Technical sheet of the case. Only significant dimensions are shown.
Figure 3. Technical sheet of the case. Only significant dimensions are shown.
Applsci 12 07631 g003
Figure 4. Complete set of platform elements (placed in the case): STM32F4 evaluation board and peripherals such as two thermometers, light-emitting diode (LED), fan, and H-bridge.
Figure 4. Complete set of platform elements (placed in the case): STM32F4 evaluation board and peripherals such as two thermometers, light-emitting diode (LED), fan, and H-bridge.
Applsci 12 07631 g004
Figure 5. The performance comparison between platform. The results were obtained for M = 1000 and N p = 1000 ; M = 500 and N p = 1000 ; M = 500 and N p = 500 ; and single thread only.
Figure 5. The performance comparison between platform. The results were obtained for M = 1000 and N p = 1000 ; M = 500 and N p = 1000 ; M = 500 and N p = 500 ; and single thread only.
Applsci 12 07631 g005
Figure 6. Experimental results for 1000 particles; the measured value (red), estimated values from assumed models (blue and black), and outdoor measurement (gray); and the input signals.
Figure 6. Experimental results for 1000 particles; the measured value (red), estimated values from assumed models (blue and black), and outdoor measurement (gray); and the input signals.
Applsci 12 07631 g006
Figure 7. Experimental results for 500 particles; the measured value (red), estimated values from assumed models (blue and black), and outdoor measurement (gray); and the input signals.
Figure 7. Experimental results for 500 particles; the measured value (red), estimated values from assumed models (blue and black), and outdoor measurement (gray); and the input signals.
Applsci 12 07631 g007
Figure 8. Experimental results for 100 particles; plots of the measured value (red), estimated values from assumed models (blue and black), and outdoor measurement (gray); and the input signals.
Figure 8. Experimental results for 100 particles; plots of the measured value (red), estimated values from assumed models (blue and black), and outdoor measurement (gray); and the input signals.
Applsci 12 07631 g008
Figure 9. Comparison of estimation errors from B1, B21, and B31 experiments for model (10) (red) and (12) (blue).
Figure 9. Comparison of estimation errors from B1, B21, and B31 experiments for model (10) (red) and (12) (blue).
Applsci 12 07631 g009
Figure 10. Experimental results for 1000 particles; the measured value (red), estimated values from assumed models (blue and black), and outdoor measurement (gray); and the input signals.
Figure 10. Experimental results for 1000 particles; the measured value (red), estimated values from assumed models (blue and black), and outdoor measurement (gray); and the input signals.
Applsci 12 07631 g010
Table 1. Specification of the hardware platform used in the experiments.
Table 1. Specification of the hardware platform used in the experiments.
Platform AProcessorAMD Ryzen 7 2700 (3.20 GHz)
MemoryDDR4/64 GB
Operating systemMicrosoft Windows 10 (×64)
Platform BProcessorIntel Core i5 4210M (2.60 GHz)
MemoryDDR3/8 GB
Operating systemMicrosoft Windows 8.1 (×64)
Platform CProcessorIntel Atom D525 (1.80 GHz)
MemoryDDR3/4 GB
Operating systemMicrosoft Windows 7 (×64)
Platform DProcessorSTM32F407VGT6 (168 MHz)
Memory192 kB
Operating systemn/a
Table 2. Performance comparison between platform D (O) and D (S).
Table 2. Performance comparison between platform D (O) and D (S).
Number of Iterations Number of Particles Average Execution Time D (S) (ms) Average Execution Time D (O) (ms)
500 500 23,247 640
500 1000 46,374 1376
1000 1000 92,950 3112
Table 3. Comparison of the energy efficiency of the platform; the lowest value of Energy was marked by bold.
Table 3. Comparison of the energy efficiency of the platform; the lowest value of Energy was marked by bold.
PlatformProcessing Time (s)Consumed Energy (Wh)
A0.2490.0068
B0.2600.0030
C1.7670.0155
D (O)3.1100.0012
D (S)91.7500.0358
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Share and Cite

MDPI and ACS Style

Michalski, J.; Retinger, M.; Kozierski, P.; Zietkiewicz, J. Temperature Control Unit—Modeling and Implementation of a Particle Filter on a Microcontroller. Appl. Sci. 2022, 12, 7631. https://doi.org/10.3390/app12157631

AMA Style

Michalski J, Retinger M, Kozierski P, Zietkiewicz J. Temperature Control Unit—Modeling and Implementation of a Particle Filter on a Microcontroller. Applied Sciences. 2022; 12(15):7631. https://doi.org/10.3390/app12157631

Chicago/Turabian Style

Michalski, Jacek, Marek Retinger, Piotr Kozierski, and Joanna Zietkiewicz. 2022. "Temperature Control Unit—Modeling and Implementation of a Particle Filter on a Microcontroller" Applied Sciences 12, no. 15: 7631. https://doi.org/10.3390/app12157631

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop