Package frclib.sensor

Class FrcCANCoder

java.lang.Object
com.ctre.phoenix6.jni.CtreJniWrapper
com.ctre.phoenix6.hardware.ParentDevice
com.ctre.phoenix6.hardware.core.CoreCANcoder
com.ctre.phoenix6.hardware.CANcoder
frclib.sensor.FrcCANCoder
All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable, AutoCloseable, TrcEncoder

public class FrcCANCoder extends com.ctre.phoenix6.hardware.CANcoder implements TrcEncoder
This class extends CANCoder and implements the FrcEncoder interface to allow compatibility to other types of encoders.
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.ctre.phoenix6.hardware.ParentDevice

    com.ctre.phoenix6.hardware.ParentDevice.MapGenerator<T extends Object>
  • Field Summary

    Fields inherited from class com.ctre.phoenix6.hardware.ParentDevice

    _emptyControl, deviceIdentifier
  • Constructor Summary

    Constructors
    Constructor
    Description
    FrcCANCoder(String instanceName, int canId)
    Constructor: Creates an instance of the object.
    FrcCANCoder(String instanceName, int canId, String canBus)
    Constructor: Creates an instance of the object.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    This method returns the number of error responses seen from the motor after sending a command.
    com.ctre.phoenix6.StatusCode
    The method returns the last error code.
    double
    This method reads the absolute position of the encoder.
    double
    This method reads the raw encoder velocity in encoder units per second.
    double
    This method returns the encoder position adjusted by scale and offset.
    double
    This method returns the encoder velocity adjusted by scale.
    boolean
    This method checks if the encoder direction is inverted.
    protected com.ctre.phoenix6.StatusCode
    recordResponseCode(String operation, com.ctre.phoenix6.StatusCode statusCode)
    This method checks for error code returned by the motor controller executing the last command.
    void
    This method resets the encoder position.
    com.ctre.phoenix6.StatusCode
    This method resets the motor controller configurations to factory default so that everything is at known state.
    com.ctre.phoenix6.StatusCode
    setAbsoluteRange(boolean range0To1)
    This method configures the absolute range mode of the encoder.
    void
    setInverted(boolean inverted)
    This method reverses the direction of the encoder.
    void
    setScaleAndOffset(double scale, double offset, double zeroOffset)
    This method sets the encoder scale and offset.
    This method returns the instance name.

    Methods inherited from class com.ctre.phoenix6.hardware.CANcoder

    close, initSendable

    Methods inherited from class com.ctre.phoenix6.hardware.core.CoreCANcoder

    clearStickyFault_BadMagnet, clearStickyFault_BadMagnet, clearStickyFault_BootDuringEnable, clearStickyFault_BootDuringEnable, clearStickyFault_Hardware, clearStickyFault_Hardware, clearStickyFault_Undervoltage, clearStickyFault_Undervoltage, clearStickyFault_UnlicensedFeatureInUse, clearStickyFault_UnlicensedFeatureInUse, clearStickyFaults, clearStickyFaults, getAbsolutePosition, getAbsolutePosition, getConfigurator, getFault_BadMagnet, getFault_BadMagnet, getFault_BootDuringEnable, getFault_BootDuringEnable, getFault_Hardware, getFault_Hardware, getFault_Undervoltage, getFault_Undervoltage, getFault_UnlicensedFeatureInUse, getFault_UnlicensedFeatureInUse, getFaultField, getFaultField, getIsProLicensed, getIsProLicensed, getMagnetHealth, getMagnetHealth, getPosition, getPosition, getPositionSinceBoot, getPositionSinceBoot, getSimState, getStickyFault_BadMagnet, getStickyFault_BadMagnet, getStickyFault_BootDuringEnable, getStickyFault_BootDuringEnable, getStickyFault_Hardware, getStickyFault_Hardware, getStickyFault_Undervoltage, getStickyFault_Undervoltage, getStickyFault_UnlicensedFeatureInUse, getStickyFault_UnlicensedFeatureInUse, getStickyFaultField, getStickyFaultField, getSupplyVoltage, getSupplyVoltage, getUnfilteredVelocity, getUnfilteredVelocity, getVelocity, getVelocity, getVersion, getVersion, getVersionBugfix, getVersionBugfix, getVersionBuild, getVersionBuild, getVersionMajor, getVersionMajor, getVersionMinor, getVersionMinor, setControl, setPosition, setPosition, setPosition, setPosition

    Methods inherited from class com.ctre.phoenix6.hardware.ParentDevice

    getAppliedControl, getDeviceHash, getDeviceID, getNetwork, getResetOccurredChecker, hasResetOccurred, isConnected, isConnected, lookupStatusSignal, lookupStatusSignal, optimizeBusUtilization, optimizeBusUtilization, optimizeBusUtilization, optimizeBusUtilizationForAll, optimizeBusUtilizationForAll, resetSignalFrequencies, resetSignalFrequencies, resetSignalFrequenciesForAll, setControlPrivate

    Methods inherited from class java.lang.Object

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

    • FrcCANCoder

      public FrcCANCoder(String instanceName, int canId, String canBus)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      canId - specifies the CAN ID of the CANCoder.
      canBus - specifies the CAN bus the CANCoder is on. Possible CAN bus strings are:
      • "rio" for the native roboRIO CAN bus
      • CANivore name or serial number
      • SocketCAN interface (non-FRC Linux only)
      • "*" for any CANivore seen by the program
      • empty string (default) to select the default for the system:
        • "rio" on roboRIO
        • "can0" on Linux
        • "*" on Windows
    • FrcCANCoder

      public FrcCANCoder(String instanceName, int canId)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      canId - specifies the CAN ID of the CANCoder.
  • Method Details

    • toString

      public String toString()
      This method returns the instance name.
      Overrides:
      toString in class Object
      Returns:
      instance name.
    • getErrorCount

      public int getErrorCount()
      This method returns the number of error responses seen from the motor after sending a command.
      Returns:
      The number of non-OK error code responses seen from the motor after sending a command.
    • getLastStatus

      public com.ctre.phoenix6.StatusCode getLastStatus()
      The method returns the last error code. If there is none, null is returned.
      Returns:
      last error code.
    • recordResponseCode

      protected com.ctre.phoenix6.StatusCode recordResponseCode(String operation, com.ctre.phoenix6.StatusCode statusCode)
      This method checks for error code returned by the motor controller executing the last command. If there was an error, the error count is incremented.
      Parameters:
      operation - specifies the operation that failed.
      statusCode - specifies the status code returned by the motor controller.
    • resetFactoryDefault

      public com.ctre.phoenix6.StatusCode resetFactoryDefault()
      This method resets the motor controller configurations to factory default so that everything is at known state.
    • setAbsoluteRange

      public com.ctre.phoenix6.StatusCode setAbsoluteRange(boolean range0To1)
      This method configures the absolute range mode of the encoder.
      Parameters:
      range0To1 - specifies true to set it to Unsigned_0To1 mode, false to Signed_PlusMinusHalf mode.
    • reset

      public void reset()
      This method resets the encoder position.
      Specified by:
      reset in interface TrcEncoder
    • getRawPosition

      public double getRawPosition()
      This method reads the absolute position of the encoder.
      Specified by:
      getRawPosition in interface TrcEncoder
      Returns:
      absolute position of the encoder. The absolute position may be unsigned (for example: [0,360) deg), or signed (for example: [-180,+180) deg). This is determined by a configuration. The default selection is unsigned.
    • getScaledPosition

      public double getScaledPosition()
      This method returns the encoder position adjusted by scale and offset.
      Specified by:
      getScaledPosition in interface TrcEncoder
      Returns:
      encoder position adjusted by scale and offset.
    • getRawVelocity

      public double getRawVelocity()
      This method reads the raw encoder velocity in encoder units per second.
      Specified by:
      getRawVelocity in interface TrcEncoder
      Returns:
      raw encoder velocity in encoder units per second.
    • getScaledVelocity

      public double getScaledVelocity()
      This method returns the encoder velocity adjusted by scale.
      Specified by:
      getScaledVelocity in interface TrcEncoder
      Returns:
      encoder velocity adjusted by scale.
    • setInverted

      public void setInverted(boolean inverted)
      This method reverses the direction of the encoder.
      Specified by:
      setInverted in interface TrcEncoder
      Parameters:
      inverted - specifies true to reverse the encoder direction, false otherwise.
    • isInverted

      public boolean isInverted()
      This method checks if the encoder direction is inverted.
      Specified by:
      isInverted in interface TrcEncoder
      Returns:
      true if encoder direction is rerversed, false otherwise.
    • setScaleAndOffset

      public void setScaleAndOffset(double scale, double offset, double zeroOffset)
      This method sets the encoder scale and offset.
      Specified by:
      setScaleAndOffset in interface TrcEncoder
      Parameters:
      scale - specifies the scale value.
      offset - specifies the offset value.
      zeroOffset - specifies the zero offset for absolute encoder.