Class A301

java.lang.Object
com.revrobotics.spark.A301
All Implemented Interfaces:
org.wpilib.hardware.motor.MotorController

public class A301 extends Object implements org.wpilib.hardware.motor.MotorController
  • Field Details

  • Constructor Details

    • A301

      public A301(int busId)
      Create a new object to control a FIRST A301 motor

      NOTE: If busId indicates a Motioncore bus, the device ID will be auto-detected.

      Parameters:
      busId - The CAN bus ID this device will be on.
    • A301

      public A301(int busId, int deviceId)
      Create a new object to control a FIRST A301 motor

      NOTE: If busId indicates a Motioncore bus, the device ID will be auto-detected and deviceId will be ignored.

      Parameters:
      busId - The CAN bus ID this device will be on.
      deviceId - The device ID.
  • Method Details

    • close

      public void close()
      Closes the FIRST A301 motor controller
    • getBusId

      public int getBusId()
      Get the configured CAN Bus ID of the FIRST A301.
      Returns:
      int CAN bus ID
    • getDeviceId

      public int getDeviceId()
      Get the configured Device ID of the FIRST A301.
      Returns:
      int device ID
    • getFirmwareVersion

      public int getFirmwareVersion()
      Get the firmware version of the FIRST A301.
      Returns:
      uint32_t Firmware version integer. Value is represented as 4 bytes, Major.Minor.Build H.Build L
    • getFirmwareString

      public String getFirmwareString()
      Get the firmware version of the FIRST A301 as a string.
      Returns:
      String Human readable firmware version string
    • hasActiveFault

      public Signal<Boolean> hasActiveFault()
      Get whether the A301 has one or more active faults.
      Returns:
      true if there is an active fault
      See Also:
    • hasStickyFault

      public Signal<Boolean> hasStickyFault()
      Get whether the A301 has one or more sticky faults.
      Returns:
      true if there is a sticky fault
      See Also:
    • hasActiveWarning

      public Signal<Boolean> hasActiveWarning()
      Get whether the A301 has one or more active warnings.
      Returns:
      true if there is an active warning
      See Also:
    • hasStickyWarning

      public Signal<Boolean> hasStickyWarning()
      Get whether the A301 has one or more sticky warnings.
      Returns:
      true if there is a sticky warning
      See Also:
    • getFaults

      public Signal<A301.Faults> getFaults()
      Get the active faults that are currently present on the A301. Faults are fatal errors that prevent the motor from running.
      Returns:
      A struct with each fault and their active value
    • getStickyFaults

      public Signal<A301.Faults> getStickyFaults()
      Get the sticky faults that were present on the A301 at one point since the sticky faults were last cleared. Faults are fatal errors that prevent the motor from running.

      Sticky faults can be cleared with clearFaults().

      Returns:
      A struct with each fault and their sticky value
    • getWarnings

      public Signal<A301.Warnings> getWarnings()
      Get the active warnings that are currently present on the A301. Warnings are non-fatal errors.
      Returns:
      A struct with each warning and their active value
    • getStickyWarnings

      public Signal<A301.Warnings> getStickyWarnings()
      Get the sticky warnings that were present on the A301 at one point since the sticky warnings were last cleared. Warnings are non-fatal errors.

      Sticky warnings can be cleared with clearFaults().

      Returns:
      A struct with each warning and their sticky value
    • clearFaults

      public REVLibError clearFaults()
      Clears all sticky faults.
      Returns:
      REVLibError.kOk if successful
    • getBusVoltage

      public Signal<Double> getBusVoltage()
      Returns the A301 bus voltage in Volts.
      Returns:
      The voltage fed into the motor controller.
    • getAppliedOutput

      public Signal<Double> getAppliedOutput()
      Returns the A301's output duty cycle.
      Returns:
      The motor controller's applied output duty cycle.
    • getMotorCurrent

      public Signal<Double> getMotorCurrent()
      Returns A301's motor current in Amps.
      Returns:
      The motor's current in Amps.
    • getMotorTemperature

      public Signal<Double> getMotorTemperature()
      Returns the motor temperature in Celsius.
      Returns:
      The motor temperature in Celsius.
    • getGearboxRPM

      public Signal<A301.GearboxRPM> getGearboxRPM()
      Returns the RPM of the A301's attached gearbox.
      Returns:
      Signal containing the gearbox RPM (@see GearboxRPM)
    • getRelativeEncoderPosition

      public Signal<Double> getRelativeEncoderPosition()
      Get the position of the motor. This returns the native units of 'rotations'.
      Returns:
      Signal containing the number of rotations of the motor
    • getEncoderVelocity

      public Signal<Double> getEncoderVelocity()
      Get the velocity of the motor. This returns the native units of 'RPM'.
      Returns:
      Signal containing the RPM of the motor
    • getAbsoluteEncoderPosition

      public Signal<Double> getAbsoluteEncoderPosition()
    • setRelativeEncoderPosition

      public REVLibError setRelativeEncoderPosition(double position)
      Set the position of the relative encoder.
      Parameters:
      position - Number of rotations of the motor
      Returns:
      REVLibError::kOk if successful
    • setAbsoluteEncoderPosition

      public REVLibError setAbsoluteEncoderPosition(double position)
      Set the position of the absolute encoder.
      Parameters:
      position - Number of rotations of the motor
      Returns:
      REVLibError::kOk if successful
    • setVelocity

      public REVLibError setVelocity(double velocity)
      Sets the velocity of the A301.
      Parameters:
      velocity - The velocity (in RPM) to set
      Returns:
      REVLibError.kOk if successful
    • setRelativePosition

      public REVLibError setRelativePosition(double position)
      Sets the relative position of the A301 (with maximum speed).
      Parameters:
      position - The relative position (in Rotations) to set
      Returns:
      REVLibError.kOk if successful
    • setRelativePositionWithSpeed

      public REVLibError setRelativePositionWithSpeed(double position, double speed)
      Sets the relative position of the A301 with a specific speed.

      Setting speed less than or equal to 0 will apply maximum speed)

      Parameters:
      position - The relative position (in Rotations) to set
      speed - The speed to approach the position at (in RPM)
      Returns:
      REVLibError.kOk if successful
    • setAbsolutePosition

      public REVLibError setAbsolutePosition(double absPosition)
      Sets the absolute position of the A301 (with maximum speed).
      Parameters:
      absPosition - The absolute position (-0.5 to 0.5) to set
      Returns:
      REVLibError.kOk if successful
    • setAbsolutePositionWithSpeed

      public REVLibError setAbsolutePositionWithSpeed(double absPosition, double speed)
      Sets the absolute position of the A301 with a specific speed.

      Setting speed less than or equal to 0 will apply maximum speed)

      Parameters:
      absPosition - The absolute position (-0.5 to 0.5) to set
      speed - The speed to approach the position at (in RPM)
      Returns:
      REVLibError.kOk if successful
    • enableAbsolutePositionContinuousInput

      public REVLibError enableAbsolutePositionContinuousInput()
      Enables continuous input for absolute position control.
      Returns:
      REVLibError::kOk if successful
    • disableAbsolutePositionContinuousInput

      public REVLibError disableAbsolutePositionContinuousInput()
      Disables continuous input for absolute position control.
      Returns:
      REVLibError::kOk if successful
    • isAbsolutePositionContinuousInputEnabled

      public boolean isAbsolutePositionContinuousInputEnabled()
      Queries the continuous input for absolute position control.
      Returns:
      true if continuous input is enabled.
    • setCurrent

      public REVLibError setCurrent(double current)
      Sets the motor current of the A301.
      Parameters:
      current - The current (in Amps) to drive the motor at
      Returns:
      REVLibError.kOk if successful
    • setThrottle

      public void setThrottle(double throttle)
      Sets the throttle of the motor controller.
      Specified by:
      setThrottle in interface org.wpilib.hardware.motor.MotorController
      Parameters:
      throttle - The throttle where -1.0 indicates full reverse and 1.0 indicates full forward.
    • getThrottle

      public double getThrottle()
      Gets the throttle of the motor controller.
      Specified by:
      getThrottle in interface org.wpilib.hardware.motor.MotorController
      Returns:
      The throttle where -1.0 represents full reverse and 1.0 represents full forward.
    • setVoltage

      public void setVoltage(double outputVolts)
      Sets the voltage output of the MotorController. This is equivalent to a call to setSetpoint(output, ControlType.kVoltage). The behavior of this call differs slightly from the WPILib documetation for this call since the device internally sets the desired voltage (not a compensation value). That means that this *can* be a 'set-and-forget' call.
      Specified by:
      setVoltage in interface org.wpilib.hardware.motor.MotorController
      Parameters:
      outputVolts - The voltage to output.
    • setInverted

      public void setInverted(boolean isInverted)
      Common interface for inverting direction of a speed controller.
      Specified by:
      setInverted in interface org.wpilib.hardware.motor.MotorController
      Parameters:
      isInverted - The state of inversion, true is inverted.
    • getInverted

      public boolean getInverted()
      Common interface for returning the inversion state of a speed controller.
      Specified by:
      getInverted in interface org.wpilib.hardware.motor.MotorController
      Returns:
      The state of inversion, true is inverted.
    • disable

      public void disable()
      Common interface for disabling a motor.
      Specified by:
      disable in interface org.wpilib.hardware.motor.MotorController
    • faultsPeriodMs

      public A301 faultsPeriodMs(int period_ms)
      Set the period (ms) of the status frame that provides the signal returned by getFaults() and getStickyFaults().

      The default period is 50ms. The maximum period is 1000ms (1s).

      If multiple periods are set for signals within the same status frame, the minimum given value will be used.

      Parameters:
      period_ms - The period in milliseconds
      Returns:
      The modified A301 object for method chaining
    • getFaultsPeriodMs

      public int getFaultsPeriodMs()
      Get the period (ms) of the status frame that provides the signal returned by getFaults() and getStickyFaults().
      Returns:
      The period in milliseconds
    • warningsPeriodMs

      public A301 warningsPeriodMs(int period_ms)
      Set the period (ms) of the status frame that provides the signal returned by getWarnings() and getStickyWarnings().

      The default period is 50ms. The maximum period is 1000ms (1s).

      If multiple periods are set for signals within the same status frame, the minimum given value will be used.

      Parameters:
      period_ms - The period in milliseconds
      Returns:
      The modified A301 object for method chaining
    • getWarningsPeriodMs

      public int getWarningsPeriodMs()
      Get the period (ms) of the status frame that provides the signal returned by getWarnings() and getStickyWarnings().
      Returns:
      The period in milliseconds
    • busVoltagePeriodMs

      public A301 busVoltagePeriodMs(int period_ms)
      Set the period (ms) of the status frame that provides the signal returned by getBusVoltage().

      The default period is 10ms. The maximum period is 1000ms (1s).

      If multiple periods are set for signals within the same status frame, the minimum given value will be used.

      Parameters:
      period_ms - The period in milliseconds
      Returns:
      The modified A301 object for method chaining
    • getBusVoltagePeriodMs

      public int getBusVoltagePeriodMs()
      Get the period (ms) of the status frame that provides the signal returned by getBusVoltage().
      Returns:
      The period in milliseconds
    • appliedOutputPeriodMs

      public A301 appliedOutputPeriodMs(int period_ms)
      Set the period (ms) of the status frame that provides the signal returned by getAppliedOutput().

      The default period is 10ms. The maximum period is 1000ms (1s).

      If multiple periods are set for signals within the same status frame, the minimum given value will be used.

      Parameters:
      period_ms - The period in milliseconds
      Returns:
      The modified A301 object for method chaining
    • getAppliedOutputPeriodMs

      public int getAppliedOutputPeriodMs()
      Get the period (ms) of the status frame that provides the signal returned by getAppliedOutput().
      Returns:
      The period in milliseconds
    • motorCurrentPeriodMs

      public A301 motorCurrentPeriodMs(int period_ms)
      Set the period (ms) of the status frame that provides the signal returned by getMotorCurrent().

      The default period is 10ms. The maximum period is 1000ms (1s).

      If multiple periods are set for signals within the same status frame, the minimum given value will be used.

      Parameters:
      period_ms - The period in milliseconds
      Returns:
      The modified A301 object for method chaining
    • getMotorCurrentPeriodMs

      public int getMotorCurrentPeriodMs()
      Get the period (ms) of the status frame that provides the signal returned by getMotorCurrent().
      Returns:
      The period in milliseconds
    • motorTemperaturePeriodMs

      public A301 motorTemperaturePeriodMs(int period_ms)
      Set the period (ms) of the status frame that provides the signal returned by getMotorTemperature().

      The default period is 10ms. The maximum period is 1000ms (1s).

      If multiple periods are set for signals within the same status frame, the minimum given value will be used.

      Parameters:
      period_ms - The period in milliseconds
      Returns:
      The modified A301 object for method chaining
    • getMotorTemperaturePeriodMs

      public int getMotorTemperaturePeriodMs()
      Get the period (ms) of the status frame that provides the signal returned by getMotorTemperature().
      Returns:
      The period in milliseconds
    • relativeEncoderPositionPeriodMs

      public A301 relativeEncoderPositionPeriodMs(int period_ms)
      Set the period (ms) of the status frame that provides the signal returned by getRelativeEncoderPosition().

      The default period is 20ms. The maximum period is 1000ms (1s).

      If multiple periods are set for signals within the same status frame, the minimum given value will be used.

      Parameters:
      period_ms - The period in milliseconds
      Returns:
      The modified A301 object for method chaining
    • getRelativeEncoderPositionPeriodMs

      public int getRelativeEncoderPositionPeriodMs()
      Get the period (ms) of the status frame that provides the signal returned by getRelativeEncoderPosition().
      Returns:
      The period in milliseconds
    • encoderVelocityPeriodMs

      public A301 encoderVelocityPeriodMs(int period_ms)
      Set the period (ms) of the status frame that provides the signal returned by getEncoderVelocity().

      The default period is 20ms. The maximum period is 1000ms (1s).

      If multiple periods are set for signals within the same status frame, the minimum given value will be used.

      Parameters:
      period_ms - The period in milliseconds
      Returns:
      The modified A301 object for method chaining
    • getEncoderVelocityPeriodMs

      public int getEncoderVelocityPeriodMs()
      Get the period (ms) of the status frame that provides the signal returned by getEncoderVelocity().
      Returns:
      The period in milliseconds
    • absoluteEncoderPositionPeriodMs

      public A301 absoluteEncoderPositionPeriodMs(int period_ms)
      Set the period (ms) of the status frame that provides the signal returned by getAbsoluteEncoderPosition().

      The default period is 20ms. The maximum period is 1000ms (1s).

      If multiple periods are set for signals within the same status frame, the minimum given value will be used.

      Parameters:
      period_ms - The period in milliseconds
      Returns:
      The modified A301 object for method chaining
    • getAbsoluteEncoderPositionPeriodMs

      public int getAbsoluteEncoderPositionPeriodMs()
      Get the period (ms) of the status frame that provides the signal returned by getAbsoluteEncoderPosition().
      Returns:
      The period in milliseconds