public class CRServo extends Motor
CRServo
represents any physical continuous-rotation servo that is connected to
the robot. Normal servos are limited in their rotation, but a continuous-rotation servo
can rotate infinitely. Because of this, a CR servo is functionally more similar to a
motor than it is to a servo. This is reflected by CRServo
being a subclass of
Motor
instead of a subclass of
Servo
.
Because of this inheritance, a physical CR servo can be referenced in software as a
motor OR as a servo. To use it as a servo, access it through
Lightning.getServo(String)
. To use a CR servo as a motor instead, call the
Lightning.getMotor(String)
method.
Motor.Encoder
Modifier and Type | Field and Description |
---|---|
private Servo |
baseServo
The servo that this object is based on.
|
static double |
FORWARD
The maximum power of the servo.
|
private boolean |
isReversed
Determines if the directionality of this cr servo is reversed or not.
|
static double |
REST
The power of the servo when the motor is at rest.
|
static double |
REVERSE
The maximum power of the servo when the motor is spinning backwards.
|
MAX_POWER, MIN_POWER, REST_POWER
Constructor and Description |
---|
CRServo(Servo baseServo)
Constructs a new
CRServo with the given Servo as a base. |
Modifier and Type | Method and Description |
---|---|
Motor.Encoder |
getEncoder()
Deprecated.
A CR servo has no way to track its position. Calling this method on a
CRServo will return null. |
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()
Deprecated.
A CR servo has no way to track its position. Calling this method on a
CRServo will return 0. |
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.
|
java.lang.String |
toString() |
private Servo baseServo
private boolean isReversed
public static final double FORWARD
public static final double REST
public static final double REVERSE
public CRServo(Servo baseServo)
CRServo
with the given Servo
as a base.baseServo
- the servo to base this CR servo on.public java.lang.String getName()
Motor
@Deprecated public Motor.Encoder getEncoder()
CRServo
will return null.Motor
Encoder
even if
there is no physical encoder attached to the physical motor.getEncoder
in class Motor
@Deprecated public int getRawPosition()
CRServo
will return 0.Motor
getRawPosition
in class Motor
public boolean isReversed()
Motor
isReversed
in class Motor
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)
Motor
setReversed
in class Motor
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()
Motor
public void setPower(double power)
Motor