mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpilibc] DriverStation: Remove ReportError and ReportWarning
Change use cases to directly call FRC_ReportError.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -56,7 +56,7 @@ ADXL362::ADXL362(SPI::Port port, Range range)
|
||||
commands[2] = 0;
|
||||
m_spi.Transaction(commands, commands, 3);
|
||||
if (commands[2] != 0xF2) {
|
||||
DriverStation::ReportError("could not find ADXL362");
|
||||
FRC_ReportError(err::Error, "{}", "could not find ADXL362");
|
||||
m_gsPerLSB = 0.0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/Timer.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
@@ -46,7 +46,7 @@ ADXRS450_Gyro::ADXRS450_Gyro(SPI::Port port)
|
||||
if (!m_simDevice) {
|
||||
// Validate the part ID
|
||||
if ((ReadRegister(kPIDRegister) & 0xff00) != 0x5200) {
|
||||
DriverStation::ReportError("could not find ADXRS450 gyro");
|
||||
FRC_ReportError(err::Error, "{}", "could not find ADXRS450 gyro");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "frc/AnalogInput.h"
|
||||
#include "frc/Base.h"
|
||||
#include "frc/Counter.h"
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
|
||||
using namespace frc;
|
||||
@@ -72,7 +72,8 @@ units::turn_t AnalogEncoder::Get() const {
|
||||
}
|
||||
}
|
||||
|
||||
frc::DriverStation::GetInstance().ReportWarning(
|
||||
FRC_ReportError(
|
||||
warn::Warning, "{}",
|
||||
"Failed to read Analog Encoder. Potential Speed Overrun. Returning last "
|
||||
"value");
|
||||
return m_lastPosition;
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/MotorSafety.h"
|
||||
@@ -113,31 +111,6 @@ DriverStation& DriverStation::GetInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
void DriverStation::ReportError(const wpi::Twine& error) {
|
||||
wpi::SmallString<128> temp;
|
||||
HAL_SendError(1, 1, 0, error.toNullTerminatedStringRef(temp).data(), "", "",
|
||||
1);
|
||||
}
|
||||
|
||||
void DriverStation::ReportWarning(const wpi::Twine& error) {
|
||||
wpi::SmallString<128> temp;
|
||||
HAL_SendError(0, 1, 0, error.toNullTerminatedStringRef(temp).data(), "", "",
|
||||
1);
|
||||
}
|
||||
|
||||
void DriverStation::ReportError(bool isError, int32_t code,
|
||||
const wpi::Twine& error,
|
||||
const wpi::Twine& location,
|
||||
const wpi::Twine& stack) {
|
||||
wpi::SmallString<128> errorTemp;
|
||||
wpi::SmallString<128> locationTemp;
|
||||
wpi::SmallString<128> stackTemp;
|
||||
HAL_SendError(isError, code, 0,
|
||||
error.toNullTerminatedStringRef(errorTemp).data(),
|
||||
location.toNullTerminatedStringRef(locationTemp).data(),
|
||||
stack.toNullTerminatedStringRef(stackTemp).data(), 1);
|
||||
}
|
||||
|
||||
bool DriverStation::GetStickButton(int stick, int button) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
@@ -145,7 +118,7 @@ bool DriverStation::GetStickButton(int stick, int button) {
|
||||
}
|
||||
if (button <= 0) {
|
||||
ReportJoystickUnpluggedError(
|
||||
"ERROR: Button indexes begin at 1 in WPILib for C++ and Java");
|
||||
"Joystick Button {} index out of range; indexes begin at 1", button);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -154,7 +127,9 @@ bool DriverStation::GetStickButton(int stick, int button) {
|
||||
|
||||
if (button > buttons.count) {
|
||||
ReportJoystickUnpluggedWarning(
|
||||
"Joystick Button missing, check if all controllers are plugged in");
|
||||
"Joystick Button {} missing (max {}), check if all controllers are "
|
||||
"plugged in",
|
||||
button, buttons.count);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -168,7 +143,7 @@ bool DriverStation::GetStickButtonPressed(int stick, int button) {
|
||||
}
|
||||
if (button <= 0) {
|
||||
ReportJoystickUnpluggedError(
|
||||
"ERROR: Button indexes begin at 1 in WPILib for C++ and Java");
|
||||
"Joystick Button {} index out of range; indexes begin at 1", button);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -177,7 +152,9 @@ bool DriverStation::GetStickButtonPressed(int stick, int button) {
|
||||
|
||||
if (button > buttons.count) {
|
||||
ReportJoystickUnpluggedWarning(
|
||||
"Joystick Button missing, check if all controllers are plugged in");
|
||||
"Joystick Button {} missing (max {}), check if all controllers are "
|
||||
"plugged in",
|
||||
button, buttons.count);
|
||||
return false;
|
||||
}
|
||||
std::unique_lock lock(m_buttonEdgeMutex);
|
||||
@@ -197,7 +174,7 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) {
|
||||
}
|
||||
if (button <= 0) {
|
||||
ReportJoystickUnpluggedError(
|
||||
"ERROR: Button indexes begin at 1 in WPILib for C++ and Java");
|
||||
"Joystick Button {} index out of range; indexes begin at 1", button);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -206,7 +183,9 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) {
|
||||
|
||||
if (button > buttons.count) {
|
||||
ReportJoystickUnpluggedWarning(
|
||||
"Joystick Button missing, check if all controllers are plugged in");
|
||||
"Joystick Button {} missing (max {}), check if all controllers are "
|
||||
"plugged in",
|
||||
button, buttons.count);
|
||||
return false;
|
||||
}
|
||||
std::unique_lock lock(m_buttonEdgeMutex);
|
||||
@@ -234,7 +213,9 @@ double DriverStation::GetStickAxis(int stick, int axis) {
|
||||
|
||||
if (axis >= axes.count) {
|
||||
ReportJoystickUnpluggedWarning(
|
||||
"Joystick Axis missing, check if all controllers are plugged in");
|
||||
"Joystick Axis {} missing (max {}), check if all controllers are "
|
||||
"plugged in",
|
||||
axis, axes.count);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@@ -256,7 +237,9 @@ int DriverStation::GetStickPOV(int stick, int pov) {
|
||||
|
||||
if (pov >= povs.count) {
|
||||
ReportJoystickUnpluggedWarning(
|
||||
"Joystick POV missing, check if all controllers are plugged in");
|
||||
"Joystick POV {} missing (max {}), check if all controllers are "
|
||||
"plugged in",
|
||||
pov, povs.count);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -600,19 +583,21 @@ DriverStation::DriverStation() {
|
||||
m_dsThread = std::thread(&DriverStation::Run, this);
|
||||
}
|
||||
|
||||
void DriverStation::ReportJoystickUnpluggedError(const wpi::Twine& message) {
|
||||
void DriverStation::ReportJoystickUnpluggedErrorV(fmt::string_view format,
|
||||
fmt::format_args args) {
|
||||
double currentTime = Timer::GetFPGATimestamp();
|
||||
if (currentTime > m_nextMessageTime) {
|
||||
ReportError(message);
|
||||
ReportErrorV(err::Error, "", 0, "", format, args);
|
||||
m_nextMessageTime = currentTime + kJoystickUnpluggedMessageInterval;
|
||||
}
|
||||
}
|
||||
|
||||
void DriverStation::ReportJoystickUnpluggedWarning(const wpi::Twine& message) {
|
||||
void DriverStation::ReportJoystickUnpluggedWarningV(fmt::string_view format,
|
||||
fmt::format_args args) {
|
||||
if (IsFMSAttached() || !m_silenceJoystickWarning) {
|
||||
double currentTime = Timer::GetFPGATimestamp();
|
||||
if (currentTime > m_nextMessageTime) {
|
||||
ReportWarning(message);
|
||||
ReportErrorV(warn::Warning, "", 0, "", format, args);
|
||||
m_nextMessageTime = currentTime + kJoystickUnpluggedMessageInterval;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include "frc/Counter.h"
|
||||
#include "frc/DigitalInput.h"
|
||||
#include "frc/DigitalSource.h"
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/DutyCycle.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
|
||||
using namespace frc;
|
||||
@@ -94,7 +94,8 @@ units::turn_t DutyCycleEncoder::Get() const {
|
||||
}
|
||||
}
|
||||
|
||||
frc::DriverStation::GetInstance().ReportWarning(
|
||||
FRC_ReportError(
|
||||
warn::Warning, "{}",
|
||||
"Failed to read DutyCycle Encoder. Potential Speed Overrun. Returning "
|
||||
"last value");
|
||||
return m_lastPosition;
|
||||
|
||||
@@ -35,13 +35,15 @@ void RuntimeError::Report() const {
|
||||
}
|
||||
|
||||
const char* frc::GetErrorMessage(int32_t* code) {
|
||||
using namespace err;
|
||||
using namespace warn;
|
||||
switch (*code) {
|
||||
#define S(label, offset, message) \
|
||||
case label: \
|
||||
case err::label: \
|
||||
return message;
|
||||
#include "frc/WPIErrors.mac"
|
||||
#undef S
|
||||
#define S(label, offset, message) \
|
||||
case warn::label: \
|
||||
return message;
|
||||
#include "frc/WPIWarnings.mac"
|
||||
#undef S
|
||||
default:
|
||||
|
||||
@@ -6,11 +6,9 @@
|
||||
|
||||
#include <hal/DriverStation.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <wpi/Format.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/livewindow/LiveWindow.h"
|
||||
#include "frc/shuffleboard/Shuffleboard.h"
|
||||
#include "frc/smartdashboard/SmartDashboard.h"
|
||||
@@ -197,11 +195,6 @@ void IterativeRobotBase::LoopFunc() {
|
||||
}
|
||||
|
||||
void IterativeRobotBase::PrintLoopOverrunMessage() {
|
||||
wpi::SmallString<128> str;
|
||||
wpi::raw_svector_ostream buf(str);
|
||||
|
||||
buf << "Loop time of " << wpi::format("%.6f", m_period.to<double>())
|
||||
<< "s overrun\n";
|
||||
|
||||
DriverStation::ReportWarning(str);
|
||||
FRC_ReportError(err::Error, "Loop time of {:.6f}s overrun",
|
||||
m_period.to<double>());
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -36,7 +36,7 @@ void Tracer::PrintEpochs() {
|
||||
wpi::raw_svector_ostream os(buf);
|
||||
PrintEpochs(os);
|
||||
if (!buf.empty()) {
|
||||
DriverStation::ReportWarning(buf);
|
||||
FRC_ReportError(warn::Warning, "{}", buf.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,15 +5,14 @@
|
||||
#include "frc/Watchdog.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <hal/Notifier.h>
|
||||
#include <wpi/Format.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/priority_queue.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc2/Timer.h"
|
||||
|
||||
@@ -114,11 +113,8 @@ void Watchdog::Impl::Main() {
|
||||
if (now - watchdog->m_lastTimeoutPrintTime > kMinPrintPeriod) {
|
||||
watchdog->m_lastTimeoutPrintTime = now;
|
||||
if (!watchdog->m_suppressTimeoutMessage) {
|
||||
wpi::SmallString<128> buf;
|
||||
wpi::raw_svector_ostream err(buf);
|
||||
err << "Watchdog not fed within "
|
||||
<< wpi::format("%.6f", watchdog->m_timeout.to<double>()) << "s\n";
|
||||
frc::DriverStation::ReportWarning(err.str());
|
||||
FRC_ReportError(warn::Warning, "Watchdog not fed within {:.6f}s",
|
||||
watchdog->m_timeout.to<double>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/MathUtil.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
@@ -20,10 +20,13 @@ PIDController::PIDController(double Kp, double Ki, double Kd,
|
||||
units::second_t period)
|
||||
: m_Kp(Kp), m_Ki(Ki), m_Kd(Kd), m_period(period) {
|
||||
if (period <= 0_s) {
|
||||
frc::DriverStation::ReportError(
|
||||
"Controller period must be a non-zero positive number!");
|
||||
FRC_ReportError(
|
||||
frc::err::Error,
|
||||
"Controller period must be a non-zero positive number, got {}!",
|
||||
period.to<double>());
|
||||
m_period = 20_ms;
|
||||
frc::DriverStation::ReportWarning("Controller period defaulted to 20ms.");
|
||||
FRC_ReportError(frc::warn::Warning, "{}",
|
||||
"Controller period defaulted to 20ms.");
|
||||
}
|
||||
static int instances = 0;
|
||||
instances++;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "frc/shuffleboard/RecordingController.h"
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace frc::detail;
|
||||
@@ -38,7 +38,8 @@ void RecordingController::AddEventMarker(
|
||||
wpi::StringRef name, wpi::StringRef description,
|
||||
ShuffleboardEventImportance importance) {
|
||||
if (name.empty()) {
|
||||
DriverStation::ReportError("Shuffleboard event name was not specified");
|
||||
FRC_ReportError(err::Error, "{}",
|
||||
"Shuffleboard event name was not specified");
|
||||
return;
|
||||
}
|
||||
m_eventsTable->GetSubTable(name)->GetEntry("Info").SetStringArray(
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <wpi/MathExtras.h>
|
||||
|
||||
#include "frc/RobotController.h"
|
||||
#include "frc/system/NumericalIntegration.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user