mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib] DriverStation: Change alliance station to use optional (#5229)
Many teams have issues trying to read the DS too early. By switching to an optional, we cause teams to check 2 things. Either 1) they explicitly check, and their code is correct, or 2) they just read .value() and their code reboots in a loop. However, because the DS will eventually connect, this 2nd case is ok, and should theoretically be undetectable on the field.
This commit is contained in:
@@ -18,14 +18,18 @@ void Robot::RobotPeriodic() {
|
||||
//
|
||||
// For example, "RET043" would indicate that the robot is on the red
|
||||
// alliance, enabled in teleop mode, with 43 seconds left in the match.
|
||||
auto string = fmt::format(
|
||||
"{}{}{}{:03}",
|
||||
frc::DriverStation::GetAlliance() == frc::DriverStation::Alliance::kRed
|
||||
? "R"
|
||||
: "B",
|
||||
frc::DriverStation::IsEnabled() ? "E" : "D",
|
||||
frc::DriverStation::IsAutonomous() ? "A" : "T",
|
||||
static_cast<int>(frc::Timer::GetMatchTime().value()));
|
||||
|
||||
std::string allianceString = "U";
|
||||
auto alliance = frc::DriverStation::GetAlliance();
|
||||
if (alliance.has_value()) {
|
||||
allianceString = alliance == frc::DriverStation::Alliance::kRed ? "R" : "B";
|
||||
}
|
||||
|
||||
auto string =
|
||||
fmt::format("{}{}{}{:03}", allianceString,
|
||||
frc::DriverStation::IsEnabled() ? "E" : "D",
|
||||
frc::DriverStation::IsAutonomous() ? "A" : "T",
|
||||
static_cast<int>(frc::Timer::GetMatchTime().value()));
|
||||
|
||||
arduino.WriteBulk(reinterpret_cast<uint8_t*>(string.data()), string.size());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user