Thursday, April 30, 2015

Final Project Part 2

A recap of where we are:

  1. Have the design, including shapes and dimensions.
  2. Have the correct gear train.
  3. Started attaching the servo.


Here is what this blog post encompasses:

  1. Connect the servo to the gear train.
  2. Writing the code.
  3. Constructing the wiring with Arduino, the sensor, and the servo.
  4. Building the supporting structure in SolidWork.

Since we were working on several things at the same time, it would be confusing to document things in a chronological order. I organized our process in this blog post to make it easier to understand. Bear in mind that not everything is in chronological order. This blog post is not intensively long in terms of text, because most of our time we spent on constructing structures, code writing, and other things that are pretty straight-forward. We also started creating our visual, but since we did not finish completely and have questions to ask Becky, this process will be recorded in future blog posts.

Servo

Wired Servo

Glued Servo
Side view
It turned out that securing the servo with a piano wire was not the best way to secure the gear to the servo. It is mildly wobbly and the wire is sort of in the way when the servo turns. We tried a couple alternatives, including removing the white top of the servo and inserting the gear to the axle of the motor. Eventually we decided on using glue. It was not the cleanest method, as some of the glue dripped down and almost glued the gear to the body of the motor. After we trimmed off excess glue, however, the gear on servo worked perfectly. (Sorry for destroying a servo!)

The Code

Now, the code really isn't the hardest thing to write. The basic idea is that we want the sensor to read data the whole day. Once it detects someone, it would start the program. After the first step, the sensor would re-detect, making sure that the person is still there, and continue the process. The servo will move a set amount of distance after a certain amount of time. Once the whole process is finished, it will rewind to the original position and start to sense people again. Here is the code.

There are a couple things to mention here. The number we used for value and for position are arbitrary numbers I put down as fillers. Ideally, the number in the while loops for value would be the reading for when someone is standing at the sink to wash hands. The position value should correspond to the number that would make the servo start at the first picture and end at the last. The direction may also reverse, since we are not completely sure which direction it goes yet. The amount of time each step takes is also not definite. We obtained the number by doubling the time that Meredith uses to VERY slowly wash her hands. In this code, we assumed that there were 8 steps in total.

The Arduino

Since our device only requires a sensor as an input and the servo motor as an output, we did not need extensive wiring. In fact, we used the smallest protoboard. 

The wiring does seem a little confusing from afar, but it's actually very clear and simple. The whites connects to ports that delivers the command from the code to the devices or vice versa. The greens connects to power sources. The blues connect to ground.

The Supporting Structure

We want to make a box from Delrin to support the whole structure. Things we keep in mind while designing the structure include sturdiness, lightness, and accessibility. The gear train can be secured by two axles through the vertical walls of the Delrin, while the bottom will secure the vertical walls as well as electronic devices. We have considered a bottomless box for lightness, but it would decrease the sturdiness significantly. We also need to secure the servo motor nicely, so that when the motor moves, all of the motion should go toward the gear train, as opposed to moving itself around in the box. We thus used some foam core to find the right measurement.
We want to cut a slit through the front wall for the servo to be secured. This measurement was the most important, since it must be precise to motorize the output gears with the right amount of movement. We eventually decided on a slit that is 0.6 cm wide and 2cm above the hole for the axle. 

As for securing, we decided that heat staking would be the best method for all connections, since it is permanent and steady. For our device, sturdiness is favored over reversibility. We also do not need smooth surface, since the device will be hung on a wall, not touching any surface. Here are our drawings in SolidWork.
Bottom. Note the missing corner is a mistake. We did not print a bottom with a missing corner.
Side walls. The two walls have the same shape.
Note that we actually use two walls to secure the gear train, because one wall would fail to hold the gear train due to the heavy front. We also wanted to put the electronic devices in between the two walls so that water would not affect them. The two walls will be exactly the same to ensure that everything fits correctly. We did not make the side because we wanted the battery box to be one side and have an open side on the other end for easy access, in case we need to change the code or the wiring. For lightness reason, we also chose the 1/8'' Delrin.

We also drew our indicator.
Rests on the chain.
Indicate steps.
The indicator is also secured by heat staking. It also serves as a test piece for the heat staking for walls and bottoms. We were able to print the indicator pieces out and to assemble them.
The length for heat staking is perfect. When we were testing the indicator on the chain, we realized that it would not stay perfectly still. We thus glued it to the chain to maintain precision.

Monday, April 20, 2015

Final Project Part 1

I was very excited when we were assigned to work on the project to instruct proper hand-washing, because I was very excited about my idea of making trees that would turn green. However, I was very quickly told that such an idea may not be applicable to the age group that we will be working with and that we should come up with a more direct visual to cue the children. Since our focus is the ensure what we make fits our "clients'" needs, we then sadly abandoned our tree design and decided to come up with a new visual demonstration, which, as a result, became the focus of our first brainstorm.

We came up with a few ideas. Based on all the materials we have used in class, we already figured that a servo motor would be the easiest to use for our purpose, since we can have very precise control over it. Another prerequisite for the visuals is that we clearly should not use any text, since the children most likely not be able to read.
After some reorganization and summarization, our visual designs all fall into these main ideas.

Brainstorm - Visuals

The first type resembles a clock.

Our idea is to have a circle sectioned, with each section containing pictures of the proper steps of washing hands (like a carnival wheel!). There would be an indicator to indicate which step the child should be doing. We considered using a frame to highlight, an arrow to point, and/or an LED that indicates the current step. We can either rotate the disk of pictures or the indicator. This would be the easiest visual to install with servo, since it requires a circular motion which the servo already has.

The second type is a linear model.

This idea would require a strip of pictures showing the steps of proper hand-washing. Similarly, the indicator could be a frame, an arrow, or an LED. We can either motorize the indicator or the strip itself. This visual would require a gear train that transforms circular motion to a linear motion.

Our third one is a little different from the previous designs. It involves indicators showing what objects near the sink should be used.
The idea is that we would have arrows with lights (or other form of indication) light up when certain objects, for example, the soap or the tap, should be used at the proper step.

With some brief deliberation, it was not hard to eliminate the third type of visual. It is not very direct and can be confusing even for adults. Plus we cannot demonstrate what the child should do exactly and not every step can be demonstrated in such manner (e.g. rubbing would be very hard to demonstrate). At this point we were relatively happy with the types of visuals we have, even though they are not the most creative or sophisticated things one can ever imagine of. We of course would have loved to come up with more visuals, but due to the need of our client, and based on some information regarding child development we received from Professor Banzaert, it was clear that all we needed was a simple and direct visual with pictures. That is what works the best for children at a young age.

Brainstorm - Indicator

Now that we have an idea of the core of our project, we decided to spend more time on the details. As said before, the three major ways of visual stimuli are frame, arrow, and light. Here are some comments we made about each stimulus:

1. Frame: 

the frame is a very strong indication that definitely draws attention to the current step. However, it also blocks part of the pictures next to the current step. We are unsure about how important it is for the children to see the other steps, but it would certainly be helpful if the children can do so.

2. Arrow: 

the arrow is a very typical indicator which would be helpful for the children to understand. However, it is also smaller. The color and thickness of the arrow is very important so that it would not just blend in with the back ground.

3. Light: 

the light could be a visible light bulb, or it could be back light. The light bulb is very direct and visible, but we are worried that it may distract the children. The back light, while not distracting, on the other hand, may not be as easily understood and may not be as obvious in a well-lit room during the day as the bath room is at CSC. The back light may also make it harder to find materials for the front part of the visual, since we will be printing out pictures.
While these are our thoughts, we would need help from the professional staff to decide on what would be the most helpful for the children.

Brainstorm - Sensor

Another important part of our project is the sensor. This is the feedback and control part. Here we have a few things to pay attention to.

  • We want to make sure that we can sense the child in some way when they come and wash their hands without mistaking people who walk by.
  • We need to pay attention to the installation so that it is water proof. This includes the device as well as the wires.

1. Type of sensor:

What we have worked so far that are applicable to our project include the ultrasonic sensor and the touch sensor.

  • Ultrasonic: This sensor is the most intuitive one to use. Our only concern came from the fact that our sensor had some connection issues when we used it with Sciborg. In a far distance, the ultrasonic sensor is also very sensitive and the range it detects is not perfectly clear.
  • Touch: The touch sensor can be consciously activated by having a child push on it before the child starts washing hands. However, this is not a step in the regular hand-washing process and would require the children to remember extra information. Certainly not the most ideal. Alternatively, we can install the touch sensor at the front of the counter, so if the child leans against the table, the sensor will be activated. The problem could be that if the child moves during the process, the machine may be confused.

2. Position of sensor:

Keep in mind that being water-proof is important.

  • Near the water tap: this is where many automatic taps have their sensors. This maybe problematic in our case, however, because our ultrasonic sensor is not very water proof, and we may include steps like rolling up sleeves that is not detectable by the sensor.
  • On the wall near the visual: this seems to be an ideal place. It is close to the rest of the device, making wiring easier. It's not close to water. The only concern may be how effective the ultrasonic sensor would be detecting the person. We will need some testing at the bathroom where it will be installed.
  • In front of the counter: we can use ultrasonic sensor or touch sensor at this location. The sensor would be close to the person we want to detect and would thus be more precise. However, it is far from the rest of the device and may make wiring hard (also need to consider water near wires). We also need to know whether the children lean against the counter top and how both sensors will be affected.
  • Right below the counter: to avoid children touching the ultrasonic sensor in front of the counter but also to have proximity between the child and the sensor, we considered putting the sensor below the counter. However, this may become problematic if anything is stored below the counter. We are also unsure of the range of the sensor. We will need testing in the bathroom if we were to choose this location.

Tips from the Experts

Now that we have a fairly clear idea of what we want to do and what we need to know, we visited Becky to ask some questions. and here are some important points from Becky.

  • The best visual for young children should be linear. This narrows down our visuals to type I.
  • It is very helpful to see all the steps. This eliminates frame as an indicator.
  • We do not want visual stimulus to be distracting. This makes an arrow the best indicator.
  • Children already start to associate colors with genders. We should avoid using gender-specific color (which is, of course, only a social construct, but is affecting the children at such an early stage) and stick with primary colors and/or black and white. In fact, a big, thick black arrow would work the best.
  • The steps of washing hands are: roll up sleeves, turn on water, rinse hands, turn off water, get soap, rub for 20 seconds, turn on water, rinse for 20 seconds, turn off water, dry hands.
  • We should use real photos to illustrate the steps. Thus, we took a series of photos with Meredith demonstrating the proper way of hand-washing. (Shout out to the super star.)
  • The visual on the wall should be no longer than 15 inches.
  • Children lean against the counter to wash hands.
Initial Assembly
Our visit to Becky made us decide on a very simple model of a linear visual with a moving black arrow that indicates each step. Our first step was then to figure out the gear train that would move the arrow indicator. We would build the rest of the supporting structure around the major gear train.

Our servo only turns 180 degrees. This means that a gear train is necessary to amplify magnitude of the linear motion created by the circular motion of the motor. Based on the length limitation of our device, we decided that the strip would be 14'' long. Based on this length, we used three pieces of lego beams with length of 16 lego units. We also used chains as a way to carry the indicator.

There are a few things to discuss here.
First is the gear ratio. We did some research on the servo motor and it turned out that the motor is not as powerful as the PicoCricket we used on the lego racer. As a result, even though we do not require much speed, which is good for creating enough torque, we still want as few gears as possible to reduce friction. Fortunately, since we have very precise control over the servo, we do not have to find the exact ratio that moves the indicator for 14'' after an 180 degree turn of the input gear. This means that as long as the indicator can go further than the linear distance of the chain when the input gear turns 180 degrees, we are good to go. We would only need some testing to figure out the number in the code. With a couple tries, we eventually settled down with a ratio of 1:5, using a 40-tooth gear as the input gear and an 8-tooth gear as the output gear. The 8-tooth gear is shares the axle with another 40-tooth gear which supports the chain and the indicator.
Then we look at the chain. It is fairly straight-forward to build the chain at the beginning, but the decision we actually had to make was at the last piece of the chain. When the chain is perfectly straight, it is, in fact, relatively tight on the gears. This creates more friction on the axle turning, and may potentially cause problem when connected to the servo motor. If we add one more piece of the chain, we will get a slightly saggy chain, but it is much freer to move. This is fine since we used a 40-tooth gear to support the chains so that the top and bottom would not interfere with each other. We thus put the indicator on the top chain and have it hang above the strip of pictures.
Last but not least, the indicator. We made a simple indicator of foam core. It should rest nicely on the chain and over the visual illustrations. We consider connecting the two pieces either through press fit or heat staking.

Now the next step is connect the gear train to the motor.

In the picture we can see that there are small holes on the servo for us to fasten things to it. Our first idea is to piano wire the input gear, so that it is aligned with the motor in the center and will transfer the motion into the gear train. We only had time to secure the gear by the end of class and didn't have time to test it. Here is a picture.


Tuesday, April 14, 2015

MATLAB Thermal System

Today we used MATLAB to simulate a thermal system.

Q1. 

In Question 1 the key equation is
     dT = -(T-Tair)*dt/(Rth*C)
Intuitively, when the system has a higher capacity, it is more resistant to change its temperature, hence a smaller dT. When the system has a higher thermal resistance, similarly, the system will have a smaller dT. Mathematically, the equation follows. Here are the graphs.

C = 2000, Rth = .85

C = 3000, Rth = .85

C = 5000, Rth = .85

C = 1000, Rth = 1

C = 1000, Rth = 0.05

C = 1000, Rth = 0.35

C = 1000, Rth = 0.85 

Q2.

To calculate the perfect P, we want to set the equation so that when T = 357K (84C), dT would be zero. Since dt =/= 0, then
     P/C - (T-Tair)/(Rth*C) = 0
Solve the equation, we have
     P = 74.1176
When we plug in the number, we will get the graph:
P = 75
Here we can see, if P is not big enough, the coffee will never reach the ideal temperature, because it is losing too much heat in the process of heating up.
P = 20

Feedback and Control

1) Bang-bang control


Here is the bang-bang control. We are assuming that the heating element has a maximum P of 200. The heating element either turns on fully or turns off completely. As the temperature increases, if we zoom in on the "flat" line in the graph, we will be able to see the temperature jumps up and down not too far from 357K. This is appropriate for many systems because it allows the temperature to stay very closely at the target temperature. However, it may be insufficient sometimes because it requires turning on and off the heating element very frequently, even if the actual temperature is only slightly off from the target temperature.

2) Proportional Control


Here is the proportional control. Clearly, the temperature cannot reach the target temperature (black line) fully, because this system, just like when we worked with Sciborg, also has a "friction". We cannot make it fully to the top, because once it's very close to the target temperature, there is not enough P to overcome the heat leaving the system. We would have needed a nudge like we did before. Proportional control is better than bang-bang in the sense that it would not require constant turning-on and -off of the heating element and can automatically adjust the amount of energy put into the system. However, we must overcome by using nudge or changing the gain. Here I changed the gain.

Here the gain is large. As a result, the coffee would get over-heated immediately and then adjust until the temperature gets close to the target temperature. However, this is probably impossible to achieve in real life, since the heating element cannot actually provide that much P. I would probably alter the code so that dE_in would never exceed Pmax*dt to see simulate a more realistic graph.

3) Delay: Bang-bang

Here is the graph simulating the delay of 10 seconds. If we compare the graph with the previous bang-bang graph, we will probably see a 10-second shift to the right from this graph.

4) Delay: Proportional

Here is the graph simulating the delay of 10 seconds. If we compare the graph with the previous proportional graph, we will probably see a 10-second shift to the right from this graph.

Thursday, April 9, 2015

MATLAB Introduction

I've heard about MATLAB for a long time and now it's finally our chance to learn it!

We started learning MATLAB by reading the book found at this address:
greenteapress.com/matlab/PhysModMatlab.pdf

Here a few of the exercises we have done in class.

Ex. 2.1
The first is to write a script that would generate the nth Fibonacci number. This program is fairly straight-forward. I actually changed a code a little after I took the screenshot:
     first = (1+sqrt(5))/2;
     second = (1+sqrt(5))/2;
     Fn = 1/sqrt(5)*(first^n - second^n)
This way it is easier to see how Fn is affected by n.

Ex. 2.3

Again, very straight forward, this script calculates the number of cars at each location after each week. Note that there is no n involved in the script, so the calculation is recursive. To reach the nth week (assuming starting at the 0th week), we must run the program for n times. While I was writing the code, I initially put a=150; and b=150; in the script. This became problematic because a and b would reset every time we run the script. As a result, we must initialize a and b in the command window and then run the script.

Ex. 3.1

In the previous exercise, we had to manually click "run" n times to get the result for the nth week. Here, using loop, MATLAB will automatically calculate the result after the nth week. Note that I used 52 here because there are about 52 weeks in a year. The number seems to stabilize at 118 and 182. If we wanted to calculate for any n, simply change the loop to: for i=1:n and then initialize n in the command window before running the program.

Ex. 3.2


This is a follow-up of the previous exercise. Here I used the semi-column to hide numerical results, since we are interested in the plot. Clearly, the graph seems to converge to the numerical value calculated in the previous exercise.
When a and b are initialized at 10000
Ex. 3.5

In this exercise, I certainly made the script more complicated than it had to be. I was in the mindset of "car_loop" where two variables are updated after each time the script is run. I would rewrite the code as follow:
     F(1) = 1;
     F(2) = 1;
     for i=3:10
           F(i) = F(i-1) + F(i-2)
     end
My only concern is if MATLAB would misinterpret F(1) with the parentheses. I would have to try this code again.

Ex. 4.6


The first image shows how to put the Fibonacci numbers into a vector. The second image shows the calculation of the ratio between Fibonacci numbers. Clearly, they converge to 1.6180, which is in fact an estimate of the golden ratio. If I were to use the long format, we could probably see more digits that converge to 1.61803... which is also the value we used to calculate each number in the first exercise.

Friday, April 3, 2015

Arduino/Sciborg

Now that we are more familiar with the Sensors, we can start to move the Sciborg! We are focused on understanding the two different types of control: bang-bang control and proportional control. Here bang-bang control refers to the type of control that only has on and off two options. Proportional control refers to when the output is proportional to some feedback factors.

Bang-Bang Control

Last time when we used time to make the Sciborg to go for 10 ft, the Sciborg would stop +/- .5 ft. This week we are using the encoder, which is a sensor in the motor that records how many turns the shaft has made. After a few trials, we decided that we will make it close to 10ft using a number around 12500.
The delay allows us to put the Sciborg on the floor and straighten it up before it starts running
We are pretty close to 10ft. Note that the Sciborg does not go straight/go at a same angel each time, so we did not spend more time getting the number more precise.


Our next task is to use bang-bang control with the ultrasonic sensor. We used the number 15 here, which is the smallest number that showed up in our previous reading with the ultrasonic code.
We were able to get the Sciborg stop wherever we wanted after a few test runs, seeing what the reading of 15 translates to distance in real life. Note that we had to make sure the whole track was clear so that it would not stop because of other objects in the way. Note that we must put the Serial.println in the loop so that the value would be updated each half second. We first tried the code without Serial.println in the loop. The Sciborg ended up going at the same speed that correspond to the initial reading.

Proportional Control

Using encoder again, we are now doing proportional control. Our goal is to have the speed of the Sciborg proportional to the number of turns in the shaft. This means that the closer we get to the target goal, the slower the Sciborg would be.



Note that the number for target position is very different from the one we used previously with an encoder, because the Sciborg would actually stop before it reaches target position, once the velocity becomes too small. So this actually never reaches the target position written in the code. However, it got us very close to the finishing line. Also, like we did with ultrasonic bang-bang control, the value for speeds must be written in the loop, so that it will be updated each 10 milliseconds.

We then added another function toward the end, called nudge, which would help the Sciborg to over come the last bit of friction and reach target position.


Note that we used a different value for target position, and that is because we used a different surface. We moved to the rug outside with a bigger friction, which in fact helped the Sciborg to go straight. The bigger friction, however, would require more turns to reach the target line in real life. I cannot figure out why exactly, but I imagine that it has something to do with slipping of the wheels.

When we were writing this code, we also had a question regarding the difference between the "if()" and "while()" command. It turned out that in the loop, "while()" command would not end until the statement in the parentheses are not true, but "if()" would only run once. As a result, we put delay in the while() command to run it repeatedly, asking Arduino to check its distance from target position.

Our next task is to use ultrasonic sensor to have the Sciborg follow something in front of it.
Before we started writing the code, we first tested how the reading correspond to distance. It turned out that for objects <20cm away from the sensor, the reading was 11. At 30cm, the reading was 20. 30cm --> 25, 40cm -->30.




This is in fact a bang-bang control, even though there are three options, as opposed to two. We then wrote another code, so that if the Sciborg gets too close to the leading object, it would back off a little.

Here is when we encountered a problem, where the reading would become very random. After a while we realized what happened. Earlier, our ground wire broke off from the sensor, and we soldered it on. And then the middle wire broke off, which we soldered on again. We probably did not do the best job soldering the wire. We tried the sensor on basic code that simply shows the reading, but same thing would happen. Since we could not fix the sensor, we were not able to run the proportional code.

  


Here is the loop part of the proportional control code:
while (analogRead(A0) < 100) {
int v1 = analogRead(A0) * 12.75;
int v2 = analogRead(A0) * 11.75;
m1.set_speed (v1);
m2.set_speed (v2);
delay (100);
}