# How to create a model for temperature control?

I have a heated compartment, inside which, there is another object heated up by independent heater. I want to control temperatures of both chamber and the object.

I could achieve this by simple PID (or PI) controllers for both chamber and object, but I would like to try more thoughtful approach :) I have two temperature sensors, and two PWM outputs for heaters. How do I identify a model for an object I want to control?

Generally you would only develop a model if (as in your case), you have something that you want to control. In that case, you should start by:

1. List the outputs that you want to control.
2. List the inputs that you can modulate.

In your case, you want to control chamber temperature and object temperature. You can modulate the chamber heater and the object heater. Now, you have to ask yourself:

1. How do the inputs affect the outputs? You should shoot for an equation in the form of $\mbox{[outputs] = f(inputs)}$

This is important because you generally only want to model the things that are pertinent to the task at hand.

For example, say you want to develop cruise control for a car. The output you want to control is vehicle speed and the input you can modulate is throttle position. Can you model coolant reservoir level? Sure, but you can also assume the coolant system is functioning normally. Can you model the internals of an automatic transmission? Sure, but you can also assume that the automatic transmission gives output power equal to input power minus some losses.

The point is, you have to make some set of assumptions about the "nominal" scenario. Once you have your initial model, you attempt to validate the model by getting test data. Typically this means feeding an actual system a particular set of inputs and recording the response, then feeding the same inputs to your model and recording the response. The results should be (very close to) the same. How close is "good enough" depends on your application, and could be anywhere from "it generally trends the same" to virtually no error.

You can try developing a rudimentary controller around an unvalidated model if you've got time to kill, but you should generally wait for validation before expending a lot of effort on the controller because math errors and faulty assumptions can cause you to have to start over with controller development.

You can also skip the mathematical description if the system is too complex to be described mathematically, or if doing so would take too much time. "Empirical modelling" runs a similar sort of tests you would use to validate a model, but with the concept that, by seeing how a particular set of inputs create an output, you can derive some pattern that you can extrapolate a model that gives outputs for other inputs.

In your case, if you're really concerned with better control, I would probably suggest trying to build an empirical model. Try a variety of inputs on only one heater and record how that impacts chamber and object temperatures. Then do the same on the other heater. Best case is the effect of each heater is decoupled or weakly correlated to the other temperature - the space heater only heats the space and the object heater only heats the object. In that scenario you can have independent control, though I would imagine this would probably only happen if you had significant chamber losses relative to the output of the object heater and/or the chamber had a large thermal mass relative to the object.

And on a final note, I'll just add that, when gathering test data for a particular model, you should try varying all of the "nominal" conditions that you assumed to make sure it doesn't have an effect you should be modelling. For you, that would probably mean checking the ambient air temperature around the chamber is varied through all of the expected conditions. As I mention above you're probably more likely to achieve independent temperature control with large chamber losses (because your heaters are not bi-directional; they only make heat and cannot remove it), and the chamber losses are going to be related to ambient temperature. Testing in only hot weather (or vice-versa) will skew your results, model, and thus controller to a point that it might not be useful when the weather changes.

• Your answer is great. In addition to your response, it is noteworthy that temperature control is a non-linear control problem, which deserves some thought outright, and the dynamics of heat transfer/dissipation must be taken into account in the controller. For insulated chambers, this will be very important because it will be easier to increase temperature than to decrease it; this asymmetry will require consideration, and if nothing else, make sure that the closed-loop system is overdamped so that you might avoid this problem. Jun 17 '16 at 14:53

Chuck is right; you need to build a model so that you can appropriately choose your controller.

Temperature control is non-trivial because the underlying dynamics are non-linear. Because heat transfer has been studied extensively (see thermodynamics), you may be able to build a decent model for your system using only existing models and parameter characterization of your specific system. However, if this doesn't work for you, perhaps your system is too complex or non-linearities are not modeled correctly, you can apply machine learning to learn the model of your system.

The task of learning the model of your system is a regression task. Gaussian Process Regression will work, but k-Nearest Neighbors is a good place to start. The link is very thorough on how GPR is and can be used--KNN is on wikipedia. You will still need data from your system, but using GPR or some other machine learning technique will have the benefit of not requiring hand-crafting your model.

I know it sounds like a lot of work, and it might be overkill for what you are trying to do, but by using ML to build the model, you can confidently apply a non-linear controller--linearization may or may not be possible.

Classical modelling techniques like "PID control" are based on mathematical equations. That makes them difficult to implement. A better way for modelling heated compartment is to use object oriented design. An example for modelling a printer with python uses variables which represents the internal state and methods for statechange of the physical system. Its a little bit like designing a computer game.

It the simulation works, a solver is needed. The solver uses sampling techniques (brute-force-search) for reaching a given goal of the system. For example: if the object inside the heater should stay within a temperature range of 150 and 180 degree, the solver generates random inputs to the systems until some of them results into the given output range. A good example of how a naive physics engine works is given in the computergame "The Sims" where an oven can be set on fire.