Wednesday, March 16, 2016

SciBorg Part 2 (Sensors and Stopping After 5 Feet)

Our first challenge was to explore different sensors (an ultrasonic sensor, a light sensor, a motor encoder, and a switch) to understand how they work, and then use each sensor to make our SciBorg travel a predefined distance and then stop. We then analyzed the advantages and disadvantages of each sensor and came to a conclusion about which was most effective.

Motor Encoder

The first sensor we tried out was the motor encoder, which reports the position of the motor at a specific time. We ran a program which made motor 1 repeatedly spin forwards at speed 225 for 1 second, then spin backwards at speed 225 for 1 second. The program printed out the position of the motor at the end of each loop (once per second). One would expect the motor to spin forward x amount, so that the first position recorded is x, and then spin a distance of -x, so that the 2nd position recorded is 0 (x-x=0). However, as you can see in the picture of the printouts below, this was not the case. The motor is inconsistent, so it doesn't always spin the same distance in the same amount of time. That is, the speed you assign to the motor in the code isn't always the speed it actually goes. In addition to inconsistencies on the motor's part, perhaps the voltage from the USB port fluctuates slightly, which results in slightly different speeds. 


You can see how inconsistent one motor is, imagine trying to get two of them to work together! Next, we ran a program that printed out the positions of both motors after each second. We noticed that motor 1 was much slower than motor 2. We thought it would be interesting to plot the relationship. Below, you can see that the difference in motor position vs. time fits a quadratic relationship. We thought that perhaps we could use the equation generated to determine how much to adjust the speeds of the two motors in order to make the SciBorg drive a straight line. That's definitely not bang-bang control, though, so we'll save it for another time.


Next. we programmed our SciBorg to move forward at speed 225 and timed how long it took to travel 5 ft, which was 8 seconds. We then plugged it into the computer and read the positions of the two motors after 8 seconds. We did this several times. The average position of the slowest motor (motor 1) after 8 seconds was 6123. We then wrote a program that told the SciBorg to move forward at speed 225, and stop when the position of motor 1 was equal to or greater than 6123. Here is our code.


Here is a video of our SciBorg running the code. 



Our SciBorg stopped about 3-4 inches short of the 5 foot mark, which I think is pretty good. It stopped shorter than 5 feet because of the value we used for the stopping position, 6123. This value was an average, so depending on the trial, the motors may travel farther or less in 8 seconds. In the case shown in the video, the SciBorg was a little on the faster side, which is why it reached position 6123 sooner and stopped shorter than we hoped.

Touch Switch

The next sensor we experimented with was the tactile switch. I think this sensor was the easiest to use. When the button is unpressed, electricity can flow to the specified pin, so a reading of that pin would be high. When it is pressed, electricity flow is reduced to the specified pin, so a reading of that pin would be low. We used the values read from the pins to determine whether our car should stop or go. We placed a large piece of delrin at the 5 foot mark, supported by a trash can. The SciBorg should travel until it runs into the delrin, pushing the button and causing a pin reading of low, which tells the SciBorg to stop moving.  Below is a picture of our code and a video of our result. 



This method was extremely accurate for making the SciBorg stop after 5 ft. However, it is pretty inconvenient, because you'd probably want to be able to stop a vehicle without having to place a large obstacle in front of it. Also, depending on how fast a hypothetical vehicle is travelling, running into something in order to stop could cause damage.

Light Sensor

Next, we experimented with the light sensor. We ran a program which printed the values detected by the light sensor in order to understand which surfaces had high, moderate, and low values of light reflection. Here is a video (without the LED light turned on) in which you can see the values detected for different surfaces. 


When we turned on the LED, the sensor picked up values in the 90s for pretty much every surface we put under it. We couldn't really figure out what the LED is good for, besides showing you exactly where on the surface the sensor is reading from. Below is a video with the LED light turned on in which you can see the values detected for different surfaces. 




We noticed that the readings are more accurate when the sensor is closer to the surface (but not pushed up against it, as this blocks out light and can make a bright surface appear dark), so we attached the sensor on the car so that it would be very close to the ground.

Since the lab floor is gray, it has a relatively low value of light reflection. White paper had values in the high 90s. We put a white paper on the 5 ft mark on the lab floor. Then, we wrote a program that told the SciBorg to drive if the light reflection value was less than 90, and stop otherwise. Here is our code and a video of our result. 






The light sensor method was very effective. As you can see in the video, the SciBorg stopped almost immediately after it reached the white paper at the 5 ft mark.

Ultrasonic Sensor 

The last sensor we worked with was the ultrasonic sensor. This sensor emits sound waves which hit the nearest surface in front of the SciBorg and reflect back. The sensor measures how long it takes to receive the reflected wave back, which is used to calculate the distance to the obstacle. As the handout states, "because of acoustic phase effects in the near field, objects between 6-inches and 20-
inches may experience acoustic phase cancellation of the returning waveform resulting in inaccuracies of up to 2-inches. These effects become less prevalent as the target distance increases, and has not been observed past 20-inches. '' We decided to escape this issue by writing a program that makes the SciBorg stop when it's 2 ft away from an object. When the delrin was 2 ft from the SciBorg, the sensor read a value of about 37. We used a distance less than this value (if distance < 37) as the stopping point for our program and placed a delrin sheet 2 ft from the 5ft marker on the floor. A picture of our code and a video of our result appear below.



The ultrasonic sensor ended up being about 1.5 inches from the 5 ft mark. Pretty good, but once again, using this sensor was a little more complicated than it was worth. 

Conclusion

The tactile switch and the light sensor had the highest accuracies for stopping at the 5 ft mark. The tactile switch was the easiest to use/program for, and the light sensor was a close second. The motor encoder and the ultrasonic sensor were both inaccurate and difficult to use. 

No comments:

Post a Comment