Class ExpansionHubCRServo

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

public class ExpansionHubCRServo extends Object implements AutoCloseable
This class controls a specific servo in continuous rotation mode hooked up to an ExpansionHub.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ExpansionHubCRServo(int usbId, int channel)
    Constructs a continuous rotation 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
    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.
    void
    setThrottle(double value)
    Set the servo throttle.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ExpansionHubCRServo

      public ExpansionHubCRServo(int usbId, int channel)
      Constructs a continuous rotation 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

    • close

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

      public void setThrottle(double value)
      Set the servo throttle.

      Throttle values range from -1.0 to 1.0 corresponding to full reverse to full forward.

      Parameters:
      value - Throttle from -1.0 to 1.0.
    • 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 setThrottle().

      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