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 |
static double |
MAX_POSITION |
protected double |
maxPosition |
static double |
MIN_POSITION |
protected double |
minPosition |
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()
Get the position of the servo
|
int |
getVersion()
Version
|
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)
Set the position of the servo
|
public static final double MIN_POSITION
public static final double MAX_POSITION
protected ServoController controller
protected int portNumber
protected Servo.Direction direction
protected double minPosition
protected double maxPosition
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()
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 close()
HardwareDevice
close
in interface HardwareDevice
public ServoController getController()
public void setDirection(Servo.Direction direction)
direction
- directionpublic Servo.Direction getDirection()
public int getPortNumber()
public void setPosition(double position)
position
- from 0.0 to 1.0public double getPosition()
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