Class ExpansionHubServo
java.lang.Object
org.wpilib.hardware.expansionhub.ExpansionHubServo
- All Implemented Interfaces:
AutoCloseable
This class controls a specific servo 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.voidset(double value) Set the servo position.voidSets the servo anglevoidsetAngleRange(double minAngle, double maxAngle) Sets the angle range for the setAngle call.voidsetContinousRotationMode(boolean enable) Enables or disables continuous rotation mode.voidsetEnabled(boolean enabled) Sets if the servo output is enabled or not.voidsetFramePeriod(Time framePeriod) Sets the frame period for the servo.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
-
set
Set the servo position.Servo values range from 0.0 to 1.0 corresponding to the range of full left to full right. If continuous rotation mode is enabled, the range is -1.0 to 1.0.
- Parameters:
value- Position from 0.0 to 1.0 (-1 to 1 in CR mode).
-
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 set() 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
-
setContinousRotationMode
Enables or disables continuous rotation mode.In continuous rotation mode, the servo will interpret Set() commands to between -1.0 and 1.0, instead of 0.0 to 1.0.
- Parameters:
enable- True to enable continuous rotation mode, false to disable
-
close
Closes a servo so another instance can be constructed.- Specified by:
closein interfaceAutoCloseable
-