RobotContainer

The RobotContainer holds the instances of subsystems and helps organize commands.

 1/*----------------------------------------------------------------------------*/
 2/* Copyright (c) 2018-2019 FIRST. All Rights Reserved.                        */
 3/* Open Source Software - may be modified and shared by FRC teams. The code   */
 4/* must be accompanied by the FIRST BSD license file in the root directory of */
 5/* the project.                                                               */
 6/*----------------------------------------------------------------------------*/
 7
 8package frc.robot;
 9
10//Java imports
11import java.util.HashMap;
12import java.util.Map;
13
14//WPI imports
15import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
16import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
17import edu.wpi.first.wpilibj2.command.Command;
18
19//Command imports
20import frc.robot.commands.auto.AutoCommand;
21import frc.robot.commands.auto.DriveMotor;
22
23//Subsystem imports
24import frc.robot.subsystems.DriveTrain;
25
26/**
27 * RobotContainer Class
28 * <p>
29 * This class is used for creating the instances of subsystems and organizing commands
30 */
31public class RobotContainer
32{
33    //Define subsystems
34    public static DriveTrain drive;
35
36    //Define the auto selector
37    public static SendableChooser<String> autoChooser;
38    public static Map<String, AutoCommand> autoMode = new HashMap<>();
39
40    /**
41     * Constructor
42     */
43    public RobotContainer()
44    {
45        //Create an instance of subsystems
46        drive = new DriveTrain();
47    }
48
49    /**
50     * Used for getting the autonomous command to be executed
51     * @return autonmous command to execute
52     */
53    public Command getAutonomousCommand()
54    {
55        String mode = RobotContainer.autoChooser.getSelected();
56        SmartDashboard.putString("Chosen Auto Mode", mode);
57        return autoMode.getOrDefault(mode, new DriveMotor());
58    }
59}
  • Lines 11 - 24 are the required imports.

  • Lines 34 - 38 create the objects for required subsystems and functions.

  • Lines 43 - 47 is the RobotContainer constructor.

  • Line 46 creates the instance of the subsystem DriveTrain.

  • Lines 53 - 58 is the call to return the autonomous routine that we want the scheduler to run.