The robot also moves pretty slowly since it has to spend so much time turning

The robot also moves pretty slowly since it has to

This preview shows page 4 - 5 out of 5 pages.

The robot also moves pretty slowly, since it has to spend so much time turning left and right to find the edge of the line. Let's try a method to make the robot move faster and more accurately. Instead of telling the robot what to do based on whether it is left or right of the line (two different states), let's make it more sensitive to its position. We will let the robot travel straight if it is close to the edge of the line, and only turn left or right when it moves away from the edge it is trying to follow. Since it reacts differently to three different conditions (left of edge, right of edge, close to edge) this is called a 3-State Program . Here is the pseudocode we want to follow: Get output from the sensor If the light sensor output is greater than ( > ) 60, we must be left of the line's edge o Move forward and turn slightly to the right Otherwise the light sensor output must be less than (<) 60 o If the light sensor is less than 60 but greater than 40, we must be close to the edge Move straight forward o Otherwise the light sensor is less than 40 and we are right of the line's edge Move forward and turn slightly to the left Repeat from the beginning The code may look tricky because it has an "if" statement inside another "if" statement, but if you think carefully, you will see how to write the program. You will need to use more than one switch statement to get it to work. Ask your instructors if you need help. 4
Image of page 4
An example of a 3-state line following program. 5
Image of page 5

You've reached the end of your free preview.

Want to read all 5 pages?

  • Spring '19
  • rwewe
  • Right-wing politics, Left-wing politics

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes