Package swervelib.motors
Class TalonSRXSwerve
java.lang.Object
swervelib.motors.SwerveMotor
swervelib.motors.TalonSRXSwerve
WPI_TalonSRX Swerve Motor.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanWhether the absolute encoder is integrated.private final booleanFactory default already occurred.(package private) com.ctre.phoenix.motorcontrol.can.WPI_TalonSRXTalonSRX motor controller.private doubleThe position conversion factor.Fields inherited from class swervelib.motors.SwerveMotor
isDriveMotor -
Constructor Summary
ConstructorsConstructorDescriptionTalonSRXSwerve(int id, boolean isDriveMotor) Construct the TalonSRX swerve motor given the ID.TalonSRXSwerve(com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX motor, boolean isDriveMotor) Constructor for TalonSRX swerve motor. -
Method Summary
Modifier and TypeMethodDescriptionvoidSave the configurations from flash to EEPROM.voidClear the sticky faults on the motor controller.voidconfigureIntegratedEncoder(double positionConversionFactor) Configure the integrated encoder for the swerve module.voidconfigurePIDF(PIDFConfig config) Configure the PIDF values for the closed loop controller.voidconfigurePIDWrapping(double minInput, double maxInput) Configure the PID wrapping for the position closed loop controller.doubleconvertToNativeSensorUnits(double setpoint) Convert the setpoint into native sensor units.voidConfigure the factory defaults.getMotor()Get the motor object from the module.doubleGet the position of the integrated encoder.doubleGet the raw position.doubleGet the velocity of the integrated encoder.booleanQueries whether the absolute encoder is directly attached to the motor controller.private doubleplaceInAppropriate0To360Scope(double scopeReference, double newAngle) Put an angle within the the 360 deg scope of a reference.voidset(double percentOutput) Set the percentage output.setAbsoluteEncoder(SwerveAbsoluteEncoder encoder) Set the absolute encoder to be a compatible absolute encoder.voidsetCurrentLimit(int currentLimit) Set the current limit for the swerve drive motor, remember this may cause jumping if used in conjunction with voltage compensation.voidsetInverted(boolean inverted) Set the motor to be inverted.voidsetLoopRampRate(double rampRate) Set the maximum rate the open/closed loop output can change by.voidsetMotorBrake(boolean isBrakeMode) Set the idle mode.voidsetPosition(double position) Set the integrated encoder position.voidsetReference(double setpoint, double feedforward) Set the closed loop PID controller reference point.voidsetVoltageCompensation(double nominalVoltage) Set the voltage compensation for the swerve module motor.
-
Field Details
-
factoryDefaultOccurred
private final boolean factoryDefaultOccurredFactory default already occurred.- See Also:
-
motor
com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX motorTalonSRX motor controller. -
absoluteEncoder
private final boolean absoluteEncoderWhether the absolute encoder is integrated.- See Also:
-
positionConversionFactor
private double positionConversionFactorThe position conversion factor.
-
-
Constructor Details
-
TalonSRXSwerve
public TalonSRXSwerve(com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX motor, boolean isDriveMotor) Constructor for TalonSRX swerve motor.- Parameters:
motor- Motor to use.isDriveMotor- Whether this motor is a drive motor.
-
TalonSRXSwerve
public TalonSRXSwerve(int id, boolean isDriveMotor) Construct the TalonSRX swerve motor given the ID.- Parameters:
id- ID of the TalonSRX 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:
factoryDefaultsin classSwerveMotor
-
clearStickyFaults
public void clearStickyFaults()Clear the sticky faults on the motor controller.- Specified by:
clearStickyFaultsin classSwerveMotor
-
setAbsoluteEncoder
Set the absolute encoder to be a compatible absolute encoder.- Specified by:
setAbsoluteEncoderin classSwerveMotor- Parameters:
encoder- The encoder to use.- Returns:
- The
SwerveMotorfor 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:
configureIntegratedEncoderin classSwerveMotor- Parameters:
positionConversionFactor- The conversion factor to apply for position.
-
configurePIDF
Configure the PIDF values for the closed loop controller. 0 is disabled or off.- Specified by:
configurePIDFin classSwerveMotor- 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:
configurePIDWrappingin classSwerveMotor- Parameters:
minInput- Minimum PID input.maxInput- Maximum PID input.
-
setMotorBrake
public void setMotorBrake(boolean isBrakeMode) Set the idle mode.- Specified by:
setMotorBrakein classSwerveMotor- Parameters:
isBrakeMode- Set the brake mode.
-
setInverted
public void setInverted(boolean inverted) Set the motor to be inverted.- Specified by:
setInvertedin classSwerveMotor- Parameters:
inverted- State of inversion.
-
burnFlash
public void burnFlash()Save the configurations from flash to EEPROM.- Specified by:
burnFlashin classSwerveMotor
-
set
public void set(double percentOutput) Set the percentage output.- Specified by:
setin classSwerveMotor- 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:
setReferencein classSwerveMotor- Parameters:
setpoint- Setpoint in MPS or Angle in degrees.feedforward- Feedforward in volt-meter-per-second or kV.
-
getVelocity
public double getVelocity()Get the velocity of the integrated encoder.- Specified by:
getVelocityin classSwerveMotor- Returns:
- velocity
-
getRawPosition
public double getRawPosition()Get the raw position.- Returns:
- Position in meters or degrees.
-
getPosition
public double getPosition()Get the position of the integrated encoder.- Specified by:
getPositionin classSwerveMotor- Returns:
- Position in Meters or Degrees.
-
setPosition
public void setPosition(double position) Set the integrated encoder position.- Specified by:
setPositionin classSwerveMotor- 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:
setVoltageCompensationin classSwerveMotor- 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:
setCurrentLimitin classSwerveMotor- 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:
setLoopRampRatein classSwerveMotor- Parameters:
rampRate- Time in seconds to go from 0 to full throttle.
-
getMotor
Get the motor object from the module.- Specified by:
getMotorin classSwerveMotor- Returns:
- Motor object.
-
isAttachedAbsoluteEncoder
public boolean isAttachedAbsoluteEncoder()Queries whether the absolute encoder is directly attached to the motor controller.- Specified by:
isAttachedAbsoluteEncoderin classSwerveMotor- Returns:
- connected absolute encoder state.
-
placeInAppropriate0To360Scope
private double placeInAppropriate0To360Scope(double scopeReference, double newAngle) Put an angle within the the 360 deg scope of a reference. For example, given a scope reference of 756 degrees, assumes the full scope is (720-1080), and places an angle of 22 degrees into it, returning 742 deg.- Parameters:
scopeReference- Current Angle (deg)newAngle- Target Angle (deg)- Returns:
- Closest angle within scope (deg)
-
convertToNativeSensorUnits
public double convertToNativeSensorUnits(double setpoint) Convert the setpoint into native sensor units.- Parameters:
setpoint- Setpoint to mutate. In meters per second or degrees.- Returns:
- Setpoint as native sensor units. Encoder ticks per 100ms, or Encoder tick.
-