Monday, April 27, 2015

Light/Dark with Sciborg

Our last task with our sciborg was to get it to follow a white stripe using a brightness sensor. First, we had to do it using bang bang control, then proportional.

For bang bang control, we first tried writing a code that drove straight when it sensed it was on the light surface and turned back and forth when on a dark surface in the hope that it would find the light surface again and continue driving straight. Here is what the code for that looks like:
 

This code was unsuccessful however, because once on the dark surface, our sciborg was not able to reach the white line again. Or, if it did, it had gone in a full loop before reaching it again.

We then decided to use edge following, where turns right when on dark surfaces and left when on light surfaces. This worked very well and our sciborg was able to follow the track made by the white line. Here is our final code and  a video:

Next we tried to adjust our code so that our sciborg followed the line using proportional control. This was a difficult concept for us at first, because we couldn't figure out how to tell our sciborg how much it was on light or dark, we only knew how to tell it light vs. dark. However, after playing around with our code enough we found a way to implement proportional control by making the light value our "goal" and by calculating a reasonable gain. This way, we were able to create an "error" value based on how far our reading was from our goal value. We calculated an output equation using the gain and the error and set our speeds to output. After having to change our numbers several times and do many trials, this is what our final code looked like:


Notice that we put absolute value "bars" around our error function to account for our sciborg veering off the white line to the left or right. This ensures that our output is always positive. As a result of this adjustment, our sciborg did not zig-zag so sharply when following the line, instead making gentler adjustments to stay on track. Here is a video of our sciborg running the track using our proportional control code:



This completes our work with sciborgs and I will now be focusing my blog posts on my final project. 




Wednesday, April 22, 2015

Final Project Week 1

For our final project, my partner and I have decided to create a system so that the children have time to leave the bathroom stall before the toilet flushes, as they are often afraid of the loud noise.

Our first idea was to have the children push a button when they are done, and the button would triger an ultrasonic sensor to start sensing as well as timing. If it senses that a child is in the stall, the toilet will not flush. If it senses that there is no child, the toilet will flush. And, just in case, if it has been more than two minutes and the toilet still has not flushed, the toilet will flush.

In order to flush the toilet, my partner and I created a design using the Lego Bricktronics motor. When the toilet is cued to flush, the motor will turn for a specified time, which will turn a handle that is attached to it, which will then push the flush handle down. The handle will stay down for a couple seconds and then reverse the process to it's original position, completing the cycle of the system.

Here is what the toilet looks like at the preschool:


Below are some foam prototypes of our design (button and sensor not included in the prototype):



The foam box is to prevent the children from touching the flushing device and to protect it from any water. 




However, this design ran into some problems when we used a spring scale on actual toilets to measure the force needed to flush a toilet. The motor we currently want to work with does not have enough torque to successfully push down the flush handle. We are currently exploring other options and I will post again soon with a progress update.

Wednesday, April 15, 2015

Thermal Systems

Recently we have been using MATLAB to investigate thermal systems and how we can manipulate and simulate them using code.

For our thermal system, we are looking at the heating a cooling of a cup of coffee. First, we need to understand some basics of the system. The heat capacity, C of the coffee is defined as the ratio dE/dT, which measures the change in energy (or the energy flow) against the change in temperature, T. Now we need to look at the thermal resistance of the system, which is affected by the temperature difference (between the coffee and the air) and the heat flow. Basically, thermal resistance is asking how much the change in temperature drives the heat flow of the system, and can be written as

Rth = T-Tair/(dE/dt)

where t is time. Thus, to find the temperature change dT over the specified time dt, we get the formula:

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

Question 1
Since Rth and C both lie in the denominator of the equation for dT, by increasing them you get a small rate of change of temperature, meaning the coffee will cool more slowly over time. On the other hand, by decreasing Rth and C, you speed up the cooling process. Note that the negative sign on the lefthand side of the equation tells us that it is cooling, not heating up.

Now, suppose we add a heater to the coffee, so we are adding thermal energy into the system. In this scenario, we can write the rate of change as

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

Question 1
Now, if we want our coffee to be at 84 degrees centigrade, or 357 kelvin, we need to calculate P, the power supplied by the heater. Setting dT equal to zero, we also know that room temperature is 293 kelvin. We will use 1000 as our heat capacity and .85 as our thermal resistance. Plugging in, we get

0 = ((P/1000) - (357-293/.85(1000)))*10

64/.85 =P

P = 75.3

Below I will show you the programs on MATLAB that simulate the cooling and heating of coffee. For the heating, I will show both bang bang and proportional control of the heater, using the P value we found. 

Cooling


This code does not use P because there is no energy being put into the system, it merely simulates the temperature loss of the coffee over time as it approaches room temperature.

Heating: Bag Bang



As you can see, with bang bang control the coffee heats up the coffee quickly, supplying too much power at first, then when it reaches its ideal temperature, the heating shuts off completely. This is why the horizontal line segment of the graph looks so think, because the temperature is quickly rising and then dropping as the heat turns on and off.

Heating: Proportional Control

With proportional control heating, you will see that the curve of the graph is not as sharp as that of the bang bang heating graph. Here we implemented our P value at the desired temperature and varied it depending on the surrounding temperatures.


Proportional and Bang Bang Heating with Delay

Now we suppose that there is a 5 second delay between the time the the coffee reaches a given temperature and the time the sensor records it. To remedy this error, we will adjust our code on both the bang bang and proportional control heating codes to reflect a time recording that is five seconds earlier, so that the temperature being recorded matches the real temperature of the coffee.





As expected, these graphs record the temperature at an earlier time than on the graphs that did not account for the delay. Now the the correct temperature is recorded at the correct time.

This completes our investigation into thermal systems, but we'll continue to work with MATLAB.






Tuesday, April 14, 2015

MATLAB exercises

This past week we have been learning the basics or MATLAB, and were asked to complete a series of exercises in order to get to know the program better, which I will detail below.

Exercise 2.1

To begin, we were asked to write a code that would compute the nth term of the fibonacci sequence. The fibonacci sequence defines the first two terms as 1, and then each following term is the sum of it's two preceding terms. This is the code we wrote:


Note that we defined n=10 as a precondition. This successfully computed the nth term.

Exercise 2.3

Next, we were asked to write a script that had variables that were dependent on each other. In this case, there are two locations that each start out with 150 cars. Each week, five percent of the cars in location "a" leave to go to location "b", and 3 percent of the cars in location "b" move to location "a". our first task was to write a script that shows the final amount of cars after one week.

Note that our preconditions were to define "a" and "b" to be 150, to set a start value. You can see that after running the program (and rounding the numbers to the nearest whole integer) the adjusted values were produced.

Exercise 3.1

Now, we had to implement a loop into the function from 2.3 to account for 52 weeks. For this we used the integer "i" to count up to the number of weeks we wanted it to run for.


The final values look the same as the ones in 2.3 because I rounded the numbers to integers to begin with and after a certain point (number of weeks) the answers begin to stabilize until the number of cars in each location are the same from week to week.

Exercise 3.2

Now we added a plot to our script to see what the car transfers look like over time. Here is a photo of our sketch implementing the plot command and of our plot.


"ro" means to plot the "a vs. i" values in red circles. "bd" means to plot "b vs. i" as blue diamonds. 



You can see the values are more erratic at the bottom and then quickly level out. With initial values of "a" and "b" at 10000, it was easier to see the values change at the beginning. However since the function involves percentages it took the same amount of time fr the values to reach a stable output.

Exercise 3.5

For the next exercise, we wanted to compute the first ten numbers of the fibonacci sequence. We ended up printing the first 12 because we were printing "F", which is going up to te "i + 2th" term. We should have either said "i= 1:8" so that it would print the first ten numbers or we could have written "Print F(i-2)" to solve the problem. Either way we still found the 10th term of the sequence.


Exercise 4.6

For the last exercise we had to write a script that computes a vector for the "n+1th" term of the fibonacci sequence divided by the nth term. We would like to see if and where this converges. We had a lot of difficulties defining the "n+1th" term at first, but eventually we found a simple way to implement what we wanted. Then we plotted a graph.



You can see that it converges right above 1.6. 

This completes all of the MATLAB exercises, and soon I will post about thermal systems and more feedback & control.



Friday, April 3, 2015

Ideas for preschool project

Below are a few of my ideas for a project to implement at a preschool to aid the awareness of the children during daily activities like going to the bathroom, sitting still and washing your hands. I have pictures of rough sketches for most but not all of my ideas.

1: Bathroom lock

I was told that some children have trouble remembering to flush the toilet. To help correct this, I thought of putting a mechanism on the lock of the stall that forces the children to be mindful of whether or not they flushed. There would be a panel asking the child if he or she had flushed, and two buttons corresponding to yes and no. If the child selects yes, the bar that would be blocking the lock from being slid into the unlocked position would be raised using a gear and the child would be free to leave the stall. If the child selects no, this might trigger some sort of LED light reminding him or her to flush.

Potential problems: Child could get locked in the stall if he/she doesn't understand how to press yes. Child could learn to press yes without flushing. Time consuming machine.


2: Mats with ultrasonic sensor

I was also informed that children have trouble staying on their mats or carpet squares when they are supposed to. This then requires teachers to be constantly reminding them, which is tedious and frustrating. Instead, I thought giving them another response to pay attention to other than their teaher might be an easier way for the children to be aware of when they are getting up when they're not supposed to. For example, an LED light could go on. This way the teachers would only have to explain to the children to pay attention to their lights rather than repeatedly remind them to stay seated. An ultrasonic sensor could be attached to the mats somehow, or even multiple. This way, when the number goes past a certain specification, indicating that the child has moved too far away, a light is triggered to go on, reminding them to stay seated.

Potential Problems: The sensor could be too far that it detects other things, or too close that the readings are inaccurate. If the sensor is too visible it could be tempting to play with, but it can't be too hidden for the purpose of readings.


3: Mats with touch switches

Similar to the idea above, this idea is for an LED to go on after something has indicated that the child has moved too far from his/her mat. In this case, an array of touch switches would be spread out on the mat, underneath an added top layer of fabric. When the child sits, he or she will be pressing down on the touch switches. So, we can say that if maybe less than four of the touch switches are pressed, the child has moved too far from his or her mat and the light will turn on. 

Potential problems: Children often fidget or move, which could trigger the light accidentally. touch switches could break from the weight or constant state of being pressed; might be hard to fix or replace.


4: Faucet countdown

This idea is my least developed, but I was interested in some of the issues regarding the bathroom and this seemed like something that has potential. I was told that the children have trouble washing their hands for an appropriate amount of time, usually just rinsing and leaving. I thought there might be a way to attach something to the faucet handles that initiates a countdown out loud or visually (or both) that would indicate to the children for how long they should wash their hands. There could also be reminders about soap. I'm not sure exactly how I would go about developing this idea into something feasible, but it's just a thought to hold onto.