Skip to content

Instantly share code, notes, and snippets.

@shzcuber
Created February 12, 2022 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shzcuber/1086325cca43de130e1773f8092c1094 to your computer and use it in GitHub Desktop.
Save shzcuber/1086325cca43de130e1773f8092c1094 to your computer and use it in GitHub Desktop.
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc.robot.commands;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.DriveTrain;
public class DriveDistance extends CommandBase {
private DriveTrain driveTrain;
private double distanceToTravel;
/** Creates a new DriveStraight. */
public DriveDistance(DriveTrain driveTrain, double distanceToTravel) {
// Use addRequirements() here to declare subsystem dependencies.
addRequirements(driveTrain);
this.driveTrain = driveTrain;
this.distanceToTravel = distanceToTravel;
driveTrain.selectTurningPIDSlot();
driveTrain.zeroSensors();
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
// driveTrain.arcadeDrive(speed, 0);
driveTrain.driveStraightToPosition(distanceToTravel);
}
// Returns true when the command should end.
@Override
public boolean isFinished() {
return this.driveTrain.getRightMotorsDistance() >= this.distanceToTravel;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment