Robot activities

posted by: Ms. Martin 11 May 2010 One Comment

Work on these activities in your group.  If you are getting done early, GREAT!  I want to see you continuing to work with the robots in cool ways.  Feel free to skip around and to simply experiment.

Activity 0: song

Write a song function as outlined in the tutorial.

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.  Try to be as precise as you can, but don’t worry too much about it.  It’s going to be impossible to get it exactly right!

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.

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?

Activity 6: “Theremin”

You will write a program that beeps at different pitches based on the light sensor values.  For example, I wrote one that just adds up the three sensor values and uses that as the beep frequency.  I had mine loop for 20 seconds so that as I approach my hand to the robot, the pitch gets higher and higher.  This behavior is roughly based off of an interesting instrument called the Theremin.  Look it up!

Activity 7: Cockroach function

Your cockroach function will take one value as a parameter: the length of time the robot should move for.  Your cockroach should flee light and go towards darker places.  So, for example, if you start it near the edge of the shadow of a table, it should go under the table.  There are a few ways to implement this, but here is a simple one:

  1. read all three light sensor values
  2. if the left light sensor gives a value less than both the middle and the right light sensor, move right (remember, a low value means a bright light)
  3. if the right light sensor gives a value less than both the middle and the left light sensor, move left
  4. otherwise, go forward

Activity 8: Obstacle avoidance

The following code is the start to an obstacle avoidance program.  See if you can figure out what it does from reading it, then save it and run it.

while timeRemaining(30):
    if getObstacle("right"):
        backward(1, .1)
        turnLeft(0.7, .1)
    elif getObstacle("left"):
        backward(1, .1)
        turnRight(0.7, .1)
    else:
        forward(.5)
        wait(.1)
stop()

Right now, it’s not so hot.  What happens if you make your robot run this program while it’s directly facing a wall?  It just crashes, right?  That’s because we’re totally ignoring obstacles right in front of us!  Add a case for when there’s something right in front.  Your robot should go backwards then pick randomly with equal probability to either turn right or left.

Next, make your robot beep when it sees an obstacle.  You should use three different pitches and tone lengths for the three different obstacle positions so you can hear what your robot is doing.

Finally, make your robot stop and take a picture whenever it runs into an obstacle.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>