Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/main/java/frc/robot/commands/auto/DriveTowardsThing.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ public class DriveTowardsThing extends Command {
private static final int SLIGHT_LEFT_BOUND = 156;
private static final int STRAIGHT_BOUND = 164;
private static final int SLIGHT_RIGHT_BOUND = 265;

// Drive speed constants
private static final double FORWARD_SPEED = -0.5;
private static final double LEFT_ROTATION_SPEED = -0.1;
private static final double SLIGHT_LEFT_ROTATION_SPEED = -0.05;
private static final double SLIGHT_RIGHT_ROTATION_SPEED = 0.05;
private static final double RIGHT_ROTATION_SPEED = 0.1;
private static final double STOPPED = 0.0;

// Timeout constant
private static final int STRAIGHT_TIMEOUT_CYCLES = 150;

public DriveTowardsThing(Drivetrain drivetrain, Camera camera) {
addRequirements(drivetrain, camera);
Expand Down Expand Up @@ -72,20 +83,20 @@ public void execute() {
if (straightTimeout <= 0) {
long x = camera.getX();
if (x < LEFT_BOUND) {
drivetrain.driveRobotRelative(0.0, -0.1, 0.0);
drivetrain.driveRobotRelative(STOPPED, LEFT_ROTATION_SPEED, STOPPED);
System.out.println("AUTO - DRIVETOWARDSRING: LEFT");
} else if (x >= LEFT_BOUND && x < SLIGHT_LEFT_BOUND) {
drivetrain.driveRobotRelative(0.0, -0.05, 0.0);
drivetrain.driveRobotRelative(STOPPED, SLIGHT_LEFT_ROTATION_SPEED, STOPPED);
System.out.println("AUTO - DRIVETOWARDSRING: SLIGHT LEFT");
} else if (x >= SLIGHT_LEFT_BOUND && x < STRAIGHT_BOUND) {
drivetrain.driveRobotRelative(-0.5, 0.0, 0.0);
straightTimeout = 150;
drivetrain.driveRobotRelative(FORWARD_SPEED, STOPPED, STOPPED);
straightTimeout = STRAIGHT_TIMEOUT_CYCLES;
System.out.println("AUTO - DRIVETOWARDSRING: STRAIGHT");
} else if (x >= STRAIGHT_BOUND && x < SLIGHT_RIGHT_BOUND) {
drivetrain.driveRobotRelative(0.0, 0.05, 0.0);
drivetrain.driveRobotRelative(STOPPED, SLIGHT_RIGHT_ROTATION_SPEED, STOPPED);
System.out.println("AUTO - DRIVETOWARDSRING: SLIGHT RIGHT");
} else {
drivetrain.driveRobotRelative(0.0, 0.1, 0.0);
drivetrain.driveRobotRelative(STOPPED, RIGHT_ROTATION_SPEED, STOPPED);
System.out.println("AUTO - DRIVETOWARDSRING: RIGHT");
}
} else {
Expand Down