1. Introduction
The energy consumption of buildings includes electric energy for air heating and cooling, lighting and domestic water heating, which account for around 30% of the global energy consumption [
1]. In the European Union, the energy required to heat domestic hot water accounts for approximately 15% of the total energy consumption in the residential sector [
2]. As the electric efficiency of most buildings can be significantly increased, relevant societal impacts can be obtained by reducing energy consumption [
3,
4]. Two approaches have been proposed to promote energy savings: (i) by installing more energy-efficient equipment in buildings; or (ii) by managing energy consumption efficiently using sophisticated control strategies in automation systems [
3].
Gas instantaneous heating devices are widely used in domestic hot water production [
5] and are essential for daily activities such as personal hygiene, cleaning, and bathing. However, one of their limitations is the difficulty of keeping desired hot water temperature setpoints when changes in water flow occur. These changes are usually very fast and unpredictable, severely affecting the users’ perception of comfort. When the user imposes a sudden increase in the hot water flow rate, tankless gas water heaters (TGWHs) are not able to provide such flow, ensuring high-performance temperature control, which results in lower temperatures than the ones desired by users for some (non-negligible) time. This scenario is identified as a temperature undershoot. A similar scenario occurs when a steady flow is followed by a sudden reduction in the requested water flow, and a temperature overshoot occurs [
6]. Some of the latest and most advanced TGWHs include feedback controllers with flow and temperature sensors. However, manufacturers currently use control strategies that cannot provide high-performance responses to sudden changes in water temperature for variations in the required flow rate, mainly because it is challenging to deal with inertia, fast water flow changes and nonlinear fluid dynamics [
6]. Temperature stabilisation of TGWHs has been pursued by including additional hardware, namely bypass valves, mixing valves and reservoirs working as thermal capacitances [
6,
7]. The classical feedback controllers, proportional and proportional-integral-derivative (PID), are inappropriate for the temperature control of TGWHs [
8]. Some authors propose using advanced control techniques not requiring mathematical modelling, such as fuzzy logic control [
9,
10] and artificial neural networks [
11,
12]. In this scope, neuro-fuzzy control was also proposed to overcome the complexity of mathematical problems [
13,
14]. Classic model predictive control (MPC), adaptive MPC and gain-schedule MPC have also been proposed for water temperature control [
5,
8,
15]. Yuill, Henze and Coward [
16,
17,
18] focused on control strategies for electric water heaters, from classical techniques, such as PID control, to more advanced techniques, such as predictive control. For heat pumps, several studies have focused on predictive control to increase user comfort, improve energy efficiency, and reduce costs and gaseous emissions [
19,
20,
21], while other investigations have focused on researching new refrigerant mixtures and regulating operating parameters [
22,
23]. Additionally, Garcia and Chua [
24] proposed using a hybrid model composed of a gas and electric water heater for fast hot water supply responses while decreasing energy consumption and CO
2 emissions. Finally, Bobál et al. [
25,
26] implemented a Smith predictor control approach for heat exchangers. However, the Smith predictor requires an accurate estimation of models and dead time; moreover, it is susceptible to the linearisation operating point and designed for fixed time delays.
MPC is a promising strategy for the temperature control of buildings because it can predict the dynamic states of processes [
6,
27]. Included are the optimisation of both the thermal and electric energy supplies [
28], minimisation of energy consumption or operating costs [
29], optimisation of energy costs of entire buildings [
3], and optimisation of temperatures for air-handling units [
30] while ensuring thermal comfort. However, MPC requires a significant computational overhead to solve complex and nonlinear problems, such as those found in gas water heaters. Although predictive controllers have already been designed to outperform the combined feedforward–feedback controllers usually implemented in these devices [
15,
16,
31], their use has yet to be established by manufacturers of TGWHs due to the computational and memory resources required by MPC.
Modern microcontrollers can be used to implement complex control algorithms [
32]. As the computing capacity of microprocessors increases and electronic control units (ECUs) become more sophisticated, MPC has become feasible even for hard control applications [
33]. However, MPC algorithms’ fast and efficient software development relies on automatic code generation for quick code deployment on the selected hardware platforms [
34].
Several tools are available to solve MPC problems. First, quadratic programming (QP) solvers, such as qpOASES [
35], MOSEK [
36], ECOS [
37], OSQP [
38] and ODYS QP [
39], can effectively be used. Second, tools such as CVXGEN [
40,
41,
42,
43], FORCES [
44], FiOrdOs [
45] and QPGEN [
46] were developed to optimise the code of quadratic programming solvers. The CasADi [
47] tool generates an efficient implementation of nonlinear optimisation problems. Furthermore, tools such as µAO-MPC [
48], GRAMPC [
49], HPMPC [
50] and ACADO [
51] also use QP solvers and perform optimised automatic code generation for implementation in hardware. The MultiParametric Toolbox 3.0 [
52] generates code for implementation in software, although it is limited to explicit and constrained MPC designs in which online optimisation is not required. The AutoMATiC tool [
34] is a code-generation software package for implementing MPC algorithms on microcontrollers with low processing and memory resources. The Matlab/Simulink environment also provides toolboxes for automatic code generation. The Simulink Coder allows the generation and execution of C code from Simulink models. Embedded Coder generates optimised code for embedded systems, enabling hardware-in-the-loop (HIL) simulations.
Recent breakthroughs highlight that automatic code generation is an essential tool to produce highly efficient solvers customised for specific problems, such as those requiring the incorporation of MPC algorithms [
53]. The key to overcoming challenges related to devices with limited resources is to employ efficient algorithms with the ability to exploit the computational performance capabilities of target platforms [
54].
A preliminary simulation study was recently provided by Ehtiwesh et al. [
5] regarding the development of classic and adaptive MPCs to improve the performance of TGWHs in transient regimes. Here, we propose for the first time the development and implementation of predictive control techniques to be embedded into low-cost microcontrollers, ensuring improved users’ thermal comfort and reduced water and energy waste in response to temperature variations. First, we designed a classic MPC and an adaptive MPC, providing improved performances compared to the results achieved by Ehtiwesh et al. [
5]. A different TGWH appliance was considered, and improvements were performed to solve implementation problems, namely in the linear model and the successive linearisation approach. Then, the classic MPC controller was implemented in two low-cost microcontrollers using automatic code-generation tools and HIL simulations. The static feedback–feedforward controller was chosen as a benchmark, as TGWH manufacturers commonly use this control technique. Significant improvements were achieved as the controllers were implemented and tested on a real microcontroller with limited features. Finally, a new metric to analyse the users’ comfort is also proposed. The investigation presented in this paper highlights the significance of employing predictive control techniques to enhance the performance of TGWH systems, with a focus on minimising environmental impact and enhancing user comfort. As a result, this study contributes to the potential advancements in domestic water heaters, particularly for residential applications.
3. Results and Discussion
3.1. Simulation Results
FFPID, classic MPC and adaptive MPC controllers were evaluated in three cold start scenarios: 3.65 L/min, 5.10 L/min and 6.55 L/min. Two scenarios expressing maximum water flow rate changes were analysed: from 2.2 L/min to 8 L/min and from 8 L/min to 2.2 L/min.
In the cold start scenarios (
Figure 5,
Table 2), the rise time and settling time decreased as the flow rate increased, regardless of the control strategy, due to the dynamics and time delays of the system. This pattern highlights that higher comfort indexes are achieved for higher flow rates, which results in higher efficiencies and reduced waste of water and energy throughout the non-comfortable period. A negligible overshoot was observed when the adaptive MPC was used, differently from what was observed when the other controllers were used, highlighting the predictive MPC behaviour. The lowest comfort index was obtained using the FFPID control, whatever the simulated flow rate. The adaptive function allowed higher comfort indexes and lower overshoots, except for the intermediate flow rate of 5.10 L/min, where similar behaviours were observed between predictive controllers. This occurred because the linear solution of the MPC was linearised for a 5 L/mi flow rate, which contains the same delays as the average operating flow rate. Differently, the adaptive control allowed to overcome performance losses related to operating points far from the chosen nominal operating point.
In flow change scenarios (
Figure 6,
Table 3), temperature undershoots and overshoots occurred due to intrinsic system delays, regardless of the control strategy. Concerning the flow rate increasing scenario, the FFPID provided a slightly lower undershoot relative to responses obtained by two predictive control strategies. Shorter settling time was obtained using adaptive MPC compared to both responses obtained by the FFPID and linear MPC controller, which resulted in a higher comfort index found by the adaptive MPC. Indeed, the feedforward–feedback technique showed higher ISE, demonstrating the predictive controller’s superior ability to keep the temperature closer to the setpoint during the 60 s after disturbances. Regarding the flow rate decreasing scenario, the FFPID also achieved a lower overshoot. However, its settling time was about 11 s longer than the one obtained using the linear MPC, which required about 23 s longer than the adaptive MPC. Lower ISE was also observed for adaptive MPC compared to the responses of MPC and FFPID. The classic MPC obtained the lowest comfort index, as its behaviour expressed undesirable oscillations.
A progressive improvement of comfort levels from the solution currently used in gas water heaters to the adaptive MPC solution was achieved, as presented in the comfort graphical representation illustrated in
Figure 7. Average comfort indexes of 58.7%, 67.9% and 78.2% were obtained for the FFPID, linear MPC and adaptive MPC controllers, respectively. These results highlight that the predictive behaviour of the MPC controller holds the potential to provide high-performance responses related to system delays, ensuring a superior anticipation ability for fast power transitions after changes in the flow rate.
The simulation results provide valuable insights into the performance of different control strategies in various scenarios, namely for cold start and flow rate changes. Adopting adaptive MPC control strategies can significantly improve user comfort and energy efficiency (assessed by lower rise time, settling time, and overshoots/undershoots), highlighting its superior predictive behaviour. In some scenarios, the linear MPC presents similar performance, especially when the flow rate is close to the nominal operating point, while FFPID control consistently performs less effectively. Regarding flow rate, higher flow rates generally lead to improved comfort indexes and shorter rise times and settling times, regardless of the control strategy, because of the associated shorter time delays. In summary, these results suggest that by adopting predictive control strategies, more efficient and responsive systems can be achieved, leading to higher comfort and lower environmental impact.
3.2. Embedded Control Results
Implementing the MPC controller on low-cost microcontrollers can be a challenge due to memory and computation time constraints, and to overcome these limitations, optimisation strategies are essential. Results related to the linear optimised MPC solutions for implementation on hardware are reported hereafter, exposing the strategy to implement them. The implementation of the adaptive MPC controller was not possible using automatic code generation due to the high memory requirements. Therefore, the choice of microcontroller depends on the specific requirements of the control system and available computational resources.
The following strategy was used to implement the MPC controller in the Atmel SAMD21 microcontroller: (a) using a suboptimal solution and restricting the number of iterations in the MPC solver improves the controller responses, only requiring a 0.1% increase in the required memory; (b) decreasing the control and prediction horizons improves the controller response while significantly decreasing the memory requirements. The MPC solution optimised for the Atmega2560 microcontroller exceeded its available SRAM memory by 26.8%. Therefore, the strategy was successfully improved as follows: (i) reducing the control and prediction horizons, which have a fundamental impact on SRAM memory; (ii) linearising the plant for the maximum operating flow rate (8 L/min), as this is the flow rate with the shortest delays, and the absorption and conversion to states into system matrices decreases the plant model size.
Table 4 shows the Flash, SRAM memory and MPC parameters, for the Atmel SAMD21 and Atmega2560 microcontrollers. The FFPID controller is relatively light-weight in terms of memory usage on both microcontrollers, as it consumes a small percentage of both Flash and SRAM memory. The MPC controller requires significantly more memory, consuming a higher percentage of Flash and SRAM memory, especially in the Atmega2560 microcontroller, which highlights the inherent complexity of implementing this control strategy in low-cost hardware. Although FFPID is simple and relies on traditional control algorithms, predictive controllers require solving optimisation problems at each control step, which consumes a large amount of resources.
The temperature responses in cold start scenarios (
Figure 8) reveal faster responses of the predictive control. Moreover, the predictive controller was also able to provide: lower or equal rise times (
Table 5); lower settling times, except for the minimum flow rate scenario (2.2 L/min); lower overshoot, except for 2.2 L/min and 3.65 L/min; and consistent lower ISE and higher comfort indexes (except for 2.2 L/min). Concerning the implementation in the 32-bit microcontroller, the highest comfort difference occurred in the average flow rate, which was approximately 24% higher for MPC. Moreover, a 15% higher comfort index was obtained for the 8-bit microcontroller (when 6.55 L/min is requested).
Concerning the flow rate increasing scenario (
Figure 9), the MPC controller reached the desired temperature faster than the FFPID controller after disturbances. However, the response improvements obtained with an 8-bit microcontroller are noticeable as the flow rate increase occurred for the linearisation flow rate. Results obtained with the 32-bit microcontroller highlight that, although the MPC controller achieved a settling time 3 s longer than the FFPID controller, it provided a 1% lower undershoot and a 4% higher comfort index, as well as a significantly lower ISE, making it able to provide responses closer to the desired temperatures 60 s after disturbances (
Table 6). Regarding the implementation in the 8-bit microcontroller, the settling time decreased by 12 s, which was lowered by 8 s compared to the FFPID. Additionally, the comfort index increased by 5% relative to the one obtained for the 32-bit microcontroller, which is 9% higher than the technique currently used. Significant lower ISE and slightly lower undershoots were achieved for both controllers when the MPC controller was used.
Concerning the flow rate decreasing scenario (
Figure 9), a performance loss was expected using the 8-bit microcontroller, as the flow rate change is performed at the minimum flow rate, the opposite of the limit flow used in plant linearisation. The results show a longer settling time using the predictive controller, about 6 s and 10 s for the 32-bit and 8-bit microcontrollers, respectively (
Table 6). However, significantly lower ISE and overshoots were observed using the MPC controller for both types of low-cost hardware. The comfort index obtained in the 32-bit microcontroller was about 0.6% lower using the MPC controller due to its oscillating characteristics. However, the predictive controller presented a comfort index about 4.1% higher when implemented using the 8-bit microcontroller.
A graphical representation of the comfort the user would feel during HIL simulations is presented in
Figure 10. The comfort improvement using the MPC controller is noticeable in most HIL simulations, mainly in the cold start scenarios. Using the overall comfort index as the average of the considered events, a 55.4% comfort index for the FFPID controller and 62.2% for the MPC controller were obtained in the 32-bit microcontroller; concerning the 8-bit microcontroller, 55.9% for the FFPID controller and 60.1% for MPC controller were observed. The implementation of the MPC algorithm on the lower-performance hardware made it possible to provide higher user comfort.
4. Conclusions
This work describes the development of predictive temperature control strategies: (i) to reduce the temperature overshoot and undershoot effects of instantaneous water heaters, which usually occur during significant flow rate changes; and (ii) to reduce the rise time in cold start scenarios, such that the amount of wasted water can be reduced. Their performance was analysed both in simulation and HIL environments, in which the predictive controller was successfully embedded into two low-cost microcontrollers, such that it can be incorporated into gas water heaters by manufacturers.
Temperature overshoots and undershoots were not completely eliminated, as the water demand cannot be predicted, and the system is characterised by time delays. Even so, MPC controllers (in particular the adaptive one) were able to provide faster responses to disturbances and lower rise times in cold start scenarios, which result in lower water and energy costs, lower environmental impacts (gaseous emissions) and increased user comfort, as the duration of uncomfortable water exposure is minimised. The classic MPC controller’s performance was dependent on the operating point chosen for plant linearisation, which exhibits a superior performance. The use of successive linearisation at each instant (adaptive MPC) allowed to overcome limitations occurring when operating points are far from the chosen nominal operating point; significantly improved performances over the entire water heater operating range can be obtained. For the lowest flow rate, the performance of MPC was significantly inferior, which demonstrates the significant impact of model mismatch, particularly with time delays, and the advantage of adaptive control.
Although the predictive control requires more computational and memory resources than the FFPID control, the classic MPC controller was successfully embedded into two low-cost microcontrollers, namely 8-bit and 32-bit platforms, using an automatic code-generation tool. Similar conclusions were obtained using both a simulation environment and the HIL simulation environment incorporating these microcontrollers: (1) the predictive controller is able to reduce rise and settling times at cold starts, which can provide a significant reduction of water consumption and energy costs, as well as a relevant increase in the user comfort; (2) the predictive controller is able to provide shorter settling times and higher comfort indexes for sudden changes in water flow rates.
TGWHs have a long service life, up to 20 years, and the degradation of actuators’ performance, along with water flow restriction due to calcium build-up, has a significant impact on the appliance dynamics in the long term. One advantage of adaptive control strategies is the self-adaptation to the deterioration of plant dynamics, which is not achieved with fixed model-based control strategies, such as FFPID or classic MPC.
Future work should be conducted to assess the experimental performance and effectiveness of the developed MPC controller using real water heaters. The proposed predictive control strategy should be incorporated with other water heater control tasks, such as safety features and the control loop for the air–gas mixture; this must be performed in partnership with a TGWH manufacturer. These tests are relevant to analyse the impact of various plant characteristics that can only be considered in a real scenario, such as the time between disturbance events and the disturbance detection performance. Additionally, the adaptive MPC must be successfully embedded into low-cost microcontrollers, as it will most likely provide higher performances than classical MPC controllers. Investigation of the microcontroller requirements can help to define a more suitable hardware for the adaptive embedded implementation. A study that evaluates and compares new advancements in real-time solvers and code-generator tools built explicitly for embedded MPC should also be carried out, considering the control of TGWH. The generic code-generation platform produces excessive redundant code, and more specific and efficient tools must be employed for an optimised implementation.