There are lots of different motors that you can connect to your EV3, for example:
The first 3 of these can be connected directly to your EV3. The others require conversion cables or adapters.
These motors have different capabilities. The EV3 and NXT motors have built-in encoders that tell the EV3 how far a motor has rotated.
Motors with encoders can be accessed as regulated motors. Regulated motors have their speed controlled and can be instructed to rotate by a specific angle.
Motors without encoders, like the PF motors and RCX motors are controlled in a simpler way, as unregulated motors: you just set the power, and tell the motor to go forward or backwards and then (after some time) to stop. EV3 and NXT motors can also be treated as unregulated motors, as ths works better for some applications.
PF motors can be accessed as regulated motors if you use the Mindsensors GlideWheel-M controller (http://www.mindsensors.com/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=153).
leJOS has a set of interfaces and classes to access regulated and unregulated motors.
For example to access an EV3 large motors, you can do:
RegulatedMotor m = new EV3LargeRegulatedMotor(MotorPort.A);
and then use the motor with methods, like:
Thee four motors ports on the EV3 are referred to as MotorPort.A, MotorPort.B, MotorPort.C and MotorPort.D.
You can access motors using the Motor class like you did on the NXT. The motor class defines four motors: Motor.A, Motor.B, Motor.C and Motor.D, and you ca access them directly as regulated motors, e.g.:
/** * @deprecated use the specific class for your motor instead. */ Motor.A.rotate(180);
However, this is not recommended, as it assumes that all 4 ports are being used for NXT regulated motors, and that is probably not true, as your motors are more likely to be EV3 ones, and you may not want all 4 of them them to be regulated. So don't use the Motor class for new programs.
For regulated motors, you should use the class that corresponds to your motor. So for EV3 large motors, you should use EV3LargeRegulatedMotor, for EV3 medium motors, EV3MediumRegulatedMotor, for NXT motors, NXTRegulatedMotor for PF motors connected by a Mindsensors GlideWheel-M controller, MindsensorsGlideWheelMRegulatedMotor, and for Tetrix motors accessed via a Tetrix controller and with an encode installed, TetrixRegultedMotor. All these implement the RegulatedMotor interface, so you can declare a motor like:
RegulatedMotor leftMotor = new MindsensorsGlideWheelMRegulatedMotor(MotorPort.B);
and use it like:
Some of the methods that you can use with regulated motors are:
For the complete set of methods supported by the RegulatedMotor interface see http://www.lejos.org/ev3/docs/lejos/robotics/RegulatedMotor.html).
If you want to use an unregulated motor, you have two choices. If your motor has an encode, you can use the EncoderMotor interface, and if is hasn't you can use the DCMotor interface.
The classes that implement EncoderMotor include NXTMotor, TetrixEncoderMotor and MMXMotor.
These classes also support DCMotor. The classes that support DCMotor only, and not EncoderMotor, include RCXMotor and PFMateMotor.
There is not currently a class designed to access EV3 motors as unregulated motors, but as EV3 motors are basically the same as NXT motors when treated as unregulated motors, the NXTMotor class works.
You would normally choose to use a regulated motor if you want the speed of a motor to be accurately controlled or if you want to rotate the motor by a specific number of degrees, e.g. to move a mobile robot a specific distance.
You might choose to use a motor unregulated if you want to control the power directly rather than set a speed. A robot that fires a catapult, for example, might require this.
So to access an EV3 or NXT motors as an unregulated motor, you can do:
EncoderMotor em = new NXTMotor(MotorPort.C); em.setPower(100); em.forward(); Delay.msDelay(1000); em.stop();
To access an RCX motor using a conversion cable, you can do:
DCMotor dcm = new RCXMotor(MotorPort.D); dcm.setPower(50); dcm.forward(); Delay.msDelay(1000); dcm.stop();
A note of packages:
The interfaces used in these examples are in lejos.robotics. The main motor classes are in lejos.hardware.motor, but the classes for motors that use third-party controllers are mainly in lejos.hardware.device, and those for Tetrix motors are in lejos.hardware.device.tetrix.