Tuesday, March 29, 2016

SciBorgs and Proportional Control

For the rest of our time with ropSciBorgs we were tasked with changing the sketches we did using bang bang control to sketches that used proportional control instead. 

Proportional control is a feedback and control system where power is proportional to the error (how far reality is from the goal). Power can be calculated with the equation:

Power = Kp *  error
Error = goal - reality
Kp= gain coefficient; 

When the gain coefficient is too big the power becomes much larger than needed and there is an overshoot and then the gain coefficient is too small there is an undershoot. 

Task #1: Drive straight

In order to make our SciBorg drive straight using proportional control, we used the difference between the positions of each motor to be the error of the speed of motor 1 since motor 1 was determined to be faster than motor 2. We then set motor 2 to have a constant speed of 225.  In order to get the speed of motor 1, we added its speed error to the speed of motor 2 and multiplied it by our gain coefficient of -1. So when motor 1 has a larger position than motor 2, motor 1's speed undershoots and becomes set to a little slower than motor 2 and when motor 2 has a larger position than motor 1, motor 1's speed overshoots and becomes a little faster than motor 2.




Using the motor encoder, we were able to read that with our sketch, the difference between the positions of motor 1 and 2 went down to 3. Before, the difference would exponentially grow to over 500.


Our SciBorg drove the straightest we had ever seen it! :D
Surprisingly, on a high friction surface our SciBorg did not drive very straight. :(
On a surface with high and low friction, the SciBorg drove straight when the low friction was on the left wheel (motor 1) but it did not drive straight at all when low friction was on the right wheel (motor 2).
Our SciBorg surprisingly was able to go up most of the ramp. Using bang bang control, it could barely go up a foot of the ramp before falling off. :)
Our SciBorg was able to successfully go down the ramp :)


Task #2: Drive 10 feet and nudge

In order to make our SciBorg drive straight 10 feet and stop, we used the difference between our 10 feet position 12650 and the average of the positions of the two motors. We then used a gain coefficient of 0.01. The power was then added to 100 so that as the SciBorg got closer and closer to the 10 feet mark, it would slow down.

Our SciBorg ended up being about 3 inches away from the 10 feet mark.



We then used a function called nudge that would make the SciBorg  go at a constant speed for 1 second to help it get to the finish line. When the position of motor 2 was less than  12000, the speed of the motors is given by the speed we calculated before and when the average of the position of the two motors was more than 12000 but less than 12650, the function nudge would be performed. The function nudge would make the SciBorg travel at a constant speed of 106 for motor 1 and 120 for motor 2 for 1 second.


Our SciBorg reached the line!! :D


Task #3: Following using ultrasonic sensor

In order to make our SciBorg follow other Sciborgs using an ultrasonic sensor, we calculated the power to be 5 (the gain coeffiecient) times the error (analog reading of the sensor minus 11 (the lowest reading of the sensor)). We then set the speeds of the motors to be the power. Because we did not give a different speed for each motor, our SciBorg did not drive straight but it was able to smoothly follow a piece of Delrin.




Task #4: Following the line

In order to make our SciBorg follow the white line, we made the speed of motor 1 to be 5 (the gain coefficient) times the error (the light reading value minus 75 and then added to the speed of motor 2). Our SciBorg was able to follow the line much more smoothly and faster than when we used bang bang control. :D



Overall, I found proportional control to be much better than bang bang control because it made our SciBorg perform the tasks much better. Writing the sketches using proportional control was difficult at first but as we got more experience with it, it became much simpler and easier to use than bang bang control.

Monday, March 14, 2016

Feedback and Control Systems

We have come to wonderful time where a lot of things have become automatic and this is due to beautiful feedback and control system.

One example of a feedback and control system we encounter frequently are automatic doors. Automatic doors are able to sense that a person is in front of it either through a weight sensor usually disguised as a black mat in front of it or through optic or motion sensors that sense motion in front of it. The computational part of this system converts the digital reading from the sensors in to a command to make the doors open which is the actuation mechanism of this system. Sometimes the sensing mechanism of this system becomes a little rusty and it does not sense that someone is in front of the doors causing many people, including myself, to stand and wave around awkwardly in front of the door until it opens. The actuation mechanism of this system is pretty great. It's pretty handy to have the doors automatically open especially when your hands are full. 


Another example of a real-world feedback and control system are the ones we encounter in a public bathroom. In a lot of bathrooms, there are now automatic hand dryers, soap dispensers, faucets, and toilets. These systems sense when there is something a certain distance away from it. The computational part then converts this information to turn the hand dryer on, the soap dispenser dispense a certain amount of soap, turn on the faucet for a few seconds, and flush the toilets. The actuation mechanism of these systems are amazing since they provide sanitation to its users. The sensing mechanism of these systems are sometimes lacking though. Sometimes automatic toilets flush before people stand up, faucet sensors are too high up, and automatic hand dryers don't turn on.


Another really cool example of a feedback and control system is the water station that we have in a few buildings here in Wellesley. The sensing mechanism senses when there is something underneath it and a second or two later the actuation mechanism dispenses water and when the bottle is removed from under the sensor the actuation mechanism immediately stops the water from continuing to flow out. One thing that works poorly in this system is the time it takes for the information from the sensor to be converted to the command that makes the water stop flowing out. But overall this system is pretty great since it can get tiring pressing down on the button of the water dispenser until your whole bottle is filled and losing a few milliliters of water is not too bad.


An oven is another example of a feedback and control system. You turn on an oven and set it to a certain temperature. An oven's sensor senses the temperature of the inside of the oven. When the oven reaches the temperature you wanted it to be, heat stops being released. If the oven is still on and the temperature begins to dip, the computational part of the system sends information to the actuation part to start releasing heat again until the oven reaches the temperature you programmed it to be again. This cycle continues until you turn off the oven or if the timer you place on it goes off. A really cool part of this system is that its output is also sensed and used to create another different output. 

What ovens usually prevent us from having to do. 

Friday, March 11, 2016

SciBorgs Day II

For our second day of SciBorgs, we first had to examine how accurate was each sensor and then use Bang-Bang control to make the SciBorg drive straight, follow a white line, and follow other SciBorgs in a conga line.

Motor Encoder

The motor encoder reads the position that the motor is at per delay that it is coded. The sketch that was given to us made the wheels move forward for 1 second and backward for 1 second. We noticed that even though the the wheels moved forward and backward in the same amount of time, its position did not return to 0. This is because the motor does not accelerate to full speed at the same rate each time and because of the time it takes for the program to run and get the position of the motor.

We used the motorencoder sketch given to us in order to create a new sketch that will make both motors go at full speed until motor 2 reaches a position of 12500. We chose motor 2 instead of both motors because motor 2 went faster than motor 1 and so would get a higher position value first. When deciding what position to use to tell the SciBorg to stop at, we first tried running the program for 16 seconds (the time that we previously got as the time it took the SciBorg to travel 10 feet) and then getting the position of the SciBorg. It first said that at a position of 20500 the SciBorg would have traveled 10 feet but when we ran the program and let the SciBorg travel on the floor, 20500 actually went about 20 feet. So we then just kept trying lower and lower numbers until we got to 12500.





Touch Switch

The touch switch is a sensor that senses when it is being pressed.  The initial sketch allowed us to see on the serial monitor that when the button was pressed it would say that the button was pressed. The delay was pretty short so the program was pretty accurate. We used the sketch provided for us to make the SciBorg travel straight at full speed until it touched the Delrin Sheet and then it would stop and then continue moving again if it were not being touched.





Light Sensor

The light sensor of course senses light. We are able to read raw values and scaled values of the light readings. The scaled values ranged from 0 (dark) to 97 (light). We chose to use the scaled values since they showed a larger difference of numbers between light and dark. The values were not very accurate because depending on whether or not there was a shadow or not and how far away the sensor was really mattered. We found the the light sensor worked best at a distance of 15 mm.

In our sketch, we made the SciBorg go straight until it sensed white and then it would stop. In this travelling and stopping exactly where we want it to challenge, the light sensor was amazing at helping the SciBorg because for once, the SciBorg stopped exactly on the line like we wanted it to.



Ultrasonic Sensor

The ultrasonic sensor works by sending out ultrasonic waves to calculate how far away the object in front of it is. This sensor was not very accurate. The closest the sensor could sense is 6 inches. The lowest value we read from the sensor was 11.

We used the ultrasonic sketch provided for us to make the SciBorg go straight until it sensed something was at a minimum of 6 inches in front of it. We held a Delrin sheet at the 10 feet mark and let the SciBorg go to it at full speed and then it was actually pretty accurate and stopped a little under 6 inches in front of the sheet.





Straight Bang-Bang

In straight bang bang, we used bang bang controls to make the SciBorg drive in a straight line on different surfaces. We made it so that when the motors had the same positions, the SciBorg would continue on straight but if motor 1 was bigger, the SciBorg would make a very gentle right turn so that motor 2 could catch up and if motor 2 was bigger the SciBorg would make a slight left turn so that motor 1 could catch up.



On a surface with low friction, straight bang bang would work about 75% of the time. It really depended on how straight we set the SciBorg down. The SciBorg still tended to veer to the right.
Bang Bang straight line on surface with low friction.

On a surface with high friction, the SciBorg drove really straight. It still tended a little more to the right but it was still the straightest we had seen it. 

Bang bang straight line on surface with high friction.

On a surface with one wheel on high friction surface and the other wheel on low friction surface, the SciBorg went straight for half of the distance and then started to veer towards the carpet. 

Bang bang straight line with low friction on one wheel and high friction on the other wheel.

Going down the ramp, the SciBorg was able to go straight most of the time. 

Bang bang straight line going down the ramp.

Going up the ramp, the SciBorg had a really hard time and would always go to the right. 

Bang bang straight line going up the ramp.


Follow the Line

Follow the Line was the toughest challenge that my partners and I had faced. It took us hours to get this sketch right. We tried many many sketches. Some were way more complicated than they had to be and most did not even show that the SciBorg sensed the white line. After hours of frustrations and getting angry at our little lego robot that seemed to do what ever it wanted, we finally whipped it into shape and it followed the white line.

We made the SciBorg sense either if the sensor is on the white line or on the cardboard. If it sensed the white line, we made it move to the right towards the cardboard and when it sensed the cardboard, it would move the left towards the white line. The program would run every 5 milliseconds and so the SciBorg would sense where it was every 5 milliseconds.

We learned from Xi Xi that the magnitude of the difference between the speeds of the motors corresponded with the angle that it would turn at. Hours before we finally got the right code, we had initially wrote a sketch similar to this but the speed differences between the two motors during the turns were very small and so the SciBorg would not even turn. So once Xi Xi helped us out, we were able to play around with different speeds and angles until we found the best one.





Conga Line

In the Conga Line challenge we were supposed to use a sensor and create a sketch that would make our SciBorg follow the SciBorg in front of it. We used the ultrasonic sensor since it was able to sense objects at least 6 inches in front of it. We wrote a sketch that made our SciBorg go forward at full speed until it sensed something was a little more than 6 inches in front of it. It would then move at a slow speed and if it sensed that the SciBorg in front of it was less than 6 inches away, it would stop moving until it sensed that the SciBorg in front was no longer 6 inches away and then continue moving.




Monday, March 7, 2016

SciBorgs Day 1

a) Making Functions
Challenge: Make an LED flash the Morse code for SOS
We (Jiaming, Vivian, and I) learned that we can make functions outside of loop that we can call into the loop section letting us use the same code repeatedly without having to retype everything. It's very handy because it would suck having to read and write the same code over and over again if we can simply write it once and call it again at later.




b) SciBorg Challenges:


#1: Run both motors
We copied the code from the single motor example and added that MOTOR_2 would be referred to as m2. We then made both m1 and m2 start at set up and then loop through speeding up to full speed for 1 second, movingforward at full speed at 1 second, speeding up again for 1 second but in reverse, and then moving in reverse at full speed for 1 second. The program would also print out "Going forward slowly then fast" when it was accelerating forward and print out "Going in reverse slowly then fast" when it was accelerating backwards. 



#2: Find minimum speed
In order to find minimum speed, we plugged in different numbers for the speed of the motor. We found that the lowest speed the motor will turn the wheel at is 55 but, if the SciBorg is on the floor, it will not move at a speed of 55. 
We also found that the minimum speed the SciBorg will move when it is on the floor is 75.

#3: Hard turn
In order to make the SciBorg to make a hard turn, we made the SciBorg travel straight for 5 seconds and then we made one of its motors move turn the wheel forward at full power and the other moved the other wheel backwards at full power for half a second. The combination of a large velocity in a small amount of time resulted in a hard right turn. 





#4:Soft turn
In order to make the SciBorg make a softer turn, we made the SciBorg go straight again for 5 seconds at a speed of 150 and then after 5 seconds, we made one motor continue moving the wheel it's attached to forward at the same speed while the other motor moved the other wheel at the same speed but backwards for 2.5 seconds. A smaller velocity and longer time caused the SciBorg to make a much softer slower right turn. 






We tried making the SciBorg move straight at a speed of 150 for 5 seconds and then hopefully make it softly turn by making the motors turn the wheels in opposite directions but at the minimum speed of 75 for 2.5 seconds. This did not work. The SciBorg instead just stalled for 2.5 seconds and then continued moving straight at a speed of 150.




We also tried going straight at a speed of 100 and then turning at a speed of 100 for 2.5 seconds but that also did not work well. The SciBorg would move straight and then stall and slightly move to the right. 


#5: Travel 10 feet
We first timed how long the SciBorg would take to travel 10 feet at a speed of 225. We got that it took the SciBorg 16 seconds so we wrote an if loop saying that if the program has been running for less than 16 seconds, the SciBorg would move at a speed of 225 or else it would not move and have a speed of 0. We found that the SciBorg did not always travel in a completely straight line. It often curved slightly to the left or right. Once when we ran our 16 second code, the SciBorg nearly traveled exactly 10 feet and it was only off by about half an inch. But another time, the SciBorg was 6 inches from the 10 feet line. 






The SciBorg did not stop exactly at the line because all we told it to do was travel for 16 seconds at a speed of 225. It did not take into account that it might not travel in a completely straight path or that it might hit something or slow down causing it to not travel the total 10 feet. 

Reflection:
The hardest part of these challenges was setting up all the files. We had a problem where we accidentally put one of the files into another folder which confused Arduino. The coolest challenge was making the SciBorg make a hard turn just because it was really entertaining watching the SciBorg travel in a square path. 


Friday, March 4, 2016

Arduino Introduction Part II

For day 2 of Arduino Jennifer and I first started looking at our pattern with no delay code and board. Amy said that our board was all wrong since each LED did not have its own resistor. Then Jennifer realized that the LEDs were not behaving the way we thought our code told them to. So we first fixed our breadboard so that each LED had its own resistor and removed all the wires from the potentiometer challenge. We then played around with our code and found that we needed to make a new last time per if statement for each LED so that the LEDs would turn on and off exactly the way we wanted them too. We made it so that the the green LED would turn on and off in intervals of 1 second, the red LED would be in intervals of 3 seconds, and the blue LED would be in intervals of 5 seconds.




Challenge #5: Use a photocell to change an LED
In this challenge, we first learned about how a photocell is a resistor that takes in the amount of light in its surroundings and changes the amount of resistance depending on how much light is sensed. Using the line Serial.print() we were able to translate the number the photocell took in to a description of how bright it was. We then used the photocell to turn on and off an LED. We made it so that when the photocell thought it was "dim" (200 < value < 400) the LED would turn on and if the light value was not within that range, the LED would stay off.






Challenge #6 Use a button
In this challenge we learned how to use a button to turn on and off an LED. The LED only turns on when the button is pressed because when the button is pressed the circuit is closed and electrons are able to flow through it but when the button is not pressed, the circuit is not complete and so the LED does not turn on.





Challenge # 7 Use a Servo motor



Sweep:
The disk on the Servo continuously moves back and forth between a specified angle range. We put it to 90 degrees to 90 degrees.





Knob:
The disk rotates between 60 and 120 degrees when the potentiometer is turned from one side to the other.



Reflection:
The most difficult and frustrating challenge was fixing the pattern with no delay code. It took us a really long time to understand exactly what was going on but it was very satisfying when we were finally able to fix it. The most enjoyable part of the last challenges was controlling the LED using the photocell and button.