[examples] Prepare for RobotInit deprecation by updating examples (#6623)

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
Jade
2024-07-17 11:22:39 +08:00
committed by GitHub
parent f62a055608
commit 57fa388724
156 changed files with 260 additions and 355 deletions

View File

@@ -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);

View File

@@ -12,7 +12,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
private:

View File

@@ -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:
@@ -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

View File

@@ -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.

View File

@@ -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.

View File

@@ -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

View File

@@ -13,7 +13,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;

View File

@@ -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

View File

@@ -13,7 +13,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;

View File

@@ -14,7 +14,7 @@
*/
class Robot : public frc::TimedRobot {
public:
void RobotInit() override {}
Robot() {}
void SimulationPeriodic() override;
void TeleopInit() override;
void TeleopPeriodic() override;

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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

View File

@@ -13,7 +13,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;

View File

@@ -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.

View File

@@ -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

View File

@@ -14,7 +14,7 @@
*/
class Robot : public frc::TimedRobot {
public:
void RobotInit() override {}
Robot() {}
void RobotPeriodic() override;
void SimulationPeriodic() override;
void TeleopInit() override;

View File

@@ -14,7 +14,7 @@
*/
class Robot : public frc::TimedRobot {
public:
void RobotInit() override {}
Robot() {}
void RobotPeriodic() override;
void SimulationPeriodic() override;
void TeleopPeriodic() override;

View File

@@ -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] {

View File

@@ -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);
}

View File

@@ -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

View File

@@ -11,7 +11,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;

View File

@@ -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

View File

@@ -11,7 +11,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;

View File

@@ -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);
}
/**

View File

@@ -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

View File

@@ -13,7 +13,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;

View File

@@ -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);

View File

@@ -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();

View File

@@ -11,7 +11,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;

View File

@@ -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();

View File

@@ -11,7 +11,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;

View File

@@ -15,6 +15,14 @@
* processing.
*/
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.
std::thread visionThread(VisionThread);
visionThread.detach();
}
private:
static void VisionThread() {
// Create an HTTP camera. The address will need to be modified to have the
@@ -50,13 +58,6 @@ class Robot : public frc::TimedRobot {
outputStream.PutFrame(mat);
}
}
void RobotInit() override {
// We need to run our vision program in a separate thread. If not, our robot
// program will not run.
std::thread visionThread(VisionThread);
visionThread.detach();
}
};
#ifndef RUNNING_FRC_TESTS

View File

@@ -18,6 +18,19 @@
* processing.
*/
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:
@@ -55,18 +68,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

View File

@@ -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

View File

@@ -13,7 +13,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;

View File

@@ -13,7 +13,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);

View File

@@ -30,7 +30,7 @@ class Robot : public frc::TimedRobot {
static constexpr double kElevatorMinimumLength = 0.5;
public:
void RobotInit() override {
Robot() {
m_elevatorEncoder.SetDistancePerPulse(kMetersPerPulse);
// publish to dashboard

View File

@@ -33,7 +33,7 @@ class Robot : public frc::TimedRobot {
frc::SmartDashboard::PutNumber("Encoder", m_encoder.GetDistance());
}
void RobotInit() override {
Robot() {
// Use SetDistancePerPulse to set the multiplier for GetDistance
// This is set up assuming a 6 inch wheel with a 360 CPR encoder.
m_encoder.SetDistancePerPulse((std::numbers::pi * 6) / 360.0);

View File

@@ -11,11 +11,11 @@
* Uses the CameraServer class to automatically capture video from a USB webcam
* and send it to the FRC dashboard without doing any vision processing. This is
* the easiest way to get camera images to the dashboard. Just add this to the
* RobotInit() method in your program.
* robot class constructor.
*/
class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
Robot() {
#if defined(__linux__) || defined(_WIN32)
frc::CameraServer::StartAutomaticCapture();
#else

View File

@@ -4,7 +4,7 @@
#include "Robot.h"
void Robot::RobotInit() {
Robot::Robot() {
// Configure default commands and condition bindings on robot startup
m_robot.ConfigureBindings();
}

View File

@@ -27,7 +27,7 @@ class RapidReactCommandBot {
* Use this method to define bindings between conditions and commands. These
* are useful for automating robot behaviors based on button and sensor input.
*
* <p>Should be called during Robot::RobotInit().
* <p>Should be called in the robot class constructor.
*
* <p>Event binding methods are available on the frc2::Trigger class.
*/

View File

@@ -13,7 +13,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;

View File

@@ -6,7 +6,7 @@
#include <frc2/command/CommandScheduler.h>
void Robot::RobotInit() {}
Robot::Robot() {}
/**
* This function is called every 20 ms, no matter the mode. Use

View File

@@ -11,7 +11,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;

View File

@@ -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

View File

@@ -11,7 +11,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;

View File

@@ -29,7 +29,7 @@
*/
class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
Robot() {
wpi::SendableRegistry::AddChild(&m_robotDrive, &m_left);
wpi::SendableRegistry::AddChild(&m_robotDrive, &m_right);

View File

@@ -13,7 +13,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
Robot() {
m_trajectory = frc::TrajectoryGenerator::GenerateTrajectory(
frc::Pose2d{2_m, 2_m, 0_rad}, {}, frc::Pose2d{6_m, 4_m, 0_rad},
frc::TrajectoryConfig(2_mps, 2_mps_sq));

View File

@@ -7,7 +7,7 @@
#include <frc/shuffleboard/Shuffleboard.h>
#include <units/pressure.h>
void Robot::RobotInit() {
Robot::Robot() {
// Publish elements to shuffleboard.
frc::ShuffleboardTab& tab = frc::Shuffleboard::GetTab("Pneumatics");
tab.Add("Single Solenoid", m_solenoid);

View File

@@ -35,7 +35,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void TeleopPeriodic() override;
private:

View File

@@ -93,7 +93,7 @@ class Robot : public frc::TimedRobot {
frc::TrapezoidProfile<units::radians>::State m_lastProfiledReference;
public:
void RobotInit() override {
Robot() {
// We go 2 pi radians per 4096 clicks.
m_encoder.SetDistancePerPulse(2.0 * std::numbers::pi / 4096.0);
}

View File

@@ -92,7 +92,7 @@ class Robot : public frc::TimedRobot {
frc::TrapezoidProfile<units::meters>::State m_lastProfiledReference;
public:
void RobotInit() override {
Robot() {
// Circumference = pi * d, so distance per click = pi * d / counts
m_encoder.SetDistancePerPulse(2.0 * std::numbers::pi * kDrumRadius.value() /
4096.0);

View File

@@ -80,7 +80,7 @@ class Robot : public frc::TimedRobot {
frc::XboxController m_joystick{kJoystickPort};
public:
void RobotInit() override {
Robot() {
// We go 2 pi radians per 4096 clicks.
m_encoder.SetDistancePerPulse(2.0 * std::numbers::pi / 4096.0);
}

View File

@@ -80,7 +80,7 @@ class Robot : public frc::TimedRobot {
frc::XboxController m_joystick{kJoystickPort};
public:
void RobotInit() override {
Robot() {
// We go 2 pi radians per 4096 clicks.
m_encoder.SetDistancePerPulse(2.0 * std::numbers::pi / 4096.0);
}

View File

@@ -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

View File

@@ -13,7 +13,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;

View File

@@ -6,7 +6,7 @@
#include <frc2/command/CommandScheduler.h>
void Robot::RobotInit() {}
Robot::Robot() {}
void Robot::RobotPeriodic() {
frc2::CommandScheduler::GetInstance().Run();

View File

@@ -13,7 +13,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;

View File

@@ -21,7 +21,7 @@ class Robot : public frc::TimedRobot {
frc::Joystick m_rightStick{1};
public:
void RobotInit() override {
Robot() {
wpi::SendableRegistry::AddChild(&m_robotDrive, &m_leftMotor);
wpi::SendableRegistry::AddChild(&m_robotDrive, &m_rightMotor);

View File

@@ -20,7 +20,7 @@ class Robot : public frc::TimedRobot {
frc::XboxController m_driverController{0};
public:
void RobotInit() override {
Robot() {
wpi::SendableRegistry::AddChild(&m_robotDrive, &m_leftMotor);
wpi::SendableRegistry::AddChild(&m_robotDrive, &m_rightMotor);

View File

@@ -8,7 +8,7 @@
#include <frc/smartdashboard/SmartDashboard.h>
#include <units/length.h>
void Robot::RobotInit() {
Robot::Robot() {
// Add the ultrasonic on the "Sensors" tab of the dashboard
// Data will update automatically
frc::Shuffleboard::GetTab("Sensors").Add(m_rangeFinder);

View File

@@ -13,7 +13,7 @@
*/
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void TeleopPeriodic() override;
void TestInit() override;
void TestPeriodic() override;

View File

@@ -6,7 +6,7 @@
#include <frc2/command/CommandScheduler.h>
void Robot::RobotInit() {}
Robot::Robot() {}
/**
* This function is called every 20 ms, no matter the mode. Use

View File

@@ -11,7 +11,7 @@
class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;