O'Reilly logo

Lego Mindstorms EV3 Essentials by Abid H. Mujtaba

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Tracking a straight line

The first modification we make to Controller is to program it to follow a straight line. If the robot starts with its sensor already on top of a straight-line segment and is aligned along it, the robot will start moving forward (in a straight line) and will come to a stop when the segment ends.

This functionality is achieved by adding a number of methods to Controller and using them in the run() method, which is where Controller performs its primary function of controlling the robot.

The Controller.java file

The changes made in this step of the evolution are highlighted in the following code:

import lejos.hardware.Sound;
import lejos.hardware.port.Port;
import lejos.utility.Delay;

public class Controller
{
    private final static ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required