Ordering a drive-to-wall script

You are writing a MATLAB script that drives a two-motor EV3 robot straight towards a wall, stops once the ultrasonic sensor reads less than 0.20 m, and then displays how far the robot travelled during this move only. Put the stages of the script in the order they must run.

  1. 1.

    Call resetRotation on both motors so their encoder readings start at zero.

  2. 2.

    Connect to the brick with ev3 = legoev3('usb');.

  3. 3.

    Inside a while loop, call readDistance and leave the loop once the reading falls below 0.20 m.

  4. 4.

    Read both encoders with readRotation and display the distance travelled.

  5. 5.

    Create the two motor objects with motor and the ultrasonic sensor object with sonicSensor.

  6. 6.

    Call stop on both motors with the brake argument 1.

  7. 7.

    Set the Speed property of both motors and call start on each.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More LEGO Robot Programming with MATLAB Questions: