Package org.team1126.robot.subsystems
Class Swerve
java.lang.Object
org.team1126.lib.util.command.GRRSubsystem
org.team1126.robot.subsystems.Swerve
- All Implemented Interfaces:
edu.wpi.first.wpilibj2.command.Subsystem
The robot's swerve drivetrain.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionedu.wpi.first.wpilibj2.command.CommandaimAtHub(Supplier<edu.wpi.first.math.geometry.Translation2d> goal, DoubleSupplier maxDeceleration) Drives the robot to a target position using the P-APF while aiming at the hub.edu.wpi.first.wpilibj2.command.CommandbooleandoubleReturns the angle from the origin of our robot to the center of the hub in radians.edu.wpi.first.wpilibj2.command.CommandapfDrive(Supplier<edu.wpi.first.math.geometry.Pose2d> goal, DoubleSupplier maxDeceleration) Drives the robot to a target position using the P-APF.edu.wpi.first.wpilibj2.command.CommandapfDrive(Supplier<edu.wpi.first.math.geometry.Pose2d> goal, DoubleSupplier maxDeceleration, DoubleSupplier endTolerance) Drives the robot to a target position using the P-APF, until the robot is positioned within a specified tolerance of the target.List<edu.wpi.first.math.geometry.Pose2d> Remove @NotLogged for debuggingbooleanReturns true if the reef angle has changed.doubleReturns the distance from the origin of our robot to the center of the hub in meters.edu.wpi.first.wpilibj2.command.Commanddrive(DoubleSupplier x, DoubleSupplier y, DoubleSupplier angular) Drives the robot using driver input.edu.wpi.first.math.geometry.Pose2dedu.wpi.first.math.geometry.Pose2dgetPose()Returns the current blue origin relative pose of the robot.doubleReturns the directionless measured velocity of the robot, in m/s.booleanChecks if the origin of the robot is in the neutral zone (between the blue zone and the red zone).booleanChecks if the origin of the robot is in our alliance's zone (the blue zone if we are on the blue alliance, and the red zone if we are on the red alliance).booleanChecks if the origin of the robot is in the opposing alliance's zone (the red zone if we are on the blue alliance, and the blue zone if we are on the red alliance).voidperiodic()edu.wpi.first.wpilibj2.command.CommandHard reset of odometry to origin relative to blue origin.edu.wpi.first.wpilibj2.command.CommandResets the pose of the robot, inherently seeding field-relative movement.booleanReturnstrueif an AprilTag has been seen since the last robot loop.edu.wpi.first.wpilibj2.command.Commandstop(boolean lock) Drives the modules to stop the robot from moving.edu.wpi.first.wpilibj2.command.CommandTares the rotation of the robot.Methods inherited from class org.team1126.lib.util.command.GRRSubsystem
commandBuilder, commandBuilderMethods 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, getName, idle, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
-
Field Details
-
OFFSET
public static final double OFFSET- See Also:
-
-
Constructor Details
-
Swerve
public Swerve()
-
-
Method Details
-
periodic
public void periodic() -
getPose
public edu.wpi.first.math.geometry.Pose2d getPose()Returns the current blue origin relative pose of the robot. -
getVelocity
public double getVelocity()Returns the directionless measured velocity of the robot, in m/s. -
apfVisualization
Remove @NotLogged for debugging -
seesAprilTag
public boolean seesAprilTag()Returnstrueif an AprilTag has been seen since the last robot loop. -
changedReference
public boolean changedReference()Returns true if the reef angle has changed. -
tareRotation
public edu.wpi.first.wpilibj2.command.Command tareRotation()Tares the rotation of the robot. Useful for fixing an out of sync or drifting IMU. -
resetPose
public edu.wpi.first.wpilibj2.command.Command resetPose(Supplier<edu.wpi.first.math.geometry.Pose2d> pose) Resets the pose of the robot, inherently seeding field-relative movement.- Parameters:
pose- A supplier that returns the new blue origin relative pose to apply to the pose estimator.
-
resetOdometry
public edu.wpi.first.wpilibj2.command.Command resetOdometry()Hard reset of odometry to origin relative to blue origin. This will assume the robot's back right corner is on 0,0. -
drive
public edu.wpi.first.wpilibj2.command.Command drive(DoubleSupplier x, DoubleSupplier y, DoubleSupplier angular) Drives the robot using driver input.- Parameters:
x- The X value from the driver's joystick.y- The Y value from the driver's joystick.angular- The CCW+ angular speed to apply, from[-1.0, 1.0].
-
getFuelPose
public edu.wpi.first.math.geometry.Pose2d getFuelPose() -
apfDrive
public edu.wpi.first.wpilibj2.command.Command apfDrive(Supplier<edu.wpi.first.math.geometry.Pose2d> goal, DoubleSupplier maxDeceleration, DoubleSupplier endTolerance) Drives the robot to a target position using the P-APF, until the robot is positioned within a specified tolerance of the target.- Parameters:
goal- A supplier that returns the target blue-origin relative field location.maxDeceleration- A supplier that returns the desired deceleration rate of the robot, in m/s/s.endTolerance- The tolerance in meters at which to end the command.
-
apfDrive
public edu.wpi.first.wpilibj2.command.Command apfDrive(Supplier<edu.wpi.first.math.geometry.Pose2d> goal, DoubleSupplier maxDeceleration) Drives the robot to a target position using the P-APF. This command does not end.- Parameters:
goal- A supplier that returns the target blue-origin relative field location.maxDeceleration- A supplier that returns the desired deceleration rate of the robot, in m/s/s.
-
aimAtHub
public edu.wpi.first.wpilibj2.command.Command aimAtHub(Supplier<edu.wpi.first.math.geometry.Translation2d> goal, DoubleSupplier maxDeceleration) Drives the robot to a target position using the P-APF while aiming at the hub. This command does not end.- Parameters:
goal- A supplier that returns the target blue-origin relative field location.maxDeceleration- A supplier that returns the desired deceleration rate of the robot, in m/s/s.
-
aimAtOurZone
-
stop
public edu.wpi.first.wpilibj2.command.Command stop(boolean lock) Drives the modules to stop the robot from moving.- Parameters:
lock- If the wheels should be driven to an X formation to stop the robot from being pushed.
-
aimingAtHub
public boolean aimingAtHub() -
inOurZone
public boolean inOurZone()Checks if the origin of the robot is in our alliance's zone (the blue zone if we are on the blue alliance, and the red zone if we are on the red alliance).- Returns:
- True if we are in our zone, false otherwise.
-
inNeutralZone
public boolean inNeutralZone()Checks if the origin of the robot is in the neutral zone (between the blue zone and the red zone).- Returns:
- True if we are in the neutral zone, false otherwise.
-
inTheirZone
public boolean inTheirZone()Checks if the origin of the robot is in the opposing alliance's zone (the red zone if we are on the blue alliance, and the blue zone if we are on the red alliance).- Returns:
- True if we are in the opposing alliance's zone, false otherwise.
-
distanceToHub
public double distanceToHub()Returns the distance from the origin of our robot to the center of the hub in meters.- Returns:
- The distance from the origin of our robot to the center of the hub, recalculated every code cycle.
-
angleToHub
public double angleToHub()Returns the angle from the origin of our robot to the center of the hub in radians.- Returns:
- The angle from the origin of our robot to the center of the hub, recalculated every code cycle.
-