Class ExpansionHubServo

java.lang.Object
org.wpilib.hardware.expansionhub.ExpansionHubServo
All Implemented Interfaces:
AutoCloseable

public class ExpansionHubServo extends Object implements AutoCloseable
This class controls a specific servo hooked up to an ExpansionHub.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ExpansionHubServo(int usbId, int channel)
    Constructs a servo at the requested channel on a specific USB port.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes a servo so another instance can be constructed.
    boolean
    Gets if the underlying ExpansionHub is connected.
    void
    set(double value)
    Set the servo position.
    void
    setAngle(Angle angle)
    Sets the servo angle
    void
    setAngleRange(double minAngle, double maxAngle)
    Sets the angle range for the setAngle call.
    void
    setContinousRotationMode(boolean enable)
    Enables or disables continuous rotation mode.
    void
    setEnabled(boolean enabled)
    Sets if the servo output is enabled or not.
    void
    setFramePeriod(Time framePeriod)
    Sets the frame period for the servo.
    void
    setPulseWidth(Time pulseWidth)
    Sets the raw pulse width output on the servo.
    void
    setPWMRange(int minPwm, int maxPwm)
    Sets the PWM range for the servo.
    void
    setReversed(boolean reversed)
    Sets whether the servo is reversed.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 to
      channel - The servo channel
  • Method Details

    • set

      public void set(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. 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

      public void setAngle(Angle angle)
      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 scaled between the current angle range.
    • setPulseWidth

      public void setPulseWidth(Time pulseWidth)
      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

      public void setFramePeriod(Time framePeriod)
      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 set() 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 PWM
      maxPwm - 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 angle
      maxAngle - Maximum angle
    • setContinousRotationMode

      public void setContinousRotationMode(boolean enable)
      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

      public void close()
      Closes a servo so another instance can be constructed.
      Specified by:
      close in interface AutoCloseable