From e8791a79c7072869ebf63e2f9646195ebb2150f2 Mon Sep 17 00:00:00 2001 From: Jean Li Date: Sat, 13 Jan 2024 15:57:46 -0800 Subject: [PATCH] Added RobotAutonomous --- .vscode/settings.json | 3 +- src/main/java/frc/robot/RobotAutonomous.java | 53 ++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/main/java/frc/robot/RobotAutonomous.java diff --git a/.vscode/settings.json b/.vscode/settings.json index 4ed293b..2f1b9b3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -25,5 +25,6 @@ } }, ], - "java.test.defaultConfig": "WPIlibUnitTests" + "java.test.defaultConfig": "WPIlibUnitTests", + "java.compile.nullAnalysis.mode": "automatic" } diff --git a/src/main/java/frc/robot/RobotAutonomous.java b/src/main/java/frc/robot/RobotAutonomous.java new file mode 100644 index 0000000..29810b0 --- /dev/null +++ b/src/main/java/frc/robot/RobotAutonomous.java @@ -0,0 +1,53 @@ +// 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.nrg948.autonomous.Autonomous; + +import edu.wpi.first.wpilibj.shuffleboard.BuiltInLayouts; +import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout; +import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab; +import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; +import edu.wpi.first.wpilibj2.command.Command; +import frc.robot.subsystems.Subsystems; + +/** + * This class creates and manages the user interface operators used to select + * and configure autonomous routines. +*/ +public class RobotAutonomous { + private final SendableChooser chooser; + + /** + * Creates a new RobotAutonomous. + * + * @param subsystems The subsystems container. + */ + public RobotAutonomous(Subsystems subsystems) { + this.chooser = Autonomous.getChooser(subsystems, "frc.robot"); + } + + /** + * Returns the autonomous command selected in the chooser. + * + * @return The autonomous command selected in the chooser. + */ + public Command getAutonomousCommand(){ + return this.chooser.getSelected(); + } + + /** + * Adds the autonomous layout to the shuffleboard tab. + * + * @param tab The tab to add the layout. + */ + public void addShuffleboardLayout(ShuffleboardTab tab) { + ShuffleboardLayout layout = tab.getLayout("Autonomous", BuiltInLayouts.kList) + .withPosition(0, 0) + .withSize(2, 2); + layout.add("Routine", chooser); + } +}