RobotContainerΒΆ

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved.                        */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

package frc.robot;

//Java imports
import java.util.HashMap;
import java.util.Map;

//WPI imports
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;

//Command imports
import frc.robot.commands.auto.AutoCommand;
import frc.robot.commands.auto.DriveMotor;

//Subsystem imports
import frc.robot.subsystems.DriveTrain;

/**
 * RobotContainer Class
 * <p>
 * This class is used for creating the instances of subsystems and organizing commands
 */
public class RobotContainer
{
    //Define subsystems
    public static DriveTrain drive;

    //Define the auto selector
    public static SendableChooser<String> autoChooser;
    public static Map<String, AutoCommand> autoMode = new HashMap<>();

    /**
     * Constructor
     */
    public RobotContainer()
    {
        //Create an instance of subsystems
        drive = new DriveTrain();
    }

    /**
     * Used for getting the autonomous command to be executed
     * @return autonmous command to execute
     */
    public Command getAutonomousCommand()
    {
        String mode = RobotContainer.autoChooser.getSelected();
        SmartDashboard.putString("Chosen Auto Mode", mode);
        return autoMode.getOrDefault(mode, new DriveMotor());
    }
}
  • 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.