Partner: Rachel Hwang
1. Use the various sensors (touch, ultrasonic, brightness, and encoder) to fine-tune how exact your Sciborg (Stew) can get to the 10 foot line.
Task 1: Tweaking the Motor Encoder
The motor encoder basically can read the position that the motor is at, represented by a number (but is calculated cumulatively if the wheel keeps turning forward over many rotations). When we first ran the sketch, it ran the motor backwards and forwards for one second each. However, we noticed that the position didn't go back to zero. The first reason being that the motor after turning forwards and backwards for one second doesn't return to the exact same spot, the second reason being that because of the interval in which the motor checks itself. In this case, we had the motor check every 1 second, thus over multiple cycles of forward and backward, the lag/difference would be compounded.
Code notes:
- The code in the first image includes all of the packages and libraries required to control the motor and read the position. In addition, it sets up a variable to keep the time elapsed and a variable rpms that is the speed of the motors.
- The code in the second image sets up the Arduino to print the serial print statements in the 11520 baud setting. and tells the motors to begin.
- The code in the third image creates two variables motor1 and motor2 that will eventually store the position reading of each motor. Both motors are set to drive at the speed of rpms for 1 second, and then to go the same speed but in the opposite direction for one second.
Next, using measurements for the radius of the wheel and the length of the track (10 ft), we calculated the number of revolutions the wheels would have to go in order to go 10 feet (about 18 revolutions). We looked at the serial window, and saw a rough estimate of what the motor encoder would read after that number of revolutions (12643) and created a while loop for the motors to run while the motor encoder read value was less than 12643.
C'mon Stew! I know you can do it! (from this angle, Stew kind of looks like a bug) |
Conclusion: Pretty close, but not quite there. Probably because he doesn't move in a perfectly straight line. What are some other sensors that we can use to get him to the line?
Task 2: Tweaking the Touch Switch
We connected the touch switch to the Arduino (not an easy feat), and got the program to change the printout in the Serial window to the status of the button (pressed or unpressed). The key to getting the circuitry is using an LED in the circuit to visualize the state of the button (if electricity if flowing or not). Only one LED was sacrificed(burned out) in the testing of this process.
After we were able to get the Serial window to accurately print the status of the button, we altered the code so that the motors would stop once the button was pressed. Just to push ourselves a little bit further, we coded Stew to, once the button was pressed, stop, back up, turn around, and head the opposite direction. Cool, huh? Go, Stew, go!
Wiring:
Stew: Stop when button is pressed.
Code for final behavior:
Task 3: Tweaking the Light Sensor
In this exercise, we we attached the light sensor to the Sciborg and looked at the Serial window to see the different readings from the sensor. We also looked at how accurate the readings where with the additional LED light on and off and concluded that the LED light off was better. In order to get Stew to stop at when the light sensor was at the white line, we set the dark value for the light reading to set the motors to full power (Scaled light value < 70) on and the white tape light reading to be motors off (Scaled light value >= 70). The values ranged from 10 to 90ish. The distance to the surface was optimized after we attached the light sensor to Stew, about 2 cm.
Failed attempt (so you know we aren't always perfect):
Success:
Task 4: Tweaking the Ultrasonic Sensor
(Since I forgot to put in comments, here are the general notes on the code.) Basically we imported all of the relevant and required libraries, and set the Serial window input to be at 9600 baud. Depending on the value read from the ultrasonic sensor (the distance Stew was from something directly in front of him), change the behavior. If Stew's ultrasonic sensor read anything lower than 16, then stop (because he quickly approaching an object.)
Task 5: Use bang-bang control to get the Sciborg to go in a straight line. Bang bang control is basically on-off sensing. For example, if the air in your house gets too cold, then the heater turns on for a certain amount of time and then turns off, there is no in between. In this case, if one motor was lagging behind the other, then adjust the speeds of one motor so the other could catch up.
Task 6: More bang bang control - get your Sciborg to follow the white path!
(yellow brick road aka white tape road)
The key to success in taking apart this problem was by placing the light sensor on the edge of the tape. Take note of the light reading off the tape, on the edge, and completely over the tape. Thus, we were able to tell Stew to adjust a specific way (right or left) based on the light reading. Greater accuracy with following the path was achieved through decreasing the delay between measurements and decreasing how harsh the turn was to readjust the direction. Look at Stew wiggling is way down the white tape road! Off to Oz he goes!
(pretty jerky and misses the final turn) wait wait, reiterate!
(better, adjusted by the size of the delay and speed of the turn to adjust)
Task 7: Conga line!
Adjust the ultrasonic sensor code so that when it is far away from the object in front, go full speed ahead (with adjustments so it goes in a straight line); when it is medium distance from front object, go slow, when very close to front object, stop.
Overall, working on these exercises, the coding got easier over time, however, it was often hard to find new ways to work at the problem. Of all things, I would tell the students next year to never forget about the delay function, it is your friend!! Start by working on little steps, like going straight forward, and then working your way up. If anything goes horribly wrong or too complicated, the simply start over! Sometimes it helps to think of new solutions by starting with a clean slate! In addition, try taking apart the problem and working out how to approach it in a broad sense before you start coding!
Skills:
- bang bang control
- sci-borg coding in c
- sensing, input and output
- light sensors
- ultrasonic sensors
- touch sensors
- motor encoders
I actually really enjoy reading your blogs! :) Great job! And congrats that things worked in the end.
ReplyDeleteThanks! That is really sweet of you! I try to make them fun!
DeleteThanks! That is really sweet of you! I try to make them fun!
DeleteThe gifs are a really nice touch and it makes the blog come alive- congrats on the working sciborg!
ReplyDeleteThanks!
ReplyDelete