Energy Management Using Deep Learning-Based MPC - MATLAB
Video Player is loading.
Current Time 0:00
Duration 8:09
Loaded: 2.03%
Stream Type LIVE
Remaining Time 8:09
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected
    Video length is 8:09

    Energy Management Using Deep Learning-Based MPC

    Learn how to control a house heating system using nonlinear model predictive control (MPC) with a data-driven prediction model. In this control problem, try to minimize energy costs while maintaining the house temperature within a certain temperature range by utilizing MPC’s preview and constraint handling capabilities. You will learn how you can train a neural state-space prediction model just in a few lines of code and then use the trained model as the internal prediction model in the nonlinear MPC controller.

    Download the code and model used in this video: Energy Management Using Deep Learning-Based MPC

    Published: 10 Mar 2023

    In this video, we will show you how to control a house heating system using model predictive control with a neural safe space prediction model. Here, we see a high fidelity model of the house heating system that we're trying to control using the nonlinear NPC block. The house heating system models the heater and the thermal dynamics of the house.

    The heater input is a value between 0 and 1. And the house is subject to external disturbance, the outdoor temperature modeled by a sine wave. The control objectives in this problem are to maintain the house temperature between 20 and 22 degrees Celsius and minimize energy costs. For this problem, NPC is a better choice than traditional control as it can handle input and output constraints and has predictive capability.

    We'll utilize constrained handling for keeping the heater inputs and house temperature within certain values. And with NPC's preview capability, we'll minimize energy costs using weather forecasts and time of use electricity pricing data, which is shown in this plot. The heating cost is most expensive between 10:00 AM and 9:00 PM.

    So by taking this information into account, NPC will try to minimize the cost. NPC solves the constraint optimization problem at each time step using a prediction model, which can be challenging to obtain analytically as is often the case with house heating systems due to their complex dynamics. In such situations, we can create a data-driven prediction model, which we will demonstrate next by training a neural state space model.

    The neural state space model will represent the nonlinear dynamics shown by xStart with a neural network. The workflow we're going to follow is shown here. We start by loading the data by running this section. This data can be collected from either the real system or the high fidelity simulation model as is the case here.

    The data is used in the next section for training the neural state space model. We use the idNeuralStateSpace command to define a neural state space model with one state, two inputs, and sample time of 300 seconds. We then configure the state network and specify the training options for the network and train it. Once the training is complete, training loss and validation plots are generated.

    From the latter, we see the training took approximately 5 and 1/2 minutes. Also, note that the trained model shown in blue is not completely accurate. But this is acceptable because NPC can adjust for the discrepancy with feedback. In the next section, running this command automatically generates the MATLAB function that evaluates the state function based on the trained neural state space model as shown here.

    Now, we're ready to move on to the NPC design. In this section, we specify the sample time and prediction horizon, and then create a multi-stage non-linear NPC with one state, house temperature, one manipulated variable, heater input, and one measure disturbance outdoor temperature. We set the names for the state MV and MD. We specify the neural safe space prediction model for the controller.

    We then define the cost functions for the different stages of the controller. Looking at the cost function, we see that it consists of three terms. The first term is to minimize the cost of electricity. The second term is used to implement soft bounds on the desired temperature range. And the last term minimizes rapid changes in the heater input.

    We then specify an inequality constraint function, which is to maintain the house temperature within the prespecified lower and upper bounds. Setting soft bounds will allow small violations of these constraints. Thus, making the optimization problem easier to solve. In 2023a, we introduced automatic differentiation, which lets you generate Jacobian functions automatically.

    Using this command, we autogenerate the Jacobians for the state, cost, and inequality constraints. Prior to 2023a, you would either let the software calculate Jacobians automatically through numerical perturbations, which are slow. Or you would need to provide the Jacobian analytically, which can be challenging and error prone. Next, we specify the constraints on the manipulated variable, the heater input to keep it between 0 and 1.

    Finally, we validate the NPC object we have created. Since there is no issues, we can now move to our Simulink model to simulate the system with the designed controller. We specify the controller object in the multi-stage non-linear NPC controller block. The inputs to this block are the measured output, the manipulated variable from the previous time step, the measured disturbance, which is the outdoor temperature forecast computed by this block, and finally, the electricity pricing forecasts provided as stage parameters to the NPC controller block.

    We're now ready to run the Simulink model and take a look at the simulation results. This first plot shows the measured house temperature in purple. The upper and lower bounds for it's in blue, and the outside temperature in yellow, which indicates a cold day. On the second plot, we see the heater input generated by the non-linear NPC controller.

    As expected MV is kept within 0 and 1. And the last plot shows the fluctuation in the electricity price throughout the day with the price rising at 10:00 AM. NPC's previous capability allows it to utilize this information to preheat the house in advance and maximize the indoor temperature prior to the 10:00 AM price increase. As we see from this plot, it then turns off the heater until the house temperature drops to about 20 degrees Celsius.

    Note that we make the output bounds soft so the temperature is allowed to slightly go below the bound. In the rest of the simulation, NPC maintains a temperature close to lower bound to minimize energy costs. Once you're happy with the designed controller, if you want to generate code for deployment to embedded hardware, you can right-click the non-linear NPC block. Select C/C++ and Build This Subsystem.

    Once the code is generated, we can view it from the code generation report. In this video, we showed how you can design an NPC controller with a neural state space prediction model for a house heating system to optimize energy costs while maintaining house temperature within a desired range. This concludes the video.

    View more related videos