Class CTRESwerveMotor
- java.lang.Object
-
- frc.robot.subsystems.swervedrive.swerve.SwerveMotor
-
- frc.robot.subsystems.swervedrive.swerve.motors.CTRESwerveMotor
-
public class CTRESwerveMotor extends SwerveMotor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classCTRESwerveMotor.CTRE_pidIdxThe TalonSRX PID to use onboard.(package private) static classCTRESwerveMotor.CTRE_remoteSensor(package private) static classCTRESwerveMotor.CTRE_slotIdxThe Talon SRX Slot profile used to configure the motor to use for the PID.-
Nested classes/interfaces inherited from class frc.robot.subsystems.swervedrive.swerve.SwerveMotor
SwerveMotor.ModuleMotorType
-
-
Field Summary
Fields Modifier and Type Field Description private doublem_allowableClosedLoopErrorprivate SwerveEncoderm_angleEncoderprivate com.ctre.phoenix.motorcontrol.ControlModem_controlModeprivate java.util.function.Supplier<java.lang.Double>m_encoderRetprivate booleanm_integratedAbsEncoderprivate intm_mainPidIdprivate intm_mainPIDSlotIdprivate doublem_moduleRadkVkV feed forward for PIDprivate com.ctre.phoenix.motorcontrol.can.WPI_TalonFXm_motor-
Fields inherited from class frc.robot.subsystems.swervedrive.swerve.SwerveMotor
kD, kF, kI, kIZ, kP, m_motorType, target
-
-
Constructor Summary
Constructors Constructor Description CTRESwerveMotor(com.ctre.phoenix.motorcontrol.can.WPI_TalonFX motor, SwerveEncoder<?> encoder, SwerveMotor.ModuleMotorType type, double gearRatio, double wheelDiameter, double freeSpeedRPM, double powerLimit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doubleget()Get the current value of the encoder corresponding to the PID.doublegetAmps()Get the current output.doublegetPosition()Get the current value of the encoder.voidoptimizeCANFrames()Optimize the CAN status frames to reduce utilization.booleanreachable()Check that the link is good on the swerve module and CAN bus is able to retrieve data.booleanremoteIntegratedEncoder()Check if the absolute encoder is used inplace of the integrated encoder.voidsaveConfig()Save configuration data to the motor controller so it is persistent on reboot.voidset(double speed)Set the speed of the drive motor from -1 to 1.voidsetConversionFactor(double conversionFactor)Configures the conversion factor based upon which motor.voidsetCurrentLimit(int currentLimit)Set the current limit for the swerve drive motor, remember this may cause jumping if used in conjunction with voltage compensation.voidsetEncoder(double value)Set the encoder value.voidsetInverted(boolean inverted)Invert the motor.voidsetPIDF(double P, double I, double D, double F, double integralZone)Set the PIDF coefficients for the closed loop PID onboard the SparkMax.voidsetPIDOutputRange(double min, double max)Configure the maximum power (-1 to 1) the PID can output.voidsetTarget(double target, double feedforward)Set the target for the PID loop.voidsetVoltage(double voltage)Set the voltage of the motor.voidsetVoltageCompensation(double nominalVoltage)Set the voltage compensation for the swerve module motor.voidstop()Stop the motor by sending 0 volts to it.-
Methods inherited from class frc.robot.subsystems.swervedrive.swerve.SwerveMotor
fromMotor
-
-
-
-
Field Detail
-
m_angleEncoder
private final SwerveEncoder m_angleEncoder
-
m_integratedAbsEncoder
private final boolean m_integratedAbsEncoder
-
m_allowableClosedLoopError
private final double m_allowableClosedLoopError
-
m_controlMode
private final com.ctre.phoenix.motorcontrol.ControlMode m_controlMode
-
m_mainPIDSlotId
private final int m_mainPIDSlotId
-
m_mainPidId
private final int m_mainPidId
-
m_encoderRet
private final java.util.function.Supplier<java.lang.Double> m_encoderRet
-
m_motor
private final com.ctre.phoenix.motorcontrol.can.WPI_TalonFX m_motor
-
m_moduleRadkV
private final double m_moduleRadkV
kV feed forward for PID
-
-
Constructor Detail
-
CTRESwerveMotor
public CTRESwerveMotor(com.ctre.phoenix.motorcontrol.can.WPI_TalonFX motor, SwerveEncoder<?> encoder, SwerveMotor.ModuleMotorType type, double gearRatio, double wheelDiameter, double freeSpeedRPM, double powerLimit)
-
-
Method Detail
-
setPIDOutputRange
public void setPIDOutputRange(double min, double max)Configure the maximum power (-1 to 1) the PID can output. This helps manage voltage pull for the drive base.- Specified by:
setPIDOutputRangein classSwerveMotor- Parameters:
min- Minimum output.max- Maximum output.
-
setPIDF
public void setPIDF(double P, double I, double D, double F, double integralZone)Set the PIDF coefficients for the closed loop PID onboard the SparkMax.- Specified by:
setPIDFin classSwerveMotor- Parameters:
P- Proportional gain for closed loop. This is multiplied by closed loop error in sensor units. Default is 1.0I- Integral gain for closed loop. This is multiplied by closed loop error in sensor units every PID Loop.D- Derivative gain for closed loop. This is multiplied by derivative error (sensor units per PID loop). Default is 0.1F- Feed Fwd gain for Closed loop.integralZone- Integral Zone can be used to auto clear the integral accumulator if the sensor pos is too far from the target. This prevents unstable oscillation if the kI is too large. Value is in sensor units.
-
setConversionFactor
public void setConversionFactor(double conversionFactor)
Configures the conversion factor based upon which motor.- Specified by:
setConversionFactorin classSwerveMotor- Parameters:
conversionFactor- Conversion from RPM to MPS for drive motor, and rotations to degrees for the turning motor.
-
setTarget
public void setTarget(double target, double feedforward)Set the target for the PID loop.- Specified by:
setTargetin classSwerveMotor- Parameters:
target- The PID target to aim for.feedforward- The feedforward for this target.
-
stop
public void stop()
Stop the motor by sending 0 volts to it.- Specified by:
stopin classSwerveMotor
-
set
public void set(double speed)
Set the speed of the drive motor from -1 to 1.- Specified by:
setin classSwerveMotor- Parameters:
speed- Speed from -1 to 1.
-
setVoltage
public void setVoltage(double voltage)
Set the voltage of the motor.- Specified by:
setVoltagein classSwerveMotor- Parameters:
voltage- Voltage to output.
-
get
public double get()
Get the current value of the encoder corresponding to the PID.- Specified by:
getin classSwerveMotor- Returns:
- Current value of the encoder.
-
getPosition
public double getPosition()
Get the current value of the encoder.- Specified by:
getPositionin classSwerveMotor- Returns:
- Current value of the encoder.
-
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.
-
setEncoder
public void setEncoder(double value)
Set the encoder value.- Specified by:
setEncoderin classSwerveMotor- Parameters:
value- Value to set the encoder to.
-
reachable
public boolean reachable()
Check that the link is good on the swerve module and CAN bus is able to retrieve data.- Specified by:
reachablein classSwerveMotor- Returns:
- true on all devices are accessible over CAN.
-
remoteIntegratedEncoder
public boolean remoteIntegratedEncoder()
Check if the absolute encoder is used inplace of the integrated encoder.- Specified by:
remoteIntegratedEncoderin classSwerveMotor- Returns:
- true, if the absolute encoder is being used as the integrated controller.
-
optimizeCANFrames
public void optimizeCANFrames()
Optimize the CAN status frames to reduce utilization.- Specified by:
optimizeCANFramesin classSwerveMotor
-
saveConfig
public void saveConfig()
Save configuration data to the motor controller so it is persistent on reboot.- Specified by:
saveConfigin classSwerveMotor
-
setInverted
public void setInverted(boolean inverted)
Invert the motor.- Specified by:
setInvertedin classSwerveMotor- Parameters:
inverted- Set the motor as inverted.
-
getAmps
public double getAmps()
Description copied from class:SwerveMotorGet the current output.- Specified by:
getAmpsin classSwerveMotor- Returns:
- Output amps.
-
-