Skip to content

Commit

Permalink
Add teleop timer (#210)
Browse files Browse the repository at this point in the history
* Teleop timer for climbing

* Make teleop trigger check if fms attached

* Remove tele elapsed time print from teleopPeriodic()

* formatting

* Check robot state for teleop timer trigger

---------

Co-authored-by: manthan-acharya <[email protected]>
Co-authored-by: Jonah <[email protected]>
  • Loading branch information
3 people authored Mar 14, 2024
1 parent 7b5897a commit 180af7a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/main/java/org/littletonrobotics/frc2024/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
Expand Down Expand Up @@ -60,6 +61,8 @@ public class Robot extends LoggedRobot {
private final Timer canInitialErrorTimer = new Timer();
private final Timer canErrorTimer = new Timer();
private final Timer canivoreErrorTimer = new Timer();
private double teleStart;
private static double teleElapsedTime = 0.0;

private final Alert canErrorAlert =
new Alert("CAN errors detected, robot may not be controllable.", AlertType.ERROR);
Expand All @@ -72,6 +75,14 @@ public class Robot extends LoggedRobot {
private final Alert sameBatteryAlert =
new Alert("The battery has not been changed since the last match.", AlertType.WARNING);

public static Trigger createTeleopTimeTrigger(double teleElapsedTime) {
return new Trigger(
() ->
DriverStation.isFMSAttached()
&& DriverStation.isTeleopEnabled()
&& Robot.teleElapsedTime > teleElapsedTime);
}

/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
Expand Down Expand Up @@ -325,11 +336,15 @@ public void teleopInit() {
}
NoteVisualizer.clearAutoNotes();
NoteVisualizer.showAutoNotes();

teleStart = Timer.getFPGATimestamp();
}

/** This function is called periodically during operator control. */
@Override
public void teleopPeriodic() {}
public void teleopPeriodic() {
teleElapsedTime = Timer.getFPGATimestamp() - teleStart;
}

/** This function is called once when test mode is enabled. */
@Override
Expand Down

0 comments on commit 180af7a

Please sign in to comment.