Skip to content

Commit

Permalink
reformatted code using IntelliJ idea
Browse files Browse the repository at this point in the history
  • Loading branch information
catr1xLiu committed Jul 3, 2024
1 parent 7c17868 commit 63ba69d
Show file tree
Hide file tree
Showing 22 changed files with 1,592 additions and 1,875 deletions.
24 changes: 15 additions & 9 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@
* constants are needed, to reduce verbosity.
*/
public final class Constants {
public static final Mode currentMode = Mode.REAL;
public static final Mode currentMode = Mode.REAL;

public static enum Mode {
/** Running on a real robot. */
REAL,
public enum Mode {
/**
* Running on a real robot.
*/
REAL,

/** Running a physics simulator. */
SIM,
/**
* Running a physics simulator.
*/
SIM,

/** Replaying from a log file. */
REPLAY
}
/**
* Replaying from a log file.
*/
REPLAY
}
}
19 changes: 10 additions & 9 deletions src/main/java/frc/robot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
* call.
*/
public final class Main {
private Main() {}
private Main() {
}

/**
* Main initialization function. Do not perform any initialization here.
*
* <p>If you change your main robot class, change the parameter type.
*/
public static void main(String... args) {
RobotBase.startRobot(Robot::new);
}
/**
* Main initialization function. Do not perform any initialization here.
*
* <p>If you change your main robot class, change the parameter type.
*/
public static void main(String... args) {
RobotBase.startRobot(Robot::new);
}
}
273 changes: 151 additions & 122 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,132 +29,161 @@
* project.
*/
public class Robot extends LoggedRobot {
private Command autonomousCommand;
private RobotContainer robotContainer;

/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
// Record metadata
Logger.recordMetadata("ProjectName", BuildConstants.MAVEN_NAME);
Logger.recordMetadata("BuildDate", BuildConstants.BUILD_DATE);
Logger.recordMetadata("GitSHA", BuildConstants.GIT_SHA);
Logger.recordMetadata("GitDate", BuildConstants.GIT_DATE);
Logger.recordMetadata("GitBranch", BuildConstants.GIT_BRANCH);
switch (BuildConstants.DIRTY) {
case 0:
Logger.recordMetadata("GitDirty", "All changes committed");
break;
case 1:
Logger.recordMetadata("GitDirty", "Uncomitted changes");
break;
default:
Logger.recordMetadata("GitDirty", "Unknown");
break;
private Command autonomousCommand;
private RobotContainer robotContainer;

/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
// Record metadata
Logger.recordMetadata("ProjectName", BuildConstants.MAVEN_NAME);
Logger.recordMetadata("BuildDate", BuildConstants.BUILD_DATE);
Logger.recordMetadata("GitSHA", BuildConstants.GIT_SHA);
Logger.recordMetadata("GitDate", BuildConstants.GIT_DATE);
Logger.recordMetadata("GitBranch", BuildConstants.GIT_BRANCH);
switch (BuildConstants.DIRTY) {
case 0:
Logger.recordMetadata("GitDirty", "All changes committed");
break;
case 1:
Logger.recordMetadata("GitDirty", "Uncomitted changes");
break;
default:
Logger.recordMetadata("GitDirty", "Unknown");
break;
}

// Set up data receivers & replay source
switch (Constants.currentMode) {
case REAL:
// Running on a real robot, log to a USB stick ("/U/logs")
Logger.addDataReceiver(new WPILOGWriter());
Logger.addDataReceiver(new NT4Publisher());
break;

case SIM:
// Running a physics simulator, log to NT
Logger.addDataReceiver(new NT4Publisher());
break;

case REPLAY:
// Replaying a log, set up replay source
setUseTiming(false); // Run as fast as possible
String logPath = LogFileUtil.findReplayLog();
Logger.setReplaySource(new WPILOGReader(logPath));
Logger.addDataReceiver(new WPILOGWriter(LogFileUtil.addPathSuffix(logPath, "_sim")));
break;
}

// See http://bit.ly/3YIzFZ6 for more information on timestamps in AdvantageKit.
// Logger.disableDeterministicTimestamps()

// Start AdvantageKit logger
Logger.start();

// Instantiate our RobotContainer. This will perform all our button bindings,
// and put our autonomous chooser on the dashboard.
robotContainer = new RobotContainer();
}

// Set up data receivers & replay source
switch (Constants.currentMode) {
case REAL:
// Running on a real robot, log to a USB stick ("/U/logs")
Logger.addDataReceiver(new WPILOGWriter());
Logger.addDataReceiver(new NT4Publisher());
break;

case SIM:
// Running a physics simulator, log to NT
Logger.addDataReceiver(new NT4Publisher());
break;

case REPLAY:
// Replaying a log, set up replay source
setUseTiming(false); // Run as fast as possible
String logPath = LogFileUtil.findReplayLog();
Logger.setReplaySource(new WPILOGReader(logPath));
Logger.addDataReceiver(new WPILOGWriter(LogFileUtil.addPathSuffix(logPath, "_sim")));
break;
/**
* This function is called periodically during all modes.
*/
@Override
public void robotPeriodic() {
// Runs the Scheduler. This is responsible for polling buttons, adding
// newly-scheduled commands, running already-scheduled commands, removing
// finished or interrupted commands, and running subsystem periodic() methods.
// This must be called from the robot's periodic block in order for anything in
// the Command-based framework to work.
CommandScheduler.getInstance().run();
}

// See http://bit.ly/3YIzFZ6 for more information on timestamps in AdvantageKit.
// Logger.disableDeterministicTimestamps()

// Start AdvantageKit logger
Logger.start();

// Instantiate our RobotContainer. This will perform all our button bindings,
// and put our autonomous chooser on the dashboard.
robotContainer = new RobotContainer();
}

/** This function is called periodically during all modes. */
@Override
public void robotPeriodic() {
// Runs the Scheduler. This is responsible for polling buttons, adding
// newly-scheduled commands, running already-scheduled commands, removing
// finished or interrupted commands, and running subsystem periodic() methods.
// This must be called from the robot's periodic block in order for anything in
// the Command-based framework to work.
CommandScheduler.getInstance().run();
}

/** This function is called once when the robot is disabled. */
@Override
public void disabledInit() {}

/** This function is called periodically when disabled. */
@Override
public void disabledPeriodic() {}

/** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */
@Override
public void autonomousInit() {
autonomousCommand = robotContainer.getAutonomousCommand();

// schedule the autonomous command (example)
if (autonomousCommand != null) {
autonomousCommand.schedule();
/**
* This function is called once when the robot is disabled.
*/
@Override
public void disabledInit() {
}
}

/** This function is called periodically during autonomous. */
@Override
public void autonomousPeriodic() {}

/** This function is called once when teleop is enabled. */
@Override
public void teleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
if (autonomousCommand != null) {
autonomousCommand.cancel();

/**
* This function is called periodically when disabled.
*/
@Override
public void disabledPeriodic() {
}

/**
* This autonomous runs the autonomous command selected by your {@link RobotContainer} class.
*/
@Override
public void autonomousInit() {
autonomousCommand = robotContainer.getAutonomousCommand();

// schedule the autonomous command (example)
if (autonomousCommand != null) {
autonomousCommand.schedule();
}
}

/**
* This function is called periodically during autonomous.
*/
@Override
public void autonomousPeriodic() {
}

/**
* This function is called once when teleop is enabled.
*/
@Override
public void teleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
if (autonomousCommand != null) {
autonomousCommand.cancel();
}
}

/**
* This function is called periodically during operator control.
*/
@Override
public void teleopPeriodic() {
}

/**
* This function is called once when test mode is enabled.
*/
@Override
public void testInit() {
// Cancels all running commands at the start of test mode.
CommandScheduler.getInstance().cancelAll();
}

/**
* This function is called periodically during test mode.
*/
@Override
public void testPeriodic() {
}

/**
* This function is called once when the robot is first started up.
*/
@Override
public void simulationInit() {
}

/**
* This function is called periodically whilst in simulation.
*/
@Override
public void simulationPeriodic() {
}
}

/** This function is called periodically during operator control. */
@Override
public void teleopPeriodic() {}

/** This function is called once when test mode is enabled. */
@Override
public void testInit() {
// Cancels all running commands at the start of test mode.
CommandScheduler.getInstance().cancelAll();
}

/** This function is called periodically during test mode. */
@Override
public void testPeriodic() {}

/** This function is called once when the robot is first started up. */
@Override
public void simulationInit() {}

/** This function is called periodically whilst in simulation. */
@Override
public void simulationPeriodic() {}
}
Loading

0 comments on commit 63ba69d

Please sign in to comment.