Class SwerveSteeringSubsystem
java.lang.Object
edu.wpi.first.wpilibj2.command.SubsystemBase
xbot.common.command.BaseSubsystem
xbot.common.command.BaseSetpointSubsystem<Double>
xbot.common.subsystems.drive.swerve.SwerveSteeringSubsystem
- All Implemented Interfaces:
Sendable
,Subsystem
,DataFrameRefreshable
,SupportsSetpointLock
,IPropertySupport
-
Field Summary
Fields inherited from class xbot.common.command.BaseSetpointSubsystem
atGoal, lastTargetValueUsedforAtGoal
Fields inherited from class xbot.common.command.BaseSubsystem
aKitLog, dataFrameRefreshables
-
Constructor Summary
ConstructorDescriptionSwerveSteeringSubsystem
(SwerveInstance swerveInstance, XCANMotorController.XCANMotorControllerFactory mcFactory, XCANCoder.XCANCoderFactory canCoderFactory, PropertyFactory pf, PIDManager.PIDManagerFactory pidf, XSwerveDriveElectricalContract electricalContract) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
areTwoTargetsEquivalent
(Double target1, Double target2) double
Calculate the target motor power using software PID.void
Mark the current encoder position as facing forward (0 degrees)void
Reset the SparkMax encoder position based on the CanCoder measurement.Gets the reported position of the CANCoder.Gets the current position of the mechanism using the best available encoder.Gets current angle as a Rotation2dGets current angle in degreesgetLabel()
Gets the reported position of the encoder on the NEO motor.Gets target angle in degreesboolean
static boolean
isMotorControllerDriftTooHigh
(Angle currentCanCoderPosition, Angle currentMotorControllerPosition, double maxDelta) boolean
Gets a flag indicating whether we are using the motor controller's PID or software PID.void
periodic()
This method is called on eachCommandScheduler
loop.void
Consumes and processes inputs from the device or subsystem.void
resetPid()
Reset the software PID.void
Calculates the nearest position on the motor encoder to targetDegrees and sets the controller's PID target.void
setPower
(double power) Sets the output power of the motor.void
setTargetValue
(Double value) Sets target angle in degreesMethods inherited from class xbot.common.command.BaseSetpointSubsystem
areTwoDoublesEquivalent, areTwoDoublesEquivalent, createSetTargetCommand, createSetTargetCommand, getSetpointLock, isMaintainerAtGoal, setMaintainerIsAtGoal
Methods inherited from class xbot.common.command.BaseSubsystem
registerDataFrameRefreshable
Methods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystem
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem
defer, getCurrentCommand, getDefaultCommand, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
-
Constructor Details
-
SwerveSteeringSubsystem
@Inject public SwerveSteeringSubsystem(SwerveInstance swerveInstance, XCANMotorController.XCANMotorControllerFactory mcFactory, XCANCoder.XCANCoderFactory canCoderFactory, PropertyFactory pf, PIDManager.PIDManagerFactory pidf, XSwerveDriveElectricalContract electricalContract)
-
-
Method Details
-
getLabel
-
getPrefix
- Specified by:
getPrefix
in interfaceIPropertySupport
- Overrides:
getPrefix
in classBaseSubsystem
-
getCurrentValue
Gets current angle in degrees- Specified by:
getCurrentValue
in classBaseSetpointSubsystem<Double>
-
getCurrentRotation
Gets current angle as a Rotation2d -
getTargetValue
Gets target angle in degrees- Specified by:
getTargetValue
in classBaseSetpointSubsystem<Double>
-
setTargetValue
Sets target angle in degrees- Specified by:
setTargetValue
in classBaseSetpointSubsystem<Double>
-
setPower
public void setPower(double power) Sets the output power of the motor.- Specified by:
setPower
in classBaseSetpointSubsystem<Double>
- Parameters:
power
- The power value, between -1 and 1.
-
isCalibrated
public boolean isCalibrated()- Specified by:
isCalibrated
in classBaseSetpointSubsystem<Double>
-
calibrateHere
public void calibrateHere()Mark the current encoder position as facing forward (0 degrees) -
calibrateMotorControllerPositionFromCanCoder
public void calibrateMotorControllerPositionFromCanCoder()Reset the SparkMax encoder position based on the CanCoder measurement. This should only be called when the mechanism is stationary. -
getVelocity
-
isMotorControllerDriftTooHigh
-
getMotorController
-
getEncoder
-
getBestEncoderPosition
Gets the current position of the mechanism using the best available encoder.- Returns:
- The position in degrees.
-
getAbsoluteEncoderPosition
Gets the reported position of the CANCoder.- Returns:
- The position of the CANCoder.
-
getMotorControllerEncoderPosition
Gets the reported position of the encoder on the NEO motor.- Returns:
- The position of the encoder on the NEO motor.
-
calculatePower
public double calculatePower()Calculate the target motor power using software PID.- Returns:
- The target power required to approach our setpoint.
-
resetPid
public void resetPid()Reset the software PID. -
isUsingMotorControllerPid
public boolean isUsingMotorControllerPid()Gets a flag indicating whether we are using the motor controller's PID or software PID.- Returns:
- true if using motor controller's PID.
-
setMotorControllerPidTarget
public void setMotorControllerPidTarget()Calculates the nearest position on the motor encoder to targetDegrees and sets the controller's PID target. -
areTwoTargetsEquivalent
- Specified by:
areTwoTargetsEquivalent
in classBaseSetpointSubsystem<Double>
-
periodic
public void periodic()Description copied from class:BaseSubsystem
This method is called on eachCommandScheduler
loop.- Specified by:
periodic
in interfaceSubsystem
- Overrides:
periodic
in classBaseSubsystem
-
refreshDataFrame
public void refreshDataFrame()Description copied from interface:DataFrameRefreshable
Consumes and processes inputs from the device or subsystem.- Specified by:
refreshDataFrame
in interfaceDataFrameRefreshable
- Overrides:
refreshDataFrame
in classBaseSubsystem
-