Skip to content

Robot Code File Structure

  1. Generate a new project using the WPILib VSCode Extension
    1. Click Ctrl+Shift+P and type "WPILib: Create New Project"
    2. Choose a template, java project, in the Command Robot Style
  2. After creating this project, navigate to the src/main/java/frc/robot folder
    1. This is where all of the robot code will be stored
  3. In this project there are 6 main types of files: Main, Robot, Subsystem, Command, Container, and Constants
    1. Main
      1. Main starts the robot code. This file should almost never be edited.
    2. Robot
      1. Robot is where the robot is initialized. In this there are some helpful methods that will be used to run the code. These methods are run during certain times in the match. For example, the method robotInit() is run when the robot is turned on.
    3. Subsystems
      1. Subsystems are where the code for the different parts of the robot are stored. For example, the code for the drive train is stored in the DriveTrain subsystem. These subsystems should be lower level methods, for example controlling a motor would be done in a subsystem, but passing in a joystick command to that motor would be done in a command. Subsystems should only be initialized once.
      2. Subsystems have a built in method named periodic that runs whenever the robot is running. You should NEVER run a motor in this method.
    4. Commands
      1. Commands are used to control subsystems. They have a couple of built in helpful methods
      2. Execute is run whenever the command is running. This is where you should run the motors.
      3. Initialize is run when the command is first started. This is where you should reset the subsystems.
      4. End is run when the command is finished. This is where you should stop the motors.
      5. isFinished is run to check if the command is finished. This is where you should check if the command is done. When creating a command, you should edit this method to return true when the command is finished.
    5. Robot Container
      1. Robot Container is where subsystems, commands, and joysticks should be initialized. It is also where the commands are bound to the buttons on the joystick.
    6. Constants
      1. Constants are values that do not change throughout the code. CAN ID numbers should be stored in constants, as well as gear rations, etc.