Skip to content

Commit

Permalink
refactor(project): switched kotlin back to java
Browse files Browse the repository at this point in the history
kept kotlin in separate branch for future reference
  • Loading branch information
OmyDaGreat committed Dec 3, 2024
1 parent 5169f9a commit 7bbf1d5
Show file tree
Hide file tree
Showing 24 changed files with 1,706 additions and 1,391 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,5 @@ dokkaHtml {
description = 'Generates HTML documentation using Dokka'
group = 'documentation'
outputDirectory.set(file("${layout.buildDirectory.get().asFile.path}${File.separator}dokka"))
suppressInheritedMembers = true
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package frc.robot
package frc.robot;

import edu.wpi.first.wpilibj.RobotBase
import edu.wpi.first.wpilibj.RobotBase;

object Main {
public final class Main {
/**
* Main initialization function. Do not perform any initialization here.
*
* If you change your main robot class, change the parameter type.
*/
@JvmStatic
fun main(args: Array<String>) {
RobotBase.startRobot { Robot() }
public static void main(String... args) {
RobotBase.startRobot(Robot::new);
}
}
87 changes: 87 additions & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package frc.robot;

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

/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
* each mode, as described in the TimedRobot documentation. If you change the name of this class or
* the package after creating this project, you must also update the build.gradle file in the
* 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() {
robotContainer = new RobotContainer();

Logger.recordMetadata("ProjectName", "SwerveBaseTemplate");

if (isReal()) {
Logger.addDataReceiver(new WPILOGWriter()); // Log to a USB stick ("/U/logs")
Logger.addDataReceiver(new NT4Publisher()); // Publish data to NetworkTables
new PowerDistribution(
1, PowerDistribution.ModuleType.kRev); // Enables power distribution logging
} else {
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
}

// Logger.disableDeterministicTimestamps() // See "Deterministic Timestamps" in the
// "Understanding Data Flow" page
Logger.start(); // Start logging! No more data receivers, replay sources, or metadata values may
// be added.
}

/**
* This function is called every 20 ms, no matter the mode. Use this for items like diagnostics
* that you want ran during disabled, autonomous, teleoperated and test.
*
* <p>This runs after the mode specific periodic functions, but before LiveWindow and
* SmartDashboard integrated updating.
*/
@Override
public void robotPeriodic() {
CommandScheduler.getInstance().run();
}

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

/** This function is called once when teleop mode is initialized. */
@Override
public void teleopInit() {
if (autonomousCommand != null) {
autonomousCommand.cancel();
}
}

/** This function is called once when test mode is initialized. */
@Override
public void testInit() {
CommandScheduler.getInstance().cancelAll();
}
}
135 changes: 0 additions & 135 deletions src/main/java/frc/robot/Robot.kt

This file was deleted.

69 changes: 69 additions & 0 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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;

import com.pathplanner.lib.commands.PathPlannerAuto;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.button.*;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.robot.commands.PadDrive;
import frc.robot.subsystems.Photonvision;
import frc.robot.subsystems.SwerveSubsystem;
import frc.robot.utils.LogitechGamingPad;
import frc.robot.utils.RobotParameters.SwerveParameters.*;

/**
* 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 trigger mappings) should be declared here.
*/
public class RobotContainer {
private final SwerveSubsystem swerveSubsystem;
private final Photonvision photonvision;

private final JoystickButton padA;
private final JoystickButton padB;
private final JoystickButton padX;
private final JoystickButton padY;

/** The container for the robot. Contains subsystems, OI devices, and commands. */
public RobotContainer() {
LogitechGamingPad pad = new LogitechGamingPad(0);
padA = new JoystickButton(pad, 1);
padB = new JoystickButton(pad, 2);
padX = new JoystickButton(pad, 3);
padY = new JoystickButton(pad, 4);

photonvision = new Photonvision();
swerveSubsystem = new SwerveSubsystem(photonvision);
swerveSubsystem.setDefaultCommand(
new PadDrive(swerveSubsystem, pad, Thresholds.IS_FIELD_ORIENTED));

configureBindings();
}

/**
* Use this method to define your trigger->command mappings. Triggers can be created via the
* {@link Trigger} or our {@link JoystickButton} constructor with an arbitrary predicate, or via
* the named factories in {@link CommandGenericHID}'s subclasses for {@link
* CommandXboxController}/{@link CommandPS4Controller} controllers or {@link CommandJoystick}.
*/
private void configureBindings() {
// padA.onTrue(new InstantCommand(swerveSubsystem::addRotorPositionsforModules));
// padB.onTrue(new InstantCommand(swerveSubsystem::zeroHeading));
// padY.onTrue(new InstantCommand(swerveSubsystem::configAAcornMode));
// padX.onTrue(new InstantCommand(swerveSubsystem::configSlowMode));
}

/**
* Use this to pass the autonomous command to the main {@link Robot} class.
*
* @return the command to run in autonomous
*/
public Command getAutonomousCommand() {
return new PathPlannerAuto("Straight Auto");
}
}
67 changes: 0 additions & 67 deletions src/main/java/frc/robot/RobotContainer.kt

This file was deleted.

Loading

0 comments on commit 7bbf1d5

Please sign in to comment.