Skip to content

Commit

Permalink
[examples] Prepare for RobotInit deprecation by updating examples (#6623
Browse files Browse the repository at this point in the history
)

Co-authored-by: Tyler Veness <[email protected]>
  • Loading branch information
spacey-sooty and calcmogul authored Jul 17, 2024
1 parent f62a055 commit 57fa388
Show file tree
Hide file tree
Showing 156 changed files with 260 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
* private double angleToTote = 0;
* private double distanceToTote = 0;
*
* public Robot() {
* usbCamera = CameraServer.startAutomaticCapture(0);
* findTotePipeline = new MyFindTotePipeline();
* findToteThread = new VisionThread(usbCamera, findTotePipeline, this);
* }
*
* {@literal @}Override
* public void {@link edu.wpi.first.vision.VisionRunner.Listener#copyPipelineOutputs
* copyPipelineOutputs(MyFindTotePipeline pipeline)} {
Expand All @@ -43,13 +49,6 @@
* }
*
* {@literal @}Override
* public void robotInit() {
* usbCamera = CameraServer.startAutomaticCapture(0);
* findTotePipeline = new MyFindTotePipeline();
* findToteThread = new VisionThread(usbCamera, findTotePipeline, this);
* }
*
* {@literal @}Override
* public void autonomousInit() {
* findToteThread.start();
* }
Expand Down
3 changes: 1 addition & 2 deletions developerRobot/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public class Robot extends TimedRobot {
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {}
public Robot() {}

/** This function is run once each time the robot enters autonomous mode. */
@Override
Expand Down
3 changes: 2 additions & 1 deletion developerRobot/src/main/native/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#include <frc/TimedRobot.h>

class Robot : public frc::TimedRobot {
public:
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
void RobotInit() override {}
Robot() {}

/**
* This function is run once each time the robot enters autonomous mode
Expand Down
6 changes: 2 additions & 4 deletions wpilibc/src/main/native/include/frc/IterativeRobotBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ class IterativeRobotBase : public RobotBase {
* which will be called when the robot is first powered on. It will be called
* exactly one time.
*
* Warning: the Driver Station "Robot Code" light and FMS "Robot Ready"
* indicators will be off until RobotInit() exits. Code in RobotInit() that
* waits for enable will cause the robot to never indicate that the code is
* ready, causing the robot to be bypassed in a match.
* Note: This method is functionally identical to the class constructor so
* that should be used instead.
*/
virtual void RobotInit();

Expand Down
4 changes: 1 addition & 3 deletions wpilibc/src/test/native/cpp/TimedRobotTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ class MockRobot : public TimedRobot {
std::atomic<uint32_t> m_teleopPeriodicCount{0};
std::atomic<uint32_t> m_testPeriodicCount{0};

MockRobot() : TimedRobot{kPeriod} {}

void RobotInit() override { m_robotInitCount++; }
MockRobot() : TimedRobot{kPeriod} { m_robotInitCount++; }

void SimulationInit() override { m_simulationInitCount++; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "Robot.h"

void Robot::RobotInit() {
Robot::Robot() {
// Default to a length of 60, start empty output
// Length is expensive to set, so only set it once, then just update data
m_led.SetLength(kLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;

private:
Expand Down
25 changes: 13 additions & 12 deletions wpilibcExamples/src/main/cpp/examples/AprilTagsVision/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@
* solution!
*/
class Robot : public frc::TimedRobot {
public:
Robot() {
// We need to run our vision program in a separate thread. If not, our robot
// program will not run.
#if defined(__linux__) || defined(_WIN32)
std::thread visionThread(VisionThread);
visionThread.detach();
#else
std::fputs("Vision only available on Linux or Windows.\n", stderr);
std::fflush(stderr);
#endif
}

#if defined(__linux__) || defined(_WIN32)

private:
Expand Down Expand Up @@ -147,18 +160,6 @@ class Robot : public frc::TimedRobot {
}
}
#endif

void RobotInit() override {
// We need to run our vision program in a separate thread. If not, our robot
// program will not run.
#if defined(__linux__) || defined(_WIN32)
std::thread visionThread(VisionThread);
visionThread.detach();
#else
std::fputs("Vision only available on Linux or Windows.\n", stderr);
std::fflush(stderr);
#endif
}
};

#ifndef RUNNING_FRC_TESTS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class Robot : public frc::TimedRobot {
Robot() {
wpi::SendableRegistry::AddChild(&m_robotDrive, &m_leftMotor);
wpi::SendableRegistry::AddChild(&m_robotDrive, &m_rightMotor);
}

void RobotInit() override {
// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
// gearbox is constructed, you might have to invert the left side instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class Robot : public frc::TimedRobot {
Robot() {
wpi::SendableRegistry::AddChild(&m_robotDrive, &m_leftMotor);
wpi::SendableRegistry::AddChild(&m_robotDrive, &m_rightMotor);
}

void RobotInit() override {
// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
// gearbox is constructed, you might have to invert the left side instead.
Expand Down
2 changes: 1 addition & 1 deletion wpilibcExamples/src/main/cpp/examples/ArmBot/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <frc/smartdashboard/SmartDashboard.h>
#include <frc2/command/CommandScheduler.h>

void Robot::RobotInit() {}
Robot::Robot() {}

/**
* This function is called every 20 ms, no matter the mode. Use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <frc/smartdashboard/SmartDashboard.h>
#include <frc2/command/CommandScheduler.h>

void Robot::RobotInit() {}
Robot::Robot() {}

/**
* This function is called every 20 ms, no matter the mode. Use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class Robot : public frc::TimedRobot {
public:
void RobotInit() override {}
Robot() {}
void SimulationPeriodic() override;
void TeleopInit() override;
void TeleopPeriodic() override;
Expand Down
2 changes: 1 addition & 1 deletion wpilibcExamples/src/main/cpp/examples/CANPDP/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
Robot() {
// Put the PDP itself to the dashboard
frc::SmartDashboard::PutData("PDP", &m_pdp);
}
Expand Down
2 changes: 1 addition & 1 deletion wpilibcExamples/src/main/cpp/examples/DMA/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Robot : public frc::TimedRobot {
frc::Encoder m_encoder{0, 1};

public:
void RobotInit() override {
Robot() {
// Trigger on falling edge of dma trigger output
m_dma.SetExternalTrigger(&m_dmaTrigger, false, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <frc/smartdashboard/SmartDashboard.h>
#include <frc2/command/CommandScheduler.h>

void Robot::RobotInit() {}
Robot::Robot() {}

/**
* This function is called every 20 ms, no matter the mode. Use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Robot : public frc::TimedRobot {
frc::DutyCycleEncoder m_dutyCycleEncoder{0, fullRange, expectedZero};

public:
void RobotInit() override {
Robot() {
// If you know the frequency of your sensor, uncomment the following
// method, and set the method to the frequency of your sensor.
// This will result in more stable readings from the sensor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Robot : public frc::TimedRobot {
frc::DutyCycle m_dutyCycle{m_input}; // Duty cycle input

public:
void RobotInit() override {}
Robot() {}

void RobotPeriodic() override {
// Duty Cycle Frequency in Hz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class Robot : public frc::TimedRobot {
public:
void RobotInit() override {}
Robot() {}
void RobotPeriodic() override;
void SimulationPeriodic() override;
void TeleopInit() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class Robot : public frc::TimedRobot {
public:
void RobotInit() override {}
Robot() {}
void RobotPeriodic() override;
void SimulationPeriodic() override;
void TeleopPeriodic() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static const auto KICKER_THRESHOLD = 15_mm;

class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
Robot() {
m_controller.SetTolerance(TOLERANCE.value());

frc::BooleanEvent isBallAtKicker{&m_loop, [&kickerSensor = m_kickerSensor] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Robot : public frc::TimedRobot {
0.9 * m_feedforward.Calculate(setpoint));
}

void RobotInit() override {
Robot() {
// Add bang-bang controler to SmartDashboard and networktables.
frc::SmartDashboard::PutData("BangBangControler", &m_bangBangControler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <frc/smartdashboard/SmartDashboard.h>
#include <frc2/command/CommandScheduler.h>

void Robot::RobotInit() {}
Robot::Robot() {}

/**
* This function is called every 20 ms, no matter the mode. Use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <frc/smartdashboard/SmartDashboard.h>
#include <frc2/command/CommandScheduler.h>

void Robot::RobotInit() {}
Robot::Robot() {}

/**
* This function is called every 20 ms, no matter the mode. Use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;
Expand Down
8 changes: 3 additions & 5 deletions wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
class Robot : public frc::TimedRobot {
public:
Robot() {
wpi::SendableRegistry::AddChild(&m_drive, &m_left);
wpi::SendableRegistry::AddChild(&m_drive, &m_right);
}

void RobotInit() override {
m_gyro.SetSensitivity(kVoltsPerDegreePerSecond);
// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
// gearbox is constructed, you might have to invert the left side instead.
m_right.SetInverted(true);

wpi::SendableRegistry::AddChild(&m_drive, &m_left);
wpi::SendableRegistry::AddChild(&m_drive, &m_right);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <frc/smartdashboard/SmartDashboard.h>
#include <frc2/command/CommandScheduler.h>

void Robot::RobotInit() {}
Robot::Robot() {}

/**
* This function is called every 20 ms, no matter the mode. Use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
Robot() {
wpi::SendableRegistry::AddChild(&m_robotDrive, &m_frontLeft);
wpi::SendableRegistry::AddChild(&m_robotDrive, &m_rearLeft);
wpi::SendableRegistry::AddChild(&m_robotDrive, &m_frontRight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <frc/smartdashboard/SmartDashboard.h>
#include <frc2/command/CommandScheduler.h>

void Robot::RobotInit() {
Robot::Robot() {
// Start recording to data log
frc::DataLogManager::Start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <frc/smartdashboard/SmartDashboard.h>
#include <frc2/command/CommandScheduler.h>

void Robot::RobotInit() {
Robot::Robot() {
// Start recording to data log
frc::DataLogManager::Start();

Expand Down
Loading

0 comments on commit 57fa388

Please sign in to comment.