Monday, April 27, 2015

Final Project Week 2

Supplies

After making our foam core model, we proceeded to order materials so that we could start programming with Arduino and sketching in Solidworks.

We ordered LED lights from Adafruit:


These lights are white, so we plan to lay color films/gels over the lights to make the green, yellow and red colored lights.

We also ordered a potentiometer and obtained a NXT sound sensor from the ENGR lego cabinet. Our other supplies are the Arduino board, a 6 AA battery pack, and delrin.


Arduino

We connected our three LEDS, a potentiometer, and the sound sensor to the Arduino board. In our program, we wanted to have the lights light up based on the volume reading detected by the NXT sound sensor, as seen in the program:

We also wanted to have three different volume tolerances that can be adjusted by the teacher. Therefore, depending on the position of the potentiometer, the program would go to one of three functions: low, medium and high. Each of these functions have different sound-sensor-reading ranges for when each color light is supposed to light up.




In each of the functions, if the volume was good, the green light would light up. If the volume was a bit loud, the yellow light would light up. And, if it was too loud, the red light would light up. 


Solidworks

Once we had a basic program, subject to a lot of future testing and tweaking, we moved on to Solidworks. We used a series of tabs and notches to build a box behind the front panel, where the LED lights would be. The very back panel is also meant to have a hinge so that the teacher would be able to open the box and remove the battery pack and/or the Arduino board.



At first, we planned to use one light per color. However, we realized that the lights are rather small in size, 4.5cmx8.6cm each. So, we decided to use two lights per color. Therefore, we had to change the dimensions of the Solidworks sketch to accommodate for the extra lights. 

After adjusting the sketch for the added lights, we realized that the back panel may be too tall to piano-wire (to create a hinge). So, we decided to split some of the pieces in half, so that each half could be drilled separately.

Once we had the Solidoworks sketch done, we had to test the tabs and notches. We had to make multiple test pieces and reduced the width of the notches, as the laser cutter tends to cut the hole to be larger than specified on the file. Also, we wanted a very tight fit.


The next steps are add the LEDs to the program/Arduino board and to test the lights and program with children in a classroom. Then, we will laser cut the Solidworks sketch.


Reflection

Sketching in Solidworks was more difficult than anticipated, as we had not used the program in a while. Also, since we are using tabs and notches, the measurements have to be extremely accurate and therefore meticulous measurements have to be made. 

We tested the lights by playing a song at different volumes, but songs played from a computer most likely do not generate the same sound sensor readings as human voices do, so it is important that we do a lot of testing with people talking. 

One thing that we need to figure out is how to attach the LEDs to the front of the delrin panel and connect the wires to the back, where the Arduino board and battery pack are. We will need some kind of connectors, and possibly solder the wires.







Final Project Week 1

Can't believe that the end of the semester is so near!
Tiffany and I started our final project by brainstorming different ideas for potential projects. 

For our pitch presentation in class, we came up with two ideas: one, to build a sound level monitor for the classroom; two, to build sensors into the sitting mats so that the children stay on the mats.

For the volume monitor, we proposed that we connect three LED lights to an Arduino board, along with a sound sensor. We would program the lights to light up when the sound level, as read by the sound sensor, is tolerable, blink slowly when the volume is a bit high, and blink more quickly when the volume is too high.


For the mats, we proposed that we attach touch sensors to the bottom of the carpet squares. The touch sensors would be programmed with Arduino. A speaker would also be attached to the Arduino. When the children wiggle around or start moving off of the mat, the speaker would start playing a tune.
After presenting our ideas in class, we decided to go with the volume monitor as our project. 

The next step was to speak with the woman in charge of the children to ask her about specifics of the project. For example, what is the easiest way to provide power to the system, plug in or a battery pack? What kind of pattern should the lights have so that the children are stimulated but not over-stimulated?

After talking with the director of the children's program, we realized that the blinking lights may be too distracting for the children. At her suggestion, we instead decided to arrange the lights in a linear fashion to mimic a traffic light. We would have a green light light up when the sound level is good, a yellow light light up with the noise is increasing, and red when the volume is too high. We planned to have the panel of lights be able to be hung up on the wall. Also, because of the uncertainty of being able to find an outlet, we decided to use a battery pack. 

We also wanted to have some kind of dial so that the teacher could adjust the noise tolerance level. So, we added some kind of dial, most likely a potentiometer, so that the teacher would be able to increase or decrease the tolerance of the noise level, depending on what kind of activity the children are doing.

Next, was the foam core model. 
We planned to make the structure of the project out of delrin. The front of the board would have the three lights and a box to hide the battery pack and Arduino board. Between the yellow and green lights are also the sound sensor and dial (potentiometer).


After showing the foam model to the class, we decided to change the design so that the box was behind the panel of lights. 

The next step is to start programming with Arduino and ordering supplies! Stay tuned~

Line Following Sciborg

Our last assignment for working the sciborgs was to use a light sensor to program the sciborg so that it could follow a white line on a dark-colored background. We had to use bang-bang and proportional control to direct the steering of the sciborg. 

We approached this by looking at the light sensor readings when the sensor was on the white line and off of the white line. We created different ranges of readings and specified the sciborg to travel in a certain direction in each range of readings.

Line-following Bang-Bang

In the bang-bang program, we had the sciborg follow the area between the white line and the brown background. That way the sciborg would turn left (away from the white) if it got too close to the line, and turn right (away from the brown) if it went too much to the dark part.





Line-following Proportional

We based the proportional program on the bang-bang program. As seen below, the left and right turning speeds are proportional to how far away the sciborg is from the desired (going straight) path. 




Both of the videos are sped up, as the original videos were too long to be uploaded. 

If we had more time, I would experiment with the turning speed of the sciborg so that it wouldn't take so long to travel across the path.

Tuesday, April 14, 2015

MATLAB Part 2

Today, we used MATLAB to simulate a simple thermal system -- the temperature of a cup of coffee. We asked hypothetical questions and used MATLAB to play out the situations.


A Cooling Cup of Coffee

First we simulated a hot cup of coffee cooling down. 
We used the equation

where dT is the change in temperature, dE is the change in thermal energy, C is the heat capacity, and Rth is the thermal resistance.

We put the equation into MATLAB and got the following script:



This script created the following plot:
We predicted that by increasing the thermal resistance (Rth) or heat capacity (C), the slope of the curve would become less steep.

When we changed the Rth to 1.0, compared to the original 0.85, the curve became less steep.

Then, when the C was changed from 1000 to 2000, we got this plot:

Adding a Heater

The next part was to simulate heating up and maintaining the temperature of a pot of coffee. We calculated that in order to heat up a pot of coffee from room temperature to 84C, a good value for the power is 75.

From a given plot of temperature vs time, we deduced that C = 1000 and Rth  = 0.853.

Bang-Bang 

By incorporating power into a new script, we created a plot for temperature vs time when heating up a cup of coffee. We first simulated a bang-bang control heating system, so that when the temperature is at or below the desired temperature, the power is fully on, and when the temperature is above the desired temperature, the heating is turned off.


The zoomed-in plot shows that the temperature jumps up and down once it reaches close to the desired temperature.
With this bang-bang control, we see that when the desired maximum is reached, the temperature fluctuates between slightly above and slightly below the actual value. Bang-bang can be sometimes desirable, as it is easier to program compared to proportional control. However, it is not very accurate in reaching a desired value, for example temperature, as there is only the choice of having the system being completely on or completely off.

Proportional 

Next, we modified the script so that the heating system uses proportional control to heat the coffee. 




By using proportional control, we avoid the fluctuation of the temperature as it reaches the goal. However, we also realized that as the error, which is Tmax - Tcurrent, approaches zero, the system no longer has enough energy to continue to heat the system. As a result, the system never actually reaches the desired temperature, 357, as seen above. We saw that increasing the gain factor makes the system get closer to 357, but never actually does reach it. 

Delay

Lastly, we simulated a delay in the reading of the temperatures in the bang-bang and proportional control heating systems.

First, we modified the bang-bang heating script from earlier to incorporate a delay in the reading of the temperature. The plot shows that because of the delay, the system heats up the coffee past the desired temperature, and in response, stops heating and the temperature drops. Then, when the system senses that the temperature is too low, it starts heating it up again. The temperature bounces back and forth between over heated and under heated.




Next, we modified the proportional heating script to incorporate the delay. With this delay incorporated, the system never reaches the desired temperature.





Apart from sensor delays, in the bang-bang system, there could be a delay in when the power is turned on or off. There may also be delays in the change in the power setting of the proportional heating system. When the system changes the power supply of the system to account for the current temperature approaching the desired temperature, the power may not be adjusted right away.







Thursday, April 9, 2015

MATLAB Introduction

Today, we started our section on MATLAB. This program can be used for a variety of calculations and functions. Using Arduino and having a bit of programming experience made starting the MATLAB programming an easier transition. 

We started by introducing ourselves to MATLAB by reading Physical Modeling in MATLAB by Allen B. Downey. In chapters one through four, he writes about basic functions of the program, such as writing loops, and functions, and vectors.

As we read the chapters, we also did some of the exercises.

Fibonaci Sequence

The first exercise was to write a script to compute the nth term of the Fibonaci sequence, which can be calculated using the following equation. 

We translated the equation into something that MATLAB could read. Each portion of the equation was set as a separate variable, and then put together in one line of code at the end. We also set n as 10, so that the program computed the 10th term of the sequence. 

We ran the program and got the 10th term as 55, which was what we expected.

Car Update

The next exercise was to create a script that updates the number of cars at two rental car companies, one in Albany and one in Boston. 5% of the Albany cars get dropped off in Boston  and 3% from Boston to Albany each week. Each location started off with 150 cars, so we set the initial a and b as 150 in the command window. Then we set A and B as the number of cars in each location after one week. Then, we set a as A and b as B so that the new initial number of cars would be changed. That way, if we run the function once, it displays the number of cars in each location after one week; if we run it 10 times, it shows the cars for after 10 week, and so on.
The round function is to round the number displayed to a whole number, as one cannot have half a car.



Car Loop

Next, we were to create a loop for the previous script so that the function automatically runs a specified number of times. In this case, we set the loop to run 52 times to simulate the number of cars in each location in one year. The initial conditions for a and b were set as 150.


When we ran the loop, we found that after a while, the values of A and B stopped changing. A stopped at 118 cars while B stopped at 182 cars.

Car Loop Plot

Next, we created a script that would also plot the values of the car loop script from above. Again, the initial values were 150. The hold on ensure that the graph doesn't automatically clear the points each time. The cars in Albany were plotted by red circles, while the Boston cars were plotted in blue diamonds.


As you can see from the above graph, the values eventually stop changing. 

We also tried using initial values of 10,000 cars. The result was that the graph resembled a better parabola shape. 



Fibonaci 2

The next exercise was to write a script to compute the elements of the Fibonaci sequence using a loop. The Fibonaci sequence is calculated using the equation 

Fi = F(i-1) + F(i-2)

In order to display the first 10 terms of the sequence, F1 and F2 are set as 1. Then, inside the loop, the nth term of the sequence is the sum of the previous two terms. Then, the previous two terms are updated to the newer two terms.

Then, we generalized the loop so that any number of terms could be calculated. The value of n just needs to be specified before the script is run.

Fibonaci Ratios

The last exercise was to write a script to first calculate the vector of the nth number of terms in the Fibonaci sequence, and then calculate the vector of the ratios of F(i+1)/F(i) -- that is the ratio of two consecutive terms. Then the ratios were plotted on a graph to see if the values do indeed converge. 

The ratios were plotted versus X, which was the value of n of that specific ratio.






Friday, April 3, 2015

Arduino Day 5

We continued to work with the sciborg and were introduced to some sensors that can be used with the sciborg. We also worked on bang-bang control and proportional control.


Encoders

The first sensor that we used is called an encoder. This sensor reads the number of times the shaft of the wheel has rotated and displays the reading on the serial monitor.



The starting value is and should be zero because the wheel has not rotated yet. The ending value is not zero because the wheel has rotated a number of times, both forward and backward, and cannot get back to exactly zero.


Touch Switch

The next sensor we worked with is called the touch switch. At the front of the sciborg is a switch that you can press by lifting the big arm up and down. We wired the touch switch to the Arduino board pin 9 using the breadboard and also connected an LED light to pin 3. We ran the sample sketch of the touch switch. 




The LED stays on forever when the button is pressed because the sketch does not include that when the button is released, the light will turn off. To make the light go on only when the button is pressed, we created an if else statement in the loop.



Ultrasonic Sensor

Another cool sensor we worked with is the ultrasonic sensor. This sensor detects objects in the vicinity. The sample code allows the sensor to display the distance of the nearest object using the serial monitor. 

The smallest reading on the serial monitor is associated with an object being extremely close to the sensor. By playing with the sensor, we observed the smallest reading to be about 11 when I put my hand directly in front of the sensor. 


Feedback & Control

Fixed distance, bang-bang control

Bang-bang control means that the system is either completely on, at full speed, or completely off. In the following sketches, the sciborg uses bang-bang control. 

Last time, we were able to get the sciborg very close to the ten foot mark after several trials with the delay time. We started off with 12.5 seconds, but because the sciborg didn't go in a straight line, the 12.5s was not enough time to make it to the line. We then tested 13.5 and 14.5 seconds. The 14.5 seconds brought us the closest to the 10-foot mark -- the sciborg stopped with the center of its body on the white line!

Using the previous sketch with the 14500ms delay and the encoder sample code, we measured the rotation of the wheel shafts using the encoder sensor. The encoder reading was 14336 after traveling forward for 14.5 seconds. 

We then used the touch sensor and the ultrasonic sensor to stop the sciborg at the 10 feet, instead of using the time delay. 


With the touch sensor, we created the sketch so that the sciborg would stop when we pressed and released the button. We pressed the button when the sciborg reached the ten-foot mark.


With the ultrasonic sensor, we programmed the sciborg to move when there is an object within a reading of 30 on the ultrasonic sensor reading. That way, the sciborg could follow a hand or wooden board until it reaches the ten-foot mark. When that object is taken away and there are no objects close to sciborg, it stops moving. 


Fixed distance, proportional control

The next assignment was to use proportional control instead of bang-bang control. Proportional control means that the sciborg adjusts its speed according to how far away it is from its target. 

Proportional control involves the following equation:

Output = error x gain factor 
            = (target - current position) x gain factor

The output is the power supply, or in the case of the sciborg, the speed. The target is the desired distance travelled, in our case, ten feet, and the current position is the distance from the ten-foot mark. 

Using the ten-foot encoder reading from last time, we set the encoder reading of 14366 as the desired target, and the current position as the current encoder reading. We wanted the maximum output, or speed, to be -150. So using the equation, we calculated the gain factor to be -0.010441.

The encoder reading was put into the loop so that it would be constantly updated. The speed was set as shown below so that as the sciborg approached the target, it would slow down. 

We also created a nudge function using the ultrasonic sensor. We found that when using only proportional sketch, the sciborg would not reach the target because in the end, there would not be enough power for it to continue moving. So the nudge function makes the sciborg travel in short intervals at a low speed until it reaches the desired distance. 




We incorporated the ultrasonic sensor into the final nudge function so that we could control when the sciborg stops performing the nudge function. We used an if else statement, so that if the nearest object is greater than a reading of 15, the sciborg performs the nudge function, and if the reading is under 15, the sciborg stops.



Conga Line

The last part of the feedback and control section was to use the ultrasonic sensor to have the sciborg follow another object. This was similar to what we did for the fixed distance, bang-bang control with the ultrasonic. However, this time, we also programmed the sciborg to slow down if it got too close to the object in front of it -- that is, if the ultrasonic reading became too small.


First, is the bang-bang control conga. The sciborg is programmed to follow an object within an ultrasonic reading of 30 at full speed.




Then, we have the proportional control conga. We put the ultrasonic reading into the loop as the integer value, and set the maximum speed of the sciborg equal to (value - 11)*-10

The 11 is the minimum ultrasonic reading, so when something is extremely close to the sciborg, the speed will be zero.

We wanted the maximum speed to be between -100 and -200, so we determined the gain factor to be -10.

This way, as the object that the sciborg is following gets further away, the sciborg speeds up. If the object gets closer, the sciborg slows down, or stops.