Wednesday, May 11, 2016

Thermal Systems Part 2

This was week 2 of thermal systems on MATLAB
Last time we simulated a thermal system of a cup of coffee on a hotplate, this week we are working with a real life thermal system! By using: a heater (whose power we controled), a thermal reservoir (with a resistor in a brass casing aka a "heat sink"), and a temperature sensor/thermistor.

Deliverable 1. Calculate the physical constants: using "testthermal.m" (given) find the two parameters: thermal resistance Rth and heat capacity C.

According to our math, our theoretical time constant is a little higher than the true time constant, but this makes sense since we had to estimate when calculating the slope that was used to find C.

After we found the physical constants Rth and C we experientially measured the heating curve with these new thermal parameters.


Deliverable 2.We then modified our heat simulation from last week to fit our new thermal parameters

The simulation and the experimental are pretty similar even though they are scaled differently when we look at them closely the slopes are almost identical. The biggest difference is the the fact that the experimental graph does not start at an initial temperature of 0. The peak temperature for experimental is 335K and simulated is 327K which is a difference, but not significant enough to be too concerned.

Deliverable 3. We then started to experiment with different types of control, starting with bang bang we modified test.thermal.m to change the power supply based on whether the measure temperature is above or below the target temperature.

Table of peak temperature

Experimental Bang Bang
Simulated Bang Bang
The main difference between the simulated and the experimental bang bang is the extremity of the temperature change, which in part has to do with the scale and the long amount of time it takes to heat things up in real life. Both the simulated and the experimental show the temperature reaching the "peak" or "goal" temperature then bouncing back and forth, as expected with Bang Bang control.

Deliverable 4.Then we implemented a proportional controller for a target temperature of 340 K using Kp= 0.05, 0.2, and 0.5 W/K


Kp=0.05
Kp=0.2
Kp=0.5
Upon looking at the graphs we can tell that the system does not reach the control set point when Kp is small, which makes sense because of the nature of proportional control to correct more and more once it is close to the goal, but due to Kp being too small it never reaches goal, which means it cannot correct and will be stuck never reaching the control. In this specific example the increases are so small that it plateaus before it even reaches control.
Conversely when Kp is high it tends to overshoot the control quickly, but then it takes a while to find it's way back. Considering this knowledge and the graphs .2 seems to be the optimal gain for our system because it is a happy median between the small .05 and the large .5

Final MATLab thoughts!
This week's real life thermal systems was far more complicated than last week's simply because of the nature of real life systems, we sometimes forgot to wait long enough for it to fully cool down which lead to many inaccurate results that we thought was our code.

Final Project Week 1

Our final project is to create a product that would solve a problem for either the Child Study Center (CSC) or Jim Wice from disability services. On 3/18/16 we visited the child study center where we learned about some problems to fix. The main overarching topics are:
Health & Safety: making the CSC safer whether it's physically or mentally
ex: making the locks in the bathroom easier to use and making the flushing sound not as loud so children do not get scared.

Independence: fostering self driven behavior and discipline in children
ex: creating a device that alerts children when play time is over so they will not need to rely on teachers.

Improving Quality of Life: making the CSC more organized so more time is spent learning and playing
ex: making the CSC less noisy during quiet times or organizing the game cabinet so children get more time with toys and teachers.

Our next task was to brainstorm  3 ideas to implement in the child study. 
Our three ideas all addressed different problems
1. Problem: Kids are not tall enough to reach the top self of their cubbies to put their art projects away.
Solution: Create a movable step that the kids can use to get to the top of the cubby, there would be a control and feedback reward system with lights to tell the kids to put the cubby back.

2. Problem: Children sometimes splash the water in the "tubs" of water out of the container. 
Solution: Create a water sensor and alert system that would let the teacher know if the water level has lowered. This would also be useful to tell if the container might be leaking.

3. Problem: The children do not like washing hands and do not spend the appropriate amount of time washing their hands.
Solution: Create a sensor system which would play a song to a kid when they come near the sink to alert them to wash their hands. 

Tuesday, April 5, 2016

Thermal Systems

This week we simulated a thermal system using matlab, specifically a cup of hot coffee.

1. Simulation of a cooling cup of coffee
We found that when we varied parameters Rth and C:
Higher Rth and C= smaller dT and thterefore the less the temperature will change
Lower Rth and C =larger dT and therefore the more the temperature will change

Original Coffee Plot R=.85 C=10,000
Coffee Plot Rth=10


Coffee Plot Rth=.15

Coffee Plot C=50

Coffee Plot C=1,000,000
2. Let's add a heater
We found that if we want our coffee to heat up to the Starbucks ideal 84 degrees C
This was calculated by using the equation (shown below) and isolation the value P with
T=375 because that's what we want the coffee temperature to be (the heater temperature)
We then incorporated the heater into the program to see hoe the heater effected the program and we could deduce that: 
Rth is the change in final temperature divided by P, which means that final temperature difference depends only on P and Rth. And at equilibrium energy into the system is balanced by energy out.
C is equal to P times dT/dt so at t=0 the slope of the graph is equal to P/C

3. Feedback and Control: Bang Bang
Bang Bang control is appropriate for many thermal systems because it either turns on or off which is good because we only need it to do one thing set the temperature in the room equal to the value inputted, but it is insufficient because if the temperature goes over the right temperature it will have to keep turning itself on and off to again reach the goal temperature.


A zoomed in picture of the plot


4. Proportional Control
Compared to Bang Bang, Proportional control takes a far longer time to reach the desired temperature, this is due to the very nature of proportional control which "slows down" once it gets close to the goal. These models makes sense because in real life thermometers use bang bang control instead of proportional control, and when we compare the graphs it takes ~800 seconds for Bang Bang and ~3000 seconds for Proportional.



5. Add delay:
In reality are are tons of delays because nothing is instantaneous, so we modeled the delay between the time the coffee reaches a given temperature and when the temperature sensor records the 
temperature.

Proportional Control:
The impact of the sensor delay for proportional is that there are no temperature measurements for the first ~450 seconds and then there is a huge jump that then goes back down to a more stable (but still slightly fluctuating) temperature.


Added delay for Bang Bang:
The impact of the sensor delay is that the graph is shifted to the right. This makes sense because bang bang is just "on or off" so the delay in sensing should not change the shape of the graph.



Other delays that we should consider in a thermodynamic system is the time it takes for the heater itself to heat up.

Friday, April 1, 2016

MATLAB Introduction

 Matlab is a computing program that is widely used by engineers for modeling. Or as Allen Downey likes to call it: "a glorified calculator.
First exercise:
Exercise 1   The Fibonacci sequence, denoted F, is described by the equations F1 = 1, F2 = 1, and for i ≥ 3, Fi = Fi−1 + Fi−2. The elements of this sequence occur naturally in many plants, particularly those with petals or scales arranged in the form of a logarithmic spiral.
The following expression computes the nth Fibonacci number:
F_n=(phi^n-(-phi)^(-n))/(sqrt(5))
(1)
=((1+sqrt(5))^n-(1-sqrt(5))^n)/(2^nsqrt(5)),
We accomplished this task by putting the equation into matlab and checking it by plugging numbers into the program.




Exercise 2
Imagine that you are the owner of a car rental company with two locations, Albany and Boston. Some of your customers do “one-way rentals,” picking up a car in Albany and returning it in Boston, or the other way around. Over time, you have observed that each week 5% of the cars in Albany are dropped off in Boston, and 3% of the cars in Boston get dropped off in Albany. At the beginning of the year, there are 150 cars at each location.
Write a script called car_update that updates the number of cars in each location from one week to the next. The precondition is that the variables a and b contain the number of cars in each location at the beginning of the week. The postcondition is that a and b have been modified to reflect the number of cars that moved.

Our first inclination was to use an exponential function, which in theory works but in practice we realized that it did not update, so we made it instead to have:
anew = a - 0.05*a + 0.03*b; % albany cars after certain number of weeks
bnew = b + 0.05*a - 0.03*b; % boston cars after certain number of weeks



Exercise 3
Create a script named car_loop that uses a for loop to run car_update 52 times. Remember that before you run car_update, you have to assign values to a and b. For this exercise, start with the values a = 150 and b = 150.
If everything goes smoothly, your script will display a long stream of numbers on the screen. But it is probably too long to fit, and even if it fit, it would be hard to interpret. A graph would be much better!

Exercise 4
Modify car_loop so that each time through the loop it plots the value of aversus the value of i.
Once you get that working, modify it so it plots the values of a with red circles and the values of b with blue diamonds.

Exercise 5
We have already seen the Fibonacci sequence, F, which is defined recurrently as
Fi = Fi−1 + Fi−2 
In order to get started, you have to specify the first two elements, but once you have those, you can compute the rest. The most common Fibonacci sequence starts with F1 = 1 and F2= 1.
Write a script called fibonacci2 that uses a for loop to compute the first 10 elements of this Fibonacci sequence. As a postcondition, your script should assign the 10th element to ans.
Now generalize your script so that it computes the nth element for any value of n, with the precondition that you have to set n before you run the script. To keep things simple for now, you can assume that n is greater than 0.

Exercise 6
The ratio of consecutive Fibonacci numbers, Fn+1/Fn, converges to a constant value as nincreases. Write a script that computes a vector with the first n elements of a Fibonacci sequence (assuming that the variable n is defined), and then computes a new vector that contains the ratios of consecutive Fibonacci numbers. Plot this vector to see if it seems to converge. What value does it converge on?