[wpilib] Split DriverStation into smaller classes (#8628)

This commit is contained in:
Thad House
2026-04-18 19:56:45 -07:00
committed by GitHub
parent 58ad633ae2
commit ab2aef2c29
108 changed files with 4406 additions and 3211 deletions

View File

@@ -4,7 +4,8 @@
#include "wpi/framework/IterativeRobotBase.hpp"
#include "wpi/driverstation/DriverStation.hpp"
#include "wpi/driverstation/RobotState.hpp"
#include "wpi/driverstation/internal/DriverStationBackend.hpp"
#include "wpi/hal/DriverStation.h"
#include "wpi/hal/DriverStationTypes.h"
#include "wpi/nt/NetworkTableInstance.hpp"
@@ -91,7 +92,7 @@ wpi::units::second_t IterativeRobotBase::GetPeriod() const {
}
void IterativeRobotBase::LoopFunc() {
DriverStation::RefreshData();
wpi::internal::DriverStationBackend::RefreshData();
m_watchdog.Reset();
// Get current mode; treat disabled as unknown

View File

@@ -12,7 +12,8 @@
#include <fmt/format.h>
#include "wpi/driverstation/DriverStation.hpp"
#include "wpi/driverstation/RobotState.hpp"
#include "wpi/driverstation/internal/DriverStationBackend.hpp"
#include "wpi/hal/DriverStation.h"
#include "wpi/hal/DriverStationTypes.h"
#include "wpi/hal/HAL.h"
@@ -54,10 +55,11 @@ void OpModeRobotBase::AddPeriodic(std::function<void()> callback,
}
void OpModeRobotBase::LoopFunc() {
DriverStation::RefreshData();
wpi::internal::DriverStationBackend::RefreshData();
// Get current enabled state and opmode
const hal::ControlWord word = DriverStation::GetControlWord();
const hal::ControlWord word =
wpi::internal::DriverStationBackend::GetControlWord();
m_watchdog.Reset();
const bool enabled = word.IsEnabled();
int64_t modeId = word.IsDSAttached() ? word.GetOpModeId() : 0;
@@ -194,7 +196,7 @@ void OpModeRobotBase::StartCompetition() {
}
// Tell the DS that the robot is ready to be enabled
DriverStation::ObserveUserProgramStarting();
wpi::internal::DriverStationBackend::ObserveUserProgramStarting();
// Loop forever, calling the callback system which handles periodic functions
while (true) {
@@ -215,8 +217,8 @@ void OpModeRobotBase::AddOpModeFactory(
std::string_view group, std::string_view description,
const wpi::util::Color& textColor,
const wpi::util::Color& backgroundColor) {
int64_t id = DriverStation::AddOpMode(mode, name, group, description,
textColor, backgroundColor);
int64_t id = RobotState::AddOpMode(mode, name, group, description, textColor,
backgroundColor);
if (id != 0) {
m_opModes[id] = OpModeData{std::string{name}, std::move(factory)};
}
@@ -226,24 +228,24 @@ void OpModeRobotBase::AddOpModeFactory(OpModeFactory factory, RobotMode mode,
std::string_view name,
std::string_view group,
std::string_view description) {
int64_t id = DriverStation::AddOpMode(mode, name, group, description);
int64_t id = RobotState::AddOpMode(mode, name, group, description);
if (id != 0) {
m_opModes[id] = OpModeData{std::string{name}, std::move(factory)};
}
}
void OpModeRobotBase::RemoveOpMode(RobotMode mode, std::string_view name) {
int64_t id = DriverStation::RemoveOpMode(mode, name);
int64_t id = RobotState::RemoveOpMode(mode, name);
if (id != 0) {
m_opModes.erase(id);
}
}
void OpModeRobotBase::PublishOpModes() {
DriverStation::PublishOpModes();
RobotState::PublishOpModes();
}
void OpModeRobotBase::ClearOpModes() {
DriverStation::ClearOpModes();
RobotState::ClearOpModes();
m_opModes.clear();
}

View File

@@ -10,6 +10,7 @@
#include <utility>
#include "wpi/driverstation/DriverStation.hpp"
#include "wpi/driverstation/internal/DriverStationBackend.hpp"
#include "wpi/hal/DriverStation.hpp"
#include "wpi/hal/UsageReporting.hpp"
#include "wpi/system/Errors.hpp"
@@ -24,7 +25,7 @@ void TimedRobot::StartCompetition() {
// Tell the DS that the robot is ready to be enabled
std::puts("\n********** Robot program startup complete **********");
DriverStation::ObserveUserProgramStarting();
wpi::internal::DriverStationBackend::ObserveUserProgramStarting();
// Loop forever, calling the appropriate mode-dependent function
while (true) {