Pages

Monday, April 27, 2015

Final Project Week 2: Coding


At this point in time we did not have a lot of materials yet (button, motor, ect.) as they were still being shipped, so we focused on completing the Arduino code that would allow the button, ultrasonic sensor, and motor to communicate in the way we wanted them to (to flush the toilet). 

The actual coding process was done step by step to correctly incorporate each of these three devices, but ultimately we wanted a code that would keep the motor at a stationary position until the button was pressed. Then, once the button was pressed, the ultrasonic sensor would start reading values. If the sensor reads a value that indicates a child is present, the toilet should do nothing for a certain amount of time, allowing the child to leave the stall, and then flush. Alternatively, if the sensor doesn't sense a child, it will flush immediately. This whole process would be independent of the toilets handle's normal function, so the toilet can still be flushed manually if need be. 

The first version of our code had statements for all three devices, and four main functions it performed. The first function was a "while" statement that set up the default setting of the motor as "off." The next three functions fell under the condition that the button was pressed. Once the button is pressed the code breaks out of the "while" statement and does one of three things: (1) if the time is less than two minutes and there is a child in the stall, the motor does nothing, (2) if it has been less than two minutes and there is no child in the stall, the motor will flush the toilet, and/or (3) if the time is greater than two minutes the toilet will flush, regardless of whether or not there is a child in the stall.





At the point in time when we made this code, we did not have a motor to test on, but we could tell this code would not work as the ultrasonic sensor would only read values when the button was being held down, instead continuously after it was pressed. We tried putting "serial print" function that communicated sensor reading values in different sections of the code, but, depending on where we put it, the sensor would read one value when the button was pressed and wait until the code had run through its full loop to read a second value. 


Not too long after creating our first code, our motor device came in, so we opted for removing the sensor portions of our code until we made sure that the button/motor were communicating properly.  






The above code as able to correctly move the motor the way we wanted to. This allowed us to determine that the previous issue regarding our sensor readings was probably the result of the Millis functions we used. We ended up removing them from our code, and using delay functions in their place. When editing our code, we also realized that we technically only needed two statements for when the button is pressed rather than three (one for if the child is still in the stall, and another for when no child is in the stall).



The resulting code worked roughly in the way we wanted it to. All that was left was to fine tune the sensor values and change the delay time of the flush to 10 seconds. These values were based on our previous visit/meeting  to the preschool, which is detailed in the previous post. Our final code is as follows:




Tune in next week to see the physical setup of our device!

Friday, April 24, 2015

Final Project Week 1: Focus and Prototype

For our final project, my partner and I chose to tackle the issue of toilets being too loud and scaring children, leading to them not flushing after themselves. 

To remedy this, we decided to create a device that would give children time to leave the bathroom stall before the toilet flushed. This device would work by first having the child press a button (rather than the flush handle), which would then trigger an ultrasonic sensor to start sensing if an individual is in the stall, as well as a timer to start timing. If the sensor senses that a child is in the stall, the toilet will not flush. If it senses that there is no child, the toilet will then flush. We also wanted to make sure that the toilet flushes in a  timely manner, so we would also have the toilet automatically flush if two minutes have passed without it flushing. 


In order to delay the time at which the toilet flushed, we also needed to design a device to flush the toilet in the child's place. We originally thought to use a Lego Bricktronics motor device to manually push down the flush handle of the toilet. This device would be activated when the sensor or timer indicates that it's time for the toilet to flush. When activated, the Bricktronics motor would turn a handle attached to it that would in term push down the flush handle for a couple of seconds. The motor would then reverse directions, bringing the flush handle to its original position. This processed is demonstrated in the video below. 





Before creating a more detailed prototype of our device, we paid another visit to the preschool we were working with to get more details on the toilets we would be designing the device for. In addition to taking measurements of the toilets' dimensions and pictures of the toilets, we also talked a bit with the school's director, Becky Geer. During this meeting we leaned that the delay needed for flushing the toilets was only about 10-20 seconds rather than two minutes. 

Toilet in the Preschool:


Closeup of Flush Handle:

Once we had more details on the toilet's dimensions, we then set out to build a more detailed prototype of the flushing device using a Bricktronics motor. The to-scale prototype featured the motor, the pushing attachment, a flush handle, and a box to cover the device to prevent children from touching it and water from getting on it. 




One thing to note is that the pushing attachment for the motor is designed to reach around the lip of the toilet tank cover to properly reach the flush handed. 


Once we had the overall design of the device worked out, we then had to think about the applicability of it, specifically whether or not the motor had enough torque to successfully push down the flush handle. To test this we used a spring scale to measure the force needed to pull down the flush handle on actual toilets. What we found was that the the force needed to push the handles down was more than our current motor could handle. 

We considered changing motors or creating a gear train to remedy this issue, but eventually our instructor, Amy Banzart, suggested we use a device that worked to flush the toilet from inside the tank, rather than by pushing the toilet handle from the outside. Due to time constraints we ended up ordering an automatic flushing device to use its motor rather than creating our own .


Device Used: Santeen Home Office Indoor Sanitary
 Automatic Hands-free Sensor-based Flushing System

The above device actually contained a sensor of its own, but we took it out in order to use our own ultrasonic sensor. 

Next week we will focus on creating a code for the motor, button, and ultrasonic sensor


Tuesday, April 14, 2015

MATLAB Day 2: Thermal Systems

In an effort to further learn the uses of MATLAB, today Helena and I explored using it to investigate simple thermal systems. Using a guide created by Robert Bert and revised by our professor, Amy Banzart, Helena and I went through several heating and cooling simulations.

In the scenario we used, we sought to analyze the heating and cooling of a cup of coffee. In order to do this, we first needed to understand a couple of the equations used to model the heating/cooling of systems. 


Heat Capacity (C)

Heat capacity (C) is the number of heat units needed to raise the system's temperature by one degree. It is defined by the ratio of dE/dT, which models the change in energy against the change in temperature (T).

C=dE/dT

dE = energy change of the system during time (dt)
dT = temperature change during time (dt) 

Thermal Resistance (Rth)

Thermal Resistance is  a measurement of a temperature difference by which an object or material resists a heat flow. This property is affected by the temperature difference between and  the system's heat flow. 


Rth = (T-Tair)/(dE/dt) = "effort"/"flow"

T= Temperature of the system at time (dt)
Tair = temperature of surrounding environment
dE = energy change of the system during time (dt)
dT = temperature change during time (dt) 
dt = change in time/time step

Temperature Change (dT)

In order to model the heating/ cooling process of our system, we also needed to understand how to calculate the change in the system's temperature over time.


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

dT = temperature change during time (dt)
dt = change in time/time step
C= Specific heat capacity
dE = energy change of the system during time (dt) 
T= Temperature of the system at time (dt)
Tair = temperature of surrounding environment
Rth = thermal resistance



Question 1: Varying Thermal Resistance and Heat Capacity

In order to better understand heating and cooling systems, we wanted to see how varying the MATLAB parameters of thermal resistance (Rth) and heat capacity (C) affected the cooling behavior of our "cup of coffee". By examining the temperature change equation detailed earlier, one can hypothesize that decreasing Rth or C will increase the cooling process (or dt), while increasing these values will decrease the change in temperature (dt), as Rth and C are both located in the denominators of the equation. 

Using the below MATLAB code we then modified Rth and C, confirming our hypotheses

Original Code/Graph:




Increasing Rth or C resulted in a graph like the one below:




Decreasing Rth or C resulted in a graph like the one below:





Question 2: Adding Thermal Energy to a System at a Constant Rate P

For this situation we added a heating element that would would allow our coffee to heat up to, and stay at, a temperature of 84C (357K). Before using the heating element, however, we needed to calculate the amount of power we would need to supply to the heater (P) to get to and maintain this temperature. In order to determine P, we used the below equation setting dT equal to zero, Tair to room temperature (293K), heat capacity (C) to 1000, and thermal resistance to  0.85.



The resulting P value, 75.3, was checked using the code below:







Feedback and Control

We then wanted to incorporate P-vaues into our thermal system codes to reflect a situation where a coffee pot was being heated to, and kept at, a specific temperature (in this case 84C).


Bang-Bang Control Heating

With bang-bang control heating, the coffee heats up to the desired temperature quickly, with the heating device on at a high power until that temperature is reached. Once that temperature is reached, the heater turns off completely, until the temperature falls below the desired level. This method of heating results in a wave-like pattern of heating around the desired temperature. 







Proportional Control Heating

While bang-bang control is often easier to execute, in cases where temperature needs to be more precisely maintained (such as the storage of temperature sensitive chemicals) proportional control should be implemented. Proportional control not only allows the temperature to be more closely maintained, but also eliminates the need for the heater from constantly turning on and off, which might damage it. In the code below we implemented proportional control by setting the amount of energy supplied by the system to correspond to the current temperature of the system. The resulting graph was smoother and had no wavelike pattern around the desired temperature






Bang-Bang and Proportional Control Heating with Delay

In this final exercise we had to modify the previous two codes to account for a 5 second delay between the the time when the coffee reaches a given temperature, and when the sensor records that temperature.We addressed this situation by adjusting the time portion of the codes, allowing for the time of each temperature reading to reflect the actual time the coffee reached that temperature.   

Bang-Bang Control:





Proportional Control:







Friday, April 10, 2015

MATLAB

This past week we learned how to use MATLAB by reading the first few chapters of Physical Modeling in MATLAB by Allen Downey and doing some exercises from the book. A little background, MATLAB functions similarly to a calculator, but allows for much higher processing power. The exercises describe below allowed us to learn how to assign variables, run functions, and obtain graphs from MATLAB. 


Exercise 2.1


The first exercise was to use MATLAB to compute the nth term of the fibonacci sequence. This involved coding a function for the fibonacci sequence which defines the first two terms as 1, and then each following term is the sum of it's two preceding terms. Using the code we came up with (shown below) we set n to equal 10, and were able to get the 10th fibonacci number (F=10)




Exercise 2.3


The next exercise involved working with multiple variables that were dependent on each other. According to the exercise, there are two locations that each start out with 150 cars. Each week, five percent of the cars at location (a) go to location (b), while 3 percent of the cars at location (b) move to location (a). Our job was to use MATLAB to compute how many cars were at each location after one week. For the code below, we preconditioned  (a) and (b) to be 150



Exercise 3.1

 Once we finished the car function, the next step was to insert a loop into it that would allow us to calculate the amount of cars at each location after a certain number of weeks (in this case it was 52). In order to create a loop, we enclosed our original function in a "for" command, setting the number of times the loop should run (i) to 52. While not shown in the image below, we found that the number of cars exchanged between Boston and Albany reached equilibrium when there was 118 cars in Albany and 182 cars in Boston. 





Exercise 3.2


We then added a plot command to our script to get a visual representation of the number of cars at each location week to week. In MATLAB, our plot command creates a graph where the week number is on the y-axis, and the number of cars at that location is on the X axis. In the our graph, location (a) is represented by the red circles, and location (b) is represented by the blue diamonds. 



When we got the graph above, we realized that we had switched our x and y axis. The corrected graph is shown below. One thing to note is that as the initial number of cans increases, the graph lines get smoother.





Exercise 3.5


In this exercise we returned to the fibonacci sequence, this time aiming to use a recurrent equation to compute the first ten numbers. To do this, we used a loop function that would allow us to add the previous sequence value computed to help produce the next one. For the below code, we ended up printing 12  sequence numbers rather than 10 because we didn't account of our code which dictated that we go to the   "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 achieved the goal of the exercise. 



Exercise 4.6


The last exercise was to write a script that computes a vector for the "n+1th" term of the fibonacci sequence divided by the nth term, and then plot this vector to determine where it converges. From the plot, we determines that the values converged around 1.6.





Saturday, April 4, 2015

Arduinos: Day 4

Today Sarah Barden and I continued to work with Arduinos and Sciborgs as Part of our "Feedback and Control" unit. Our aim for this section was to troubleshoot the use of various sensors to control the movement of the Sciborg using bang-bang or proportional control. 


Encoders


An encoder is a type of sensor that  captures position information and relays that data to other devices. The position information can be read in several ways including optically and magnetically. The encoder sensor we used reads the number of times the shaft of the wheel on the Sciborg has rotated to judge position.

For this exercise, we were given the sample code below. This code start the sensor reading value at 0 and then precedes to serial print the position of the Sciborg as it moves (as read by the encoder).


Fixed Distance: Bang-Bang Control

We then modified the above code so that the Sciborg is able to travel exactly 10 ft through the use of an encoder to judge whether or not the device had reached the desired position. The code below utilizes bang-bang control to direct the movement speeds if the device.




Fixed Distance: Proportional Control

The following code uses proportional, rather than bang-bang control to ensure that the Sciborg travels exactly 10 ft, as measured by the encoder. In using proportional control, we are able to prevent possible overshoots of the desired distance due to the momentum of the wheels at full speed by gradually slowing down the Sciborg as it nears its destination.






Ultrasonic Sensor


An ultrasonic sensor can detect objects within a certain area through the use of high frequency sound waves. This sensor measures the time of flight for sound that has been transmitted to nearby objects and uses that to output a range reading. 

To start with we were given the sample code below that allows us to track what values the sensor is reading.




Sciborg: Stop at Obstacle

Once we understood how the sensor worked, and the range of values it recorded, we then set out to create a code which would stop the Sciborg whenever it got too close to an object (the sensor read a value <30).





Feedback & Control: Bang-Bang Conga Line

Now that we new how to program actions based on sensor values, we wanted to make a code that would allow the Sciborg to follow another device/object in front of it. This would be achieved using the ultrasonic sensor to first find an object to follow, then to make adjustements in position (i.e. move) to keep in line with said object. The code below uses bang bang control to achieve this. 



Feedback & Control: Proportional Conga Line

The above code resulted in jerky movements, so we adjusted it to use proportional control instead. This new code allows the Sciborg to adjust its speed based on how far away it is from other objects, and even come to a stop if it gets too close to one.






Light Sensor: Line Following


Our last assignment for working the Sciborgs involved the use of light sensors. After calibrating the light sensor and getting a sense of the range of values it was able to measure, Sarah and I set out to design a code that would allow the Sciborg to follow a white line on a dark background. 


Feedback & Control: Bang-Bang Line Following

The first method we sought to utilize was bang-bang control. The main challenge for this task was coding for both left and right turns based on sensor values. In order to ensure that the Sciborg could return to the line regardless of which direction if strayed in, we ended up creating three different "ranges" of values. The first range was when the sciborg was fully on the line; in this case the Sciborg would go straight. The second case was when the light sensor was only partially on the white line; in this case the Sciborg would turn left. The final range was when the light sensor was fully off the line; in this case the sciborg would turn right.






Feedback & Control: Proportional Line Following

Using the bang-bang code, we also created a code that used proportional control. This allowed the speed of the Sciborg's turns to be proportional to how far away from the line the sensor was. 



Reflection

Before starting this project I was not aware of how many sensors were available and their many uses. After troubleshooting the above codes/actions, however, I feel that I have a better understanding of how they work and the ways I can use them in the future. I feel the most challenging thing about these sensors, particularly the ultrasonic and light sensors, is that the readings they take can vary slightly depending on how they are calibrated. The most difficult ask was by far the line following codes. While overall the codes we created worked, the fine tuning needed to select the right turn speeds and sensor ranges was time consuming. 


Friday, April 3, 2015

Final Project: CSC Visit and Brainstorming


The semester is coming coming to a close, and with it comes the final project of this course. The goal of this project is to utilize what we've learned about feedback and control these past few weeks, as well as the technical/building experience we gained at the beginning of the course to create a device that utilizes feedback and control mechanisms to aid in the learning/classroom experience of young children between the ages of 2 and 6.

Ultimately we hope that the devices we will create can be realisticlty implemented in the classroom/school. For this reason we have budget limit of $100.


CSC Visit/Brainstorming


This week we kicked off our final project of the course by visiting a local school for children age 0-6. This visit was to find out more about the classroom environment in order to gain insights into what areas of the experience could be improved upon.

After talking a bit with the teachers and observing the students, I found several situations in which a feedback and control device could be useful.

1) Toilet Flushing Device

One issue that the teachers mentioned on visit was that the flushing of the toilets in the bathroom was too loud and sometimes scared the children. After hearing this I thought of several ways to remedy this problem using a feedback and control device. The first was to create a device that triggered a musical response whenever the toilet was flushed. The issue with this is that the musical response would increase the overall noise of the flushing and possibly be distracting to the children. Another idea was to delay the flush of the toilet until the individual has left the stall. This could be achieved using an ultrasonic sensor to determine wether or not someone is in the stall, and a motor device to autonomously flush the toilet.

2) Hand Washing Timer

Another issue in the school was that the children did not always remember to wash their hands/ wash their hands for the proper amount of time. I thought that a device that both reminded the children of the proper amount of time to wash one's hands and also displayed minimally engaging images to keep  them there during that time would be helpful. This device would use an ultrasonic or touch sensor to judge when the faucet has been turned on. When turned on, the device will begin to display an LED pattern of some kind for about 15 seconds (the time you should wash your hands), after which it would turn off and reset for the next time the faucet is turned on. 

3) Greenhouse Heater Control

I love gardening, so I was sad to hear that the plants in the school's greenhouse did not fair so well during the winter due to the cold air let in when the door was opened. I think an easy way to remedy this problem is to create a device that senses when the door has been opened via either touch switch or temperature sensor, and then communicates the the greenhouse's heater to turn on. 


Group Brainstorming 

For this final project I will be working together with Helena Maurer. We met together to brainstorm some more, and narrowed our ideas to the following two to pitch to our instructor.