mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib] Split DriverStation into smaller classes (#8628)
This commit is contained in:
@@ -4,21 +4,21 @@
|
||||
|
||||
#include "Robot.hpp"
|
||||
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/driverstation/MatchState.hpp"
|
||||
#include "wpi/driverstation/RobotState.hpp"
|
||||
|
||||
void Robot::RobotPeriodic() {
|
||||
// pull alliance port high if on red alliance, pull low if on blue alliance
|
||||
m_allianceOutput.Set(wpi::DriverStation::GetAlliance() ==
|
||||
wpi::DriverStation::Alliance::RED);
|
||||
m_allianceOutput.Set(wpi::MatchState::GetAlliance() == wpi::Alliance::RED);
|
||||
|
||||
// pull enabled port high if enabled, low if disabled
|
||||
m_enabledOutput.Set(wpi::DriverStation::IsEnabled());
|
||||
m_enabledOutput.Set(wpi::RobotState::IsEnabled());
|
||||
|
||||
// pull auto port high if in autonomous, low if in teleop (or disabled)
|
||||
m_autonomousOutput.Set(wpi::DriverStation::IsAutonomous());
|
||||
m_autonomousOutput.Set(wpi::RobotState::IsAutonomous());
|
||||
|
||||
// pull alert port high if match time remaining is between 30 and 25 seconds
|
||||
auto matchTime = wpi::DriverStation::GetMatchTime();
|
||||
auto matchTime = wpi::MatchState::GetMatchTime();
|
||||
m_alertOutput.Set(matchTime <= 30_s && matchTime >= 25_s);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/driverstation/MatchState.hpp"
|
||||
#include "wpi/driverstation/RobotState.hpp"
|
||||
#include "wpi/system/Timer.hpp"
|
||||
|
||||
void Robot::RobotPeriodic() {
|
||||
@@ -23,20 +24,19 @@ void Robot::RobotPeriodic() {
|
||||
// alliance, enabled in teleop mode, with 43 seconds left in the match.
|
||||
|
||||
std::string allianceString = "U";
|
||||
auto alliance = wpi::DriverStation::GetAlliance();
|
||||
auto alliance = wpi::MatchState::GetAlliance();
|
||||
if (alliance.has_value()) {
|
||||
if (alliance == wpi::DriverStation::Alliance::RED) {
|
||||
if (alliance == wpi::Alliance::RED) {
|
||||
allianceString = "R";
|
||||
} else {
|
||||
allianceString = "B";
|
||||
}
|
||||
}
|
||||
|
||||
auto string =
|
||||
fmt::format("{}{}{}{:03}", allianceString,
|
||||
wpi::DriverStation::IsEnabled() ? "E" : "D",
|
||||
wpi::DriverStation::IsAutonomous() ? "A" : "T",
|
||||
static_cast<int>(wpi::Timer::GetMatchTime().value()));
|
||||
auto string = fmt::format(
|
||||
"{}{}{}{:03}", allianceString, wpi::RobotState::IsEnabled() ? "E" : "D",
|
||||
wpi::RobotState::IsAutonomous() ? "A" : "T",
|
||||
static_cast<int>(wpi::Timer::GetMatchTime().value()));
|
||||
|
||||
arduino.WriteBulk(reinterpret_cast<uint8_t*>(string.data()), string.size());
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
#include "Robot.hpp"
|
||||
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/driverstation/RobotState.hpp"
|
||||
#include "wpi/driverstation/internal/DriverStationBackend.hpp"
|
||||
#include "wpi/hal/DriverStation.h"
|
||||
#include "wpi/internal/DriverStationModeThread.hpp"
|
||||
|
||||
@@ -22,19 +23,20 @@ void Robot::StartCompetition() {
|
||||
wpi::internal::DriverStationModeThread modeThread{wpi::hal::GetControlWord()};
|
||||
|
||||
// Create an opmode per robot mode
|
||||
wpi::DriverStation::AddOpMode(wpi::RobotMode::AUTONOMOUS, "Auto");
|
||||
wpi::DriverStation::AddOpMode(wpi::RobotMode::TELEOPERATED, "Teleop");
|
||||
wpi::DriverStation::AddOpMode(wpi::RobotMode::TEST, "Test");
|
||||
wpi::DriverStation::PublishOpModes();
|
||||
wpi::RobotState::AddOpMode(wpi::RobotMode::AUTONOMOUS, "Auto");
|
||||
wpi::RobotState::AddOpMode(wpi::RobotMode::TELEOPERATED, "Teleop");
|
||||
wpi::RobotState::AddOpMode(wpi::RobotMode::TEST, "Test");
|
||||
wpi::RobotState::PublishOpModes();
|
||||
|
||||
wpi::util::Event event{false, false};
|
||||
wpi::DriverStation::ProvideRefreshedDataEventHandle(event.GetHandle());
|
||||
wpi::internal::DriverStationBackend::ProvideRefreshedDataEventHandle(
|
||||
event.GetHandle());
|
||||
|
||||
// Tell the DS that the robot is ready to be enabled
|
||||
wpi::DriverStation::ObserveUserProgramStarting();
|
||||
wpi::internal::DriverStationBackend::ObserveUserProgramStarting();
|
||||
|
||||
while (!m_exit) {
|
||||
modeThread.InControl(wpi::DriverStation::GetControlWord());
|
||||
modeThread.InControl(wpi::internal::DriverStationBackend::GetControlWord());
|
||||
if (IsDisabled()) {
|
||||
Disabled();
|
||||
while (IsDisabled()) {
|
||||
|
||||
Reference in New Issue
Block a user