From f5c7e7bb6e336456a6b6e0bd37a19401bf669128 Mon Sep 17 00:00:00 2001 From: DJB755 <78251113+DJB755@users.noreply.github.com> Date: Sat, 3 Aug 2024 23:21:59 -0400 Subject: [PATCH] changed constructor --- .../networking-utilities/portforwarding.rst | 8 +-- .../trajectories/trajectory-generation.rst | 2 +- .../basic-programming/alliancecolor.rst | 2 +- .../software/basic-programming/java-gc.rst | 2 +- .../basic-programming/reading-stacktraces.rst | 60 +++++++++---------- .../basic-programming/robot-preferences.rst | 2 +- .../structuring-command-based-project.rst | 4 +- .../layouts-with-code/sending-data.rst | 2 +- ...autonomous-program-from-smartdashboard.rst | 2 +- ...ying-status-of-commands-and-subsystems.rst | 2 +- .../enabling-test-mode.rst | 12 ++-- .../motors/wpi-drive-classes.rst | 12 ++-- .../hardware-apis/sensors/counters.rst | 14 ++--- .../sensors/encoders-software.rst | 4 +- .../hardware-apis/sensors/gyros-software.rst | 24 ++++---- .../swerve-drive-odometry.rst | 2 +- ...rray-values-published-by-networktables.rst | 8 +-- .../software/networktables/robot-program.rst | 6 +- .../pathweaver/integrating-robot-program.rst | 4 +- source/docs/software/telemetry/datalog.rst | 8 +-- ...sing-generated-code-in-a-robot-program.rst | 4 +- .../roborio/using-multiple-cameras.rst | 18 +++--- .../using-the-cameraserver-on-the-roborio.rst | 2 +- .../robotbuilder-created-code.rst | 6 +- ...est-drivetrain-program-cpp-java-python.rst | 6 +- 25 files changed, 107 insertions(+), 109 deletions(-) diff --git a/source/docs/networking/networking-utilities/portforwarding.rst b/source/docs/networking/networking-utilities/portforwarding.rst index 8d68fa7857..9b58d8c594 100644 --- a/source/docs/networking/networking-utilities/portforwarding.rst +++ b/source/docs/networking/networking-utilities/portforwarding.rst @@ -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); } @@ -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); } diff --git a/source/docs/software/advanced-controls/trajectories/trajectory-generation.rst b/source/docs/software/advanced-controls/trajectories/trajectory-generation.rst index bb17b560e1..80ace5da5e 100644 --- a/source/docs/software/advanced-controls/trajectories/trajectory-generation.rst +++ b/source/docs/software/advanced-controls/trajectories/trajectory-generation.rst @@ -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 `_ 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``). Concatenating Trajectories -------------------------- diff --git a/source/docs/software/basic-programming/alliancecolor.rst b/source/docs/software/basic-programming/alliancecolor.rst index b8dd95ad3d..f58e9a620d 100644 --- a/source/docs/software/basic-programming/alliancecolor.rst +++ b/source/docs/software/basic-programming/alliancecolor.rst @@ -3,7 +3,7 @@ Get Alliance Color The ``DriverStation`` class (`Java `__, `C++ `__, :py:class:`Python `) 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 `). +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 `). Getting your Alliance Color and Doing an Action ----------------------------------------------- diff --git a/source/docs/software/basic-programming/java-gc.rst b/source/docs/software/basic-programming/java-gc.rst index bf3a217eda..66b402db7d 100644 --- a/source/docs/software/basic-programming/java-gc.rst +++ b/source/docs/software/basic-programming/java-gc.rst @@ -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(); } diff --git a/source/docs/software/basic-programming/reading-stacktraces.rst b/source/docs/software/basic-programming/reading-stacktraces.rst index 6693711b71..d6ce6c7613 100644 --- a/source/docs/software/basic-programming/reading-stacktraces.rst +++ b/source/docs/software/basic-programming/reading-stacktraces.rst @@ -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 + 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.(PWM.java:66) at edu.wpi.first.wpilibj.motorcontrol.PWMMotorController.(PWMMotorController.java:27) at edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax.(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); } diff --git a/source/docs/software/basic-programming/robot-preferences.rst b/source/docs/software/basic-programming/robot-preferences.rst index 3c015da980..d9ea4e3eb5 100644 --- a/source/docs/software/basic-programming/robot-preferences.rst +++ b/source/docs/software/basic-programming/robot-preferences.rst @@ -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. diff --git a/source/docs/software/commandbased/structuring-command-based-project.rst b/source/docs/software/commandbased/structuring-command-based-project.rst index f089fb3be0..35e1c5be2f 100644 --- a/source/docs/software/commandbased/structuring-command-based-project.rst +++ b/source/docs/software/commandbased/structuring-command-based-project.rst @@ -27,9 +27,7 @@ As ``Robot`` (`Java None: + def Robot(self) -> None: enableLiveWindowInTest(true) Explicitly vs. implicit test mode display @@ -44,7 +44,7 @@ Explicitly vs. implicit test mode display BuiltInAccelerometer accel; @Override - public void robotInit() { + public Robot() { leftDrive = new PWMSparkMax(0); rightDrive = new PWMSparkMax(1); arm = new PWMVictorSPX(2); @@ -60,7 +60,7 @@ Explicitly vs. implicit test mode display frc::BuiltInAccelerometer accel{}; frc::PWMVictorSPX arm{3}; - void Robot::RobotInit() { + void Robot::Robot() { wpi::SendableRegistry::SetName(&arm, "SomeSubsystem", "Arm"); wpi::SendableRegistry::SetName(&accel, "SomeSubsystem", "Accelerometer"); } @@ -70,7 +70,7 @@ Explicitly vs. implicit test mode display from wpilib import BuiltInAccelerometer, PWMSparkMax, PWMVictorSPX from wpiutil import SendableRegistry - def robotInit(self) -> None: + def Robot(self) -> None: leftDrive = PWMSparkMax(0) rightDrive = PWMSparkMax(1) arm = PWMVictorSPX(2) diff --git a/source/docs/software/hardware-apis/motors/wpi-drive-classes.rst b/source/docs/software/hardware-apis/motors/wpi-drive-classes.rst index d7f890421a..6aafaa60e4 100644 --- a/source/docs/software/hardware-apis/motors/wpi-drive-classes.rst +++ b/source/docs/software/hardware-apis/motors/wpi-drive-classes.rst @@ -41,7 +41,7 @@ As of 2022, the right side of the drivetrain is **no longer** inverted by defaul PWMSparkMax m_motorRight = new PWMSparkMax(0); @Override - public void robotInit() { + public Robot() { m_motorRight.setInverted(true); } @@ -50,13 +50,13 @@ As of 2022, the right side of the drivetrain is **no longer** inverted by defaul frc::PWMSparkMax m_motorLeft{0}; public: - void RobotInit() override { + void Robot() override { m_motorRight.SetInverted(true); } .. code-block:: python - def robotInit(self): + def Robot(self): self.motorRight = wpilib.PWMSparkMax(0) self.motorRight.setInverted(True) @@ -174,7 +174,7 @@ Many FRC\ |reg| drivetrains have more than 1 motor on each side. Classes derived :language: java :lines: 19-25 - In robotInit or Subsystem constructor: + In Robot or Subsystem constructor: .. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.3.2/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/subsystems/DriveSubsystem.java :language: java @@ -190,7 +190,7 @@ Many FRC\ |reg| drivetrains have more than 1 motor on each side. Classes derived .. tab-item:: C++ (Source) :sync: C++ (Source) - In robotInit or Subsystem constructor: + In Robot or Subsystem constructor: .. remoteliteralinclude:: https://raw.githubusercontent.com/wpilibsuite/allwpilib/v2024.3.2/wpilibcExamples/src/main/cpp/examples/RamseteCommand/cpp/subsystems/DriveSubsystem.cpp :language: c++ @@ -203,7 +203,7 @@ Many FRC\ |reg| drivetrains have more than 1 motor on each side. Classes derived .. code-block:: python - def robotInit(self): + def Robot(self): frontLeft = wpilib.Spark(1) rearLeft = wpilib.Spark(2) left = wpilib.MotorControllerGroup(frontLeft, rearLeft) diff --git a/source/docs/software/hardware-apis/sensors/counters.rst b/source/docs/software/hardware-apis/sensors/counters.rst index d2e5da15b0..550a23cd62 100644 --- a/source/docs/software/hardware-apis/sensors/counters.rst +++ b/source/docs/software/hardware-apis/sensors/counters.rst @@ -38,7 +38,7 @@ In two-pulse mode, the :code:`Counter` will count up for every edge/pulse on the Counter counter = new Counter(Counter.Mode.k2Pulse); @Override - public void robotInit() { + public Robot() { // Set up the input channels for the counter counter.setUpSource(1); counter.setDownSource(2); @@ -53,7 +53,7 @@ In two-pulse mode, the :code:`Counter` will count up for every edge/pulse on the // Create a new Counter object in two-pulse mode frc::Counter counter{frc::Counter::Mode::k2Pulse}; - void Robot::RobotInit() { + void Robot::Robot() { // Set up the input channels for the counter counter.SetUpSource(1); counter.SetDownSource(2); @@ -75,7 +75,7 @@ In semi-period mode, the :code:`Counter` will count the duration of the pulses o Counter counter = new Counter(Counter.Mode.kSemiperiod); @Override - public void robotInit() { + public Robot() { // Set up the input channel for the counter counter.setUpSource(1); @@ -122,7 +122,7 @@ In pulse-length mode, the counter will count either up or down depending on the Counter counter = new Counter(Counter.Mode.kPulseLength); @Override - public void robotInit() { + public Robot() { // Set up the input channel for the counter counter.setUpSource(1); @@ -138,7 +138,7 @@ In pulse-length mode, the counter will count either up or down depending on the // Create a new Counter object in two-pulse mode frc::Counter counter{frc::Counter::Mode::kPulseLength}; - void Robot::RobotInit() { + void Robot::Robot() { // Set up the input channel for the counter counter.SetUpSource(1); @@ -161,7 +161,7 @@ In external direction mode, the counter counts either up or down depending on th Counter counter = new Counter(Counter.Mode.kExternalDirection); @Override - public void robotInit() { + public Robot() { // Set up the input channels for the counter counter.setUpSource(1); counter.setDownSource(2); @@ -175,7 +175,7 @@ In external direction mode, the counter counts either up or down depending on th // Create a new Counter object in two-pulse mode frc::Counter counter{frc::Counter::Mode::kExternalDirection}; - void RobotInit() { + void Robot() { // Set up the input channels for the counter counter.SetUpSource(1); counter.SetDownSource(2); diff --git a/source/docs/software/hardware-apis/sensors/encoders-software.rst b/source/docs/software/hardware-apis/sensors/encoders-software.rst index 654f4c8028..12368e9d14 100644 --- a/source/docs/software/hardware-apis/sensors/encoders-software.rst +++ b/source/docs/software/hardware-apis/sensors/encoders-software.rst @@ -481,7 +481,7 @@ Encoders can be used on a robot drive to create a simple "drive to distance" rou DifferentialDrive drive = new DifferentialDrive(leftLeader::set, rightLeader::set); @Override - public void robotInit() { + public void Robot() { // Configures the encoder's distance-per-pulse // The robot moves forward 1 foot per encoder rotation // There are 256 pulses per encoder rotation @@ -520,7 +520,7 @@ Encoders can be used on a robot drive to create a simple "drive to distance" rou frc::DifferentialDrive drive{[&](double output) { leftLeader.Set(output); }, [&](double output) { rightLeader.Set(output); }}; - void Robot::RobotInit() { + void Robot::Robot() { // Configures the encoder's distance-per-pulse // The robot moves forward 1 foot per encoder rotation // There are 256 pulses per encoder rotation diff --git a/source/docs/software/hardware-apis/sensors/gyros-software.rst b/source/docs/software/hardware-apis/sensors/gyros-software.rst index 1a9d4dc778..da866cdb12 100644 --- a/source/docs/software/hardware-apis/sensors/gyros-software.rst +++ b/source/docs/software/hardware-apis/sensors/gyros-software.rst @@ -182,7 +182,7 @@ Displaying the robot heading on the dashboard // Use gyro declaration from above here - public void robotInit() { + public Robot() { // Places a compass indicator for the gyro heading on the dashboard Shuffleboard.getTab("Example tab").add(gyro); } @@ -191,7 +191,7 @@ Displaying the robot heading on the dashboard // Use gyro declaration from above here - void Robot::RobotInit() { + void Robot::Robot() { // Places a compass indicator for the gyro heading on the dashboard frc::Shuffleboard.GetTab("Example tab").Add(gyro); } @@ -200,7 +200,7 @@ Displaying the robot heading on the dashboard from wpilib.shuffleboard import Shuffleboard - def robotInit(self): + def Robot(self): # Use gyro declaration from above here # Places a compass indicator for the gyro heading on the dashboard @@ -239,7 +239,7 @@ The following example shows how to stabilize heading using a simple P loop close DifferentialDrive drive = new DifferentialDrive(leftLeader::set, rightLeader::set); @Override - public void robotInit() { + public Robot() { // Configures the encoder's distance-per-pulse // The robot moves forward 1 foot per encoder rotation // There are 256 pulses per encoder rotation @@ -279,7 +279,7 @@ The following example shows how to stabilize heading using a simple P loop close frc::DifferentialDrive drive{[&](double output) { leftLeader.Set(output); }, [&](double output) { rightLeader.Set(output); }}; - void Robot::RobotInit() { + void Robot::Robot() { // Invert the right side of the drivetrain. You might have to invert the other side rightLeader.SetInverted(true); @@ -302,7 +302,7 @@ The following example shows how to stabilize heading using a simple P loop close from wpilib import MotorControllerGroup from wpilib.drive import DifferentialDrive - def robotInit(self): + def Robot(self): # Use gyro declaration from above here # The gain for a simple P loop @@ -362,7 +362,7 @@ The following example shows how to stabilize heading using a simple P loop close DifferentialDrive drive = new DifferentialDrive(leftMotors, rightMotors); @Override - public void robotInit() { + public Robot() { rightMotors.setInverted(true); } @@ -401,7 +401,7 @@ The following example shows how to stabilize heading using a simple P loop close frc::DifferentialDrive drive{leftMotors, rightMotors}; - void Robot::RobotInit() { + void Robot::Robot() { rightMotors.SetInverted(true); } @@ -423,7 +423,7 @@ The following example shows how to stabilize heading using a simple P loop close from wpilib import MotorControllerGroup from wpilib.drive import DifferentialDrive - def robotInit(self): + def Robot(self): # Use gyro declaration from above here # The gain for a simple P loop @@ -483,7 +483,7 @@ Much like with heading stabilization, this is often accomplished with a PID loop DifferentialDrive drive = new DifferentialDrive(leftMotors, rightMotors); @Override - public void robotInit() { + public Robot() { rightMotors.setInverted(true); } @@ -514,7 +514,7 @@ Much like with heading stabilization, this is often accomplished with a PID loop frc::DifferentialDrive drive{leftMotors, rightMotors}; - void Robot::RobotInit() { + void Robot::Robot() { rightMotors.SetInverted(true); } @@ -532,7 +532,7 @@ Much like with heading stabilization, this is often accomplished with a PID loop from wpilib import MotorControllerGroup from wpilib.drive import DifferentialDrive - def robotInit(self): + def Robot(self): # Use gyro declaration from above here # The gain for a simple P loop diff --git a/source/docs/software/kinematics-and-odometry/swerve-drive-odometry.rst b/source/docs/software/kinematics-and-odometry/swerve-drive-odometry.rst index fc3c9245d3..439ee6957a 100644 --- a/source/docs/software/kinematics-and-odometry/swerve-drive-odometry.rst +++ b/source/docs/software/kinematics-and-odometry/swerve-drive-odometry.rst @@ -79,7 +79,7 @@ The fourth optional argument is the starting pose of your robot on the field (as from wpimath.geometry import Rotation2d class MyRobot: - def robotInit(self): + def Robot(self): # Locations for the swerve drive modules relative to the robot center. frontLeftLocation = Translation2d(0.381, 0.381) frontRightLocation = Translation2d(0.381, -0.381) diff --git a/source/docs/software/networktables/reading-array-values-published-by-networktables.rst b/source/docs/software/networktables/reading-array-values-published-by-networktables.rst index e866eb17f6..de8284f059 100644 --- a/source/docs/software/networktables/reading-array-values-published-by-networktables.rst +++ b/source/docs/software/networktables/reading-array-values-published-by-networktables.rst @@ -14,7 +14,7 @@ You can verify the names of the NetworkTables topics used for publishing the val In this case the values are stored in a table called GRIP and a sub-table called myContoursReport. You can see that the values are in brackets and there are 2 values in this case for each topic. The NetworkTables topic names are centerX, centerY, area, height and width. -Both of the following examples are extremely simplified programs that just illustrate the use of NetworkTables. All the code is in the robotInit() method so it's only run when the program starts up. In your programs, you would more likely get the values in code that is evaluating which direction to aim the robot in a command or a control loop during the autonomous or teleop periods. +Both of the following examples are extremely simplified programs that just illustrate the use of NetworkTables. All the code is in the Robot() method so it's only run when the program starts up. In your programs, you would more likely get the values in code that is evaluating which direction to aim the robot in a command or a control loop during the autonomous or teleop periods. Writing a Program to Access the Topics -------------------------------------- @@ -26,7 +26,7 @@ Writing a Program to Access the Topics DoubleArraySubscriber areasSub; @Override - public void robotInit() { + public Robot() { NetworkTable table = NetworkTableInstance.getDefault().getTable("GRIP/mycontoursReport"); areasSub = table.getDoubleArrayTopic("area").subscribe(new double[] {}); } @@ -48,7 +48,7 @@ Writing a Program to Access the Topics nt::DoubleArraySubscriber areasSub; - void Robot::RobotInit() override { + void Robot::Robot() override { auto table = nt::NetworkTableInstance::GetDefault().GetTable("GRIP/myContoursReport"); areasSub = table->GetDoubleArrayTopic("area").Subscribe({}); } @@ -67,7 +67,7 @@ Writing a Program to Access the Topics .. code-block:: python - def robotInit(self): + def Robot(self): table = ntcore.NetworkTableInstance.getDefault().getTable("GRIP/mycontoursReport") self.areasSub = table.getDoubleArrayTopic("area").subscribe([]) diff --git a/source/docs/software/networktables/robot-program.rst b/source/docs/software/networktables/robot-program.rst index 90f8afc66b..4042a32343 100644 --- a/source/docs/software/networktables/robot-program.rst +++ b/source/docs/software/networktables/robot-program.rst @@ -20,7 +20,7 @@ The example robot program below publishes incrementing X and Y values to a table DoublePublisher xPub; DoublePublisher yPub; - public void robotInit() { + public Robot() { // Get the default instance of NetworkTables that was created automatically // when the robot program starts NetworkTableInstance inst = NetworkTableInstance.getDefault(); @@ -61,7 +61,7 @@ The example robot program below publishes incrementing X and Y values to a table nt::DoublePublisher xPub; nt::DoublePublisher yPub; - void RobotInit() { + void Robot() { // Get the default instance of NetworkTables that was created automatically // when the robot program starts auto inst = nt::NetworkTableInstance::GetDefault(); @@ -99,7 +99,7 @@ The example robot program below publishes incrementing X and Y values to a table class EasyNetworkTableExample(wpilib.TimedRobot): - def robotInit(self) -> None: + def Robot(self) -> None: # Get the default instance of NetworkTables that was created automatically # when the robot program starts inst = ntcore.NetworkTableInstance.getDefault() diff --git a/source/docs/software/pathplanning/pathweaver/integrating-robot-program.rst b/source/docs/software/pathplanning/pathweaver/integrating-robot-program.rst index c979489d64..73287769ed 100644 --- a/source/docs/software/pathplanning/pathweaver/integrating-robot-program.rst +++ b/source/docs/software/pathplanning/pathweaver/integrating-robot-program.rst @@ -17,7 +17,7 @@ The ``fromPathweaverJson`` (Java) / ``FromPathweaverJson`` (C++) static methods Trajectory trajectory = new Trajectory(); @Override - public void robotInit() { + public Robot() { try { Path trajectoryPath = Filesystem.getDeployDirectory().toPath().resolve(trajectoryJSON); trajectory = TrajectoryUtil.fromPathweaverJson(trajectoryPath); @@ -34,7 +34,7 @@ The ``fromPathweaverJson`` (Java) / ``FromPathweaverJson`` (C++) static methods frc::Trajectory trajectory; - void Robot::RobotInit() { + void Robot::Robot() { fs::path deployDirectory = frc::filesystem::GetDeployDirectory(); deployDirectory = deployDirectory / "paths" / "YourPath.wpilib.json"; trajectory = frc::TrajectoryUtil::FromPathweaverJson(deployDirectory.string()); diff --git a/source/docs/software/telemetry/datalog.rst b/source/docs/software/telemetry/datalog.rst index 53db8ce892..1efe5d2b50 100644 --- a/source/docs/software/telemetry/datalog.rst +++ b/source/docs/software/telemetry/datalog.rst @@ -23,7 +23,7 @@ Log files are initially named ``FRC_TBD_{random}.wpilog`` until the DS connects. On startup, all existing log files where a DS has not been connected will be deleted. If there is less than 50 MB of free space on the target storage, ``FRC_`` log files are deleted (oldest to newest) until there is 50 MB free OR there are 10 files remaining. -The most basic usage of DataLogManager only requires a single line of code (typically this would be called from ``robotInit``). This will record all NetworkTables changes to the data log. +The most basic usage of DataLogManager only requires a single line of code (typically this would be called from ``Robot``). This will record all NetworkTables changes to the data log. .. tab-set-code:: @@ -124,7 +124,7 @@ The LogEntry classes can be used in conjunction with DataLogManager to record va DoubleLogEntry myDoubleLog; StringLogEntry myStringLog; - public void robotInit() { + public Robot() { // Starts recording to data log DataLogManager.start(); @@ -153,7 +153,7 @@ The LogEntry classes can be used in conjunction with DataLogManager to record va wpi::log::DoubleLogEntry myDoubleLog; wpi::log::StringLogEntry myStringLog; - void RobotInit() { + void Robot() { // Starts recording to data log frc::DataLogManager::Start(); @@ -184,7 +184,7 @@ The LogEntry classes can be used in conjunction with DataLogManager to record va ) class MyRobot(TimedRobot): - def robotInit(self): + def Robot(self): # Starts recording to data log DataLogManager.start() diff --git a/source/docs/software/vision-processing/grip/using-generated-code-in-a-robot-program.rst b/source/docs/software/vision-processing/grip/using-generated-code-in-a-robot-program.rst index 4cc955e167..c95980285f 100644 --- a/source/docs/software/vision-processing/grip/using-generated-code-in-a-robot-program.rst +++ b/source/docs/software/vision-processing/grip/using-generated-code-in-a-robot-program.rst @@ -70,7 +70,7 @@ In this first part of the program you can see all the import statements for the .. code-block:: java @Override - public void robotInit() { + public Robot() { UsbCamera camera = CameraServer.startAutomaticCapture(); camera.setResolution(IMG_WIDTH, IMG_HEIGHT); @@ -89,7 +89,7 @@ In this first part of the program you can see all the import statements for the drive = new DifferentialDrive(left, right); } -The **robotInit()** method is called once when the program starts up. It creates a **CameraServer** instance that begins +The **Robot()** method is called once when the program starts up. It creates a **CameraServer** instance that begins capturing images at the requested resolution (IMG_WIDTH by IMG_HEIGHT). Next an instance of the class **VisionThread** is created. VisionThread begins capturing images from the camera asynchronously diff --git a/source/docs/software/vision-processing/roborio/using-multiple-cameras.rst b/source/docs/software/vision-processing/roborio/using-multiple-cameras.rst index c5468e3379..0a86cf39d6 100644 --- a/source/docs/software/vision-processing/roborio/using-multiple-cameras.rst +++ b/source/docs/software/vision-processing/roborio/using-multiple-cameras.rst @@ -19,7 +19,7 @@ If you're interested in just switching what the driver sees, and are using Smart NetworkTableEntry cameraSelection; @Override - public void robotInit() { + public Robot() { camera1 = CameraServer.startAutomaticCapture(0); camera2 = CameraServer.startAutomaticCapture(1); @@ -48,7 +48,7 @@ If you're interested in just switching what the driver sees, and are using Smart nt::NetworkTableEntry cameraSelection; - void RobotInit() override { + void Robot() override { camera1 = frc::CameraServer::StartAutomaticCapture(0); camera2 = frc::CameraServer::StartAutomaticCapture(1); @@ -78,7 +78,7 @@ If you're interested in just switching what the driver sees, and are using Smart from ntcore import NetworkTableInstance class MyRobot(wpilib.TimedRobot): - def robotInit(self): + def Robot(self): self.joy1 = wpilib.Joystick(0) self.cameraSelection = NetworkTableInstance.getDefault().getTable("").getEntry("CameraSelection") wpilib.CameraServer.launch("vision.py:main") @@ -128,7 +128,7 @@ If you're using some other dashboard, you can change the camera used by the came Joystick joy1 = new Joystick(0); @Override - public void robotInit() { + public Robot() { camera1 = CameraServer.startAutomaticCapture(0); camera2 = CameraServer.startAutomaticCapture(1); server = CameraServer.getServer(); @@ -153,7 +153,7 @@ If you're using some other dashboard, you can change the camera used by the came frc::Joystick joy1{0}; bool prevTrigger = false; - void RobotInit() override { + void Robot() override { camera1 = frc::CameraServer::StartAutomaticCapture(0); camera2 = frc::CameraServer::StartAutomaticCapture(1); server = frc::CameraServer::GetServer(); @@ -193,7 +193,7 @@ By default, the cscore library is pretty aggressive in turning off cameras not i Joystick joy1 = new Joystick(0); @Override - public void robotInit() { + public Robot() { camera1 = CameraServer.startAutomaticCapture(0); camera2 = CameraServer.startAutomaticCapture(1); server = CameraServer.getServer(); @@ -223,7 +223,7 @@ By default, the cscore library is pretty aggressive in turning off cameras not i cs::VideoSink server; frc::Joystick joy1{0}; bool prevTrigger = false; - void RobotInit() override { + void Robot() override { camera1 = frc::CameraServer::StartAutomaticCapture(0); camera2 = frc::CameraServer::StartAutomaticCapture(1); server = frc::CameraServer::GetServer(); @@ -255,7 +255,7 @@ By default, the cscore library is pretty aggressive in turning off cameras not i from ntcore import NetworkTableInstance class MyRobot(wpilib.TimedRobot): - def robotInit(self): + def Robot(self): self.joy1 = wpilib.Joystick(0) self.cameraSelection = NetworkTableInstance.getDefault().getTable("").getEntry("CameraSelection") wpilib.CameraServer.launch("vision.py:main") @@ -307,4 +307,4 @@ By default, the cscore library is pretty aggressive in turning off cameras not i try a lower resolution or a different pixel format (VIDIOC_STREAMON: No space left on device) - If you're using Option 3 it will give you this error during ``RobotInit()``. Thus you should just try your desired resolution and adjusting as necessary until you both don't get that error and don't exceed the radio bandwidth limitations. + If you're using Option 3 it will give you this error during ``Robot()``. Thus you should just try your desired resolution and adjusting as necessary until you both don't get that error and don't exceed the radio bandwidth limitations. diff --git a/source/docs/software/vision-processing/roborio/using-the-cameraserver-on-the-roborio.rst b/source/docs/software/vision-processing/roborio/using-the-cameraserver-on-the-roborio.rst index ad9ca54929..1a4aaf8799 100644 --- a/source/docs/software/vision-processing/roborio/using-the-cameraserver-on-the-roborio.rst +++ b/source/docs/software/vision-processing/roborio/using-the-cameraserver-on-the-roborio.rst @@ -30,7 +30,7 @@ The following program starts automatic capture of a USB camera like the Microsof Advanced Camera Server Program ------------------------------ -In the following example a thread created in robotInit() gets the Camera Server instance. Each frame of the video is individually processed, in this case drawing a rectangle on the image using the OpenCV ``rectangle()`` method. The resultant images are then passed to the output stream and sent to the dashboard. You can replace the ``rectangle`` operation with any image processing code that is necessary for your application. You can even annotate the image using OpenCV methods to write targeting information onto the image being sent to the dashboard. +In the following example a thread created in Robot() gets the Camera Server instance. Each frame of the video is individually processed, in this case drawing a rectangle on the image using the OpenCV ``rectangle()`` method. The resultant images are then passed to the output stream and sent to the dashboard. You can replace the ``rectangle`` operation with any image processing code that is necessary for your application. You can even annotate the image using OpenCV methods to write targeting information onto the image being sent to the dashboard. .. tab-set:: diff --git a/source/docs/software/wpilib-tools/robotbuilder/introduction/robotbuilder-created-code.rst b/source/docs/software/wpilib-tools/robotbuilder/introduction/robotbuilder-created-code.rst index 6372a6b43f..71c37a73cf 100644 --- a/source/docs/software/wpilib-tools/robotbuilder/introduction/robotbuilder-created-code.rst +++ b/source/docs/software/wpilib-tools/robotbuilder/introduction/robotbuilder-created-code.rst @@ -90,7 +90,7 @@ Main Robot Program * used for any initialization code. */ @Override - public void robotInit() { + public Robot() { // Instantiate our RobotContainer. This will perform all our button bindings, and put our // autonomous chooser on the dashboard. m_robotContainer = RobotContainer.getInstance(); @@ -196,7 +196,7 @@ Main Robot Program class Robot : public frc::TimedRobot { // {1} public: - void RobotInit() override; + void Robot() override; void RobotPeriodic() override; void DisabledInit() override; void DisabledPeriodic() override; @@ -229,7 +229,7 @@ Main Robot Program #include #include - void Robot::RobotInit() {} + void Robot::Robot() {} /** * This function is called every robot packet, no matter the mode. Use diff --git a/source/docs/zero-to-robot/step-4/creating-test-drivetrain-program-cpp-java-python.rst b/source/docs/zero-to-robot/step-4/creating-test-drivetrain-program-cpp-java-python.rst index fc3f296778..e002b6b41c 100644 --- a/source/docs/zero-to-robot/step-4/creating-test-drivetrain-program-cpp-java-python.rst +++ b/source/docs/zero-to-robot/step-4/creating-test-drivetrain-program-cpp-java-python.rst @@ -406,16 +406,16 @@ Robot Initialization .. code-block:: c++ - void RobotInit() {} + void Robot() {} .. tab-item:: Python :sync: python .. code-block:: python - def robotInit(self): + def Robot(self): -The ``RobotInit`` method is run when the robot program is starting up, but after the constructor. The ``RobotInit`` for our sample program inverts the right side of the drivetrain. Depending on your drive setup, you might need to invert the left side instead. +The ``Robot`` method is run when the robot program is starting up, but after the constructor. The ``Robot`` for our sample program inverts the right side of the drivetrain. Depending on your drive setup, you might need to invert the left side instead. .. note:: In C++, the drive inversion is handled in the ``Robot()`` constructor above.