Package com.marswars.swerve_lib.module
Class Module
java.lang.Object
com.marswars.mechanisms.MechBase
com.marswars.swerve_lib.module.Module
- All Implemented Interfaces:
SubsystemIoBase
- Direct Known Subclasses:
ModuleTalonFX
Base class for swerve modules with drive and steer control.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDrive motor control mode selection.static enumSteer motor control mode selection.Nested classes/interfaces inherited from class com.marswars.mechanisms.MechBase
MechBase.ConstructedMotors -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final SwerveModuleConfigprotected final Debouncerprotected final Alertprotected final com.marswars.swerve_lib.module.ModuleInputsAutoLoggedprotected final Alertprotected final intprotected NeutralModeValueprotected SwerveModuleStateprotected final Debouncerprotected final Alert -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetAngle()Returns the current turn angle of the module.Returns the module state (turn angle and drive velocity).doubleReturns the module velocity in rotations/sec (Phoenix native units).Returns the module position (turn angle and drive position).doubleReturns the current drive position of the module in meters.Returns the module setpoint state (turn angle and drive velocity).Returns the translation of the module in the robot's coordinate system.doubleReturns the current drive velocity of the module in meters per second.doubleReturns the module position in radians.voidrunCharacterization(double output) Runs the module with the specified output while controlling to zero degrees.voidrunSetpoint(SwerveModuleState state, Module.DriveControlMode DriveMode, Module.SteerControlMode SteerMode) Runs the module with the specified setpoint state.abstract voidsetDriveGains(int slot, SlotConfigs gains) Set the gains for the module drive motors to the given slotabstract voidsetDriveOpenLoop(double output) Run the drive motor at the specified open loop value.abstract voidsetDriveVelocity(double velocityRadPerSec) Run the drive motor at the specified velocity.voidStores the current encoder reading as an offsetvoidSets the neutral mode for both motorsabstract voidsetSteerGains(SlotConfigs gains) Set the gains for the module steer motors to the given slotabstract voidsetSteerOpenLoop(double output) Run the turn motor at the specified open loop value.abstract voidsetSteerPosition(Rotation2d rotation) Run the turn motor to the specified rotation.voidstop()Disables all outputs to motors.Methods inherited from class com.marswars.mechanisms.MechBase
configMotors, configMotors, getLoggingKey, getMechName, setMotorCurrentLimitMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.marswars.subsystem.SubsystemIoBase
logData, readInputs, writeOutputs
-
Field Details
-
config_
-
module_index_
protected final int module_index_ -
neutral_mode_
-
setpoint_
-
inputs_
protected final com.marswars.swerve_lib.module.ModuleInputsAutoLogged inputs_ -
drive_conn_deb_
-
steer_conn_deb_
-
drive_disconnected_alert_
-
steer_disconnected_alert_
-
module_encoder_alert_
-
-
Constructor Details
-
Module
-
-
Method Details
-
runSetpoint
public void runSetpoint(SwerveModuleState state, Module.DriveControlMode DriveMode, Module.SteerControlMode SteerMode) Runs the module with the specified setpoint state. Mutates the state to optimize it. -
runCharacterization
public void runCharacterization(double output) Runs the module with the specified output while controlling to zero degrees. -
stop
public void stop()Disables all outputs to motors. -
getAngle
Returns the current turn angle of the module. -
getPositionMeters
public double getPositionMeters()Returns the current drive position of the module in meters. -
getVelocityMetersPerSec
public double getVelocityMetersPerSec()Returns the current drive velocity of the module in meters per second. -
getPosition
Returns the module position (turn angle and drive position). -
getCurrentState
Returns the module state (turn angle and drive velocity). -
getSetpointState
Returns the module setpoint state (turn angle and drive velocity). -
getWheelRadiusCharacterizationPosition
public double getWheelRadiusCharacterizationPosition()Returns the module position in radians. -
getFFCharacterizationVelocity
public double getFFCharacterizationVelocity()Returns the module velocity in rotations/sec (Phoenix native units). -
getTranslation
Returns the translation of the module in the robot's coordinate system.- Returns:
- Translation2d representing the module's position in meters
-
setDriveOpenLoop
public abstract void setDriveOpenLoop(double output) Run the drive motor at the specified open loop value. -
setSteerOpenLoop
public abstract void setSteerOpenLoop(double output) Run the turn motor at the specified open loop value. -
setDriveVelocity
public abstract void setDriveVelocity(double velocityRadPerSec) Run the drive motor at the specified velocity. -
setSteerPosition
Run the turn motor to the specified rotation. -
setDriveGains
Set the gains for the module drive motors to the given slot -
setSteerGains
Set the gains for the module steer motors to the given slot -
setModuleOffset
public void setModuleOffset()Stores the current encoder reading as an offset -
setNeutralMode
Sets the neutral mode for both motors
-