public abstract class BaseRegulatedMotor extends EV3DevMotorDevice implements RegulatedMotor
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 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, DEVICE_ROOT_PATH, LEGO_PORT, LEGO_SENSOR, MODE, PATH_DEVICE
BRICKPI, EV3BRICK, PISTORMS
Constructor and Description |
---|
BaseRegulatedMotor(java.lang.String 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 |
backward()
Causes motors to rotate backwards until
stop() or flt() is called. |
void |
brake()
Removes power from the motor and creates a passive electrical load.
|
void |
close()
Close the motors regulator.
|
void |
coast()
Set the motors into float mode.
|
void |
forward()
Causes motors to rotate forward until
stop() or flt() is called. |
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()
Returns the tachometer count.
|
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.
|
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)
causes motors to rotate to limitAngle;
if immediateReturn is true, method returns immediately and the motors stops by itself and getTachoCount should be within +- 2 degrees if the limit angle If any motors method is called before the limit is reached, the rotation is canceled. |
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 |
stop()
Causes motors to stop, pretty much
instantaneously.
|
boolean |
suspendRegulation()
Removes this motors from the motors regulation system.
|
detect, getIntegerAttribute, getPlatform, getStringAttribute, setIntegerAttribute, setStringAttribute
releaseOnClose
private int speed
protected int acceleration
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)
motorPort
- motor portmoveP
- movePmoveI
- moveImoveD
- moveDholdP
- holdPholdI
- holdIholdD
- holdDoffset
- offsetmaxSpeed
- maxSpeedpublic void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface RegulatedMotor
close
in class Device
public boolean suspendRegulation()
public int getTachoCount()
Encoder
getTachoCount
in interface Encoder
Encoder.getTachoCount()
public float getPosition()
public void forward()
BaseMotor
stop()
or flt()
is called.public void backward()
BaseMotor
stop()
or flt()
is called.public void coast()
public void brake()
public void hold()
public void stop()
public boolean isMoving()
isStalled()
;public void setSpeed(int speed)
setSpeed
in interface RegulatedMotor
speed
- value in degrees/secpublic void resetTachoCount()
resetTachoCount
in interface Encoder
public void rotate(int angle, boolean immediateReturn)
rotate
in interface RegulatedMotor
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.RegulatedMotor.rotate(int, boolean)
public void rotate(int angle)
rotate
in interface RegulatedMotor
angle
- anglepublic void rotateTo(int limitAngle, boolean immediateReturn)
RegulatedMotor
rotateTo
in interface RegulatedMotor
limitAngle
- to which the motors 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 RegulatedMotor
limitAngle
- Angle to rotate to.public int getSpeed()
getSpeed
in interface RegulatedMotor
public boolean isStalled()
isStalled
in interface RegulatedMotor
public int getRotationSpeed()
getRotationSpeed
in interface Tachometer