Final Project Brainstorming and Design


Brainstorming

My partner, Sabrina, and I did some brainstorming for our final project.  We spent about 15 minutes just coming up with many ideas and then narrowed it down to two general projects: Hand Washing and Noise Level.  We presented our ideas for these two projects in class.

Sabrina and I decided on the project on the left that helps children control their noise level in the classroom.  We took some of our basic ideas and brainstormed more about specific design details, such as the mechanisms, how we would connect lights and motors, and what would happen for each sound level.  


When we went over our ideas and narrowed it down, we came up with this first idea:

-Three colored areas of the circle.  Each third of the circle would have LEDs on the outside rim corresponding with the color of the section, and there would be the corresponding face in the middle of each section.
-A Servo motor in the center (behind the circle) controls an arrow that moves between the areas
- The lights turn on one by one as the arrow moves around the circle.  For example, as the arrow passes a light in the green section, it turns on, and then the next one as the arrow passes it, etc.  When the volume lowers again, the arrow moves backward, and each light turns off as the arrow passes it
-Motor also controls messages next to colored areas.   The messages correspond to each color and noise level.
-The sound sensor attached near bottom, connects to the Arduino on the back.


Design

Initial Design Ideas

We started out with this original circular design with three colored wedges, similar to the one in the image above.  Our design later changed to be a linear representation rather than a circular representation.  This is because young children understand the linear progression more than the circular idea.

Keeping this in mind, we changed our second main idea to a shape like volume symbol of a computer, a shape that fanned out like a sound wave.  We got rid of the arrow that pointed to each section and set up the LEDs in curved rows.  We kept the smiley faces and the messages.  We created a rough foam model of this design




Questions to consider

As we made our model and talked about design, we came up with lots of questions.  We went back and talked to one of the teachers in the classroom.  The following are some questions and notes we took down that addressed some questions and issues.

Are flashing LEDs too distracting for the kids?
Yes, flashing LEDs would make the students too interested in it.  Our LEDs will just light up and not flash.

What sound volume is too loud and too soft?
There are different appropriate sound levels during, for example, nap time and play time.  Sabrina and I will go to their classroom and do testing on the sound sensor.  We will possibly have different settings for the teacher to adjust during different activities, using a potentiometer that adjusts the parameters for each color.

Where is a good place for this and how should it be powered?
We visited the classroom and found a good spot on the wall in the oldest classroom.  The teacher said battery-powered would be the best, so that the device can be portable, and could be used in many different places.

What should the messages be for the different red/yellow/green sections?
The messages can be just on the red and green sections.  We are going to create messages that are easily detachable and changeable so that the wording can be changed.  The messages will be behind the device and will be moved out by an actuator, gear, and Legos. 





MATLAB Introduction


MATLAB

We started our new unit today on MATLAB.  I am working with my new partner Sabrina on this unit (Here's her blog: sabrinaattemptsengineering.blogspot.com)  We will also be working on the final project together.

We started by reading the first four chapters of Allen Downey's Physical Modeling in MATLAB and doing some of the exercises to familiarize ourselves with programming in MATLAB.


Exercise 2.1 -  Fibonacci Sequence 

The fibonacci numbers are a sequence of numbers where the next number is the sum of the previous two: 1, 1, 2, 3, 5, 8, 13, 21, . . .   The following is our first exercise to learn simple coding in MATLAB, and to make sure we got the order of operations correct.


In our code, we decided to split the expression inside the brackets into two elements.  By doing it this way, we reduce the number of parentheses we must use and we don't get so confused.  We name these elements by creating variables called first_element and second_element, and then use those variables in the next expression.  In the command window below, you can see that when we set n = 10, the answer is 55, which is the 10th term in the Fibonacci sequence.





Exercise 2.3 - Car Rental Update

Now things got a little more complicated.  We had the following problem to solve and code.  Our first step was actually understanding the problem and the math behind it.  We did some diagrams and created equations to work it out.


At first, we had our equations as you see in the following code.  To update the number of cars for a, we take away 5% of a and add 3% of b.  The equations are correct, but we realized we were missing a step when the numbers did not come out correctly. The problem is the following:  a and b both start at 150.  Then a updates.  Then b updates, but when b is updating, it is using the value for a that has already been updated, not the original 150.  We fixed this problem in the second code below.  We update the values using anew and bnew and then set a and b to the new values.  After several weeks we see that the number of cars reaches an equilibrium.

Car Update (Almost Correct!)


Car Update (Correct!)



Exercise 3.1 - Car Update with Loop

For the next exercise, we kept the same problem and the same code, but just added a for loop to the code.


Here, we take our code from the last example and add a for loop.  Inside the loop, we have our previous function that updates the number of cars.  The loop runs 52 times, so that the last values will show the number of cars in each location at the end of 52 weeks (1 year).


So at the end of a year, we see that the number of cars in each location reach an equilibrium.  To visualize this, we will learn in the next exercise that we can plot these points over time.



Exercise 3.2 - Car Update Loop with Plot 

Next in our reading we learned how to make plots from our code.  We took our previous code for the Car Update Loop and added code to plot the points.  This way we could see the equilibrium that each city reached.


We added three lines to our code.  "Hold on" tells the plot to keep the previous points during the loop.  Then we plot the values of a versus i with 'ro' red circles.  Then we plot the values of b versus i with 'bd' blue diamonds.


Y-axis: Number of cars.  X-axis: Time in number of weeks.
Initial number of cars in Albany and Boston is 150.
Albany (a) is represented by red circles and Boston (b) is represented by blue diamonds. 



Exercise 3.5 - Fibonacci Sequence with Loop

Now, back to the Fibonacci sequence.  This time, we will add a loop that can compute any number in the sequence.  


First, we have to tell it the first two terms: 1 and 1.  Here we are using a function notation, where F is the function and the number in the parentheses is the term number.  Hence F(1) means the first term and F(2) is the second term.  So F(n) means that we can set n to be something and compute the nth term.  The for loop will run from 3 to n, and inside the loop all we have is the function specifying the Fibonacci sequence.  The next term is the sum of the previous two terms.


To test our code, we set n to be 10, and the result was 55, which is correct.  We tested out 15 and the 15th term of the Fibonacci is 610!




Exercise 4.6 - Fibonacci Ratios with Plot


This last exercise was the most confusing of the afternoon.  It took us a while to actually understand the question.  Basically, take the Fibonacci sequence: 1, 1, 2, 3, 5, 8, 13, . . .  and divide the next term by the previous term, so 1/1 = 1;  2/1 = 2;   3/2 = 1.5;  5/3 = 1.667.  These are the ratios we want to compare.   Over time these ratios converge, or get close to one number.  If I list out the ratios, you can see that they start to converge somewhere around 1.618:  1,  2,  1.5,  1.667,  1.600,  1.625,  1.615,  1.619,  1.618,  1.618.  You can see these ratios in the command window below.

In our code, we have the loop from last time and the only thing we added was the second for loop/  For this loop we have it going from 2 to n, and the function we have is R(n) for ratios.  It take the nth term and divides is by the n-1 term.  For example if I were computing R(2), it would be R(2) = F(2)/F(1), which is 1/1 and so R(2) = 1.  Then, we plot ratio versus n with blue circles.


In the following plot of the Fibonacci ratios, we can see the convergence behavior.  For the first 10 or so terms, the ratios are drastically different and after that, the ratios only differ by small decimals so they seem to converge on one value.



Final Thoughts

That is it for our first day of MATLAB!  I found coding in MATLAB to be pretty similar to the other coding languages I already know, just a few minor syntax differences.  It was great to see that we can apply this to useful situations and I can see why MATLAB is used to model so many things in the sciences.  Next class, we will using MATLAB to model thermal systems, heating and cooling things down.  Also, since we were given our partner assignments today, we will be working on our project during the next few classes in addition to finishing up MATLAB, so look for those updates as well!

Final Project Ideas (CSC Visit)

For our ENGR 160 final project, we are going to design products to improve young childrens' classroom experiences.  We observed preschool-aged children during their class time and talked to the teachers about some of the problems they had in the classroom.  We asked them what we might be able to do to help them in the classroom and what could help the children.

Some challenges we learned about were:
  • Keeping the children on their mats:
    • During certain class times, the teacher has all the children sit on small rectangular mats to keep them still. Sometimes the kids stray off their mats, and teachers have to constantly remind them to stay on their mats.
  • Letting them know not to splash water out of the water table:
    • Each classroom has a water table with toys in it for children to play with.  However, they often like to splash water around and it gets on the floor, making it slippery.
  • Making sure the noise level is not too loud
    • The classrooms often get loud during free play time, especially with older children.  Teachers must frequently remind them to use their inside voices.
  • Reminding the kids to wash their hands with soap and water after using the bathroom
  • The kids are sometimes scared by the toilet flushing loudly
  • The lock on the bathroom isn't easy to open.


A few ideas I am interested in are monitoring the noise level in the class, keeping the kids on their mats, and making sure the kids wash their hands after the bathroom.

Noise Level ideas

  • Creating some type of meter with red, yellow, and green
  • Using something that senses noise level or loudness
  • Need to make sure it doesn't make sound or excite children too much
Keeping Children on Mats
  • Touch sensor on mat
  • Light turns on when child is not on mat, turns off when child is on mat
  • Maybe have a tool for the teacher to know who is off their mat
Washing Hands
  • Sound of toilet flushes causes something to happen at sink, maybe a light or message reminder
  • Lights indicating steps of hand washing
  • Ultrasonic sensor to sense when child is at sink

Arduino Day 4 (Sciborg Part 2)

Today, we learned about and experimented with three new feedback mechanisms: motor encoders, touch switch sensor, and ultrasonic sensor.  Then, we will use these sensors with our sciborg to implement two types of control: bang-bang control and proportional control.

Motor Encoders

The following sample code for encoders measure the number of rotations of the motors.  The encoder reads the current position and these values are printed.  In the sample code, the wheel moves backward and forward, and the encoder reads the current position of the motor.  The starting value for the encoder should be zero because we reset the encoder to zero in the void setup when we have "m.set_pos(0)".  The end value is not zero because we don't reset the encoder to zero within the loop.




Touch Switch

There is a touch switch on the front of our sciborg.  This can detect when the touch switch is activated and when it is not (e.g. the sciborg runs into an obstacle).  The touch switch is wired to a digital pin on the Arduino and also to ground.

Wiring for Touch Switch and LED

The following sample code includes the LED and the touch switch. When the touch switch is pressed, the LED turns on, but stays on forever and will not turn off when we let go of the touch switch.  Our job was to fix this and make the LED change according to the touch switch. We wanted to modify the sample code to make the LED turn on when the touch switch is pressed down and turn off when the touch switch is not pressed down.  All we have to do is add an else statement to the if statement.




Touch Switch with LED

At first, the LED did the opposite of what we wanted.  It would turn off when the switch was activated and stay on when it was not activated.  We weren't really sure what was happening, but played around with the code and wiring to see what was going on.  The code below is what we had for our first attempt.

Then, we modified the code once we figured out what was wrong.  The code in the loop is identical from the previous picture, but we think it had to do with the mode of the touch switch in the setup.  The mode in the first attempt was just "Input" (we're not sure what happened there?) and in the following code for the second attempt, we changed the mode to back to "Input-Pullup".  This switches the input. Additionally, for some reason it would not work when we wired the touch sensor to the LED, so as you can see in the comments, we took that wire out from our first attempt.  In the video, we have the LED turning on and off with the touch switch.




Ultrasonic Sensor

The ultrasonic sensor measures the distance from objects surrounding around it.  For example, if nothing is in front of the sensor, the printed values are large, and then as the sensor approaches a wall, the values become smaller, indicating there is something close to the sensor.  As you might guess, this can be useful for helping our sciborg avoid obstacles.  The following is the sample code for the ultrasonic sensor.  The sample code here gives value in the serial monitor that corresponds to distances.  A low number indicates something is near to the sensor and a large number indicates the sensor does not sense anything near it.  The sensor can also pick up readings from the sides, not just straight in front of it.




Feedback and Control

A. Fixed Distance, bang-bang control

In Day 3 of Arduinos we made our sciborg travel 10 feet by determining the time it would take and setting out motors to stop after that given amount of time.  In this bang-bang control task, we were able to get our sciborg within a few centimeters of 10 feet.

**Explain testing of values

Now we are using our new sensors to have the sciborg stop in different ways.  We used the ultrasonic sensor to control the point at which our sciborg would stop in front of an obstacle.  In our testing, we found that using the ultrasonic sensor, our sciborg would stop about 10cm short.  We could lower the parameter of how far away it should stop, but the ultrasonic sensor also isn't very steady.  A very lower value doesn't the sciborg to stop in time.



This code is a combination of the ultrasonic sensor code and basic motor sciborg code.  We have the ultrasonic sensor reading values and the motors are controlled by those values.  If the sensor does not sense anything in front, meaning the sensor values are greater than 30, the motors are set to forward at full speed and if the sensor senses an obstacle, meaning the values are less than 30, the motors set the speed to zero.



B. Fixed distance, proportional control

First we had our sciborg travel 10 feet using bang-bang control, and now we want to use proportional control.  Proportional control means that, as the sciborg gets closer to its goal, its speed will be proportional to the remaining distance.  Thus, it slows down as it gets closer to 10 feet.

Using proportional control means we need to do some calculations.  Here in our code the equation we used was Speed = distance * gain, where distance is the distance remaining or error (goal - actual) and gain is a constant that we calculate.  We find the gain constant by taking the maximum speed of the motors 255 and dividing by the total distance.  In this case, we are using the distance 13000 because that is the number of rotations (measured by the encoder) needed to travel 10 feet.  We determined this value by testing different encoder values for the sciborg.  Our gain constant is 0.0196.  Our encoders count down from 13000 to 0, so we take the current reading from the encoder and multiply this by the gain constant. So when the sciborg is at the beginning, it's position is 13000 and this multiplied by 0.0196 is the maximum speed 255.  (This is because we divided 13000 by 255 to get the gain constant in the first place).  Then as the sciborg continues, the current encoder value is decreasing and multiplying by the gain results in a smaller number for the speed.  Therefore it slows down.

There is a typo in this code.  In the last if statement the gain constant should be 0.0196, not 0.02125.  Originally we had a higher gain constant, but later re-did our calculations.  The sciborg in the video is running the correct code.

You might notice there is a function in our code called nudge().  In proportional control, one issue is that around 9 feet, the speed has been getting smaller and smaller, so the sciborg is moving very slow and at some point can no longer move.  However, it hasn't reached 10 feet.  As we found earlier, the sciborg has a minimum speed where the motors are no longer able to move the car.  This value is around 50 for our sciborg.  To solve the problem, we created a function that nudges the sciborg to the end when it can no longer move under the proportional control.  If the speed of the sciborg gets lower than 70 and the sciborg has still not reached its goal, we call a function called  nudge.  This function turns the motors on and off and will continue to do so until 10 feet is reached.






C. Conga Line

Next implemented bang-bang control and proportional control in a different task.  This is the conga line, where we want the sciborg to follow something in front of it.

For bang-bang control, we decided to have the sciborg turn left or right.  Here, if the sensor doesn't sense anything the car turns left and if it senses something it turns right.  This way, when we moved our sheet of Delrin in front of it, it moves forward and slightly right, and then when we moved back with the Delrin it moved forward and slightly left.  This allows our sciborg to 'search' for objects in front of it to follow, while also (somewhat) traveling in a straight line.



At first, we didn't think about doing bang-bang by just having the sciborg move forward.  We could do this by having he motors turn on when nothing is in front of the sensor (meaning the Delrin is further in front of it)  and turn off when something is in front of the sensor (when it's really close to the Delrin).

When we coded for the the conga line with proportional control, we had our sciborg just traveling straight.  Proportional control for the conga line involves having the sciborg move faster when the Delrin sheet is far away and slower when the Delrin sheet is close.


Our next step is using bang-bang and proportional control to have our sciborg follow a white line on the floor.  We are going to use a new sensor that measures brightness!