Tasks for December 14 and 15
For the next couple of days, you will be working with Python functions, looping, random numbers and taking pictures.
Please make sure you have a comment at the top of your programs saying who is in your group. Place all activities in a single file. Feel free to play around and try things! Just make sure all your group members get a turn at the keyboard and that you’re staying focused on Python. Reading the news, playing games, etc, will severely lower your grade. There’s a lot to explore here. If you’re bored, ask me for some Python tutorials, ask me how to use the other sensors, etc — the sky is the limit.
Activity 1: go function
Write a function named go that takes distance as a parameter and makes the robot go that many inches. To do this, you will need to experiment with how much distance a robot covers over different amounts of time and write an equation to relate distance to time. To do this, you may want to get a marker and have your robot draw lines that you can then measure with a ruler.
The call go(6) should make your robot go 6 inches, the call go(0) shouldn’t do anything and a call on go(1.5) should make your robot go 1.5 inches.
Activity 2: random movement
Write a function that makes your robot go forward a random number of inches between 1 and 6, then turns a random amount (range of your choice) and repeats. Your function should take one parameter: how long the robot should repeat this for. For example, the call rand_moves(10) should make your robot make random moves for 10 seconds. Similarly, a call on rand_moves(15) should make your robot move randomly for 15 seconds.
Activity 3: pictures
Write a function that will take a picture, show it, wait 3 seconds, go forward 1 second. Your function should take one parameter: the number of times to repeat this. For example, a call on pictures(10) should make your robot take a picture, display it, wait 3 seconds, go forward 1 second and repeat the whole thing 10 times.
Activity 4: random pictures
Write a function that will make your robot go forward and turn randomly and then take a picture. Once the picture is shown on the screen, the user should be asked whether the picture shows what they’re looking for. Your robot should repeat this behavior until the user says that yes, they saw what they were looking for. For example, if your robot is meant to be looking for a whiteboard eraser that’s a couple of feet away, you might have to say no to three or four pictures before the robot orients itself such that your camera takes a picture of the eraser.
This example will help — copy it and run it to see how it works:
def ask_question():
ans = raw_input("Do you think robots are amazing? ")
while(ans != "yes"):
ans = raw_input("No seriously... robots are awesome, right?" )
print "!!!"
Notice that this prompts the user over and over again until they agree that robots are amazing. In other words, while the user’s answer isn’t yes, the value of the variable ans gets a new value from the user. You will need to use this same idea to get the user to react to each picture the robot takes.
Activity 5: creep bot!
Combine your knowledge of the joyStick() command with taking pictures to have your robot repeatedly take pictures as you drive it around. How well can you navigate without seeing your robot?




