Instructional Material: Exercise: Using Regulated Motors

The EV3 supports a variety of motors. The EV3 kit comes with two types of motors, large and medium. This relates to their size and power. The leJOS API contains two main types of motor control classes, regulated and unregulated. Regulated motors have two classes, EV3LargeReguatedMotor and EV3MediumRegulatedMotor. Unregulated motors have one class, UnregulatedMotor.

UnregulatedMotor can be used with either the large or medium motors. Unregulated motor speeds are controlled by power level only. Regulated motors use rotational speed and rotational targets (angles) to control thier speed and use the motor's internal tachometers to make sure speeds and rotations are accurate. Regulated motors can be set to rotate at a speed set as degrees per second. These motors can also be set to rotate a specific number of degrees then stop. These motors can be set to run on thier own to these rotational targets while your code continues with other tasks. These classes have a number of methods that allow you monitor the motor's operation.

Here is an example of doing motor control with regulated motor classes. In ev3.exercises create a new class called DriveRegulated and paste the code below into that class.

When you test this code, you can hold your robot and press the enter button at each phase to see how the motors operate. You can then un-comment the SetAcceleration() methods to see how this affects motor starting and stopping.

The example shows controlling motor speed with setSpeed() which sets speed in degrees per second and rotate()  / rotateTo() which cause the motor to turn the specified amount in degrees and then stop.

 

Material Type: 
Lab Activity
Education Level: 
Middle School
High School
Focus Subject: 
Computing / Computer Science
Robotics Software
HW Platform: 
EV3
SW Platform: 
Java
Interactivity Style: 
Mixed