Tuesday, April 14, 2015

Matlab 2


To further our understanding about MATLAB, we had to show a code that simulates how a cup of coffee cools to room temperature. The code and resulting graph. The graph plots time on the x axis and the temperature of the coffee on the y axis. Note all temperature is in Kelvin.

Question 1: How does the cooling behavior change if we vary the parameters Rth (thermal resistance) and C (heat capacity)?

 If you increase Rth and C, the coffee will retain more heat and the graph will decrease slower and the coffee will stay hot longer.
Rth increased from .8 to 2.85 while C stayed the same.

Rth stayed the same, while C increased from 1000 to 2000
Rth increased from .85 to 2.85 and C increased from 1000 to 2000
On the other hand, if C and Rth decrease, the coffee will not retain heat as well and the coffee will cool off much quicker.
Rth decreased from .85 to .15 while C stayed the same

Rth stayed the same, while C decreased from 1000 to 100

Rth decreased from .85 to .15 while C decreased from 1000 to 100

Then we needed to add a heater to the coffee. If the coffee started at room temperature and turn the heating element on, the element would add thermal energy to the system at a constant rate P.

Question 2: Calculate the value for P if we want our coffee to heat up to the Starbucks ideal of 84 degrees Celsius or 357 Kelvin?

P=75.29- We were given an equation in class and we then solved it to find this number

Once we found P, we needed to incorporate P into our program to see how it would affect the system. Over time, the coffee heated up to the desired temperature.


Then, we needed to modify the program to simulate a temperature controller that uses bang-bang control to reach and maintain the desired temperature.


Below is a zoomed in version of the graph.

Page 9. Question 1: Why is bang-bang control appropriate for many thermal systems? When might it be insufficient?

It is appropriate for thermal systems because it heats up to the desired temperature as fast as possible and is also cheap and easy to implement. The reason why our proportional control heated up faster than our bang bang control was because the max power in our proportional control is a lot larger than our max power in our bang bang control. However, it could be insufficient if it would be detrimental if the temperature went above the desired temperature as bang-bang control will ends up going a small amount over the desired temperature.  

Then we needed to create a program that uses proportional control to reach and maintain the desired temperature.




Page 9. Question 2: How does this approach compare to bang-bang?

This approach never reaches the desired value, though it does get very close.

After, we assumed that there was a delay between the time the coffee reaches a given temperature and when the temperature sensor records that temperature. We needed to modify both of of our programs to include the affect of adding a "sensor delay".

Bang Bang Control
The impact of the sensor delay is that the temperature gets read 5 seconds after it was initially read. Because of the delay, the first 5 seconds of the graph show a temperature of 293. It also doesn't turn the power on as often since it records temperature of the coffee 5 seconds after it reads the temperature.

Proportional Delay

The sensor delay has the effect that the temperature gets recorded 5 seconds after it was initially read. Therefore, the first 5 seconds of the graph are at a temperature of 293. The temperature also goes over the desired temperature since it records the temperature 5 seconds after it has read it. Then the system will turn off the power after it has gone over the desired temperature by 5 seconds.

Question2: What other delay(s) might you expect in your thermodynamic system, apart from sensor delays? 

One other delay can be an action delay. There could be a delay when the power is supposed to turn on to when it actually turns on.

Reflection:
I completely understand bang bang and proportional control now. It took us a long time to do the last problem with the delay because of small syntax errors. So I know that it is important reread the code to fix all errors.


Friday, April 10, 2015

MATLAB Introduction

This week we started to learn MATLAB by reading the first chapters of Physical Modeling in MATLAB by Allen Downey and doing some exercises from the book.

The first exercise 2.1 was to translate the equation of the nth number of the fibonacci sequence in MATLAB.


2.3- calculate the number of cars in two locations, Boston and Albany, of a rental car company each week. Each week 5% of the cars in Albany are dropped off in Boston and 3% of the cars in Boston are dropped off in Albany. This script updates the number of cars in Boston and Albany each week. At the beginning of the year, 150 cars are at both locations.

Exercise 3:1- Use the for loop to run car.update 52 times. This would tell us how many cars will be in Boston and Albany at the end of the year. The year starts with 150 cars in Boston and 150 cars in Albany.

Exercise 3:2- We modified the car_loop so that it will plot the number of cars in Boston and Albany each week over time. The cars in Boston are in blue diamonds and the cars in Albany are in red circles.

Then, we started with there being 10000 cars in Albany and 10000 cars in Boston at the start of the year.

3:5- Compute the first ten digits of the fibonacci sequence using the recurrent equation. 


 Then, generalize the equation to compute the first n digits of the fibonacci sequence.

4.6- Write a script that computes a vector of the first n values of the Fibonacci sequence. Then compute a new vector that computes the ratio of consecutive values of the Fibonacci sequence. Plot the vector. The ratio of consecutive Fibonacci values seems to converge on about 1.6.







Friday, April 3, 2015

Arduino Part 3

ENCODER
We started using a sensor called an encoder that transmits how many times the shaft has rotated. The program will tell you how many times it has rotated in the serial monitor. The code for the encoder. The sciborg will move backward for 200 loops and then forward for 200 loops.
The starting value for the encoder is at 0 because at the start of every run, the sciborg hasn't gone anywhere. The ending value is also zero because the sciborg goes forward 200 turns goes in reverse for 200 turns. 200-200=0. However, the end value isn't always zero because inertia stops the sciborg from starting immediately. 

TOUCH SWITCH
The front of the sciborg has a touch switch that senses when it hits an obstacle. The switch is a lego button that you integrate into the sciborg using the breadboard. The touch switch program turns on a LED on the sciborg. However, the LED doesn't turn off because the code doesn't specify that it turns off.

Then we modified the code so that the light will only turn on when the button is pressed. 

ULTRASONIC SENSOR
An ultrasonic sensor can detect objects within a certain area. They use high frequency sound to detect and localize objects. They measure the time of flight for sound that has been transmitted to and back from nearby objects and use that to output a range reading. 

FEEDBACK AND CONTROL ACTIVITIES

Fixed distance, bang bang control
In a previous sketch we got the car to go 10 ft after a certain number of milliseconds. The first time we did it we only got about halfway to the finish line. However, by the end we were able to get within 2cm of the finish line every time that we let the motor go. We then needed to get the sciborg to move 10 feet using both the ultrasonic sensor and the touch sensor. We got exactly 10 feet with the touch sensor but only got within 5 cm with the ultrasonic sensor.

Ultrasonic Sensor
Touch Sensor


Fixed distance, proportional control
We wrote a sketch that uses proportional control to go exactly 10 feet using the encoder. As the sciborg got closer to the 10 feet mark, it went slower.
However, when we did this, the sciborg would stop a foot from the end because there was not enough power supplied to the motors to get to the end. So we made a code called nudge to add to the end of the proportional control so it would get to the end. Nudge causes our car to move a very small distance by very briefly turning on the motors at low power.

Nudge
Nudge on Proportional Control
This allowed our sciborg to get within a centimeter of the 10 foot mark every time

Conga Line
We needed to make a code so that our sciborg will follow something in front of it in a straight line. First using bang bang control, and then using proportional control.
Bang Bang Control
Conga Line Proportional
Both worked very well. The sciborg moved a lot more smoothly with proportional control than bang bang control. However we had a hard time making our sciborg run straight for all assignments.





Final Project

For our final project, we need to make something for children. Some of the things typically have problems with is that they want to wiggle and move instead of staying on their carpet square and it is hard for children to lock and unlock the bathroom doors. Some children also have a hard time remembering to take only one paper towel, flush the toilet, or wash their hands.


Possible Project Ideas:
1) Create a new carpet square so the children know when they are on the mat or not. This could be implemented by emitting a sound when children get off the square.
2)Create a mechanism that would make the bathroom toilets quieter or less scary when flushed. This could be implemented by having another song play over the sound of the toilet.
3)Create a system so children know how loud they are being in the room. This could be implemented by having a sound sensor hooked up with the lights. When the sound is too loud, the lights would turn off to create a more soothing environment for the children and to let them know they were too loud.
4)Create a mat to put under the water table or sand table so children know when water or sand is             hitting the floor.