Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of robotInit from FRC Docs #2689

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Often teams may wish to connect directly to the roboRIO for controlling their ro
.. code-block:: java

@Override
public void robotInit() {
public Robot() {
PortForwarder.add(8888, "wpilibpi.local", 80);
}

.. code-block:: c++

void Robot::RobotInit {
void Robot::Robot {
wpi::PortForwarder::GetInstance().Add(8888, "wpilibpi.local", 80);
}

Expand All @@ -39,13 +39,13 @@ To stop forwarding on a specified port, simply call ``remove(int port)`` with po
.. code-block:: java

@Override
public void robotInit() {
public void Robot() {
PortForwarder.remove(8888);
}

.. code-block:: c++

void Robot::RobotInit {
void Robot::Robot {
wpi::PortForwarder::GetInstance().Remove(8888);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Here is an example of generating a trajectory using clamped cubic splines for th

.. note:: The Java code utilizes the `Units <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/math/util/Units.html>`_ utility, for easy unit conversions.

.. note:: Generating a typical trajectory takes about 10 ms to 25 ms. This isn't long, but it's still highly recommended to generate all trajectories on startup (``robotInit``).
.. note:: Generating a typical trajectory takes about 10 ms to 25 ms. This isn't long, but it's still highly recommended to generate all trajectories on startup (``Robot``).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should say something like Robot constructor


Concatenating Trajectories
--------------------------
Expand Down
2 changes: 1 addition & 1 deletion source/docs/software/basic-programming/alliancecolor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Get Alliance Color

The ``DriverStation`` class (`Java <https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/DriverStation.html>`__, `C++ <https://github.wpilib.org/allwpilib/docs/release/cpp/classfrc_1_1_driver_station.html>`__, :py:class:`Python <robotpy:wpilib.DriverStation>`) has many useful features for getting data from the Driver Station computer. One of the most important features is ``getAlliance`` (Java & Python) / ``GetAlliance`` (C++).

Note that there are three cases: red, blue, and no color yet. It is important that code handles the third case correctly because the alliance color will not be available until the Driver Station connects. In particular, code should not assume that the alliance color will be available during constructor methods or `robotInit`, but it should be available by the time `autoInit` or `teleopInit` is called. FMS will set the alliance color automatically; when not connected to FMS, the alliance color can be set from the Driver Station (see :ref:`"Team Station" on the Operation Tab <docs/software/driverstation/driver-station:Operation Tab>`).
Note that there are three cases: red, blue, and no color yet. It is important that code handles the third case correctly because the alliance color will not be available until the Driver Station connects. In particular, code should not assume that the alliance color will be available during constructor methods or `Robot`, but it should be available by the time `autoInit` or `teleopInit` is called. FMS will set the alliance color automatically; when not connected to FMS, the alliance color can be set from the Driver Station (see :ref:`"Team Station" on the Operation Tab <docs/software/driverstation/driver-station:Operation Tab>`).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be changed, as now it's redundant


Getting your Alliance Color and Doing an Action
-----------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion source/docs/software/basic-programming/java-gc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Sometimes the garbage collector won't run frequently enough to keep up with the

Timer m_gcTimer = new Timer();

public void robotInit() {
public Robot() {
m_gcTimer.start();
}

Expand Down
60 changes: 30 additions & 30 deletions source/docs/software/basic-programming/reading-stacktraces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ To start, search above the ``unexpected error has occurred`` for the stack trace

.. code-block:: text

Error at frc.robot.Robot.robotInit(Robot.java:24): Unhandled exception: java.lang.NullPointerException
at frc.robot.Robot.robotInit(Robot.java:24)
Error at frc.robot.Robot.Robot(Robot.java:24): Unhandled exception: java.lang.NullPointerException
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that this is not what the stack trace would look like

at frc.robot.Robot.Robot(Robot.java:24)
at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:94)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:335)
at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(RobotBase.java:387)
Expand All @@ -59,11 +59,11 @@ To start, search above the ``unexpected error has occurred`` for the stack trace

* The error happened while running line ``24`` inside of ``Robot.java``

* ``robotInit`` was the name of the method executing when the error happened.
* ``Robot`` was the name of the method executing when the error happened.

* ``robotInit`` is a function in the ``frc.robot.Robot`` package (AKA, your team's code)
* ``Robot`` is a function in the ``frc.robot.Robot`` package (AKA, your team's code)

* ``robotInit`` was called from a number of functions from the ``edu.wpi.first.wpilibj`` package (AKA, the WPILib libraries)
* ``Robot`` was called from a number of functions from the ``edu.wpi.first.wpilibj`` package (AKA, the WPILib libraries)

The list of indented lines starting with the word ``at`` represent the state of the *stack* at the time the error happened. Each line represents one method, which was *called by* the method right below it.

Expand All @@ -75,13 +75,13 @@ To start, search above the ``unexpected error has occurred`` for the stack trace
at frc.robot.Robot.buggyMethod(TooManyBugs.java:1138)
at frc.robot.Robot.barInit(Bar.java:21)
at frc.robot.Robot.fooInit(Foo.java:34)
at frc.robot.Robot.robotInit(Robot.java:24)
at frc.robot.Robot.Robot(Robot.java:24)
at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:94)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:335)
at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(RobotBase.java:387)
at java.base/java.lang.Thread.run(Thread.java:834)

In this case: ``robotInit`` called ``fooInit``, which in turn called ``barInit``, which in turn called ``buggyMethod``. Then, during the execution of ``buggyMethod``, the ``NullPointerException`` occurred.
In this case: ``Robot`` called ``fooInit``, which in turn called ``barInit``, which in turn called ``buggyMethod``. Then, during the execution of ``buggyMethod``, the ``NullPointerException`` occurred.

.. tab-item:: C++

Expand All @@ -106,11 +106,11 @@ To start, search above the ``unexpected error has occurred`` for the stack trace

* The error happened while running line ``20`` inside of ``Robot.cpp``

* ``RobotInit`` was the name of the method executing when the error happened.
* ``Robot`` was the name of the method executing when the error happened.

* ``RobotInit`` is a function in the ``Robot::`` namespace (AKA, your team's code)
* ``Robot`` is a function in the ``Robot::`` namespace (AKA, your team's code)

* ``RobotInit`` was called from a number of functions from the ``frc::`` namespace (AKA, the WPILib libraries)
* ``Robot`` was called from a number of functions from the ``frc::`` namespace (AKA, the WPILib libraries)


This "call stack" window represents the state of the *stack* at the time the error happened. Each line represents one method, which was *called by* the method right below it.
Expand Down Expand Up @@ -175,7 +175,7 @@ For example, consider the following code:
PWMSparkMax armMotorCtrl;

@Override
public void robotInit() {
public Robot() {
armMotorCtrl.setInverted(true);
}

Expand All @@ -185,7 +185,7 @@ For example, consider the following code:

class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
void Robot() override {
motorRef->SetInverted(false);
}

Expand All @@ -205,8 +205,8 @@ When run, you'll see output that looks like this:
.. code-block:: text

********** Robot program starting **********
Error at frc.robot.Robot.robotInit(Robot.java:23): Unhandled exception: java.lang.NullPointerException
at frc.robot.Robot.robotInit(Robot.java:23)
Error at frc.robot.Robot.Robot(Robot.java:23): Unhandled exception: java.lang.NullPointerException
at frc.robot.Robot.Robot(Robot.java:23)
at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:107)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:373)
at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:463)
Expand All @@ -218,7 +218,7 @@ When run, you'll see output that looks like this:
Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:395): The startCompetition() method (or methods called by it) should have handled the exception above.


Reading the stack trace, you can see that the issue happened inside of the ``robotInit()`` function, on line 23, and the exception involved "Null Pointer".
Reading the stack trace, you can see that the issue happened inside of the ``Robot()`` function, on line 23, and the exception involved "Null Pointer".

By going to line 23, you can see there is only one thing which could be null - ``armMotorCtrl``. Looking further up, you can see that the ``armMotorCtrl`` object is declared, but never instantiated.

Expand Down Expand Up @@ -260,7 +260,7 @@ A functional implementation could look like this:
PWMSparkMax armMotorCtrl;

@Override
public void robotInit() {
public void Robot() {
armMotorCtrl = new PWMSparkMax(0);
armMotorCtrl.setInverted(true);
}
Expand All @@ -271,7 +271,7 @@ A functional implementation could look like this:

class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
void Robot() override {
motorRef = &m_armMotor;
motorRef->SetInverted(false);
}
Expand Down Expand Up @@ -301,7 +301,7 @@ For example, consider the following code:
int shoulderToElbow_in = 0; //TODO

@Override
public void robotInit() {
public void Robot() {
armLengthRatio = elbowToWrist_in / shoulderToElbow_in;
}

Expand All @@ -311,7 +311,7 @@ For example, consider the following code:

class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
void Robot() override {
armLengthRatio = elbowToWrist_in / shoulderToElbow_in;
}

Expand All @@ -333,8 +333,8 @@ When run, you'll see output that looks like this:


********** Robot program starting **********
Error at frc.robot.Robot.robotInit(Robot.java:24): Unhandled exception: java.lang.ArithmeticException: / by zero
at frc.robot.Robot.robotInit(Robot.java:24)
Error at frc.robot.Robot.Robot(Robot.java:24): Unhandled exception: java.lang.ArithmeticException: / by zero
at frc.robot.Robot.Robot(Robot.java:24)
at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:107)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:373)
at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:463)
Expand Down Expand Up @@ -389,7 +389,7 @@ A functional implementation could look like this:
int shoulderToElbow_in = 3;

@Override
public void robotInit() {
public Robot() {

armLengthRatio = elbowToWrist_in / shoulderToElbow_in;

Expand All @@ -402,7 +402,7 @@ A functional implementation could look like this:

class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
void Robot() override {
armLengthRatio = elbowToWrist_in / shoulderToElbow_in;
}

Expand Down Expand Up @@ -435,7 +435,7 @@ For example, consider the following code:
PWMSparkMax leftRearMotor;

@Override
public void robotInit() {
public Robot() {
leftFrontMotor = new PWMSparkMax(0);
leftRearMotor = new PWMSparkMax(0);
}
Expand All @@ -446,7 +446,7 @@ For example, consider the following code:

class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
void Robot() override {
m_frontLeftMotor.Set(0.5);
m_rearLeftMotor.Set(0.25);
}
Expand All @@ -468,10 +468,10 @@ When run, you'll see output that looks like this:
.. code-block:: text

********** Robot program starting **********
Error at frc.robot.Robot.robotInit(Robot.java:25): Unhandled exception: edu.wpi.first.hal.util.AllocationException: Code: -1029
Error at frc.robot.Robot.RobotBase(Robot.java:25): Unhandled exception: edu.wpi.first.hal.util.AllocationException: Code: -1029
PWM or DIO 0 previously allocated.
Location of the previous allocation:
at frc.robot.Robot.robotInit(Robot.java:24)
at frc.robot.Robot.Robot(Robot.java:24)
at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:107)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:373)
at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:463)
Expand All @@ -482,7 +482,7 @@ When run, you'll see output that looks like this:
at edu.wpi.first.wpilibj.PWM.<init>(PWM.java:66)
at edu.wpi.first.wpilibj.motorcontrol.PWMMotorController.<init>(PWMMotorController.java:27)
at edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax.<init>(PWMSparkMax.java:35)
at frc.robot.Robot.robotInit(Robot.java:25)
at frc.robot.Robot.Robot(Robot.java:25)
at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:107)
at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:373)
at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:463)
Expand Down Expand Up @@ -566,7 +566,7 @@ In the example, the left motor controllers are plugged into :term:`PWM` ports ``
PWMSparkMax leftRearMotor;

@Override
public void robotInit() {
public Robot() {

leftFrontMotor = new PWMSparkMax(0);
leftRearMotor = new PWMSparkMax(1);
Expand All @@ -580,7 +580,7 @@ In the example, the left motor controllers are plugged into :term:`PWM` ports ``

class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
void Robot() override {
m_frontLeftMotor.Set(0.5);
m_rearLeftMotor.Set(0.25);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Initializing Preferences

Preferences are stored using a name, the key. It's helpful to store the key in a constant, like ``kArmPositionKey`` and ``kArmPKey`` in the code above to avoid typing it multiple times and avoid typos. We also declare variables, ``kArmKp`` and ``armPositionDeg`` to hold the data retrieved from preferences.

In ``robotInit``, each key is checked to see if it already exists in the Preferences database. The ``containsKey`` method takes one parameter, the key to check if data for that key already exists in the preferences database. If it doesn't exist, a default value is written. The ``setDouble`` method takes two parameters, the key to write and the data to write. There are similar methods for other data types like booleans, ints, and strings.
In ``Robot``, each key is checked to see if it already exists in the Preferences database. The ``containsKey`` method takes one parameter, the key to check if data for that key already exists in the preferences database. If it doesn't exist, a default value is written. The ``setDouble`` method takes two parameters, the key to write and the data to write. There are similar methods for other data types like booleans, ints, and strings.

If using the Command Framework, this type of code could be placed in the constructor of a Subsystem or Command.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ As ``Robot`` (`Java <https://github.com/wpilibsuite/allwpilib/blob/main/wpilibjE
:linenos:
:lineno-start: 22

In Java, an instance of ``RobotContainer`` should be constructed during the ``robotInit()`` method - this is important, as most of the declarative robot setup will be called from the ``RobotContainer`` constructor.

In C++, this is not needed as RobotContainer is a value member and will be constructed during the construction of ``Robot``.
In Java and C++, an instance of ``RobotContainer`` should be constructed during the ``Robot()`` method - this is important, as most of the declarative robot setup will be called from the ``RobotContainer`` constructor.

.. tab-set::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ If data needs to be updated (for example, the output of some calculation done on

from wpilib.shuffleboard import Shuffleboard

def robotInit(self):
def Robot(self):
tab = Shuffleboard.getTab("Vision")
self.distanceEntry = tab.add("Distance to target", 0).getEntry()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ In ``Robot.java`` / ``Robot.h``, create a variable to hold a reference to a ``Se
Setting Up Options
^^^^^^^^^^^^^^^^^^

The chooser allows you to pick from a list of defined elements, in this case the strings we defined above. In ``robotInit``, add your options created as strings above using ``setDefaultOption`` or ``addOption``. ``setDefaultOption`` will be the one selected by default when the dashboard starts. The ``putData`` function will push it to the dashboard on your driver station computer.
The chooser allows you to pick from a list of defined elements, in this case the strings we defined above. In ``Robot``, add your options created as strings above using ``setDefaultOption`` or ``addOption``. ``setDefaultOption`` will be the one selected by default when the dashboard starts. The ``putData`` function will push it to the dashboard on your driver station computer.

.. tab-set::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Displaying the Scheduler Status

SmartDashboard.putData(CommandScheduler.getInstance())

You can display the status of the Scheduler (the code that schedules your commands to run). This is easily done by adding a single line to the ``RobotInit`` method in your RobotProgram as shown here. In this example the Scheduler instance is written using the ``putData`` method to SmartDashboard. This line of code produces the display in the previous image.
You can display the status of the Scheduler (the code that schedules your commands to run). This is easily done by adding a single line to the ``Robot`` method in your RobotProgram as shown here. In this example the Scheduler instance is written using the ``putData`` method to SmartDashboard. This line of code produces the display in the previous image.

.. image:: images/displaying-status-of-commands-and-subsystems/commands-running.png
:alt: The schedulers is showing which commands are being run.
Expand Down
Loading