public abstract class BaseRegulatedMotor extends Device 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.
Example:
TODO: Fix the name
Motor.A.setSpeed(720);// 2 RPM
Motor.C.setSpeed(720);
Motor.A.forward();
Motor.C.forward();
Delay.msDelay(1000);
Motor.A.stop();
Motor.C.stop();
Motor.A.rotateTo( 360);
Motor.A.rotate(-720,true);
while(Motor.A.isMoving()Thread.yield();
int angle = Motor.A.getTachoCount(); // should be -360
LCD.drawInt(angle,0,0);
Modifier and Type | Field and Description |
---|---|
protected int |
acceleration |
protected int |
MAX_SPEED_AT_9V |
protected static int |
NO_LIMIT |
protected MotorRegulator |
reg |
protected float |
speed |
protected TachoMotorPort |
tachoPort |
Constructor and Description |
---|
BaseRegulatedMotor(Port port,
MotorRegulator regulator,
int typ,
float moveP,
float moveI,
float moveD,
float holdP,
float holdI,
float holdD,
int offset,
int maxSpeed)
Use this constructor to assign a variable of type motor connected to a particular port.
|
BaseRegulatedMotor(TachoMotorPort port,
MotorRegulator regulator,
int typ,
float moveP,
float moveI,
float moveD,
float holdP,
float holdI,
float holdD,
int offset,
int maxSpeed)
Use this constructor to assign a variable of type motor connected to a particular port.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(RegulatedMotorListener listener)
Add a motor listener.
|
void |
backward()
Causes motor to rotate backwards until
stop() or flt() is called. |
void |
close()
Close the motor regulator.
|
void |
endSynchronization()
Complete a set of synchronized motor operations.
|
void |
flt()
Set the motor into float mode.
|
void |
flt(boolean immediateReturn)
Set the motor into float mode.
|
void |
forward()
Causes motor to rotate forward until
stop() or flt() is called. |
int |
getAcceleration()
returns acceleration in degrees/second/second
|
int |
getLimitAngle()
Return the angle that this Motor is rotating to.
|
float |
getMaxSpeed()
Returns the maximum speed that can be maintained by the regulation system based upon the
current state of the battery.
|
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.
|
boolean |
isStalled()
Return true if the motor is currently stalled.
|
void |
lock(int power)
Deprecated.
The regulator will always try to hold position unless the
motor is set into float mode using flt().
|
RegulatedMotorListener |
removeListener()
Removes the RegulatedMotorListener from this class.
|
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 |
setAcceleration(int acceleration)
sets the acceleration rate of this motor in degrees/sec/sec
The default value is 6000; Smaller values will make speeding up. |
void |
setSpeed(float 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 |
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 |
setStallThreshold(int error,
int time)
Set the parameters for detecting a stalled motor.
|
void |
startSynchronization()
Begin a set of synchronized motor operations
|
void |
stop()
Causes motor to stop, pretty much
instantaneously.
|
void |
stop(boolean immediateReturn)
Causes motor to stop, pretty much
instantaneously.
|
boolean |
suspendRegulation()
Removes this motor from the motor regulation system.
|
void |
synchronizeWith(RegulatedMotor[] syncList)
Specify a set of motors that should be kept in synchronization with this one.
|
void |
waitComplete()
Wait until the current movement operation is complete (this can include
the motor stalling).
|
releaseOnClose
protected final int MAX_SPEED_AT_9V
protected static final int NO_LIMIT
protected final MotorRegulator reg
protected TachoMotorPort tachoPort
protected float speed
protected int acceleration
public BaseRegulatedMotor(TachoMotorPort port, MotorRegulator regulator, int typ, float moveP, float moveI, float moveD, float holdP, float holdI, float holdD, int offset, int maxSpeed)
port
- to which this motor is connectedpublic BaseRegulatedMotor(Port port, MotorRegulator regulator, int typ, float moveP, float moveI, float moveD, float holdP, float holdI, float holdD, int offset, int maxSpeed)
port
- to which this motor is connectedpublic 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.forward
in interface BaseMotor
BasicMotor.forward()
public void backward()
BaseMotor
stop()
or flt()
is called.backward
in interface BaseMotor
BasicMotor.backward()
public void flt()
public void flt(boolean immediateReturn)
flt
in interface RegulatedMotor
immediateReturn
- If true do not wait for the motor to actually stoppublic void stop()
public void stop(boolean immediateReturn)
stop
in interface RegulatedMotor
immediateReturn
- if true do not wait for the motor to actually stoppublic boolean isMoving()
isStalled()
;public void waitComplete()
waitComplete
in interface RegulatedMotor
public void rotateTo(int limitAngle, boolean immediateReturn)
RegulatedMotor
rotateTo
in interface RegulatedMotor
limitAngle
- 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 setSpeed(int speed)
setSpeed
in interface RegulatedMotor
speed
- value in degrees/secpublic void setSpeed(float speed)
speed
- value in degrees/secpublic void setAcceleration(int acceleration)
setAcceleration
in interface RegulatedMotor
acceleration
- public int getAcceleration()
public int getLimitAngle()
getLimitAngle
in interface RegulatedMotor
public void resetTachoCount()
resetTachoCount
in interface Encoder
public void addListener(RegulatedMotorListener listener)
addListener
in interface RegulatedMotor
listener
- public RegulatedMotorListener removeListener()
RegulatedMotor
removeListener
in interface RegulatedMotor
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 completeRegulatedMotor.rotate(int, boolean)
public void rotate(int angle)
rotate
in interface RegulatedMotor
angle
- public void rotateTo(int limitAngle)
rotateTo
in interface RegulatedMotor
limitAngle
- Angle to rotate to.public int getSpeed()
getSpeed
in interface RegulatedMotor
@Deprecated public void lock(int power)
power
- - a value between 1 and 100;public boolean isStalled()
isStalled
in interface RegulatedMotor
public void setStallThreshold(int error, int time)
setStallThreshold
in interface RegulatedMotor
error
- The error thresholdtime
- The time that the error threshold needs to be exceeded for.public int getRotationSpeed()
getRotationSpeed
in interface Tachometer
public float getMaxSpeed()
RegulatedMotor
getMaxSpeed
in interface RegulatedMotor
public void synchronizeWith(RegulatedMotor[] syncList)
synchronizeWith
in interface RegulatedMotor
syncList
- an array of motors to synchronize with.public void startSynchronization()
startSynchronization
in interface RegulatedMotor
public void endSynchronization()
endSynchronization
in interface RegulatedMotor