Class SparkTap.MotorView

java.lang.Object
frc.lib.lowlevel.SparkTap.MotorView
Enclosing class:
SparkTap

public class SparkTap.MotorView extends Object
Dedicated view into the shared CAN telemetry table for a specific motor.
  • Method Details

    • getTimestampUs

      public long getTimestampUs(SparkTap.Frame frame)
      Gets the exact FPGA microsecond timestamp of the most recent CAN frame.
      Parameters:
      frame - The status frame to get the timestamp for.
      Returns:
      The FPGA timestamp in microseconds.
    • getLastSeenTimestampUs

      public long getLastSeenTimestampUs()
      Gets the timestamp of the most recent CAN frame 0 in microseconds, or 0 if no frame has been received.
      Returns:
      The FPGA timestamp of the most recently seen frame in microseconds.
    • getSequenceNumber

      public int getSequenceNumber(SparkTap.Frame frame)
      Gets the current sequence number for a given frame.
      Parameters:
      frame - The status frame to check.
      Returns:
      The sequence number.
    • isConnected

      public boolean isConnected(double timeoutSeconds)
      Checks if the motor has sent any CAN frames within the specified timeout.
      Parameters:
      timeoutSeconds - Time to wait before considering the device disconnected.
      Returns:
      True if a frame has been received within the timeout, false otherwise.
    • isConnected

      public boolean isConnected()
      Checks if the motor is connected (defaults to 100ms timeout).
      Returns:
      True if connected, false otherwise.
    • getForwardLimit

      public boolean getForwardLimit()
      Checks if the forward hard limit switch is reached. Found in Status 0.
      Returns:
      True if the limit switch is reached, false otherwise.
    • getReverseLimit

      public boolean getReverseLimit()
      Checks if the reverse hard limit switch is reached. Found in Status 0.
      Returns:
      True if the limit switch is reached, false otherwise.
    • getForwardSoftLimit

      public boolean getForwardSoftLimit()
      Checks if the forward soft limit is reached. Found in Status 0.
      Returns:
      True if the soft limit is reached, false otherwise.
    • getReverseSoftLimit

      public boolean getReverseSoftLimit()
      Checks if the reverse soft limit is reached. Found in Status 0.
      Returns:
      True if the soft limit is reached, false otherwise.
    • getInverted

      public boolean getInverted()
      Checks if the motor is currently configured as inverted. Found in Status 0.
      Returns:
      True if the motor is inverted, false otherwise.
    • getAppliedOutput

      public double getAppliedOutput()
      Gets the Applied Output (Duty Cycle) from -1.0 to 1.0. Found in Status 0.
      Returns:
      The applied output from -1.0 to 1.0.
    • getBusVoltage

      public double getBusVoltage()
      Gets the Bus Voltage (Input Voltage) in Volts. Found in Status 0.
      Returns:
      The bus voltage in Volts.
    • getOutputCurrent

      public double getOutputCurrent()
      Gets the Output Current (Stator Current) in Amps. Found in Status 0.
      Returns:
      The output current in Amps.
    • getMotorTemperature

      public int getMotorTemperature()
      Gets the Motor Temperature in Celsius from Status 0.
      Returns:
      The motor temperature in degrees Celsius.
    • getInputCurrent

      public double getInputCurrent()
      Calculates the estimated Input (Supply) Current in Amps. This is derived from Applied Output * Output Current.
      Returns:
      The calculated input current in Amps.
    • getFaults

      public long getFaults()
      Gets the full 64-bit fault and warning bitfield. Found in Status 1.
      Returns:
      The fault and warning bitfield.
    • getActiveFaults

      public int getActiveFaults()
      Gets the 8-bit bitfield of currently active faults. Found in Status 1.
      Returns:
      The active faults bitfield.
    • getStickyFaults

      public int getStickyFaults()
      Gets the 8-bit bitfield of sticky faults (faults that occurred since boot). Found in Status 1.
      Returns:
      The sticky faults bitfield.
    • getActiveWarnings

      public int getActiveWarnings()
      Gets the 8-bit bitfield of currently active warnings. Found in Status 1.
      Returns:
      The active warnings bitfield.
    • getStickyWarnings

      public int getStickyWarnings()
      Gets the 8-bit bitfield of sticky warnings. Found in Status 1.
      Returns:
      The sticky warnings bitfield.
    • isFollower

      public boolean isFollower()
      Checks if the motor is currently in Follower Mode. Found in Status 1.
      Returns:
      True if the motor is in follower mode, false otherwise.
    • hasResetOccurred

      public boolean hasResetOccurred()
      Checks if the device has reset since the last time faults were cleared. Found in Status 1.
      Returns:
      True if a reset has occurred, false otherwise.
    • getPosition

      public double getPosition()
      Gets the position from the internal encoder. Found in Status 2.

      This value is affected by positionConversionFactor

      Returns:
      The position in Rotations.
    • getVelocity

      public double getVelocity()
      Gets the velocity from the internal encoder. Found in Status 2.

      This value is affected by velocityConversionFactor

      Returns:
      The velocity.
    • getLatencyCompensatedPosition

      public double getLatencyCompensatedPosition()
      Latency Compensation. Atomically reads position, velocity, and timestamp from the same CAN frame and extrapolates the position to the current FPGA microsecond. Found in Status 2.

      This code is affected by both positionConversionFactor and velocityConversionFactor which both have to be the same units for the latency compensation to be accurate. If they are different, the extrapolation will be incorrect. Also make sure the velocity is unit/second.

      Returns:
      The mathematically time-aligned position in Rotations.
    • getAbsoluteEncoderVelocity

      public double getAbsoluteEncoderVelocity()
      Gets the absolute encoder velocity. Found in Status 5.

      This value is affected by velocityConversionFactor.

      Returns:
      The absolute encoder velocity.
    • getAbsoluteEncoderPosition

      public double getAbsoluteEncoderPosition()
      Gets the absolute encoder position. Found in Status 5.

      This value is affected by positionConversionFactor.

      Returns:
      The absolute encoder position