# TalonFXSwerve
declaration: package: swervelib.motors, class: TalonFXSwerve

Package swervelib.motors

# Class TalonFXSwerve

java.lang.Object
swervelib.motors.SwerveMotor
swervelib.motors.TalonFXSwerve

public class TalonFXSwerve extends SwerveMotor
`TalonFX` Swerve Motor. Made by Team 1466 WebbRobotics.

## Field Summary

Fields
Modifier and Type
Field
Description
`private final boolean`
`absoluteEncoder`
Whether the absolute encoder is integrated.
`private com.ctre.phoenix6.configs.TalonFXConfiguration`
`configuration`
Current TalonFX configuration.
`private double`
`conversionFactor`
Conversion factor for the motor.
`private final boolean`
`factoryDefaultOccurred`
Factory default already occurred.
`private final com.ctre.phoenix6.controls.MotionMagicVoltage`
`m_angleVoltageSetter`
Motion magic angle voltage setter.
`private final com.ctre.phoenix6.controls.VelocityVoltage`
`m_velocityVoltageSetter`
Velocity voltage setter for controlling drive motor.
`(package private) com.ctre.phoenix6.hardware.TalonFX`
`motor`
TalonFX motor controller.

### Fields inherited from class swervelib.motors.SwerveMotor

`isDriveMotor, maximumRetries`

## Constructor Summary

Constructors
Constructor
Description
`TalonFXSwerve(int id, boolean isDriveMotor)`
Construct the TalonFX swerve motor given the ID.
`TalonFXSwerve(int id, String canbus, boolean isDriveMotor)`
Construct the TalonFX swerve motor given the ID and CANBus.
`TalonFXSwerve(com.ctre.phoenix6.hardware.TalonFX motor, boolean isDriveMotor)`
Constructor for TalonFX swerve motor.

## Method Summary

Modifier and Type
Method
Description
`void`
`burnFlash()`
Save the configurations from flash to EEPROM.
`void`
`clearStickyFaults()`
Clear the sticky faults on the motor controller.
`void`
`configureCANStatusFrames(int CANStatus1)`
Set the CAN status frames.
`void`
`configureCANStatusFrames(int CANStatus1, int CANStatus2, int CANStatus3, int CANStatus4, int CANStatus8, int CANStatus10, int CANStatus12, int CANStatus13, int CANStatus14, int CANStatus21, int CANStatusCurrent)`
Set the CAN status frames.
`void`
`configureIntegratedEncoder(double positionConversionFactor)`
Configure the integrated encoder for the swerve module.
`void`
`configurePIDF(PIDFConfig config)`
Configure the PIDF values for the closed loop controller.
`void`
`configurePIDWrapping(double minInput, double maxInput)`
Configure the PID wrapping for the position closed loop controller.
`void`
`factoryDefaults()`
Configure the factory defaults.
`Object`
`getMotor()`
Get the motor object from the module.
`double`
`getPosition()`
Get the position of the integrated encoder.
`double`
`getVelocity()`
Get the velocity of the integrated encoder.
`boolean`
`isAttachedAbsoluteEncoder()`
Queries whether the absolute encoder is directly attached to the motor controller.
`void`
`set(double percentOutput)`
Set the percentage output.
`SwerveMotor`
`setAbsoluteEncoder(SwerveAbsoluteEncoder encoder)`
Set the absolute encoder to be a compatible absolute encoder.
`void`
`setCurrentLimit(int currentLimit)`
Set the current limit for the swerve drive motor, remember this may cause jumping if used in conjunction with voltage compensation.
`void`
`setInverted(boolean inverted)`
Set the motor to be inverted.
`void`
`setLoopRampRate(double rampRate)`
Set the maximum rate the open/closed loop output can change by.
`void`
`setMotorBrake(boolean isBrakeMode)`
Set the idle mode.
`void`
`setPosition(double position)`
Set the integrated encoder position.
`void`
`setReference(double setpoint, double feedforward)`
Set the closed loop PID controller reference point.
`void`
`setReference(double setpoint, double feedforward, double position)`
Set the closed loop PID controller reference point.
`void`
`setVoltageCompensation(double nominalVoltage)`
Set the voltage compensation for the swerve module motor.

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

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

## Field Details

### factoryDefaultOccurred

private final boolean factoryDefaultOccurred
Factory default already occurred.

See Also:
  - Constant Field Values

### absoluteEncoder

private final boolean absoluteEncoder
Whether the absolute encoder is integrated.

See Also:
  - Constant Field Values

### m_angleVoltageSetter

private final com.ctre.phoenix6.controls.MotionMagicVoltage m_angleVoltageSetter
Motion magic angle voltage setter.

### m_velocityVoltageSetter

private final com.ctre.phoenix6.controls.VelocityVoltage m_velocityVoltageSetter
Velocity voltage setter for controlling drive motor.

### conversionFactor

private double conversionFactor
Conversion factor for the motor.

### motor

com.ctre.phoenix6.hardware.TalonFX motor
TalonFX motor controller.

### configuration

private com.ctre.phoenix6.configs.TalonFXConfiguration configuration
Current TalonFX configuration.

## Constructor Details

### TalonFXSwerve

public TalonFXSwerve(com.ctre.phoenix6.hardware.TalonFX motor, boolean isDriveMotor)
Constructor for TalonFX swerve motor.

Parameters:
  `motor` - Motor to use.
  `isDriveMotor` - Whether this motor is a drive motor.

### TalonFXSwerve

public TalonFXSwerve(int id, String canbus, boolean isDriveMotor)
Construct the TalonFX swerve motor given the ID and CANBus.

Parameters:
  `id` - ID of the TalonFX on the CANBus.
  `canbus` - CANBus on which the TalonFX is on.
  `isDriveMotor` - Whether the motor is a drive or steering motor.

### TalonFXSwerve

public TalonFXSwerve(int id, boolean isDriveMotor)
Construct the TalonFX swerve motor given the ID.

Parameters:
  `id` - ID of the TalonFX on the canbus.
  `isDriveMotor` - Whether the motor is a drive or steering motor.

## Method Details

### factoryDefaults

public void factoryDefaults()
Configure the factory defaults.

Specified by:
  `factoryDefaults` in class `SwerveMotor`

### clearStickyFaults

public void clearStickyFaults()
Clear the sticky faults on the motor controller.

Specified by:
  `clearStickyFaults` in class `SwerveMotor`

### setAbsoluteEncoder

public SwerveMotor setAbsoluteEncoder(SwerveAbsoluteEncoder encoder)
Set the absolute encoder to be a compatible absolute encoder.

Specified by:
  `setAbsoluteEncoder` in class `SwerveMotor`
Parameters:
  `encoder` - The encoder to use.
Returns:
  The `SwerveMotor` for single line configuration.

### configureIntegratedEncoder

public void configureIntegratedEncoder(double positionConversionFactor)
Configure the integrated encoder for the swerve module. Sets the conversion factors for position and velocity.

Specified by:
  `configureIntegratedEncoder` in class `SwerveMotor`
Parameters:
  `positionConversionFactor` - The conversion factor to apply for position.

  Degrees:
  `360 / (angleGearRatio * encoderTicksPerRotation)`

  Meters:
  `(Math.PI * wheelDiameter) / (driveGearRatio * encoderTicksPerRotation)`

### configureCANStatusFrames

public void configureCANStatusFrames(int CANStatus1)
Set the CAN status frames.

Parameters:
  `CANStatus1` - Applied Motor Output, Fault Information, Limit Switch Information

### configureCANStatusFrames

public void configureCANStatusFrames(int CANStatus1, int CANStatus2, int CANStatus3, int CANStatus4, int CANStatus8, int CANStatus10, int CANStatus12, int CANStatus13, int CANStatus14, int CANStatus21, int CANStatusCurrent)
Set the CAN status frames.

Parameters:
  `CANStatus1` - Applied Motor Output, Fault Information, Limit Switch Information
  `CANStatus2` - Selected Sensor Position (PID 0), Selected Sensor Velocity (PID 0), Brushed Supply Current Measurement, Sticky Fault Information
  `CANStatus3` - Quadrature Information
  `CANStatus4` - Analog Input, Supply Battery Voltage, Controller Temperature
  `CANStatus8` - Pulse Width Information
  `CANStatus10` - Motion Profiling/Motion Magic Information
  `CANStatus12` - Selected Sensor Position (Aux PID 1), Selected Sensor Velocity (Aux PID 1)
  `CANStatus13` - PID0 (Primary PID) Information
  `CANStatus14` - PID1 (Auxiliary PID) Information
  `CANStatus21` - Integrated Sensor Position (Talon FX), Integrated Sensor Velocity (Talon FX)
  `CANStatusCurrent` - Brushless Supply Current Measurement, Brushless Stator Current Measurement

### configurePIDF

public void configurePIDF(PIDFConfig config)
Configure the PIDF values for the closed loop controller. 0 is disabled or off.

Specified by:
  `configurePIDF` in class `SwerveMotor`
Parameters:
  `config` - Configuration class holding the PIDF values.

### configurePIDWrapping

public void configurePIDWrapping(double minInput, double maxInput)
Configure the PID wrapping for the position closed loop controller.

Specified by:
  `configurePIDWrapping` in class `SwerveMotor`
Parameters:
  `minInput` - Minimum PID input.
  `maxInput` - Maximum PID input.

### setMotorBrake

public void setMotorBrake(boolean isBrakeMode)
Set the idle mode.

Specified by:
  `setMotorBrake` in class `SwerveMotor`
Parameters:
  `isBrakeMode` - Set the brake mode.

### setInverted

public void setInverted(boolean inverted)
Set the motor to be inverted.

Specified by:
  `setInverted` in class `SwerveMotor`
Parameters:
  `inverted` - State of inversion.

### burnFlash

public void burnFlash()
Save the configurations from flash to EEPROM.

Specified by:
  `burnFlash` in class `SwerveMotor`

### set

public void set(double percentOutput)
Set the percentage output.

Specified by:
  `set` in class `SwerveMotor`
Parameters:
  `percentOutput` - percent out for the motor controller.

### setReference

public void setReference(double setpoint, double feedforward)
Set the closed loop PID controller reference point.

Specified by:
  `setReference` in class `SwerveMotor`
Parameters:
  `setpoint` - Setpoint in MPS or Angle in degrees.
  `feedforward` - Feedforward in volt-meter-per-second or kV.

### setReference

public void setReference(double setpoint, double feedforward, double position)
Set the closed loop PID controller reference point.

Specified by:
  `setReference` in class `SwerveMotor`
Parameters:
  `setpoint` - Setpoint in meters per second or angle in degrees.
  `feedforward` - Feedforward in volt-meter-per-second or kV.
  `position` - Only used on the angle motor, the position of the motor in degrees.

### getVelocity

public double getVelocity()
Get the velocity of the integrated encoder.

Specified by:
  `getVelocity` in class `SwerveMotor`
Returns:
  velocity in Meters Per Second, or Degrees per Second.

### getPosition

public double getPosition()
Get the position of the integrated encoder.

Specified by:
  `getPosition` in class `SwerveMotor`
Returns:
  Position in Meters or Degrees.

### setPosition

public void setPosition(double position)
Set the integrated encoder position.

Specified by:
  `setPosition` in class `SwerveMotor`
Parameters:
  `position` - Integrated encoder position. Should be angle in degrees or meters.

### setVoltageCompensation

public void setVoltageCompensation(double nominalVoltage)
Set the voltage compensation for the swerve module motor.

Specified by:
  `setVoltageCompensation` in class `SwerveMotor`
Parameters:
  `nominalVoltage` - Nominal voltage for operation to output to.

### setCurrentLimit

public void setCurrentLimit(int currentLimit)
Set the current limit for the swerve drive motor, remember this may cause jumping if used in conjunction with voltage compensation. This is useful to protect the motor from current spikes.

Specified by:
  `setCurrentLimit` in class `SwerveMotor`
Parameters:
  `currentLimit` - Current limit in AMPS at free speed.

### setLoopRampRate

public void setLoopRampRate(double rampRate)
Set the maximum rate the open/closed loop output can change by.

Specified by:
  `setLoopRampRate` in class `SwerveMotor`
Parameters:
  `rampRate` - Time in seconds to go from 0 to full throttle.

### getMotor

public Object getMotor()
Get the motor object from the module.

Specified by:
  `getMotor` in class `SwerveMotor`
Returns:
  Motor object.

### isAttachedAbsoluteEncoder

public boolean isAttachedAbsoluteEncoder()
Queries whether the absolute encoder is directly attached to the motor controller.

Specified by:
  `isAttachedAbsoluteEncoder` in class `SwerveMotor`
Returns:
  connected absolute encoder state.