In some scenario, PID control is not enough. Model Predictive Control (MPC) is another control algorithm that can handle complex systems.
What is Model Predictive Control (MPC)?
Model Predictive Control (MPC) is an advanced control algorithm that uses a dynamic model of the system to predict future behavior and optimize control inputs. It is widely used in process control, robotics, automotive, and other fields where complex systems need to be controlled.
The maths behind MPC is more complicated than PID. We will use an oven as an example to explain the MPC algorithm. Oven is a common household appliance and it is easy to understand as an example. Using a nuclear reactor as an example may be too daunting.
In this post, I will explain the MPC algorithm and how to implement it for an oven control system.
We will start by modeling the oven system, then discretize the model for implementation on a microcontroller. We will also consider disturbances like door opening and incorporate them into the model. Finally, we will simulate the MPC control strategy to regulate the oven temperature.
Identify the Key Variables
First, we need to identify the key variables that describe the oven’s behavior. These include:
- State Variable: Oven temperature
- Control Input: Heating element power
- Disturbances: Ambient temperature, door opening, etc.
The state variable represents the internal state of the system that we want to control.
The control input is the variable we can manipulate to achieve our control objectives.
Disturbances are external factors that affect the system but are not directly controlled. In the context of PID, disturbances are often either ignored, or handled by the integral term. In MPC, disturbances are explicitly modeled and accounted for in the control strategy. In the case of an oven, the ambient temperature and door opening can be considered as disturbances that affect the oven temperature.
Basic Heat Transfer Principles
The temperature dynamics of an oven can be modeled using principles of heat transfer, typically focusing on conduction and convection. The rate of change of the oven temperature can be described by an energy balance equation.
Conduction refers to the transfer of heat through a solid material, such as the walls of the oven. Convection refers to the transfer of heat between a solid surface and a fluid (e.g., air) moving over the surface. In the case of an oven, convection is the dominant mode of heat transfer.
We would only consider convection in this simple model.
The heat transfer rate can be described by Newton’s Law of Cooling, which states that the rate of heat transfer is proportional to the temperature difference between the object and the surrounding environment. The simple equation of heat transfer can be given by:
Where:
is the overall heat transfer coefficient. is the oven temperature at time . is the ambient temperature.
Energy Balance Equation
Where:
is the oven temperature at time . is the power of the heating element at time . is the efficiency of the heating element (fraction of electrical energy converted to heat). is the thermal capacity of the oven (amount of energy required to change the temperature). is the overall heat transfer coefficient (accounts for heat losses to the environment). is the ambient temperature.
Thermal Capacity
Heat Added
Heat Lost
By putting them all together, the formula is like a balance between how fast heat is being added and how fast it’s being lost. If more heat is being added than lost, the temperature will go up
Discretize the Model
Microcontrollers operate in a digital environment, meaning they process data in discrete time steps, e.g. every millisecond.
Continuous-time models, like differential equations, cannot be directly implemented on digital systems without discretization. For implementation in a digital controller like MPC, the continuous-time model needs to be discretized.
Assuming a sampling time
Where:
is the oven temperature at the -th sampling time. is the heating power at the -th sampling time.
To use this model, the parameters
Example Calculation
Assume we have the following parameters:
- Thermal capacity
- Efficiency
- Heat transfer coefficient
- Sampling time
- Ambient temperature
For an initial oven temperature
Refining the Model
In practice, the model can be refined by considering additional factors like heat losses due to door openings, non-linear effects, and more complex heat transfer mechanisms.
In the following section, I will use adding door opening as a disturbance to refine the model.
Adding Door Opening as a Disturbance
Let’s denote the door opening event as a binary variable
To know that the door is opened, an additional sensor is also needed, such as a switch or a proximity sensor.
Next, we should model the heat loss due to the door opening. When the door is opened, a significant amount of heat escapes. This can be modeled as a term proportional to the temperature difference between the oven interior and the ambient temperature. This model only considers the convective heat loss through the open door.
Let
Where:
is a coefficient representing the rate of heat loss when the door is open.
Next, we incorporate this heat loss term into the energy balance equation.
Originally, the energy balance equation was:
The modified energy balance equation including the door opening effect becomes, adding the heat loss term
Expand the heat loss term
Then, discretize the modified continuous-time model to get the discrete-time model:
The maths is done, now let’s see an example calculation.
Let’s assume the following parameters for the door opening effect:
Given:
- Initial oven temperature
- Heating power
- Ambient temperature
- Door opening status
(door is open)
Using the modified discrete-time model:
Substitute the values:
Here, the oven temperature drops significantly due to the heat loss when the door is opened.