public class DcMotorImpl extends java.lang.Object implements DcMotor
DcMotorController
DcMotor.RunMode, DcMotor.ZeroPowerBehavior
DcMotorSimple.Direction
HardwareDevice.Manufacturer
Modifier and Type | Field and Description |
---|---|
protected DcMotorController |
controller |
protected DcMotorSimple.Direction |
direction |
protected DcMotor.RunMode |
mode |
protected int |
portNumber |
Constructor and Description |
---|
DcMotorImpl(DcMotorController controller,
int portNumber)
Constructor
|
DcMotorImpl(DcMotorController controller,
int portNumber,
DcMotorSimple.Direction direction)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this device
|
java.lang.String |
getConnectionInfo()
Get connection information about this device in a human readable format
|
DcMotorController |
getController()
Get DC motor controller
|
int |
getCurrentPosition()
Get the current encoder value.
|
java.lang.String |
getDeviceName()
Returns a string suitable for display to the user as to the type of device
|
DcMotorSimple.Direction |
getDirection()
Get the direction
|
HardwareDevice.Manufacturer |
getManufacturer()
Returns an indication of the manufacturer of this device.
|
int |
getMaxSpeed()
Returns the current maximum targetable speed for this motor when the motor is
running in one of the PID modes.
|
DcMotor.RunMode |
getMode()
Get the current mode
|
int |
getPortNumber()
Get port number
|
double |
getPower()
Get the current motor power
|
boolean |
getPowerFloat()
Is motor power set to float?
|
int |
getTargetPosition()
Get the current motor target position.
|
int |
getVersion()
Version
|
DcMotor.ZeroPowerBehavior |
getZeroPowerBehavior()
Returns the current behavior of the motor were a power level of zero to be applied.
|
protected void |
internalSetMode(DcMotor.RunMode mode) |
protected void |
internalSetPower(double power) |
protected void |
internalSetTargetPosition(int position) |
boolean |
isBusy()
Is the motor busy?
|
void |
resetDeviceConfigurationForOpMode()
Resets the device's configuration to that which is expected at the beginning of an OpMode.
|
void |
setDirection(DcMotorSimple.Direction direction)
Set the direction
|
void |
setMaxSpeed(int encoderTicksPerSecond)
When the motor is running in one of the PID modes
the value set using the
setPower() method is indicative of a
desired motor velocity rather than a raw power level. |
void |
setMode(DcMotor.RunMode mode)
Set the current mode
|
void |
setPower(double power)
Set the current motor power
|
void |
setPowerFloat()
Deprecated.
|
void |
setTargetPosition(int position)
Set the motor target position, using an integer.
|
void |
setZeroPowerBehavior(DcMotor.ZeroPowerBehavior zeroPowerBehavior)
Sets the behavior of the motor when a power level of zero is applied.
|
protected DcMotorController controller
protected int portNumber
protected DcMotorSimple.Direction direction
protected DcMotor.RunMode mode
public DcMotorImpl(DcMotorController controller, int portNumber)
controller
- DC motor controller this motor is attached toportNumber
- portNumber position on the controllerpublic DcMotorImpl(DcMotorController controller, int portNumber, DcMotorSimple.Direction direction)
controller
- DC motor controller this motor is attached toportNumber
- portNumber port number on the controllerdirection
- direction this motor should spinpublic HardwareDevice.Manufacturer getManufacturer()
HardwareDevice
getManufacturer
in interface HardwareDevice
public java.lang.String getDeviceName()
HardwareDevice
getDeviceName
in interface HardwareDevice
public java.lang.String getConnectionInfo()
HardwareDevice
getConnectionInfo
in interface HardwareDevice
public int getVersion()
HardwareDevice
getVersion
in interface HardwareDevice
public void resetDeviceConfigurationForOpMode()
HardwareDevice
resetDeviceConfigurationForOpMode
in interface HardwareDevice
public void close()
HardwareDevice
close
in interface HardwareDevice
public DcMotorController getController()
getController
in interface DcMotor
DcMotor.getPortNumber()
public void setDirection(DcMotorSimple.Direction direction)
setDirection
in interface DcMotorSimple
direction
- directionDcMotorSimple.getDirection()
public DcMotorSimple.Direction getDirection()
getDirection
in interface DcMotorSimple
DcMotorSimple.setDirection(Direction)
public int getPortNumber()
getPortNumber
in interface DcMotor
DcMotor.getController()
public void setPower(double power)
setPower
in interface DcMotorSimple
power
- from -1.0 to 1.0DcMotorSimple.getPower()
,
DcMotor.setMode(DcMotor.RunMode)
,
DcMotor.setPowerFloat()
protected void internalSetPower(double power)
public void setMaxSpeed(int encoderTicksPerSecond)
DcMotor
setPower()
method is indicative of a
desired motor velocity rather than a raw power level. In those modes, the
setMaxSpeed()
method provides the interpretation of the speed to which
a value of 1.0 passed to setPower()
should correspond.setMaxSpeed
in interface DcMotor
encoderTicksPerSecond
- the maximum targetable speed for this motor when the motor is
in one of the PID modes, in units of encoder ticks per second.DcMotor.RunMode.RUN_USING_ENCODER
,
DcMotor.RunMode.RUN_TO_POSITION
,
DcMotor.getMaxSpeed()
public int getMaxSpeed()
DcMotor
getMaxSpeed
in interface DcMotor
DcMotor.setMaxSpeed(int)
public double getPower()
getPower
in interface DcMotorSimple
DcMotorSimple.setPower(double)
public boolean isBusy()
isBusy
in interface DcMotor
DcMotor.setTargetPosition(int)
public void setZeroPowerBehavior(DcMotor.ZeroPowerBehavior zeroPowerBehavior)
DcMotor
setZeroPowerBehavior
in interface DcMotor
zeroPowerBehavior
- the new behavior of the motor when a power level of zero is applied.DcMotor.ZeroPowerBehavior
,
DcMotorSimple.setPower(double)
public DcMotor.ZeroPowerBehavior getZeroPowerBehavior()
DcMotor
getZeroPowerBehavior
in interface DcMotor
@Deprecated public void setPowerFloat()
setPowerFloat
in interface DcMotor
DcMotorSimple.setPower(double)
,
DcMotor.getPowerFloat()
,
DcMotor.setZeroPowerBehavior(ZeroPowerBehavior)
public boolean getPowerFloat()
getPowerFloat
in interface DcMotor
DcMotor.setPowerFloat()
public void setTargetPosition(int position)
setTargetPosition
in interface DcMotor
position
- range from Integer.MIN_VALUE to Integer.MAX_VALUEDcMotor.getCurrentPosition()
,
DcMotor.setMode(RunMode)
,
DcMotor.RunMode.RUN_TO_POSITION
,
DcMotor.getTargetPosition()
,
DcMotor.isBusy()
protected void internalSetTargetPosition(int position)
public int getTargetPosition()
getTargetPosition
in interface DcMotor
DcMotor.setTargetPosition(int)
public int getCurrentPosition()
getCurrentPosition
in interface DcMotor
DcMotor.getTargetPosition()
,
DcMotor.RunMode.STOP_AND_RESET_ENCODER
public void setMode(DcMotor.RunMode mode)
setMode
in interface DcMotor
mode
- run modeDcMotor.RunMode
,
DcMotor.getMode()
protected void internalSetMode(DcMotor.RunMode mode)
public DcMotor.RunMode getMode()
getMode
in interface DcMotor
DcMotor.RunMode
,
DcMotor.setMode(RunMode)