Tuesday, April 16, 2013

Final Project: Testing of Critical Elements

Today was all about testing key elements. For our project (music reader), these important parts were the photo cells and the mechanism that moved the sheet music (scroll) along.

1.) Photocells:

We first obtained 8 photocells so that the sensor mechanism can detect 8 different notes. We attached these pieces with Lego (the photocells are connected to Lego pieces). Jamie drew black circles on a white sheet of paper to check if the photo cells were able to report different numbers for when they detected white and black.

Our photocells (music reading mechanism)

We checked with the photocells to see how wide the scroll would have to be.

We drew black dots and gray dots (gray dots did not work well at first). On white, the numbers reported were in the low 800's, whereas on black surfaces, numbers around high 800 - low 900 were shown.

We then noticed that the photocell mechanism cast shadows on the white paper. To solve this problem, we thought we should build a "shield" around the photocell mechanism. However, this still cast a shadow, so we decided to use a LED light (flashlight) to make the surface (the mechanism would be focusing on) brighter.

We created this temporary "shield" with sticky note pads.

Our photocell mechanism with the "shield" (still temporary) and the LED light.

We tested the photocells to white and black surfaces.

We used PICO Cricket to program the photocells. 


Our program on PICO Blocks. We learned to program in text (versus using the blocks). We made the music reader (still in progress) chirp whenever the photocells detected light (number became greater than 550).

Conclusion:
We got to the point where we programmed four of the eight photocells to play a sound when it detected a light with value of more than 550. We also made it so that the four notes were different (in pitch).

2.) Scroll Moving Mechanism:

We had ideas of having a conveyor belt-like mechanism but decided to build a mechanism that would unwind and move the scroll (sheet music) along. 

We first tried to punch holes on the scroll ends and attach to these Lego pieces (scroll ends). But the pieces that stuck out prevented the scrolls from rolling in circles (there were occasional jerks in movement), so we tried to hold the paper in place by using paper clips. This method also failed because the paper clips were not secure (kept moving about the Lego rod). 

(Paper clip method did not work. This also created jerks in movement.)

Another problem was that we held the motor and the scroll parts to test the movement but soon realized this was not the best way to test this critical element. Therefore, we built a temporary base for the music reader with Lego pieces mainly for stability and to estimate the size of our music reader (since this scroll moving mechanism would take up the most amount of space). 

Our temporary base for the music reader.

We also realized there were jerks in the movement because the scroll was not long enough (we had taped two pieces of paper for greater length). Instead, we went to the library and obtained a longer piece of paper. 

(The video files were too great in size, so I could not upload them).

Conclusion: Obtaining a longer piece of paper (which we need anyway to have a full song) and the constructing of the base improved the mechanism and allowed for smoother movement. 





Friday, April 12, 2013

Final Project: Goal, Brainstorming, Research, Pugh Chart

Group: Hannah, Jamie, Punzi (Julia)

Goal: 

Initial rough sketch.

We wrote down our goal to make sure we knew what we were doing and where we were heading. We also added some scribbles and rough sketches to brainstorm. We thought of having conveyor belts, photo cells, and wondered if we wanted actual music notes or "guitar hero-like notes" for our sheet music.


(Rewrote our goal to be clearer and more organized.)

We talked to different professors about light sensors (photo cells, mindstorm NXT light sensors, etc.) and about programs (PICO blocks or MATLAB) as part of our research to determine which methods or ways would be ideal for our music player/reader.


Our Pugh Chart.

We created a Pugh chart to compare different methods or parts and decided we were going to use simplified natural music notes for our sheet music, photo cells for our light (black vs. white) sensing mechanism, and PICO/LOGO to program our music reader.


More on Part A: Sensor and Programming

We were brainstorming and researching. We broke down our goal into three parts: (a) sensor and programming, (b) feeding and structure, and (c) ambitious goals. Our idea was that the photo cells would detect the black music notes while there is some motor or belt mechanism that moves the sheet music (scroll) along so the device can read and play a simple piece. 



Ideas on structure. (Will probably be modified.)

Ambitious Goals.

Brief Reflection:

I really enjoyed going through these engineering processes because it really helped me understand what I was doing and became more interested and passionate about my assignment.

Wednesday, April 10, 2013

Random


Worked with Bromothymol Blue (indicator) in Chemistry 205 Lab. Had fun creating these solutions. Writing the lab report was not fun.

Thermal Systems Part II


Deliverable 1:
A blog post (or section of a post) containing a MATLAB figure,
such as the one below, showing your experimentally measured heating curve along
with a derivation of the thermal parameters that you have deduced from the figure.
You should also document your time constant, and how the expected time for the
system to respond, based on that time constant, matches the actual time.

Our experimentally measured heating curve 

Values deduced from the curve above:
Rth (thermal resistance) = 18.897 K/W
C (heat capacity) = 5.476 J/K

time constant = Rth * C = 103.479972 J/W (expected)
actual time constant = 63.2% (426.5633 K - 303.7299 K) = 77.6307 J/K
They didn't match because there were several areas of possible errors (such as the error from calculating the initial slope). 

In physical terms, the time constant is defined as the time required for the system
to reach ~63.2% of its final asymptotic value.

------------------------------------------------------------------------------------------------------------

Deliverable 2: 
Your modified heatsim.m program, which generates
simulated heating curve. Comment on the ways in which the results of the
simulation agree and / or disagree with the experimentally measured results.

Modified program. (Title should be %simulation of resistor.)

Plot for the program above.

Our simulated heat curve was a lot smoother with a steeper slope until the temperature stabilized. It was a lot smoother because in real life, temperature is constantly changing due to various factors, which is why the experimentally measured plot has more oscillations. 

------------------------------------------------------------------------------------------------------------

Deliverable 3: 
Implement a bang-bang controller in MATLAB with a target
temperature of 340 K. How does the behavior of bang-bang control in actual
thermal system compare to the simulation you did last time? (You’ll need to insert
the correct values of the thermal parameters into your simulation.) Include the
answer to this last question as a comment at the beginning of the MATLAB script
you submit.


The bang-bang control causes more obvious oscillations, which is reasonable. The heat curve above showed the heating of the metal resistor until it reached its hottest point. Here, with the bang-bang controller, we had a target temperature, and in order to reach that target, power was turned on and off depending on the "current" temperature at the moment (of course, there would be some delays). 



Bang-bang controller program (We need to include more comments next time.)

Plot from our bang-bang controller

------------------------------------------------------------------------------------------------------------

Deliverable 4: 
You should turn in your results, the main one being the graphical
comparison of the simulation and experiment. Provide a short description of each figure so we
know what the data are. You should also include the MATLAB scripts that you
used to create these figures, identifying the values of the heat capacity and thermal
resistance that you deduced. Also make sure to answer the bulleted questions
below.

• Can you explain why the system does not reach the control set point when
the proportional gain is small? 
This is because if the gain is too small, the system errors or disturbances become significant and prevents the system from reaching the set point. Even when the error is large, not enough power is supplied. 

• How does the system behave when the proportional gain is high? 
When the proportional gain is too high, too much power is applied even when that amount of power is not desired (when the error is small). We do not want full or large amounts of power for the whole time. 

• What seems to be the “optimal” gain setting for your system? 

To determine the "optimal" gain for our system, first, we thought about the initial point. Our starting temperature was about 303K, while our target temperature was 340 K. This meant that the difference in temperature or our error was about 37K. To reach 340K, we needed full power which would be 100 (in percent but is actually 6.5 W in real life). 

100 = gain * 37
gain = 2.7

Our program for the Proportional Controller

Plot for the Proportional Controller

The proportional controller definitely had smaller, more unnoticeable oscillations than the bang-bang controller had. Also, compared to the experimentally obtained plot which immediately started heating up, the proportional controller had a smoother rise to this target temperature. 

Our proportional controller (with blows)

You can see that the blows caused larger oscillations, but the temperature returned to 340K or a value close to 340 K, which was what we wanted. 

------------------------------------------------------------------------------------------------------------

Deliverable 5:
Your final MATLAB script that controls the temperature of the system. Make
sure to add lots of comments explaining what your program is doing.

• Relevant experimental data, in the form of well-labeled graphs, from your
constant temperature hot-wire anemometer experiments. Your graphs should
make a compelling case for how well (or perhaps not well) your hot-wire
anemometer is working.

• Your simulation of a PI controller and a comparison to the experimental
data.

Our program using PI controller (both proportional and integral)

At first, we struggled with the gain values and noticed our target temperature was not reached or was surpassed. We realized that the "error" was significant in our "if then" statement because this "error" affected the integral error. (At first, we used integral error in our if then statement.) Also, we were initially experimenting with only the integral gain values. However, we realized we also had to change the normal gain (proportional gain) also.

Final Values: 
proportional gain = 2 (slightly less than 2.7, which was what we used for our proportional controller)
integral gain = 0.35 (after experimenting with 0.2 and 0.5). 

Plot for our PI controller

We noticed the oscillations were fewer and more spread out compared to our proportional controller and bang-bang controller. Also, compared to our experimentally obtained plot, this plot was a lot smoother. 

Plot after blowing 

The blow caused some oscillations, but the controller made the temperature return to a value close to 340 K, the target temperature. This plot looked similar to the plot created by the proportional controller after blowing. 


------------------------------------------------------------------------------------------------------------












Monday, April 1, 2013

Thermal Systems Part I

After reading and trying several exercises on MATLAB, we were given a packet on thermal systems to work on.


Question 1: How does the cooling behavior change if we vary the parameters Rth
and C? Figure this out using intuition and the above equations, and then vary these
parameters in your program to confirm your conclusions.

Answer:

By looking at the equation, dT/dt = -(T - Tair)/(Rth * C), one can see that as Rth increases, it requires more "effort" required to lose energy. Similarly, as C (heat capacity) increases, it becomes "harder" for the coffee to lose energy (or heat), shown by a smaller change in temperature (measure of transfer of heat).

I varied these parameters in my program to confirm my conclusions. I changed Rth to 0.95 (versus 0.85) and noticed T-Tair or delta T was smaller in magnitude. I noticed similar results when I increased the value of C.

Program Used:


Question 2: Calculate a good value for P if we want our coffee to heat up to the
Starbucks ideal 84°C?

Answer:




Working backwards. Given a plot like the one above, can you deduce the thermal
parameters C and Rth ?

One could determine Rth because at a given T (dT/dt = 0),one knows Tair, P is given, C cancels out, and T can of course be read from the plot.

One could also determine C because one can find an approximate value of dT/dt by looking at the slope of the curve in the beginning (because dT/dt is clearer there). Also, P is given, T can be read from the plot, Tair is given, and Rth is given. 


1) Modify the above programs to simulate a temperature controller that uses
bang-bang control to reach and maintain the desired temperature. Bang-bang
control is a very common approach for thermostats. Why is bang-bang control
appropriate for many thermal systems? When might it be insufficient?

Bang bang control is appropriate for many thermal systems because bang bang control either turns on or off the power whenever a limit is reached (temperature is too high or too low). For many thermal systems (like the ones inside our homes), this oscillation is not significant. It is okay for our houses to be a couple of degrees off from the temperature we want. However, for thermal systems that must be more exact (with little to basically no oscillations), bang bang control would be inefficient.



2) Create a program that uses proportional control to reach and maintain the
desired temperature. How does this approach compare to bang-bang control?
Using proportional control makes a system run a lot "smoother" without any noticeable back and forth (power on and off) movements or oscillations. First, it take some time to reach the desired the temperature, but the system stays at that temperature. Bang bang control makes sure the temperature (at the moment) stays within a range. When a limit is reached (the inequality), the system tells the power to either turn on or off completely. With proportional control, the feedback is in proportional (directly related to) to the error or the degree of divergence from the target (what we want). 

3) Suppose there is a delay between the time the coffee reaches a given
temperature and when the temperature sensor records that temperature. Modify
both of your programs to include this effect, along the lines of the programs on the
next few pages that I showed in class, which explore the effect of adding a “sensor
delay” to a simulation of moving a SciBorg lego car a particular distance. What is
the impact of this “sensor delay” on your system in each case? What other delay(s)
might you expect in your thermodynamic system, apart from sensor delays?

Bang-bang control with delay:

Bang bang control with sensor delay makes the system take longer (in terms of time) to turn on or off the power to stay within a range. Thus, the oscillations are more spread out. 

Proportional control with delay:

Proportional control with sensor delay has a small bump on the plot because the delay causes the system to keep increasing or decreasing the temperature until it realizes (after the delay time) that the temperature has passed the desired/target temperature. Then, the system decreases or increases to adjust to the target temperature.

Other delays may include delay for the heater to actually begin the heating process and the delay from the thermometer (to measure the temperature at that moment and report the temperature value).



Thursday, March 28, 2013

Hiking

Mt. Liberty in New Hampshire
I hiked there over spring break, and it was a tiring but also a great experience.


Modeling & Simulation

We learned the basics of Matlab using the first four chapters of Allen Downey's Physical Modeling in MATLAB.

(Will add more screenshots soon...)

We had several assignments from the book:

  • Exercise 2.1: fibonacci1 script
  • Exercise 2.3: car_update script
  • Exercise 3.1: car_loop script
  • Exercise 3.2: car_loop script with plotting.  Also try initial values of a & b = 10000
  • Exercise 3.5: fibonacci2 sequence script
  • Exercise 4.6: plotting fibonacci ratios
  • Experiment with the following simulation of the trajectory of a hit baseball. For what angle is the horizontal distance maximized? 
-------------------------------------------------------------------------------------------------------------------------------------------------------------
For Exercise 2.1 , we broke down the Fibonacci term formula into smaller parts (by assigning variables to represent each part) to make the program easier to debug. We also allowed the user to enter the desired value of n (to determine the nth fibonacci number). I've read about and learned the very basics of Python and realized program languages can be different yet similar.


Exercises 2.3, 3.1, 3.2 combined: We were given two locations (Albany and Boston) and the rates of car movements (3% and 5% respectively). We used a for loop to continue the exchange until a certain number of weeks. (The user was able to type in his/her desired number of weeks.) Since the total number of cars was 20,000 (by the conservation of cars), we assigned b(i+1) as 20,000 - a(i+1). 

Exercise 3.5: This was our second Fibonacci sequence assignment, where we had to use a for loop to compute the first 10 elements of the sequence. We allowed the user to enter the number of terms, so this program would work for any term of the sequence. 


Exercise 4.6: This was our third Fibonacci sequence assignment, and here, this program computes a vector (X) with the first n elements of a Fibonacci sequence and then computes a new vector (R) that contains the ratios
of consecutive Fibonacci numbers. The user was able to enter the value of n. This was one of the more challenging programs to write because I found it challenging to create vectors (I really had to read and reread the section on vectors to better understand the concepts). We discovered that the value of convergence was about 1.618 (golden ratio). 

Trajectory of a Hit Baseball

Program:

% Model of trajectory of hit baseball. Assumes no air drag. 
% What angle maximizes the distance travelled? 

clf % clear the previous figure
hold on % allow plotting of multiple figures
angle = 30; % angle baseball hit, in degrees
velocity = 45.5 % initial velocity of baseball, in meters/sec
rads = angle * pi / 180;
velocity_x(1) = velocity * cos(rads); % horizontal velocity of baseball
velocity_y(1) = velocity * sin(rads); % vertical velocity of baseball
x(1) = 0; % x position of batter
y(1) = 1; % assume baseball hit 1 meter off ground
dt = 0.1; % time step for simulation, in seconds
g = 9.8; % gravitational constant, in meters/sec^2
i = 1 % iteration index
while y(i) > 0 
    x(i+1) = x(i) + velocity_x(i)*dt; % Update x position 
    y(i+1) = y(i) + velocity_y(i)*dt; % Update y position
    velocity_y(i+1) = velocity_y(i) - g*dt; % y velocity changes due to gravity
    velocity_x(i+1) = velocity_x(i); % x velocity doesn't change (assume no air drag)
    plot(x(i), y(i), 'r.-');  % display a red dot for each point, and connect them with lines
    i = i + 1; % change index for next iteration
end
x(i) % Display the final x value.

Although this was not the best method, I used the "trial and error" method. From physics, I had learned that 45 degrees would give the largest horizontal distance. However, using this program, 44 degrees gave a larger horizontal distance value than 45 degrees did. So, I substituted in different values (close to 45 degrees) for the angle and determined that the largest x(i) or the horizontal distance was 262.8410 (when angle = 45.5 degrees).

I will try to determine a better way to solve this program, perhaps by using some maximum function/tool.