Three or more state programs Pro Preview

So far we have created programs that have two outcomes. For that purpose, we have used a switch block. We set some condition and based on its outcome we either do one action or other. Now, we will take a look at how we can program the robot to have 3 or more different responses to the environment.

To access the full video please subscribe to FLLCasts.com

Subscribe

  • #893
  • 30 Mar 2018

Let us take the example with the 3-state line following with the following setup:

So, if we put just a switch block that compares whether the value read by the color sensor is less than 27: 

the robot will not know what to do in case the value is greater than 27. If the value is less than 27, it is obvious that the robot should turn right. However, in that case, when the value isn't less than 27, the robot has to either go straight forward or turn left. If the value is less than 43, the robot should go straight, but if it is greater, then it should turn left. How can the robot decide what to do?

The same way it has made the decision to turn right - with another switch block. If we put another switch block comparing the value to 37, we will have our issue resolved. Due to the fact that the second switch is evaluated only if the first one is false, when comparing to 43 we know that the value is greater or equal to 20.

content picture

The use of switch inside another switch is called nested switch.

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for Instructors Remote Training
  • 136
  • 280:11
  • 156
Image for Competition programming
  • 7
  • 0
  • 8
  • 3d_rotation 1
Image for Level D2. "Seafaring". Robotics with LEGO
  • 24
  • 2:49
  • 107
Image for Lesson 6 - Catching the wind
  • 3
  • 5
  • 9
  • 3d_rotation 1
Image for Level C1. "Transportation". Robotics with LEGO
  • 33
  • 1:03
  • 110
Image for Robotics with LEGO - Level 2.0 - Robots in Factories
  • 44
  • 15:01
  • 129
Image for Robotics with LEGO - Level 2.0 - Robots in Factories
  • 44
  • 15:01
  • 129
Image for Lesson 5 - Robo Car
  • 6
  • 4
  • 11
  • 3d_rotation 1
Image for Robotics with LEGO - Level 2.5 - Maritime Journey
  • 42
  • 3:52
  • 133
Image for Lesson 5 - Personal Yacht
  • 7
  • 3
  • 10
  • 3d_rotation 0
Image for Robotics with LEGO - Level 2.5 - Maritime Journey
  • 42
  • 3:52
  • 133
Image for Lesson 6 - Catching the wind
  • 4
  • 5
  • 11
  • 3d_rotation 1
Image for Stay @ Home SPIKE Prime Course
  • 4
  • 0:33
  • 27