Class ExpansionHubServo
java.lang.Object
org.wpilib.hardware.expansionhub.ExpansionHubServo
- All Implemented Interfaces:
AutoCloseable
This class controls a specific servo in positional/servo mode hooked up to an ExpansionHub.
-
Constructor Summary
ConstructorsConstructorDescriptionExpansionHubServo(int usbId, int channel) Constructs a servo at the requested channel on a specific USB port. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes a servo so another instance can be constructed.booleanGets if the underlying ExpansionHub is connected.voidSets the servo angle.voidsetAngleRange(double minAngle, double maxAngle) Sets the angle range for the setAngle call.voidsetEnabled(boolean enabled) Sets if the servo output is enabled or not.voidsetFramePeriod(Time framePeriod) Sets the frame period for the servo.voidsetPosition(double value) Set the servo position.voidsetPulseWidth(Time pulseWidth) Sets the raw pulse width output on the servo.voidsetPWMRange(int minPwm, int maxPwm) Sets the PWM range for the servo.voidsetReversed(boolean reversed) Sets whether the servo is reversed.
-
Constructor Details
-
ExpansionHubServo
public ExpansionHubServo(int usbId, int channel) Constructs a servo at the requested channel on a specific USB port.- Parameters:
usbId- The USB port ID the hub is connected tochannel- The servo channel
-
-
Method Details
-
setPosition
public void setPosition(double value) Set the servo position.Servo values range from 0.0 to 1.0 corresponding to the range of full left to full right.
- Parameters:
value- Position from 0.0 to 1.0.
-
setAngle
Sets the servo angle.Servo angles range defaults to 0 to 180 degrees, but can be changed with setAngleRange().
- Parameters:
angle- Position in angle units. Will be clamped to be within the current angle range.
-
setPulseWidth
Sets the raw pulse width output on the servo.- Parameters:
pulseWidth- Pulse width
-
setEnabled
public void setEnabled(boolean enabled) Sets if the servo output is enabled or not. Defaults to false.- Parameters:
enabled- True to enable, false to disable
-
setFramePeriod
Sets the frame period for the servo. Defaults to 20ms.- Parameters:
framePeriod- The frame period
-
isHubConnected
public boolean isHubConnected()Gets if the underlying ExpansionHub is connected.- Returns:
- True if hub is connected, otherwise false
-
setReversed
public void setReversed(boolean reversed) Sets whether the servo is reversed.This will reverse both setPosition() and setAngle().
- Parameters:
reversed- True to reverse, false for normal
-
setPWMRange
public void setPWMRange(int minPwm, int maxPwm) Sets the PWM range for the servo. By default, this is 600 to 2400 microseconds.Maximum must be greater than minimum.
- Parameters:
minPwm- Minimum PWMmaxPwm- Maximum PWM
-
setAngleRange
public void setAngleRange(double minAngle, double maxAngle) Sets the angle range for the setAngle call. By default, this is 0 to 180 degrees.Maximum angle must be greater than minimum angle.
- Parameters:
minAngle- Minimum anglemaxAngle- Maximum angle
-
close
public void close()Closes a servo so another instance can be constructed.- Specified by:
closein interfaceAutoCloseable
-