Skip to content

Commit

Permalink
Fix formatting, add javadocs and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkerMeyers committed Jan 13, 2024
1 parent 6953095 commit 19b6bee
Show file tree
Hide file tree
Showing 12 changed files with 772 additions and 153 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ java {
targetCompatibility = JavaVersion.VERSION_17
}

def ROBOT_MAIN_CLASS = "frc.robot.Main"
def ROBOT_MAIN_CLASS = "bhs.devilbotz.Main"

// Define my targets (RoboRIO) and artifacts (deployable files)
// This is added by GradleRIO's backing project DeployUtils.
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/bhs/devilbotz/BuildConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package bhs.devilbotz;

/**
* Automatically generated file containing build version information.
*/
public final class BuildConstants {
public static final String MAVEN_GROUP = "";
public static final String MAVEN_NAME = "Crescendo2024";
public static final String VERSION = "unspecified";
public static final int GIT_REVISION = 6;
public static final String GIT_SHA = "6953095ae13c329bcab835ed51bd92802e10b482";
public static final String GIT_DATE = "2024-01-10 22:36:31 EST";
public static final String GIT_BRANCH = "main";
public static final String BUILD_DATE = "2024-01-12 14:32:22 EST";
public static final long BUILD_UNIX_TIME = 1705087942925L;
public static final int DIRTY = 1;

private BuildConstants(){}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
// 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;
package bhs.devilbotz;

import edu.wpi.first.wpilibj.RobotBase;

/**
* Main initialization function. Do not perform any initialization here.
*/
public final class Main {
private Main() {}
private Main() {
}

public static void main(String... args) {
RobotBase.startRobot(Robot::new);
}
public static void main(String... args) {
RobotBase.startRobot(Robot::new);
}
}
187 changes: 187 additions & 0 deletions src/main/java/bhs/devilbotz/Robot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// 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 bhs.devilbotz;

import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import org.littletonrobotics.junction.LoggedRobot;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.networktables.NT4Publisher;
import org.littletonrobotics.junction.wpilog.WPILOGWriter;

/**
* The main robot class, which is responsible for handling initialization of the robot in different
* modes.
*
* <p>AdvantageKit is initialized in {@link #robotInit()}.
*
* @see LoggedRobot
* @see Logger
*/
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.
*
* <p>Note that this will be called before the AdvantageKit logging system is initialized.
*/
@Override
public void robotInit() {
// START: Setup AdvantageKit

// Record build metadata generated by Gversion
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");
case 1 -> Logger.recordMetadata("GitDirty", "Uncommitted changes");
default -> Logger.recordMetadata("GitDirty", "Unknown");
}

// Set up data receivers & replay source

// We will add support for replay mode later
/*if (Constants.AdvantageKit.REPLAY_MODE) {
// Running in replay mode
setUseTiming(false); // Run as fast as possible
String logPath =
LogFileUtil
.findReplayLog(); // Pull the replay log from AdvantageScope (or prompt the user)
Logger.setReplaySource(new WPILOGReader(logPath)); // Read replay log
Logger.addDataReceiver(
new WPILOGWriter(
LogFileUtil.addPathSuffix(logPath, "_sim"))); // Save outputs to a new log
} else {*/
if (isReal()) {
// Running on real robot
Logger.addDataReceiver(new WPILOGWriter("/media/sda1/")); // Log to a USB stick
Logger.addDataReceiver(new NT4Publisher()); // Publish data to NetworkTables
} else {
// Running in simulation
Logger.addDataReceiver(new WPILOGWriter("")); // Log to a file in the current directory
Logger.addDataReceiver(new NT4Publisher()); // Publish data to NetworkTables
}
// }

// Start logging! No more data receivers, replay sources, or metadata values maybe added.
Logger.start();

// END: Setup AdvantageKit
robotContainer = new RobotContainer();
}

/**
* This function is called every robot packet, no matter the mode. Use this for items like
* diagnostics that you want ran during disabled, autonomous, teleoperated and test.
*/
@Override
public void robotPeriodic() {
CommandScheduler.getInstance().run();
}

/**
* This function is called once each time the robot enters Disabled mode.
*/
@Override
public void disabledInit() {
}

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

/**
* This function is called once each time the robot enters any mode except Disabled after leaving
* Disabled mode.
*/
@Override
public void disabledExit() {
}


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

if (autonomousCommand != null) {
autonomousCommand.schedule();
}
}

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

/**
* This function is called once each time the robot exists Autonomous
*/
@Override
public void autonomousExit() {
}

/**
* This function is called once each time the robot enters Teleop mode.
*/
@Override
public void teleopInit() {
if (autonomousCommand != null) {
autonomousCommand.cancel();
}
}

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

/**
* This function is called once each time the robot enters any mode except Disabled after leaving
* Teleop mode.
*/
@Override
public void teleopExit() {
}

/**
* This function is called once each time the robot enters Test mode.
*/
@Override
public void testInit() {
CommandScheduler.getInstance().cancelAll();
}

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

/**
* This function is called once each time the robot enters any mode except Disabled after leaving
* Test mode.
*/
@Override
public void testExit() {
}
}
45 changes: 45 additions & 0 deletions src/main/java/bhs/devilbotz/RobotContainer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 bhs.devilbotz;

import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;

/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
* "declarative" paradigm, very little robot logic should actually be handled in the {@link Robot}
* periodic methods (other than the scheduler calls). Instead, the structure of the robot (including
* subsystems, commands, and button mappings) should be declared here.
*
* @see Robot
* @see Command
*/
public class RobotContainer {
/**
* The container for the robot. Contains subsystems, OI devices, and commands.
*/
public RobotContainer() {
configureBindings();
}

/**
* Use this method to define your button->command mappings. Buttons can be created by instantiating
* a {@link edu.wpi.first.wpilibj.GenericHID GenericHID} or one of its subclasses ({@link
* edu.wpi.first.wpilibj.Joystick Joystick} or {@link edu.wpi.first.wpilibj.XboxController
* XboxController}), and then passing it to a {@link edu.wpi.first.wpilibj2.command.button.JoystickButton
* JoystickButton}.
*/
private void configureBindings() {
}

/**
* Use this to pass the autonomous command to the main {@link Robot} class.
*
* @return the command to run in autonomous
*/
public Command getAutonomousCommand() {
return Commands.print("No autonomous command configured");
}
}
Loading

0 comments on commit 19b6bee

Please sign in to comment.