public class Motor
extends java.lang.Object
Motor
represents any physical DC motor that is connected to the robot.Modifier and Type | Class and Description |
---|---|
class |
Motor.Encoder
An
Encoder represents a physical encoder that is attached to a specific
motor. |
Modifier and Type | Field and Description |
---|---|
private com.qualcomm.robotcore.hardware.DcMotor |
basemotor
The
DcMotor that this object is based on. |
private Motor.Encoder |
encoder
The encoder that is attached to this motor.
|
static double |
MAX_POWER
The maximum power of the motor.
|
static double |
MIN_POWER
The maximum power of the motor when the motor is spinning backwards.
|
private double |
power
The current power of the motor.
|
static double |
REST_POWER
The power of the motor when the motor is at rest.
|
Constructor and Description |
---|
Motor(com.qualcomm.robotcore.hardware.DcMotor basemotor)
Constructs a new motor that uses the given
DcMotor as a base. |
Modifier and Type | Method and Description |
---|---|
Motor.Encoder |
getEncoder()
Gets the encoder attached to this motor.
|
java.lang.String |
getName()
Gets the name of the device as it is defined in the configuration file.
|
double |
getPower()
Gets the current movement power of this motor.
|
int |
getRawPosition()
Gets the raw encoder position value of this motor.
|
boolean |
isReversed()
Determines if the motor's output direction is reversed from its inputs.
|
void |
setPower(double power)
Sets the movement power of this motor.
|
void |
setReversed(boolean reversed)
Sets if the motor's output direction is reversed from its inputs.
|
void |
stop()
Stops the motor.
|
java.lang.String |
toString() |
private com.qualcomm.robotcore.hardware.DcMotor basemotor
DcMotor
that this object is based on.private Motor.Encoder encoder
private double power
public static final double MAX_POWER
public static final double REST_POWER
public static final double MIN_POWER
public Motor(com.qualcomm.robotcore.hardware.DcMotor basemotor)
DcMotor
as a base.basemotor
- the base Motor
public java.lang.String getName()
public Motor.Encoder getEncoder()
Encoder
even if
there is no physical encoder attached to the physical motor.public int getRawPosition()
public boolean isReversed()
true
if the motor's output is reversed from its inputs, or
false
if the motor's ouput has the same polarity as its input.public void setReversed(boolean reversed)
reversed
- true
if the motor's output is reversed from its inputs, or
false
if the motor's ouput has the same polarity as its input.public double getPower()
public void setPower(double power)
power
- the movement power; between -1 and 1.public void stop()
public java.lang.String toString()
toString
in class java.lang.Object