CS 1020 - Homework 2 - Improve the follow-line program

Due: Wednesday, 1/9

  1. Print out your code from lab 2 and submit it at the beginning of class on Wednesday

  2. Read pages 1-21 in the course pack, and review the Sciborg code.

  3. Improving follow-line
    Your mission for Wednesday, should you choose to accept it, is to turn your ideas from lab 1, question 4 into reality by writing a better follow-line program. If you are successful, your Sciborg should be able to run a race like today's in less than half of the time it takes with the old follow-line code!

    Here are some hints:

    1. Review your notes from class and do the reading to further your understanding of Handy Logo.

    2. A common idea is to make the Sciborg do a slight-left turn and a slight-right turn instead of the hard left and right that it does under the present algorithm. This can be achieved by changing the power of the motors (and thus the speed of the wheels). Each motor has a power range from 0 to 8, where 8 is full power. This is the default level if none is specified. You can use a command like
      left-wheel setpower 4 on thisway
      to turn on the left motor at half power (we are using the existing Sciborg definition for left-wheel here).

      If you want to use this strategy, you should define a slight-left and a slight-right procedure. Experiment with different power levels. (A good idea here is to define a new global variable "low" and create procedures called low+1 and low-1, similar to the ones we have for black, which can be used to change the value of low on the Handy Board.)

    3. Keep the two light sensors fairly close together. We will set up a race course with some long straight sections. Your Sciborg should detect if both sensors see black, and should be able to follow those sections in a straight line. If one sensor veers off the line, however, the Sciborg should do a slight turn the appropriate way and continue turning until both sensors can see the line again.

    4. Think hard about what should happen if neither sensor can see the line. You may want to introduce a global variable to "remember" which sensor saw the line last (use the procedure "beep-on-off" from lecture 2 as an example).

    This is a fairly tricky programming assignment. Be sure to ask or email us for help, and also try to get debugging help from your classmates.

    Make sure you document your program well (use comments to explain in plain English what's going on), and add your names in a comment at the top. Hand in a printout of your code.

    Sciborg Grand Prix

    Wednesday's lab will begin with another race to test your improved programs - this is your chance to win the coveted Sciborg Grand Prix trophy. Sciborgs will have to follow a long, slightly curvy line to the end, make the U-turn and come back to the starting point. To help with the U-turn, we will add a box at the end of the track. Use the bump sensor to detect it and do a speedy 180-degree turn. There will be a few hazards for cars that stray too far from the line, so your improved follow-line algorithm should prevent this from happening. The race course will be set up in the hallway outside our lab. Make sure your light sensors (and wheels!) can handle the linoleum flooring.

    Besides working on your program, you may also want to improve the mechanical design of your car, to make it go fast and smooth. One problem many cars often have is that the coaster wheel doesn't move freely, which makes it hard for the car to turn. To avoid this problem, try to keep most of the weight of the car over the main wheels.

    Be sure to have a working car by Wednesday morning - there will be very little time for last-minute adjustments.