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.

Tuesday, March 1, 2016

Arduino Introduction

Last Friday the class started our new project with an introduction to Arduino. My partner for this new project is Jennifer.


Challenge #1: Blink with delay of 10
For this challenge we learned that time in Arduino is in milliseconds so a delay of 10 is 10 milliseconds which is so fast that the human eye cannot register it.

Challenge #2 Pattern with 3 different LEDs using the delay function
We added an output per pin and set their delays to be different intervals.



Challenge #3 Use potentiometer to change LED blinking behavior



Challenge #4 Pattern 3 different LEDs without using the delay function




Reflection:
I found figuring out what to comment was the hardest part since I initially did not understand how the language of Arduino worked but as I got more experience with it the easier it got and the more enjoyable it became. The greatest part of learning Arduino was seeing our code work. Watching the LEDs blink the way we wanted them to was so satisfying.