
public abstract class BaseRegulatedMotor extends EV3DevDevice implements RegulatedMotor
forward, backward, reverseDirection, stop
and flt. To set each motor's velocity, use setSpeed .
The maximum velocity of the motor is limited by the battery voltage and load.
With no load, the maximum degrees per second is about 100 times the voltage
(for the large EV3 motor). setAcceleration(int acceleration) method.
The methods rotate(int angle) and rotateTo(int ange)
use the tachometer to control the position at which the motor stops, usually within 1 degree
or 2. RegulatedMotorListener interface may register with this class.
It will be informed each time the motor starts or stops.
isStalled() returns true.
| Modifier and Type | Field and Description |
|---|---|
protected int |
acceleration |
private java.lang.String |
BRAKE |
private java.lang.String |
COMMAND |
private java.lang.String |
DUTY_CYCLE |
private int |
local_speed |
private java.lang.String |
MODE |
private java.lang.String |
POSITION |
private boolean |
regulationFlag |
private java.lang.String |
RESET |
private java.lang.String |
RUN_FOREVER |
private java.lang.String |
RUN_TO_ABS_POS |
private java.lang.String |
RUN_TO_REL_POS |
protected float |
speed |
private java.lang.String |
SPEED |
private java.lang.String |
SPEED_REGULATION |
private java.lang.String |
SPEED_REGULATION_OFF |
private java.lang.String |
SPEED_REGULATION_ON |
private java.lang.String |
STATE |
private java.lang.String |
STATE_RUNNING |
private java.lang.String |
STATE_STALLED |
private java.lang.String |
STOP |
private static java.lang.String |
SYSTEM_CLASS_NAME |
private static java.lang.String |
SYSTEM_PORT_CLASS_NAME |
PATH_DEVICE| Constructor and Description |
|---|
BaseRegulatedMotor(java.lang.String motorPort,
float moveP,
float moveI,
float moveD,
float holdP,
float holdI,
float holdD,
int offset,
int maxSpeed) |
| Modifier and Type | Method and Description |
|---|---|
void |
backward()
Causes motor to rotate backwards until
stop() or flt() is called. |
void |
close()
Close the motor regulator.
|
void |
flt()
Set the motor into float mode.
|
void |
forward()
Causes motor to rotate forward until
stop() or flt() is called. |
float |
getPosition()
Returns the current position that the motor regulator is trying to
maintain.
|
int |
getRotationSpeed()
Return the current velocity.
|
int |
getSpeed()
Return the current target speed.
|
int |
getTachoCount()
Returns the tachometer count.
|
boolean |
isMoving()
This method returns true if the motor is attempting to rotate.
|
private boolean |
isRunning() |
boolean |
isStalled()
Return true if the motor is currently stalled.
|
void |
resetTachoCount()
Reset the tachometer associated with this motor.
|
void |
rotate(int angle)
Rotate by the requested number of degrees.
|
void |
rotate(int angle,
boolean immediateReturn)
Rotate by the request number of degrees.
|
void |
rotateTo(int limitAngle)
Rotate to the target angle.
|
void |
rotateTo(int limitAngle,
boolean immediateReturn)
causes motor to rotate to limitAngle;
if immediateReturn is true, method returns immediately and the motor stops by itself and getTachoCount should be within +- 2 degrees if the limit angle If any motor method is called before the limit is reached, the rotation is canceled. |
void |
setSpeed(int speed)
Sets desired motor speed , in degrees per second;
The maximum reliably sustainable velocity is 100 x battery voltage under
moderate load, such as a direct drive robot on the level.
|
void |
stop()
Causes motor to stop, pretty much
instantaneously.
|
boolean |
suspendRegulation()
Removes this motor from the motor regulation system.
|
connect, getIntegerAttribute, getStringAttribute, setIntegerAttribute, setStringAttributegetElements, readFloat, readInteger, readString, writeInteger, writeStringreleaseOnCloseprotected float speed
protected int acceleration
private static final java.lang.String SYSTEM_CLASS_NAME
private static final java.lang.String SYSTEM_PORT_CLASS_NAME
private final java.lang.String MODE
private final java.lang.String SPEED_REGULATION
private final java.lang.String SPEED_REGULATION_ON
private final java.lang.String SPEED_REGULATION_OFF
private final java.lang.String POSITION
private final java.lang.String SPEED
private final java.lang.String DUTY_CYCLE
private final java.lang.String COMMAND
private final java.lang.String RUN_FOREVER
private final java.lang.String BRAKE
private final java.lang.String STOP
private final java.lang.String RESET
private final java.lang.String RUN_TO_REL_POS
private final java.lang.String RUN_TO_ABS_POS
private final java.lang.String STATE
private final java.lang.String STATE_RUNNING
private final java.lang.String STATE_STALLED
private int local_speed
private boolean regulationFlag
public BaseRegulatedMotor(java.lang.String motorPort,
float moveP,
float moveI,
float moveD,
float holdP,
float holdI,
float holdD,
int offset,
int maxSpeed)
public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in interface RegulatedMotorclose in class Devicepublic boolean suspendRegulation()
public int getTachoCount()
EncodergetTachoCount in interface EncoderEncoder.getTachoCount()public float getPosition()
public void forward()
BaseMotorstop() or flt() is called.public void backward()
BaseMotorstop() or flt() is called.public void flt()
public void stop()
public boolean isMoving()
isStalled();public void setSpeed(int speed)
setSpeed in interface RegulatedMotorspeed - value in degrees/secpublic void resetTachoCount()
resetTachoCount in interface Encoderprivate boolean isRunning()
public void rotate(int angle,
boolean immediateReturn)
rotate in interface RegulatedMotorangle - number of degrees to rotate relative to the current positionimmediateReturn - if true do not wait for the move to complete
Rotate by the requested number of degrees. Wait for the move to complete.angle - RegulatedMotor.rotate(int, boolean)public void rotate(int angle)
rotate in interface RegulatedMotorangle - public void rotateTo(int limitAngle,
boolean immediateReturn)
RegulatedMotorrotateTo in interface RegulatedMotorlimitAngle - to which the motor will rotate, and then stop (in degrees). Includes any positive or negative int, even values > 360.immediateReturn - iff true, method returns immediately, thus allowing monitoring of sensors in the calling thread.public void rotateTo(int limitAngle)
rotateTo in interface RegulatedMotorlimitAngle - Angle to rotate to.public int getSpeed()
getSpeed in interface RegulatedMotorpublic boolean isStalled()
isStalled in interface RegulatedMotorpublic int getRotationSpeed()
getRotationSpeed in interface Tachometer