-
Notifications
You must be signed in to change notification settings - Fork 268
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>`). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
----------------------------------------------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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. | ||
|
||
|
@@ -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++ | ||
|
||
|
@@ -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. | ||
|
@@ -175,7 +175,7 @@ For example, consider the following code: | |
PWMSparkMax armMotorCtrl; | ||
|
||
@Override | ||
public void robotInit() { | ||
public Robot() { | ||
armMotorCtrl.setInverted(true); | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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) | ||
|
@@ -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. | ||
|
||
|
@@ -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); | ||
} | ||
|
@@ -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); | ||
} | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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) | ||
|
@@ -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; | ||
|
||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
@@ -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); | ||
} | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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); | ||
|
@@ -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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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