44
55package frc .robot ;
66
7+ import org .littletonrobotics .junction .LoggedRobot ;
8+ import org .littletonrobotics .junction .Logger ;
9+
710import edu .wpi .first .wpilibj .TimedRobot ;
811import edu .wpi .first .wpilibj .smartdashboard .SendableChooser ;
912import edu .wpi .first .wpilibj .smartdashboard .SmartDashboard ;
13+ import edu .wpi .first .wpilibj2 .command .Command ;
14+ import edu .wpi .first .wpilibj2 .command .CommandScheduler ;
15+ import frc .crevolib .configs .CTREConfigs ;
16+ import frc .robot .driver .DriverXbox ;
17+ import frc .robot .operator .OperatorXbox ;
1018
1119/**
1220 * The methods in this class are called automatically corresponding to each mode, as described in
1321 * the TimedRobot documentation. If you change the name of this class or the package after creating
1422 * this project, you must also update the Main.java file in the project.
1523 */
16- public class Robot extends TimedRobot {
17- private static final String kDefaultAuto = "Default" ;
18- private static final String kCustomAuto = "My Auto" ;
19- private String m_autoSelected ;
20- private final SendableChooser <String > m_chooser = new SendableChooser <>();
24+ /**
25+ * The VM is configured to automatically run this class, and to call the functions corresponding to
26+ * each mode, as described in the TimedRobot documentation. If you change the name of this class or
27+ * the package after creating this project, you must also update the build.gradle file in the
28+ * project.
29+ */
30+ public class Robot extends LoggedRobot {
31+ public static final CTREConfigs ctreConfigs = new CTREConfigs ();
32+
33+ private Command m_autonomousCommand ;
34+ private RobotContainer m_robotContainer ;
35+ // private boolean constantRPM;
36+
37+ /**
38+ * This method cancels all commands and returns subsystems to their default commands and the
39+ * gamepad configs are reset so that new bindings can be assigned based on mode This method
40+ * should be called when each mode is intialized
41+ */
42+ public static void resetCommandsAndButtons () {
43+ CommandScheduler .getInstance ().cancelAll (); // Disable any currently running commands
44+ CommandScheduler .getInstance ().getActiveButtonLoop ().clear ();
45+
46+ // Reset Config for all gamepads and other button bindings
47+ // Driver.getInstance().resetConfig();
48+ // Operator.getInstance().resetConfig();
49+ DriverXbox .getInstance ().resetConfig ();
50+ OperatorXbox .getInstance ().resetConfig ();
51+ }
52+
2153
2254 /**
2355 * This function is run when the robot is first started up and should be used for any
2456 * initialization code.
2557 */
26- public Robot () {
27- m_chooser .setDefaultOption ("Default Auto" , kDefaultAuto );
28- m_chooser .addOption ("My Auto" , kCustomAuto );
29- SmartDashboard .putData ("Auto choices" , m_chooser );
58+ @ Override
59+ public void robotInit () {
60+ // Instantiate our RobotContainer. This will perform all our button bindings, and put our
61+ // autonomous chooser on the dashboard.
62+ Logger .start ();
63+ //CameraServer.startAutomaticCapture();
64+ m_robotContainer = new RobotContainer ();
3065 }
3166
3267 /**
@@ -37,68 +72,90 @@ public Robot() {
3772 * SmartDashboard integrated updating.
3873 */
3974 @ Override
40- public void robotPeriodic () {}
75+ public void robotPeriodic () {
76+ // Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled
77+ // commands, running already-scheduled commands, removing finished or interrupted commands,
78+ // and running subsystem periodic() methods. This must be called from the robot's periodic
79+ // block in order for anything in the Command-based framework to work.
80+
81+ CommandScheduler .getInstance ().run ();
82+ }
4183
4284 /**
43- * This autonomous (along with the chooser code above) shows how to select between different
44- * autonomous modes using the dashboard. The sendable chooser code works with the Java
45- * SmartDashboard. If you prefer the LabVIEW Dashboard, remove all of the chooser code and
46- * uncomment the getString line to get the auto name from the text box below the Gyro
47- *
48- * <p>You can add additional auto modes by adding additional comparisons to the switch structure
49- * below with additional strings. If using the SendableChooser make sure to add them to the
50- * chooser code above as well.
85+ * This function is called once each time the robot enters Disabled mode.
5186 */
5287 @ Override
53- public void autonomousInit () {
54- m_autoSelected = m_chooser .getSelected ();
55- // m_autoSelected = SmartDashboard.getString("Auto Selector", kDefaultAuto);
56- System .out .println ("Auto selected: " + m_autoSelected );
88+ public void disabledInit () {
89+ resetCommandsAndButtons ();
5790 }
5891
59- /** This function is called periodically during autonomous. */
6092 @ Override
61- public void autonomousPeriodic () {
62- switch (m_autoSelected ) {
63- case kCustomAuto :
64- // Put custom auto code here
65- break ;
66- case kDefaultAuto :
67- default :
68- // Put default auto code here
69- break ;
70- }
93+ public void disabledPeriodic () {
94+
7195 }
7296
73- /** This function is called once when teleop is enabled. */
97+ /**
98+ * This autonomous runs the autonomous command selected by your {@link RobotContainer} class.
99+ */
74100 @ Override
75- public void teleopInit () {}
101+ public void autonomousInit () {
102+ resetCommandsAndButtons ();
103+ m_autonomousCommand = m_robotContainer .getAutonomousCommand ();
76104
77- /** This function is called periodically during operator control. */
105+ // schedule the autonomous command (example)
106+ if (m_autonomousCommand != null ) {
107+ m_autonomousCommand .schedule ();
108+ }
109+ }
110+
111+ /**
112+ * This function is called periodically during autonomous.
113+ */
78114 @ Override
79- public void teleopPeriodic () {}
115+ public void autonomousPeriodic () {
116+
117+ }
80118
81- /** This function is called once when the robot is disabled. */
82119 @ Override
83- public void disabledInit () {}
120+ public void teleopInit () {
121+ // This makes sure that the autonomous stops running when
122+ // teleop starts running. If you want the autonomous to
123+ // continue until interrupted by another command, remove
124+ // this line or comment it out.
125+ resetCommandsAndButtons ();
126+ }
84127
85- /** This function is called periodically when disabled. */
128+ /**
129+ * This function is called periodically during operator control.
130+ */
86131 @ Override
87- public void disabledPeriodic () {}
132+ public void teleopPeriodic () {
133+ }
88134
89- /** This function is called once when test mode is enabled. */
90135 @ Override
91- public void testInit () {}
136+ public void testInit () {
137+ // Cancels all running commands at the start of test mode.
138+ resetCommandsAndButtons ();
139+ }
92140
93- /** This function is called periodically during test mode. */
141+ /**
142+ * This function is called periodically during test mode.
143+ */
94144 @ Override
95- public void testPeriodic () {}
145+ public void testPeriodic () {
146+ }
96147
97- /** This function is called once when the robot is first started up. */
148+ /**
149+ * This function is called once when the robot is first started up.
150+ */
98151 @ Override
99- public void simulationInit () {}
152+ public void simulationInit () {
153+ }
100154
101- /** This function is called periodically whilst in simulation. */
155+ /**
156+ * This function is called periodically whilst in simulation.
157+ */
102158 @ Override
103- public void simulationPeriodic () {}
159+ public void simulationPeriodic () {
160+ }
104161}
0 commit comments