Package frc.robot.commands
Class DriveCommands.AltDriveDistance
java.lang.Object
edu.wpi.first.wpilibj2.command.Command
frc.robot.commands.DriveCommands.AltDriveDistance
- All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable
- Enclosing class:
DriveCommands
public static class DriveCommands.AltDriveDistance
extends edu.wpi.first.wpilibj2.command.Command
Alternate implementation of the above method using a class instead of a command. Slightly more verbose, but easier to read.
Our team usually uses code that looks like the above command.
Usage is basically the same, however add new in front of the function call.
Example: new DriveCommands.AltDriveDistance(5)
NOTE: Class Commands do not extend FunctionalCommand, however Function Commands do return FunctionalCommand.
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.wpi.first.wpilibj2.command.Command
edu.wpi.first.wpilibj2.command.Command.InterruptionBehavior
-
Field Summary
Fields inherited from class edu.wpi.first.wpilibj2.command.Command
m_requirements
-
Constructor Summary
ConstructorDescriptionAltDriveDistance
(double distance) Constructor, or what parameters the code takes in. -
Method Summary
Modifier and TypeMethodDescriptionvoid
end
(boolean interrupted) Called once the command ends or is interrupted.void
execute()
Called every time the scheduler runs while the command is scheduled.void
Called when the command is initially scheduled.boolean
Returns true when the command should end.Methods inherited from class edu.wpi.first.wpilibj2.command.Command
addRequirements, alongWith, andThen, andThen, asProxy, beforeStarting, beforeStarting, cancel, deadlineWith, finallyDo, finallyDo, getInterruptionBehavior, getName, getRequirements, getSubsystem, handleInterrupt, hasRequirement, ignoringDisable, initSendable, isScheduled, onlyIf, onlyWhile, raceWith, repeatedly, runsWhenDisabled, schedule, setName, setSubsystem, unless, until, withInterruptBehavior, withName, withTimeout
-
Constructor Details
-
AltDriveDistance
public AltDriveDistance(double distance) Constructor, or what parameters the code takes in.- Parameters:
distance
- The distance the XRP drives in inches
-
-
Method Details
-
initialize
public void initialize()Called when the command is initially scheduled. Sets the XRP's speed to zero to prepare it for moving, and resets the sensors that detect how much the wheels have turned.- Overrides:
initialize
in classedu.wpi.first.wpilibj2.command.Command
-
execute
public void execute()Called every time the scheduler runs while the command is scheduled. Makes the XRP drive forward.- Overrides:
execute
in classedu.wpi.first.wpilibj2.command.Command
-
end
public void end(boolean interrupted) Called once the command ends or is interrupted. Stops the XRP.- Overrides:
end
in classedu.wpi.first.wpilibj2.command.Command
-
isFinished
public boolean isFinished()Returns true when the command should end. Checks if the average distance traveled by the XRP's wheels is high enough.- Overrides:
isFinished
in classedu.wpi.first.wpilibj2.command.Command
-