public abstract class BaseRegulatedMotor extends EV3DevMotorDevice
forward, backward, reverseDirection, stop
and flt
. To set each motors's velocity, use setSpeed
.
The maximum velocity of the motors 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 motors). setAcceleration(int acceleration)
method.
The methods rotate(int angle)
and rotateTo(int ange)
use the tachometer to control the position at which the motors stops, usually within 1 degree
or 2. RegulatedMotorListener
interface may register with this class.
It will be informed each time the motors starts or stops.
isStalled()
returns true.
Modifier and Type | Field and Description |
---|---|
protected int |
acceleration |
private java.util.List<RegulatedMotorListener> |
listenerList |
private static Logger |
log |
protected int |
MAX_SPEED_AT_9V |
private boolean |
regulationFlag |
private int |
speed |
AUTO_MODE, BRAKE, COAST, COMMAND, DC_MOTOR, DUTY_CYCLE, HOLD, POLARITY, POLARITY_INVERSED, POLARITY_NORMAL, POSITION, POSITION_SP, POWER, RESET, RUN_DIRECT, RUN_FOREVER, RUN_TO_ABS_POS, RUN_TO_REL_POS, SPEED, STATE, STATE_RUNNING, STATE_STALLED, STOP, STOP_COMMAND, TACHO_MOTOR
ADDRESS, DEVICE, LEGO_PORT, LEGO_SENSOR, MODE, PATH_DEVICE
EV3DEV_ROOT_PATH, EV3DEV_TESTING_KEY, ROOT_PATH
Constructor and Description |
---|
BaseRegulatedMotor(Port motorPort,
float moveP,
float moveI,
float moveD,
float holdP,
float holdI,
float holdD,
int offset,
int maxSpeed)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(RegulatedMotorListener regulatedMotorListener) |
void |
backward() |
void |
brake()
Removes power from the motor and creates a passive electrical load.
|
void |
coast() |
void |
endSynchronization() |
void |
flt() |
void |
flt(boolean b)
Set the motors into float mode.
|
void |
forward() |
float |
getMaxSpeed() |
float |
getPosition()
Returns the current position that the motors regulator is trying to
maintain.
|
int |
getRotationSpeed()
Return the current velocity.
|
int |
getSpeed()
Return the current target speed.
|
int |
getTachoCount() |
void |
hold()
Causes the motor to actively try to hold the current position.
|
boolean |
isMoving()
This method returns true if the motors is attempting to rotate.
|
boolean |
isStalled()
Return true if the motors is currently stalled.
|
RegulatedMotorListener |
removeListener() |
void |
resetTachoCount()
Reset the tachometer associated with this motors.
|
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) |
void |
setAcceleration(int acceleration) |
void |
setSpeed(int speed)
Sets desired motors 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 |
startSynchronization() |
void |
stop()
Causes motors to stop, pretty much
instantaneously.
|
void |
stop(boolean b) |
boolean |
suspendRegulation()
Removes this motors from the motors regulation system.
|
void |
synchronizeWith(RegulatedMotor[] regulatedMotors) |
void |
waitComplete() |
detect, getIntegerAttribute, getStringAttribute, setIntegerAttribute, setStringAttribute
getMotorPort, getPlatform, getSensorPort
getROOT_PATH
private static final Logger log
protected final int MAX_SPEED_AT_9V
private int speed
protected int acceleration
private boolean regulationFlag
private final java.util.List<RegulatedMotorListener> listenerList
public BaseRegulatedMotor(Port motorPort, float moveP, float moveI, float moveD, float holdP, float holdI, float holdD, int offset, int maxSpeed)
motorPort
- motor portmoveP
- movePmoveI
- moveImoveD
- moveDholdP
- holdPholdI
- holdIholdD
- holdDoffset
- offsetmaxSpeed
- maxSpeedpublic boolean suspendRegulation()
public int getTachoCount()
lejos.robotics.RegulatedMotor#getTachoCount()
public float getPosition()
public void forward()
public void backward()
public void flt(boolean b)
public void flt()
public void coast()
public void brake()
public void hold()
public void stop()
public void stop(boolean b)
public boolean isMoving()
isStalled()
;public void setSpeed(int speed)
speed
- value in degrees/secpublic void resetTachoCount()
public void rotate(int angle, boolean immediateReturn)
angle
- 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.public void rotate(int angle)
angle
- anglepublic void rotateTo(int limitAngle, boolean immediateReturn)
public void rotateTo(int limitAngle)
limitAngle
- Angle to rotate to.public int getSpeed()
public boolean isStalled()
public int getRotationSpeed()
public void addListener(RegulatedMotorListener regulatedMotorListener)
public RegulatedMotorListener removeListener()
public void waitComplete()
public float getMaxSpeed()
public void setAcceleration(int acceleration)
public void synchronizeWith(RegulatedMotor[] regulatedMotors)
public void startSynchronization()
public void endSynchronization()