Class ExpansionHubMotor

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

public class ExpansionHubMotor extends Object implements AutoCloseable
This class controls a specific motor and encoder hooked up to an ExpansionHub.
  • Constructor Details

    • ExpansionHubMotor

      public ExpansionHubMotor(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 motor channel
  • Method Details

    • close

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

      public void setDutyCycle(double dutyCycle)
      Sets the duty cycle.
      Parameters:
      dutyCycle - The duty cycle between -1 and 1 (sign indicates direction).
    • setVoltage

      public void setVoltage(Voltage voltage)
      Sets the voltage to run the motor at. This value will be continously scaled to match the input voltage.
      Parameters:
      voltage - The voltage to drive the motor at
    • setPositionSetpoint

      public void setPositionSetpoint(double setpoint)
      Command the motor to drive to a specific position setpoint. This value will be scaled by setDistancePerCount and influenced by the PID constants.
      Parameters:
      setpoint - The position setpoint to drive the motor to
    • setVelocitySetpoint

      public void setVelocitySetpoint(double setpoint)
      Command the motor to drive to a specific velocity setpoint. This value will be scaled by setDistancePerCount and influenced by the PID constants.
      Parameters:
      setpoint - The velocity setpoint to drive the motor to
    • setEnabled

      public void setEnabled(boolean enabled)
      Sets if the motor output is enabled or not. Defaults to false.
      Parameters:
      enabled - True to enable, false to disable
    • setFloatOn0

      public void setFloatOn0(boolean floatOn0)
      Sets if the motor should float or brake when 0 is commanded. Defaults to false.
      Parameters:
      floatOn0 - True to float when commanded 0, false to brake
    • getCurrent

      public Current getCurrent()
      Gets the current being pulled by the motor.
      Returns:
      Motor current
    • setDistancePerCount

      public void setDistancePerCount(double perCount)
      Sets the distance per count of the encoder. Used to scale encoder readings.
      Parameters:
      perCount - The distance moved per count of the encoder
    • isHubConnected

      public boolean isHubConnected()
      Gets if the underlying ExpansionHub is connected.
      Returns:
      True if hub is connected, otherwise false
    • getEncoderVelocity

      public double getEncoderVelocity()
      Gets the current velocity of the motor encoder. Scaled into distancePerCount units.
      Returns:
      Encoder velocity
    • getEncoderPosition

      public double getEncoderPosition()
      Gets the current position of the motor encoder. Scaled into distancePerCount units.
      Returns:
      Encoder position
    • setReversed

      public void setReversed(boolean reversed)
      Sets if the motor and encoder should be reversed.
      Parameters:
      reversed - True to reverse encoder, false otherwise
    • resetEncoder

      public void resetEncoder()
      Reset the encoder count to 0.
    • getVelocityPidConstants

      Gets the PID constants object for velocity PID.
      Returns:
      Velocity PID constants object
    • getPositionPidConstants

      Gets the PID constants object for position PID.
      Returns:
      Position PID constants object
    • follow

      public void follow(ExpansionHubMotor leader)
      Sets this motor to follow another motor on the same hub.

      This does not support following motors that are also followers. Additionally, the direction of both motors will be the same.

      Parameters:
      leader - The motor to follow