Friday, April 15, 2016

Final Project Week 2

Partner: Katrina Montales

This week we finalized our order plans and worked on a mockup of our first prototype.

Material Order Plans:
  • We already have all the legos that we could need (stored in the lego cabinet)
  • weight sensor --> color sensor --> light sensor
    • The weight sensor was phased out of our plan, we decided we no longer needed to sense the weight of the marble, but have it release a marble on the set time interval.
    • The color sensor was prohibitively expensive ($40 of our $50 budget) Although Amy offered to buy it outside of our budget because she could use a color sensor in later classes, we found a way around our problem. Necessity breeds innovation, right?
    • We are trying to see if, just based on the sensitivity of the light sensor, figure out when the compartmentalized marble holder needs to be shifted over
  • We want a clear pipe to hold the marbles so we can see the various colors that correspond to the duration of different activities. The diameter of the marbles is approx. 9/16'' so we need a tube that has an inner diamater between 10/16'' and 1''.
  • 3 total motors + Arduino + Bricktonix shield for controlling the motors and feedback from the light sensor
  • Lastly, we need various colored marbles (to represent time)! 

Initially, we tried to minimize the number of motors needed to power the shifting mechanism. However, this would not have been possible with the way that the marbles fill the second container (orange).





So we created a model that has two motors shifting the marble containers, pushing them in opposite directions!








The second problem we tackled was using a light sensor. We needed to find a way to have the light sensor sense if there are were marbles left in the tube, or if it should shift to load in the next activity's marbles. 
Ideally, we would be able to have a light sensor right underneath the stack of marbles that could point upwards and sense if there were any remaining marbles that needed to be released. However, given the size and shape of the light sensor, this was not an option.



So we devised a plan to have the light sensor be shifted off center. With this plan, we would have to build up some legos on top off the face of the sensor so to protect it from marbles falling directly on the sensor. The idea behind this plan is that when all of the marbles of a specific color run out, then the light sensor will sense a high light value and shift the marble container over and release the next activity's marbles.






Alternate plan:
Attach the light sensor to a point behind the releasing mechanism so that when the light sensor senses that there is no marble there, then it will shift over the marble container (and also the bottom marble container).  If this doesn't work, we discussed using an ultrasonic sensor to sense the distance to the nearest object for marble detection. All trial an error, but hard to do without actual marbles!

In addition brown platform underneath the top container is fixed, functioning as the bottom of the marble container. However the marble container itself does not have a bottom, so that it can be shifted over, releasing the marbles simply through the use of gravity.







Also, I wrote out some pseudo-code for planning out how we should approach each part of our project. I find that it is much easier to take apart the problem in english, and then translate that into code rather than trying to balance it all in my head at once.

Thanks for reading! I'll update you again in a within week!

Thursday, April 14, 2016

MATLAB: So take of all your clothes~ (thermal systems part 2)

Partner: Katrina Montales

In this activity, we worked with an actual thermal system composed of the following parts:
  • heater - a 50 ohm resister powered by 18 V supply (we can control adjust the power) that converts electrical energy into thermal energy
  • thermal reservoir - the resister is inside a brass casing with good thermal conductivity (note: do not touch)
  • temperature sensor (thermistor) - has contact with the thermal reservoir, it is wired into a 10 kilo-ohm resistor, creating a "voltage divider circuit"
Baseline information about our specific thermal system (given):

Task 1: run the script test_thermal.m that runs for 300 seconds at 100% power (6.5 Watts) and calculate the unknown physical parameters Rth and C

test_serial code:

test_thermal code:

Resultant graph (note the little blips in the first run were due to disturbance in the environment (someone moving the thermal reservoir, changing the measured temperature)):
let the thermal reservoir cool down and ran the program again, no blips!






























Calculate Rth and C:
(for a refresher on these equations, see MATLAB: It's getting hot in here~ (thermal systems part 1))
Gut check your work:



The time constant is about 138 seconds.

The graph shows that y(300) = 378K and y(1) = 315K. Thus the time constant is the x value that corresponds to the y-value of (378K-315K)*(63.2%) = 39.82. Using a ruler, we determined that the value of time with a temperature change of 39.82 degrees is about 130 seconds, which is close to the calculated time constant value of 137.74 seconds.

In laypeople terms, we predict the heater will heat up 63.2% in 130 seconds, which is close to what the experimental data showed for 137 seconds. Not bad!

Task 2: Run Matlab simulation of the heatsim.m (using the Rth, C, and P that we calculated):

heatsim.m code:



(heatsim vs actual)



Ignoring the difference in scaling, the differences between the experiment and simulation were not that different. The simulation predicts that the heater could heat up at a rate much faster than in reality (perhaps due to environmental factors or delays). 

Task 3: Bang-bang Control -- modify test_thermal.m to change the power based on whether the measured temperature is above or below the target temperature (340K)

Bang-Bang experiment failed code (we never turned the heater back on):


Our failed bang-bang experiment:



Success!




Bang-bang simulation code:



Overall, the differences between the experiment and simulation are not all too large. There are more dramatized differences in the temperature changes when the experiment has the heater on and off, but this is probably because there are more delays between the actual temperature of the heater and the time that the sensor senses the temperature and adjusts the power. All in all, pretty closely well replicated results!


Task 4: Proportional Control
-review on proportional control-
error = target state - present state
set power = Kp * (target temp - T) when Kp is the proportional gain coefficient

Code for Simulation:


Code for Experiment:



Kp = 0.02, Simulation(top) and Experimental (bottom)




The simulation shows a very minor increase in temperature while the experiment shows even less or no change in temperature over the 300 seconds. What we can see in both the simulation and the experiment is that a proportional gain coefficient of 0.02 is far too little power to create significant temperature change, thus we never reach the control set point.























Kp = 0.2, Simulation(top) and Experimental (bottom)



The simulation shows a more gradual but constant increase in temperature from t=0 to t=50 while the experiment shows that the heater takes a little while to "heat up". In other words, there seems to be a small delay in the temperature increase in the experiment because the power takes a little bit of a buffer time to create an actual change in temperature. In both the simulation and experiment, we do not achieve the target temperature because the power (theoretical and actual) being supplied to the heater is still too small.




















Kp = 0.5, Simulation(left) and Experimental (right)

The simulation shows a very steep initial change in temperature in the first 50 seconds. In the experiment, we also see a very steep initial increase in temperature, but it is delayed a little bit, as seen in the previous experiment as the heater takes some time to heat up. In addition the slope of the rate of increase in temperature for the experiment is not as steep as that of the simulation because the experimental data is limited by reality. In reality, we are limited to 6.5 Watts of power. However, even if we put in an infinite amount of power (aside from all dangerous and actual problems with that), there would still be a limit to how fast the heater could heat up, making the slope of the temperature increase less steep than that of the simulation.

















When the gain is too small (0.05), the experimental results do not show a significant temperature change. If the gain is too high, the system behaves very similar to that of a bang-bang controller, since the thermal system is basically at full power until the target temperature is achieved, rendering the temperature graph for the first 50 seconds practically linear. (more power is not always better!) Thus, the ideal gain is somewhere between 0.2 and 0.5 so that we can reach the target temperature, but still more efficiently use the power.

Reflection:
In this assignment, we were able to see how the simulations and actual experimental results were similar and different. Although they are often very similar, there are a couple of differences due to limitations of reality -- such as delays and power limits. In addition, this was a great way to practice coding for bang-bang and proportional control because we were able to see the actual experimental results of code that was not correct. Thermal systems are not only interesting, but also important to the final projects tackling the problem of temperature regulation for people who can no longer do so. Just as in this assignment's experiments, there are limitations to how hot and how fast you can heat up someone while keeping everything safe. Just 100 years ago, houses were smaller because they could much more efficiently be heated and maintained at the ideal temperature because there was less air to heat-up and maintain. Thanks to modern technology and the implementation of ventilation systems, we have a bit more control over heating and temperature regulation, but we still have far to go! If you want to read more about modern air temperature regulation and heating in thermal systems, check out the nest -- the smart way to heat/cool your home that fluctuates as people are in or not in the home.

Animals have complex heat regulation systems too!



Monday, April 11, 2016

Final Project Week 1

Partner: Katrina Montales

Problem: For our final project, we are working to solve one of the problems of the Child Study Center (CSC). We want to create scheduling cues, a way to show/teach kids the concept of time. This entails visualizing how long an activity will be and how long it has been.

We were inspired by this video of a marble music machine.

Our goal: Help the children (ages 2 - 6) visualize how much time is left or has elapsed in an activity.

Benefit: Kids are able to understand how long is left without bothering the teacher. Conceptualize time and translate a concrete image of an amount of marbles to the abstract idea of time.

Original plan for marble releasing mechanism
Mechanism: A motor and Arduino/bricktonics shield controlled marble releasing mechanism. Our original plan was along the lines of this. However, when we started working with the legos we had, we found a track that we could use gears to regulate the release of one marble.

Sensing/Feedback/Control: We plan on using a weight sensor under the marble collector cup to tell the Arduino how much weight is in the cup and calculate how much time until the next marble should be released.


Note: Becky wanted us to find a way to keep the different marbles, representing different activities to stay sorted (so for easier resetting of the mechanism after the end of the day). In addition, she wanted two buttons: one that would release all of the marbles for one activity (effectively ending that activity, if, say, an activity ends early), and one to delay/increase the length of the activity (perhaps proportional to the number of times it is pressed.)

Physical Aspects to Create: A marble releasing mechanism, path for the marbles, rotating cup that holds the marbles to sort them by color.

Progress thus far:


Katrina turns our not yet functional motor by hand. 2x2 block is our fake marble.

Monday, April 4, 2016

MATLAB: It's gettin' hot in here~ (thermal systems part 1)


Partner: Katrina Montales

Thermal Systems:
(link to the background on thermal systems above)

**NOTE: all temperatures are in Kelvin**


Question 1: The Cooling Behavior



Consider the equation for dT:


If we increase Rth or C, then we expect the change in temperature to decrease (less steep of a slope)
Red is the given Rth, Blue is the program run with lower Rth


If we decrease Rth or C, then we expect the change in temperature to increase (more steep of a slope)




Question 2: Add a Heater
Suppose the coffee starts out at room temperature and we turn on a heating element that adds thermal energy to the system at a constant rate P.
Consider the following altered equation for dT:


Calculate a good value for P if we want our coffee to heat up to the Starbucks idea 84C, using the Rth from the MATLAB script:
dT = 0 = P  _ T - Tair
dt           C      Rth*C

T - Tair = P
   Rth

P = 64/0.85 = 75





Can we find C and Rth by working backwards?

Rth: At equilibrium, the heat from the heater is equal the the heat leaving the coffee into the room
So, P = Teq-Tair
                 Rth
Rth = deltaT(final) =  63K  = 0.84 K/W
                 P               75W

C: When t = 0, for a very short dt, there is only energy going into the system:
So, dT = dE = Pdt
                C       C
               dT = P
               dt     C
C =        P          =    75W    = 1000J/K
       initial slope    0.075K/s


Question 3: Bang Bang Coffee Heater Temperature Control
Bang bang control is appropriate for many thermal systems because they require a lot of energy and so, in some cases, it may be better to have the heater on high for a short period of time and then turn it off. However, this can be inefficient, as we see in the graph, when trying to maintain the coffee's temperature. (Even though it was efficient when we were heating up the coffee)

Question 5a: note about the code - modified to include a delay of 2 seconds to reflect a real world sensor delay. (the delay was modeled by the expression mod(t, delay) == 0, meaning every 2 seconds enter the loop and check the temperature)









w/ sensor delay:


(they look pretty similar, eh? That is because bang-bang control isn't changed much with a delay, see a larger change in proportional control)

*the red is the temperature of the coffee when the heater is on, the blue is when the heater is off*

Question 4: Proportional Control Coffee Heating
How does the proportional control approach compare to bang-bang control? This was different because the coffee was heated in a much more precise way -- meaning we were not heating the coffee at full power if it was near the ideal temperature (that would be wasteful!). With the delay, we were able to model and visualize when the heat sensor was actually measuring the temperature and adjusting the power.

The delay was modeled by the expression mod(t, delay) == 0 meaning the sensor would sense the coffee's temperature after every delay amount of time.





Proportional Control w/o delay:


(temperature after 1500 seconds on the heater)

Proportional w/ delay of 35s:


(temperature after 1500 seconds on the heater)

Proportional w/ delay of 45s:


(temperature after 1500 seconds on the heater)
Interestingly enough, the delay separated the times the heater was able to readjust the power output, allowing it to get closer to the ideal temperature (rather than inching at an increment too little to make a difference (remember nudge?)).

In the real world, one might expect there to be a sensor delays, computational delays (computer doing calculations, though that is super fast!), heater delay (warming up/cooling down), etc. Delays all over the place! (psst: this is why we use MATLAB to model the ideal situation)

Skills:

  • MATLAB plotting
  • while/if/for loops
  • delays in matlab
  • bang bang control
  • proportional control