We started using a sensor called an encoder that transmits how many times the shaft has rotated. The program will tell you how many times it has rotated in the serial monitor. The code for the encoder. The sciborg will move backward for 200 loops and then forward for 200 loops.
The starting value for the encoder is at 0 because at the start of every run, the sciborg hasn't gone anywhere. The ending value is also zero because the sciborg goes forward 200 turns goes in reverse for 200 turns. 200-200=0. However, the end value isn't always zero because inertia stops the sciborg from starting immediately.
TOUCH SWITCH
The front of the sciborg has a touch switch that senses when it hits an obstacle. The switch is a lego button that you integrate into the sciborg using the breadboard. The touch switch program turns on a LED on the sciborg. However, the LED doesn't turn off because the code doesn't specify that it turns off.
Then we modified the code so that the light will only turn on when the button is pressed.
ULTRASONIC SENSOR
An ultrasonic sensor can detect objects within a certain area. They use high frequency sound to detect and localize objects. They measure the time of flight for sound that has been transmitted to and back from nearby objects and use that to output a range reading.
FEEDBACK AND CONTROL ACTIVITIES
Fixed distance, bang bang control
In a previous sketch we got the car to go 10 ft after a certain number of milliseconds. The first time we did it we only got about halfway to the finish line. However, by the end we were able to get within 2cm of the finish line every time that we let the motor go. We then needed to get the sciborg to move 10 feet using both the ultrasonic sensor and the touch sensor. We got exactly 10 feet with the touch sensor but only got within 5 cm with the ultrasonic sensor.
Ultrasonic Sensor
Touch Sensor
Fixed distance, proportional control
We wrote a sketch that uses proportional control to go exactly 10 feet using the encoder. As the sciborg got closer to the 10 feet mark, it went slower.
However, when we did this, the sciborg would stop a foot from the end because there was not enough power supplied to the motors to get to the end. So we made a code called nudge to add to the end of the proportional control so it would get to the end. Nudge causes our car to move a very small distance by very briefly turning on the motors at low power.
Nudge
Nudge on Proportional Control
This allowed our sciborg to get within a centimeter of the 10 foot mark every time
Conga Line
We needed to make a code so that our sciborg will follow something in front of it in a straight line. First using bang bang control, and then using proportional control.
Bang Bang Control
Conga Line Proportional
Both worked very well. The sciborg moved a lot more smoothly with proportional control than bang bang control. However we had a hard time making our sciborg run straight for all assignments.
I liked this post a lot because it really clearly explained what your goals were and how you accomplished them in your code! Documenting how precisely your sciborg came to completing the 10 feet tasks was a great idea, and providing the reasoning for why we needed the nudge loop was a good insight as well.
ReplyDeleteNice job on this post:) I liked how clearly you have outlined and explained the steps in the process. I especially liked that you took the time to explain why the encoder doesn't actually stop at 200. good work:)
ReplyDelete