How to make simple a program for line following with a switch? Pro Preview

We should all know how to follow a line in the most simple way possible. If the sensor detects that it is not above a line, the robot turns to the line. If the sensor detects that it is over the line, it turns away from it. But let's do this with a Switch Block. 

To access the full video please subscribe to FLLCasts.com

Subscribe

  • #1257
  • 08 May 2019

The logic of the program is the same and even better. This variant of the line following with a Switch Block does is not influenced by the color of the floor, but only by the color of the line. We start by placing a Switch block that checks if the surface below the sensor is black.

If it is black we turn left/right:content picture

If it is not black we turn the other way:content picture

At the end we put everything in a loop and our robot is ready to follow a line. Be careful to configure all the motor blocks that make the robot turn to have the settings 'ON'. If we use blocks for only one motor, we should stop this motor, in the case where it should not move. Otherwise your robot will not turn. 

Why are we using a Switch Block? The greatest advantage of this variant of following a line is that in this case the robot program does not block and wait. When we use Wait blocks, everything in the loop waits one block to complete and then execute another block. But in this variant because the Switch block completes right a way, there is no wait. This allows us to also do other checks in the loop.  

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for Level D2. "Seafaring". Robotics with LEGO
  • 24
  • 2:49
  • 107
Image for Lesson 4 - Yacht
  • 4
  • 5
  • 8
  • 3d_rotation 1