Intro CS Assignments
Assignments by week:
Fall Term:
Winter Term:
Spring Term:
Tuesday, March 26
Description
Welcome Back, LineFollower
Homework
  • You're starting on the Line Follower robot today. Students who would like a skeleton class should copy the code from the following two files into their project:

    1. LineFollower.java
    2. NormalizationFilter.java (you do not need to edit or even read this class; it is used by the LineFollower to calibrate the color sensor)

    The LineFollower class sets up some helpful variables, and also outlines a basic flow for the program to try and follow a line. You are not required to use this exact set of methods. What I've provided is a suggestion, but you can solve the problem however you'd like. That said, if you're unsure about how to proceed, stick to what I've given you for now.

    There are several methods in the skeleton, all well-commented. Some are complete and ready to use, while others will need to have code added by you.

    To start, complete the turn method. This method, when given a number of degrees, runs the motors so that the robot is facing that many degrees away from its center position. For example, if you said turn(90, false); the robot would be facing 90 degrees to the right when done. If you said turn(-360, false) the robot would turn to the left in a complete circle.

    The turn() method needs to have a way to convert "robot degrees" into "motor degrees". If you measure how far apart the wheels of your robot are, and you know the diameter of the wheels, you should be able to generate a reasonable estimate of the ratio from one to the other. You can use this relationship to convert robot headings into motor rotations.

  • Come to next class with an attempt at the turn() method already written.
Thursday, March 28
Description
LineFollower
Homework
  • Continue working on LineFollower robot.
  • Your next assignment is to work on the findInitialLine() method. It needs to take the following actions:

    1. Using your completed turn() method, turn the robot in a full circle (or more).
    2. During the turn, repeatedly take samples. (Remember that if you pass true for the immediateReturn parameter, it will cause your program to run other code while the turn is still running.)
    3. Keep track of the brightest sample you've seen so far. When you take a new sample, compare it to the brightest. If it's brighter, remember that as the new brightest value. Additionally, remember the position of the motors so you can return to the point where your robot observed the brightest sample.
    4. When the robot completes its turn sequence, "rewind" the motors back to the position where it saw the brightest sample. This should be the tape location, so the robot is ready to go.
  • Optional hint: to help debug your program, have the robot make a noise every time it sees a new "brightest" reading. You can make a beep by including this line of code in your program:

    brick.getAudio().playTone(440, 500);

Friday, March 29
Description
LineFollower
Homework
  • Continue working on LineFollower robot.
  • It's now time to write the findLine() and followLine() methods.

    The approach is similar to that of findInitialLine() in that you're going to start the motors moving and then take samples from the light sensor and look for a certain condition. For findLine() you're looking for a reading that says you're on the line (you should stop the motors and return true). For followLine(), you're looking for a reading that says you're off the line (you should stop the motors and return).

    Because each of these methods picks up where the other left off, they work together to accomplish the task. If you want to test them in isolation, start with followLine() and just have findLine() return true. You can manually place your robot on the line and let followLine() do its job.