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
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
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
-
setPulseWidth
Sets the raw pulse width output on the servo.- Parameters:
pulseWidth- Pulse width
-
setEnabled
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
Gets if the underlying ExpansionHub is connected.- Returns:
- True if hub is connected, otherwise false
-
setReversed
Sets whether the servo is reversed.This will reverse both setPosition() and setAngle().
- Parameters:
reversed- True to reverse, false for normal
-
setPWMRange
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
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
Closes a servo so another instance can be constructed.- Specified by:
closein interfaceAutoCloseable
-