Monday, April 4, 2016

MATLAB: Thermal Systems

Task:

In this exercise, we will be looking Newton's Law of Cooling in relations to the change in temperature of a cup of coffee.

Newton's Law of Cooling: dE/dt = -k(T-Tair)
     - the negative sign in front of the constant k indicates energy leaving a system

Effort and Flow: R = deltaV/I = "effort"/"flow"
     - change in voltage over current equals resistance

Using Newton's Law of Cooling and voltage across objects with a current I, we can rewrite an equation for Rth, thermal resistance, and the change in energy of a system during a change in time, dt.

1: Changing Rth and C

How does the cooling behavior change if we vary the parameters Rth and C?
dT = ((T-Tair)/(RthC))*dt

  • dT: change in temperature
  • T: initial coffee temperature
  • Tair: ambient temperature
  • Rth: thermal resistance
  • C: heat capacity
  • dt: time step



If either Rth or C are increased, dT will increase because they are both inversely proportional to dT.

This is what the code looks like of the equation above from time = 0 to the maximum 1500 seconds.

To the left are two graphs of decreasing Rth and C.  Decreasing either one of the other, or both, results in a quicker decrease in temperature.

The picture on top is of decreasing Rth.

The picture below is of decreasing C.  In that graph, C is decreased more than Rth was in the graph above giving the graph a quicker decrease in temperature.
















Let's take a look of what would happen if Rth and C are increased.

The graph to the right above is of increasing Rth while the one below is of increasing C.  Again, C is increased more.

By increasing Rth and C, the drop in temperature becomes more gradual, to a point where the decrease in relation to time seems very linear.

2: Adding a Heater

Calculate a good value for P if we want our coffee to heat up to the Starbucks ideal 84 degree Celsius, using the Rth form the MATLAB script.

dT = dE/C = ((P/C) - ((T-Tair)/(RthC)))*dt

  • P: power/speed


Magnolia, Vivian and I rewrote the equation above for P.  We coded it in our script and set constants for the other values.  Using MATLAB, P was calculated to be 75.

3: Temperature Controller - Bang Bang

Write a script using bang bang control to reach and maintain the desired temperature of 84 degrees Celsius.  Why is bang-bang control appropriate for many thermal systems and when might it be insufficient?

Bang-bang control ensures the temperature is at the said temperature because bang-bang continuously turns on and off to reach and maintain goal temp.  However, it is insufficient because with only two settings of on and off, it can be both annoying and impractical.
































Code reads:
If temperature is less than 357 Kelvins, the energy going in the system (heater) is power times the time step.  The energy going out the system is ((T-Tair)/Rth)*dt.  The resulting energy of the system the energy coming in minus the energy coming out.  But if the temperature is equal to or greater than 357 Kelvins, no energy is going in and will begin to lose heat but needs to maintain the desired temperature.



This is what the graph looks like of the coffee reaching the desired temperature and maintaining that temperature using bang bang.  Because this is bang-bang control, once the desired temperature is reached, the temperature continuously drops and goes up to maintain that temperature.

The graph below is a zoomed in picture of the graph above to show the changing temperature.















4: Temperature Controller - PID

Create a program that uses proportional control to reach and maintain the desired temperature.  How does this approach compare to bang-bang control?

Like always, PID is a lot smoother than bang-bang.  Using what we learned from using proportional control to control our SciBorg a week ago, we used the same equation to integrate it into our MATLAB program for this problem.





























Code reads:
The temperature difference is the goal (final equilibrium rate) minus the ambient temperature.  With trial and error, we multiplied the temperature difference with 25/17 and added B, our gain constant.  Those two equations make up the PID control.  In our terminal, our temperature difference was calculated to be 0.1321.


Using proportional control, this much smoother graph of reaching the desired temperature was created.

A continuous drop and increase in temperature is no longer apparent now that bang-bang is not used.







5: Delay

Modify the program so that there is a delay time between when the coffee reaches the given temperature and when the temperature sensor records that temperature.































Code reads:
We set the value of n, and if that value minus delay, which we set a value for above in the code is greater than 0, then we used PID control to reach the desired temperature while adding in the delay time.  Otherwise, the power is 0, which will be seen in the first ~400 seconds on the graph to the right.  If the power supplied by the heater is greater than vmax (max speed), then the power is set to be the max speed.




1 comment: