Package frc.robot.subsystems.swerve
Class Swerve
java.lang.Object
edu.wpi.first.wpilibj2.command.SubsystemBase
frc.robot.subsystems.swerve.Swerve
Swerve Subsystem
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddrive(Translation2d translation, double rotation, boolean fieldRelative, boolean isOpenLoop) Tele-Op Drive methodvoidfollowTrajectory(choreo.trajectory.SwerveSample sample) Follow Choreo TrajectoryGet current Chassis SpeedsGet Field Relative HeadingGet Rotation from the gyroGet Rotation of robot from odometryGet Swerve Module PositionsGet Swerve Module StatesgetPose()Get Position on field from OdometrydoubleGets a list containing all 4 swerve module positionsvoidmoveToPose(Pose2d pose) Move to a Pose2dvoidmoveToPose(Pose2d pose, double maxVelocity) Move to a Pose2dvoidmoveToPose(Pose2d pose, double maxSpeed, double maxAcceleration) Move to a Pose2dvoidperiodic()voidResets the gyro field relative driving offsetvoidSet Field Relative Offset based on PosevoidresetOdometry(Pose2d pose) Set the position on the field with given Pose2dvoidsetModuleStates(ChassisSpeeds chassisSpeeds) Sets swerve module states using Chassis Speeds.voidsetModuleStates(SwerveModuleState[] desiredStates) Set Swerve Module StatesvoidSets motors to 0 or inactive.voidsetSpeedMultiplier(double multiplier) static booleanDetermine whether or not to flight the auto pathstop()teleOpDrive(CommandXboxController controller, boolean fieldRelative, boolean openLoop) Creates a command for driving the swerve drive during tele-opvoidwheelsIn()Make an X pattern with the wheelsMethods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystemMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem
defer, getCurrentCommand, getDefaultCommand, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
-
Field Details
-
swerveMods
-
state
-
initGyroBool
public boolean initGyroBool -
initGyro
-
-
Constructor Details
-
Swerve
Swerve Subsystem
-
-
Method Details
-
drive
public void drive(Translation2d translation, double rotation, boolean fieldRelative, boolean isOpenLoop) Tele-Op Drive method- Parameters:
translation- The magnitude in XYrotation- The magnitude in rotationfieldRelative- Whether or not field relativeisOpenLoop- Whether or not Open or Closed Loop
-
setModuleStates
Set Swerve Module States- Parameters:
desiredStates- Array of desired states
-
setModuleStates
Sets swerve module states using Chassis Speeds.- Parameters:
chassisSpeeds- The desired Chassis Speeds
-
getChassisSpeeds
Get current Chassis Speeds- Returns:
- The current
ChassisSpeeds
-
getModuleStates
Get Swerve Module States- Returns:
- Array of Swerve Module States
-
getModulePositions
Get Swerve Module Positions- Returns:
- Array of Swerve Module Positions
-
getPose
Get Position on field from Odometry- Returns:
- Pose2d on the field
-
resetOdometry
Set the position on the field with given Pose2d- Parameters:
pose- Pose2d to set
-
getHeading
Get Rotation of robot from odometry- Returns:
- Heading of robot relative to the field as
Rotation2d
-
getGyroYaw
Get Rotation from the gyro- Returns:
- Current rotation/yaw of gyro as
Rotation2d
-
getFieldRelativeHeading
Get Field Relative Heading- Returns:
- The current field relative heading in
Rotation2d
-
resetFieldRelativeOffset
public void resetFieldRelativeOffset()Resets the gyro field relative driving offset -
resetFieldRelativeOffsetBasedOnPose
public void resetFieldRelativeOffsetBasedOnPose()Set Field Relative Offset based on Pose -
periodic
public void periodic() -
setMotorsZero
public void setMotorsZero()Sets motors to 0 or inactive. -
wheelsIn
public void wheelsIn()Make an X pattern with the wheels -
getSwerveModulePositions
Gets a list containing all 4 swerve module positions -
shouldFlipPath
public static boolean shouldFlipPath()Determine whether or not to flight the auto path- Returns:
- True if flip path to Red Alliance, False if Blue
-
setSpeedMultiplier
public void setSpeedMultiplier(double multiplier) -
getSpeedMultiplier
public double getSpeedMultiplier() -
teleOpDrive
public Command teleOpDrive(CommandXboxController controller, boolean fieldRelative, boolean openLoop) Creates a command for driving the swerve drive during tele-op- Parameters:
controller- The driver controllerfieldRelative- Whether the movement is relative to the field or absoluteopenLoop- Open or closed loop system
-
stop
-
followTrajectory
public void followTrajectory(choreo.trajectory.SwerveSample sample) Follow Choreo Trajectory- Parameters:
sample- Swerve Sample
-
moveToPose
Move to a Pose2d- Parameters:
pose- Desired Pose2d
-
moveToPose
Move to a Pose2d- Parameters:
pose- Desired Pose2d
-
moveToPose
Move to a Pose2d- Parameters:
pose- Desired Pose2d
-