Sie sind auf Seite 1von 6

Matthew Owens

EV3 Motor Guide


There are two motors for the EV3 system, large and medium. The large
motor is larger and more powerful than the medium motor, but the medium motor
responds faster. The large motors top speed is between 160 and 170 rpm (9601020 deg/s), it has a stall torque of 40 Ncm, and running torque of 20 Ncm. The
stall torque of a motor is the amount of force the motor will apply when something
is preventing it from moving. The hardware specs of the medium motor are: 240250 rpm (1440-1500 deg/s), 12 Ncm stall torque, and 8 Ncm torque. 1
The large and medium motors are controlled through the
EV3LargeRegulatedMotor and EV3MediumRegulatedMotor classes respectively. They
can be set to run until interrupted, rotate a certain number of degrees, and rotate to
a certain position. The motors are controlled to one degree accuracy. Motors can
move either forward or backward.2
The following methods are common to both types of motors. 3
Controlling the Motor:
setSpeed(int speed): Sets the desired speed (in degrees per second) for the
motor to rotate once it is started. This method does not cause the motor to move; it
only changes the settings for when it does move.
setAcceleration(int acceleration): Sets the acceleration in degrees/sec/sec for
all motor operations. Default value is 6000, which is meant to get the motor to the
desired speed as quickly as possible. Smaller values should be specified to get a
smoother operation.
rotate(int displacement): Rotates the motor the specified angle from its current
position. If you call rotate(360) the motor will rotate forward 1 revolution no matter
what its starting position is. Specifying a negative angle as the argument causes
the motor to rotate backwards.
rotateTo(int targetAngle): Rotates the motor to the specified angle relative to the
motors starting position. Calling rotateTo(250) will result in the motor moving in
whatever direction it needs to in order to get to 250 degrees past its starting
position. This holds true even after calling a method such as forward() and for
specifying negative angles.
forward(): causes the motor to rotate forward until a stopping method is called or
the program exits.
backward(): causes the motor to rotate backward until a stopping method is called
or the program exits..
stop(): Applies brakes to stop the motor, cancels any running motor operations.
flt(): Allows the motor to float to a stop without using brakes, cancels running motor
operations.

resetTachoCount(): resets the starting position (for methods such as rotateTo) to


the current position. This cancels any currently running motor operations.
waitComplete(): waits to return until the current motor operation has completed.
Getting information from the motor:
getAcceleration(): returns the current acceleration in deg/sec/sec.
getTachoCount(): returns the current tachometer count.
getPosition(): returns the current position as calculated by the regulator. If
everything goes according to plan, this will be the same value returned by
getTachoCount and corresponds to the motors actual position.
getPosition(): returns the current position of the motor, as calculated by the
regulator. This may be different from the motors actual position if the motor has
been forced to move.
isMoving(): returns a Boolean value corresponding to whether the motor is
attempting to rotate or not. If the motor is trying to rotate but is stalled (because it
is being held in place by some force) isMoving will return true.
isStalled(): returns true if the motor is attempting to move but cannot.
getLimitAngle(): returns the angle the motor is currently rotating to as a result of
a rotateTo or rotate call.
getSpeed(): returns the target speed of the motor in deg/sec. This may not match
the actual speed depending on load.
Many of the methods have a Boolean immediateReturn argument, which specifies
whether the method returns immediately or if the method returns after the
operation is carried out. It appears default behavior is to return immediately. This
can cause motor actions to not behave as expected if the program exits while an
operation is in progress.
Motors can also be accessed as unregulated motors, which is desirable for
applications that require the power of the motor to be controlled instead of the
speed. This could be useful for robots where you are trying to launch something
because you would set the power to 100, instead of setting the speed of the motor.
Although this is not officially supported for EV3 motors, they will be treated as NXT
motors when accessed in unregulated mode. Here is an example:
EncoderMotor m = new UnregulatedMotor(MotorPort.A);
m.setPower(100); //Full power
m.forward();
Thread.sleep(5000);
m.setPower(10); //Painfully slow
m.backward();
Thread.sleep(5000);

I wrote a sample program that demonstrates the basic motor functions. It can
easily be run on any robot with 4 wheels and a large motor attached to the A port.

package edu.scranton.mowens;
import lejos.hardware.lcd.LCD;
import lejos.hardware.motor.EV3LargeRegulatedMotor;
import lejos.hardware.port.MotorPort;
public class MotorDemo {
public static void main(String[] args) throws InterruptedException {
LCD.drawString("Motor Demo", 0, 0);
EV3LargeRegulatedMotor m = new EV3LargeRegulatedMotor(MotorPort.A);
m.setSpeed(900);

//Move back and forth 3 times


for(int i=0; i < 3; i++) {
LCD.clear();
LCD.drawInt(i, 0, 0);
m.forward();
Thread.sleep(2000);
m.backward();
Thread.sleep(2000);
m.stop();
Thread.sleep(1000);
}
//Rotate 360 Degrees in each direction
LCD.clear();
LCD.drawString("Rotation test", 0, 0);
m.rotate(360);
Thread.sleep(1000);
m.rotate(-360);

//Rotate to specific degrees


LCD.clear();
LCD.drawString("Incremental Rotation", 0, 0);
m.rotateTo(0);
Thread.sleep(500);
m.rotateTo(45);
Thread.sleep(500);
m.rotateTo(90);
Thread.sleep(500);
m.rotateTo(135);
Thread.sleep(500);
m.rotateTo(180);
m.close();

}
}

1: EV3 User Guide, http://www.nr.edu/csc200/labs-ev3/ev3-user-guide-EN.pdf


2: LeJOS EV3 Wiki, http://sourceforge.net/p/lejos/wiki/Motors/
3: LeJOs Documentation,
http://www.lejos.org/ev3/docs/lejos/hardware/motor/BaseRegulatedMotor.html#forw
ard--

Das könnte Ihnen auch gefallen