# CANCoderSwerve
declaration: package: swervelib.encoders, class: CANCoderSwerve

Package swervelib.encoders

# Class CANCoderSwerve

java.lang.Object
swervelib.encoders.SwerveAbsoluteEncoder
swervelib.encoders.CANCoderSwerve

public class CANCoderSwerve extends SwerveAbsoluteEncoder
Swerve Absolute Encoder for CTRE CANCoders.

## Field Summary

Fields
Modifier and Type
Field
Description
`private Alert`
`cannotSetOffset`
An `Alert` for if the absolute encoder offset cannot be set.
`com.ctre.phoenix6.hardware.CANcoder`
`encoder`
CANCoder with WPILib sendable and support.
`private Alert`
`magnetFieldLessThanIdeal`
An `Alert` for if the CANCoder magnet field is less than ideal.
`private Alert`
`readingFaulty`
An `Alert` for if the CANCoder reading is faulty.
`private Alert`
`readingIgnored`
An `Alert` for if the CANCoder reading is faulty and the reading is ignored.

### Fields inherited from class swervelib.encoders.SwerveAbsoluteEncoder

`maximumRetries, readingError`

## Constructor Summary

Constructors
Constructor
Description
`CANCoderSwerve(int id)`
Initialize the CANCoder on the standard CANBus.
`CANCoderSwerve(int id, String canbus)`
Initialize the CANCoder on the CANivore.

## Method Summary

Modifier and Type
Method
Description
`void`
`clearStickyFaults()`
Clear sticky faults on the encoder.
`void`
`configure(boolean inverted)`
Configure the absolute encoder to read from [0, 360) per second.
`void`
`factoryDefault()`
Reset the encoder to factory defaults.
`Object`
`getAbsoluteEncoder()`
Get the instantiated absolute encoder Object.
`double`
`getAbsolutePosition()`
Get the absolute position of the encoder.
`double`
`getVelocity()`
Get the velocity in degrees/sec.
`boolean`
`setAbsoluteEncoderOffset(double offset)`
Sets the Absolute Encoder Offset within the CANcoder's Memory.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### encoder

public com.ctre.phoenix6.hardware.CANcoder encoder
CANCoder with WPILib sendable and support.

### magnetFieldLessThanIdeal

private Alert magnetFieldLessThanIdeal
An `Alert` for if the CANCoder magnet field is less than ideal.

### readingFaulty

private Alert readingFaulty
An `Alert` for if the CANCoder reading is faulty.

### readingIgnored

private Alert readingIgnored
An `Alert` for if the CANCoder reading is faulty and the reading is ignored.

### cannotSetOffset

private Alert cannotSetOffset
An `Alert` for if the absolute encoder offset cannot be set.

## Constructor Details

### CANCoderSwerve

public CANCoderSwerve(int id)
Initialize the CANCoder on the standard CANBus.

Parameters:
  `id` - CAN ID.

### CANCoderSwerve

public CANCoderSwerve(int id, String canbus)
Initialize the CANCoder on the CANivore.

Parameters:
  `id` - CAN ID.
  `canbus` - CAN bus to initialize it on.

## Method Details

### factoryDefault

public void factoryDefault()
Reset the encoder to factory defaults.

Specified by:
  `factoryDefault` in class `SwerveAbsoluteEncoder`

### clearStickyFaults

public void clearStickyFaults()
Clear sticky faults on the encoder.

Specified by:
  `clearStickyFaults` in class `SwerveAbsoluteEncoder`

### configure

public void configure(boolean inverted)
Configure the absolute encoder to read from [0, 360) per second.

Specified by:
  `configure` in class `SwerveAbsoluteEncoder`
Parameters:
  `inverted` - Whether the encoder is inverted.

### getAbsolutePosition

public double getAbsolutePosition()
Get the absolute position of the encoder. Sets `SwerveAbsoluteEncoder.readingError` on erroneous readings.

Specified by:
  `getAbsolutePosition` in class `SwerveAbsoluteEncoder`
Returns:
  Absolute position in degrees from [0, 360).

### getAbsoluteEncoder

public Object getAbsoluteEncoder()
Get the instantiated absolute encoder Object.

Specified by:
  `getAbsoluteEncoder` in class `SwerveAbsoluteEncoder`
Returns:
  Absolute encoder object.

### setAbsoluteEncoderOffset

public boolean setAbsoluteEncoderOffset(double offset)
Sets the Absolute Encoder Offset within the CANcoder's Memory.

Specified by:
  `setAbsoluteEncoderOffset` in class `SwerveAbsoluteEncoder`
Parameters:
  `offset` - the offset the Absolute Encoder uses as the zero point in degrees.
Returns:
  if setting Absolute Encoder Offset was successful or not.

### getVelocity

public double getVelocity()
Get the velocity in degrees/sec.

Specified by:
  `getVelocity` in class `SwerveAbsoluteEncoder`
Returns:
  velocity in degrees/sec.