Line Following and Proportional Controls (EV3)

The aim of this challenge is to create a robot vehicle that follows a line and avoids collisions with obstacles – including other vehicles!

Robot design

A simple EV3 line follower

All you need for the most basic version of this challenge is a simple two-wheel robot, such as the Robot Educator Model with a Colour Sensor (referred to, and used as, a Light Sensor throughout this post), positioned at the front of the robot, pointing down.

Instructions for the Robot Educator Model are in the booklet that comes with the core set and in the EV3 Software.

Control theory

Control theory is a branch of engineering and mathematics that is particularly important in robotics. It deals with how a dynamic system with inputs (e.g. a robot) responds to feedback to modify its behaviour.

This challenge provides a very basic introduction to controls, including simple bang-bang controls and proportional controls.

Challenge ideas

Here is a selection of challenge ideas and sample solutionsโ€ฆ

1. A gentle stop

Can you create a robot that slows to a gentle stop when it sees an obstacle?

Gentle stop sample solution

2. Safe following distance

What if you want the robot to stop short of the obstacle (or follow another vehicle at a safe distance)?

Safe following distance – sample solution

Note: The multiplier of โ€œ2โ€ in this example is the proportional gain. You will need to experiment with this value. If it is set too small, the robot will not consistently reach the target distance (because of friction and/or stalling of the motors at low power). Too high and the robot will overshoot the target and may end up oscillating around the target distance.

Once you get this working, it’s fun to have a line of robots following each other…

It’s clear that the robots aren’t really following each other, and it doesn’t take long before they start breaking formation. This is particularly obvious towards the end of the clip.

What we really need is a better way to keep the robots in line…

3. Basic line following

How can you make a robot follow a line using a single light sensor?

Here is a sample program for a single Light Sensor using a bang-bang control.

The idea is that the robot will follow the edge of the line, by deliberately driving off it one way, and then driving the other way back onto it.

Basic line follow sample code

Notes:

  • The Switch is set to Colour Sensor > Compare > Reflected Light Intensity. Why?
  • You may need to adjust the Threshold Value of the Switch to find a value between the light background and the dark line. Use Port View on the brick or in the EV3 Software to help with this.
  • If your robot is struggling around the tightest corners, how can you adjust the Move Tank > Power Left / Power Right settings to make even tighter turns?

4. Smooth line following

What about making the robot follow a line more smoothly?

Here is a sample program for a single Light Sensor using a proportional control.

Smooth line following – sample solution

Notes:

  • This program uses a Colour Sensor block set to Measure > Reflected Light Intensity to take a light reading and then feeds this value into the Math blocks.
  • The Math Blocks are configured to evaluate these formulas:
    • Left motor = a + b x (c โ€“ d)
    • Right motor = a – b x (c โ€“ d)
      • a = default motor power
      • b = gain
      • c = target value
      • d = sensor reading
  • The difference between the target value and the sensor reading, (c โ€“ d) in our formula, is known as the error.

5. Intelligent highway

Can you modify your proportional line following robot so that it maintains a safe following distance behind the robot ahead of it?

Here is an example that combines a bang-bang approach to prevent driving into an obstacle with a proportional line follow. It is, however, also possible to combine two proportional controls.

Intelligent highway – sample solution

The result is something like this…

Assessment

Here is a possible approach to assessing this challenge.

Grade Performance
A+ Your car is the safest. Youโ€™re a defensive driving superstar.
A Your car follows the line and other cars reliably and smoothly.
B Your car reliably follows the line and stops when it sees another car or obstacle.
C Your car reliably follows the line or stops when it sees another car or obstacle.
t You have something resembling a vehicle.
The following two tabs change content below.

Rob Torok

I'm a teacher in Tasmania, Australia, and have been using LEGO MINDSTORMS with my students since 2001. I'm the editor in chief for LEGO Engineering (this site) as well as the content editor for LEGO Education Australia (LEGOeducation.com.au).

Latest posts by Rob Torok (see all)