# RobotBuilder Created Code

## The Layout of a RobotBuilder Generated Project

.. image:: images/robotbuilder-created-code-java.png
  :height: 500

.. image:: images/robotbuilder-created-code-cpp.png
  :height: 500

A RobotBuilder generated project consists of a package (in Java) or a folder (in C++) for Commands and another for Subsystems. Each command or subsystem object is stored under those containers. At the top level of the project you'll find the robot main program (RobotContainer.java/C++).

For more information on the organization of a Command Based robot, see :doc:`/docs/software/commandbased/structuring-command-based-project`

## Autogenerated Code
.. tab-set-code::

    ```java
    // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS
    m_chooser.setDefaultOption("Autonomous", new Autonomous());
    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS

    SmartDashboard.putData("Auto Mode", m_chooser);
    ```

    ```c++
    // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS
    m_chooser.SetDefaultOption("Autonomous", new Autonomous());
    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS

    frc::SmartDashboard::PutData("Auto Mode", &m_chooser);
    ```

When the robot description is modified and code is re-exported RobotBuilder is designed to not modify any changes you made to the file, thus preserving your code. This makes RobotBuilder a full-lifecycle tool. To know what code is OK to be modified by RobotBuilder, it generates sections that will potentially have to be rewritten delimited with some special comments. These comments are shown in the example above. Don't add any code within these comment blocks, it will be rewritten next time the project is exported from RobotBuilder.

If code inside one of these blocks must be modified, the comments can be removed, but this will prevent further updates from happening later. In the above example, if the //BEGIN and //END comments were removed, then later another required subsystem was added in RobotBuilder, it would not be generated on that next export.

.. tab-set-code::

    ```java
    // ROBOTBUILDER TYPE: Robot.
    ```

    ```c++
    // ROBOTBUILDER TYPE: Robot.
    ```

Additionally, each file has a comment defining the type of file. If this is modified or deleted, RobotBuilder will completely regenerate the file deleting any code added both inside and outside the AUTOGENERATED CODE blocks.

## Main Robot Program
.. tab-set::

    .. tab-item:: Java

        .. literalinclude:: ../resources/RBGearsBot2025Java/src/main/java/frc/robot/Robot.java
           :language: Java
           :lines: 11-
           :emphasize-lines: 17,48,68-73,89-90
           :lineno-match:

    .. tab-item:: C++ (Header)

        .. literalinclude:: ../resources/RBGearsBot2025CPP/src/main/include/Robot.h
           :language: C++
           :lines: 11-
           :emphasize-lines: 9
           :lineno-match:

    .. tab-item:: C++ (Source)

        .. literalinclude:: ../resources/RBGearsBot2025CPP/src/main/cpp/Robot.cpp
           :language: C++
           :lines: 11-
           :emphasize-lines: 24,40-44,54-57
           :lineno-match:


This is the main program generated by RobotBuilder. There are a number of parts to this program (highlighted sections):

1. This class extends TimedRobot. TimedRobot will call your ``autonomousPeriodic()`` and ``teleopPeriodic()`` methods every 20ms.
2. In the robotPeriodic method which is called every 20ms, make one scheduling pass.
3. The autonomous command provided is scheduled at the start of autonomous in the ``autonomousInit()`` method and canceled at the end of the autonomous period in ``teleopInit()``.


## RobotContainer
.. tab-set::

    .. tab-item:: Java

        .. literalinclude:: ../resources/RBGearsBot2025Java/src/main/java/frc/robot/RobotContainer.java
           :language: Java
           :lines: 11-
           :emphasize-lines: 33-36, 39-41, 62-72, 80, 92, 108-130
           :lineno-match:

    .. tab-item:: C++ (Header)

        .. literalinclude:: ../resources/RBGearsBot2025CPP/src/main/include/RobotContainer.h
           :language: C++
           :lines: 11-
           :emphasize-lines: 38-41, 56-58
           :lineno-match:

    .. tab-item:: C++ (Source)

        .. literalinclude:: ../resources/RBGearsBot2025CPP/src/main/cpp/RobotContainer.cpp
           :language: C++
           :lines: 11-
           :emphasize-lines: 26-36, 43, 53, 67-74
           :lineno-match:

This is the RobotContainer generated by RobotBuilder which is where the subsystems and operator interface are defined. There are a number of parts to this program (highlighted sections):

1. Each of the subsystems is declared here. They can be passed as parameters to any commands that require them.
2. If there is an autonomous command provided in RobotBuilder robot properties, it is added to the Sendable Chooser to be selected on the dashboard.
3. The code for all the operator interface components is generated here.
4. In addition the code to link the OI buttons to commands that should run is also generated here.
5. Commands to be run on a subsystem when no other commands are running are defined here.
6. Commands to be run via a dashboard are defined here.

