public class Servo extends java.lang.Object implements HardwareDevice
| Modifier and Type | Class and Description |
|---|---|
static class |
Servo.Direction
Motor direction
|
| Modifier and Type | Field and Description |
|---|---|
protected ServoController |
controller |
protected Servo.Direction |
direction |
protected double |
limitPositionMax |
protected double |
limitPositionMin |
static double |
MAX_POSITION |
static double |
MIN_POSITION |
protected int |
portNumber |
| Constructor and Description |
|---|
Servo(ServoController controller,
int portNumber)
Constructor
|
Servo(ServoController controller,
int portNumber,
Servo.Direction direction)
COnstructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close this device
|
java.lang.String |
getConnectionInfo()
Get connection information about this device in a human readable format
|
ServoController |
getController()
Get Servo Controller
|
java.lang.String |
getDeviceName()
Device Name
|
Servo.Direction |
getDirection()
Get the direction
|
int |
getPortNumber()
Get Channel
|
double |
getPosition()
Returns the position to which the servo was last commanded, or Double.NaN if that is
unavailable.
|
int |
getVersion()
Version
|
protected void |
internalSetPosition(double position) |
void |
scaleRange(double min,
double max)
Automatically scale the position of the servo.
|
void |
setDirection(Servo.Direction direction)
Set the direction
|
void |
setPosition(double position)
Commands the servo to move to a designated position.
|
public static final double MIN_POSITION
public static final double MAX_POSITION
protected ServoController controller
protected int portNumber
protected Servo.Direction direction
protected double limitPositionMin
protected double limitPositionMax
public Servo(ServoController controller, int portNumber)
controller - Servo controller that this servo is attached toportNumber - physical port number on the servo controllerpublic Servo(ServoController controller, int portNumber, Servo.Direction direction)
controller - Servo controller that this servo is attached toportNumber - physical port number on the servo controllerdirection - FORWARD for normal operation, REVERSE to reverse operationpublic java.lang.String getDeviceName()
HardwareDevicegetDeviceName in interface HardwareDevicepublic java.lang.String getConnectionInfo()
HardwareDevicegetConnectionInfo in interface HardwareDevicepublic int getVersion()
HardwareDevicegetVersion in interface HardwareDevicepublic void close()
HardwareDeviceclose in interface HardwareDevicepublic ServoController getController()
public void setDirection(Servo.Direction direction)
direction - directionpublic Servo.Direction getDirection()
public int getPortNumber()
public void setPosition(double position)
position - the commanded servo position. Should be in the range [0.0, 1.0].getPosition()protected void internalSetPosition(double position)
public double getPosition()
setPosition(double),
Double.isNaN(double)public void scaleRange(double min,
double max)
throws java.lang.IllegalArgumentException
For example, if scaleRange(0.2, 0.8) is set; then servo positions will be
scaled to fit in that range.
setPosition(0.0) scales to 0.2
setPosition(1.0) scales to 0.8
setPosition(0.5) scales to 0.5
setPosition(0.25) scales to 0.35
setPosition(0.75) scales to 0.65
This is useful if you don't want the servo to move past a given position, but don't want to manually scale the input to setPosition each time. getPosition() will scale the value back to a value between 0.0 and 1.0. If you need to know the actual position use Servo.getController().getServoPosition(Servo.getChannel()).
min - minimum position of the servo from 0.0 to 1.0max - maximum position of the servo from 0.0 to 1.0java.lang.IllegalArgumentException - if out of bounds, or min >= max