Package frc.team88.swerve.module
Class SwerveModule
- java.lang.Object
-
- frc.team88.swerve.module.SwerveModule
-
public class SwerveModule extends java.lang.Object
Represents a single swerve module that is composed of a PIDMotor for wheel control, a PIDMotor for azimuth control, and a PositionVelocitySensor for absolute azimuth sensing.
-
-
Constructor Summary
Constructors Constructor Description SwerveModule(SwerveMotor[] motors, PositionSensor azimuthSensor, SwerveModuleConfiguration config)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WrappedAngle
getAzimuthPosition()
Gets the current azimuth position.WrappedAngle
getAzimuthPositionFlipped()
Gets the current azimuth position, accounting for wheel reversal.double
getAzimuthVelocity()
Gets the current azimuth velocity.WrappedAngle
getCommandedAzimuthPosition()
Gets the current commanded azimuth position from the trapezoidal profile.double
getCommandedAzimuthVelocity()
Gets the current commanded azimuth velocity from the trapezoidal controller.double
getCommandedWheelVelocity()
Gets the current commanded wheel velocity output by the PID controller.SwerveModuleConfiguration
getConfig()
Gets the config for this module.Vector2D
getLocation()
Gets the location of this module.double
getMaxWheelSpeed()
Gets the maximum speed that can be commanded to the wheel within the limits of the motor.SwerveMotor[]
getMotors()
Gets the motors used by this module.WrappedAngle
getTargetAzimuthPosition()
Gets the azimuth position set as the target for the azimuth controller.double
getTargetAzimuthVelocity()
Gets the azimuth velocity set as the target for the azimuth controller.double
getTargetWheelVelocity()
Gets the wheel velocity set as the target for the wheel controller.double
getWheelVelocity()
Gets the current velocity of the wheel.void
set(double wheelSpeed, WrappedAngle azimuthPosition)
Sets the wheel speed and azimuth position.void
set(double wheelSpeed, WrappedAngle azimuthPosition, double azimuthVelocity)
Sets the wheel speed and azimuth position/velocity.void
setBrake()
Sets both motors on this module to brake mode.void
setCoast()
Sets both motors on this module to coast mode.void
setRawWheelVelocities(double wheelVelocity, double azimuthVelocity)
Sets the raw velocity values for the wheel and azimuth.
-
-
-
Constructor Detail
-
SwerveModule
public SwerveModule(SwerveMotor[] motors, PositionSensor azimuthSensor, SwerveModuleConfiguration config)
Constructor.- Parameters:
motors
- The 2 motors on this module, with units of rotations per second.azimuthSensor
- The sensor for absolute azimuth angle, in degrees.config
- The configuration data for this module.
-
-
Method Detail
-
set
public void set(double wheelSpeed, WrappedAngle azimuthPosition)
Sets the wheel speed and azimuth position. The azimuth velocity is assumed to be 0.- Parameters:
wheelSpeed
- The wheel speed to set, in feet per second.azimuthPosition
- The azimuth position to set, in degrees.
-
set
public void set(double wheelSpeed, WrappedAngle azimuthPosition, double azimuthVelocity)
Sets the wheel speed and azimuth position/velocity.- Parameters:
wheelSpeed
- The wheel speed to set, in feet per second.azimuthPosition
- The azimuth position to set, ignoring potential wheel reversal, in degrees.azimuthVelocity
- The azimuth velocity to target when the position is reached, in degrees per second.
-
setRawWheelVelocities
public void setRawWheelVelocities(double wheelVelocity, double azimuthVelocity)
Sets the raw velocity values for the wheel and azimuth.- Parameters:
wheelVelocity
- The wheel velocity to set, in feet per second.azimuthVelocity
- The azimuth velocity to set, in degrees per second.
-
setCoast
public void setCoast()
Sets both motors on this module to coast mode.
-
setBrake
public void setBrake()
Sets both motors on this module to brake mode.
-
getWheelVelocity
public double getWheelVelocity()
Gets the current velocity of the wheel.- Returns:
- The velocity of the wheel, in feet per second.
-
getAzimuthPosition
public WrappedAngle getAzimuthPosition()
Gets the current azimuth position.- Returns:
- The current azimuth position, in degrees.
-
getAzimuthPositionFlipped
public WrappedAngle getAzimuthPositionFlipped()
Gets the current azimuth position, accounting for wheel reversal.- Returns:
- The current azimuth position, in degrees.
-
getAzimuthVelocity
public double getAzimuthVelocity()
Gets the current azimuth velocity.- Returns:
- The current azimuth velocity, in degrees per second.
-
getCommandedWheelVelocity
public double getCommandedWheelVelocity()
Gets the current commanded wheel velocity output by the PID controller.- Returns:
- The commanded wheel velocity, in feet per second.
-
getCommandedAzimuthPosition
public WrappedAngle getCommandedAzimuthPosition()
Gets the current commanded azimuth position from the trapezoidal profile.- Returns:
- The current commanded azimuth position, in degrees.
-
getCommandedAzimuthVelocity
public double getCommandedAzimuthVelocity()
Gets the current commanded azimuth velocity from the trapezoidal controller.- Returns:
- The commanded azimuth velocity, in degrees per second.
-
getTargetWheelVelocity
public double getTargetWheelVelocity()
Gets the wheel velocity set as the target for the wheel controller.- Returns:
- The target wheel velocity, in feet per second.
-
getTargetAzimuthPosition
public WrappedAngle getTargetAzimuthPosition()
Gets the azimuth position set as the target for the azimuth controller.- Returns:
- The target azimuth position, in degrees.
-
getTargetAzimuthVelocity
public double getTargetAzimuthVelocity()
Gets the azimuth velocity set as the target for the azimuth controller.- Returns:
- The target azimuth velocity, in degrees per second.
-
getLocation
public Vector2D getLocation()
Gets the location of this module.- Returns:
- A position vector from the robot's origin to the location of this module, in feet. The positive x-axis points forwards, and the positive y-axis points left.
-
getMotors
public SwerveMotor[] getMotors()
Gets the motors used by this module.- Returns:
- The motors used by this module.
-
getConfig
public SwerveModuleConfiguration getConfig()
Gets the config for this module.- Returns:
- This module's config.
-
getMaxWheelSpeed
public double getMaxWheelSpeed()
Gets the maximum speed that can be commanded to the wheel within the limits of the motor.- Returns:
- The max speed, in feet per second.
-
-