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

The limited sweep

In this iteration of the Controller class, we attempt to resolve two issues, namely limiting the sweep to a specified maximum angle and keeping the robot from deviating from a straight-line segment.

Code changes (Controller.java)

This solution involves modifications to sweepClockwise() as a prototype. I will only present the parts of the code that have changed since the last iteration. The first change we made is to introduce two new members (variables) in the class:

   private final static float DELAYS_PER_DEG = 100.0f / 180;
   private final static int SMALL_ROT = 10;

The first variable DELAYS_PER_DEG encapsulates our empirical knowledge that 100 delays roughly corresponds to 180 degrees of rotation (this number may be different for ...

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