mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[wpilib] Deprecate getInstance() in favor of static functions (#3440)
Co-authored-by: Noam Zaks <imnoamzaks@gmail.com>
This commit is contained in:
@@ -29,7 +29,7 @@ ADXL345_I2C::ADXL345_I2C(I2C::Port port, Range range, int deviceAddress)
|
||||
HAL_Report(HALUsageReporting::kResourceType_ADXL345,
|
||||
HALUsageReporting::kADXL345_I2C, 0);
|
||||
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "ADXL345_I2C", port);
|
||||
wpi::SendableRegistry::AddLW(this, "ADXL345_I2C", port);
|
||||
}
|
||||
|
||||
void ADXL345_I2C::SetRange(Range range) {
|
||||
|
||||
@@ -37,7 +37,7 @@ ADXL345_SPI::ADXL345_SPI(SPI::Port port, ADXL345_SPI::Range range)
|
||||
HAL_Report(HALUsageReporting::kResourceType_ADXL345,
|
||||
HALUsageReporting::kADXL345_SPI);
|
||||
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "ADXL345_SPI", port);
|
||||
wpi::SendableRegistry::AddLW(this, "ADXL345_SPI", port);
|
||||
}
|
||||
|
||||
void ADXL345_SPI::SetRange(Range range) {
|
||||
|
||||
@@ -72,7 +72,7 @@ ADXL362::ADXL362(SPI::Port port, Range range)
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_ADXL362, port + 1);
|
||||
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "ADXL362", port);
|
||||
wpi::SendableRegistry::AddLW(this, "ADXL362", port);
|
||||
}
|
||||
|
||||
void ADXL362::SetRange(Range range) {
|
||||
|
||||
@@ -58,7 +58,7 @@ ADXRS450_Gyro::ADXRS450_Gyro(SPI::Port port)
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_ADXRS450, port + 1);
|
||||
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "ADXRS450_Gyro", port);
|
||||
wpi::SendableRegistry::AddLW(this, "ADXRS450_Gyro", port);
|
||||
}
|
||||
|
||||
static bool CalcParity(int v) {
|
||||
|
||||
@@ -15,7 +15,7 @@ using namespace frc;
|
||||
|
||||
AnalogAccelerometer::AnalogAccelerometer(int channel)
|
||||
: AnalogAccelerometer(std::make_shared<AnalogInput>(channel)) {
|
||||
wpi::SendableRegistry::GetInstance().AddChild(this, m_analogInput.get());
|
||||
wpi::SendableRegistry::AddChild(this, m_analogInput.get());
|
||||
}
|
||||
|
||||
AnalogAccelerometer::AnalogAccelerometer(AnalogInput* channel)
|
||||
@@ -56,6 +56,6 @@ void AnalogAccelerometer::InitAccelerometer() {
|
||||
HAL_Report(HALUsageReporting::kResourceType_Accelerometer,
|
||||
m_analogInput->GetChannel() + 1);
|
||||
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "Accelerometer",
|
||||
m_analogInput->GetChannel());
|
||||
wpi::SendableRegistry::AddLW(this, "Accelerometer",
|
||||
m_analogInput->GetChannel());
|
||||
}
|
||||
|
||||
@@ -50,8 +50,8 @@ void AnalogEncoder::Init() {
|
||||
m_counter.SetDownSource(
|
||||
m_analogTrigger.CreateOutput(AnalogTriggerType::kFallingPulse));
|
||||
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "DutyCycle Encoder",
|
||||
m_analogInput->GetChannel());
|
||||
wpi::SendableRegistry::AddLW(this, "DutyCycle Encoder",
|
||||
m_analogInput->GetChannel());
|
||||
}
|
||||
|
||||
units::turn_t AnalogEncoder::Get() const {
|
||||
|
||||
@@ -23,7 +23,7 @@ using namespace frc;
|
||||
|
||||
AnalogGyro::AnalogGyro(int channel)
|
||||
: AnalogGyro(std::make_shared<AnalogInput>(channel)) {
|
||||
wpi::SendableRegistry::GetInstance().AddChild(this, m_analog.get());
|
||||
wpi::SendableRegistry::AddChild(this, m_analog.get());
|
||||
}
|
||||
|
||||
AnalogGyro::AnalogGyro(AnalogInput* channel)
|
||||
@@ -41,7 +41,7 @@ AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel)
|
||||
|
||||
AnalogGyro::AnalogGyro(int channel, int center, double offset)
|
||||
: AnalogGyro(std::make_shared<AnalogInput>(channel), center, offset) {
|
||||
wpi::SendableRegistry::GetInstance().AddChild(this, m_analog.get());
|
||||
wpi::SendableRegistry::AddChild(this, m_analog.get());
|
||||
}
|
||||
|
||||
AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel, int center,
|
||||
@@ -124,8 +124,7 @@ void AnalogGyro::InitGyro() {
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Gyro, m_analog->GetChannel() + 1);
|
||||
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "AnalogGyro",
|
||||
m_analog->GetChannel());
|
||||
wpi::SendableRegistry::AddLW(this, "AnalogGyro", m_analog->GetChannel());
|
||||
}
|
||||
|
||||
void AnalogGyro::Calibrate() {
|
||||
|
||||
@@ -34,7 +34,7 @@ AnalogInput::AnalogInput(int channel) {
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogChannel, channel + 1);
|
||||
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "AnalogInput", channel);
|
||||
wpi::SendableRegistry::AddLW(this, "AnalogInput", channel);
|
||||
}
|
||||
|
||||
AnalogInput::~AnalogInput() {
|
||||
|
||||
@@ -34,7 +34,7 @@ AnalogOutput::AnalogOutput(int channel) {
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogOutput, m_channel + 1);
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "AnalogOutput", m_channel);
|
||||
wpi::SendableRegistry::AddLW(this, "AnalogOutput", m_channel);
|
||||
}
|
||||
|
||||
AnalogOutput::~AnalogOutput() {
|
||||
|
||||
@@ -18,7 +18,7 @@ AnalogPotentiometer::AnalogPotentiometer(int channel, double fullRange,
|
||||
double offset)
|
||||
: AnalogPotentiometer(std::make_shared<AnalogInput>(channel), fullRange,
|
||||
offset) {
|
||||
wpi::SendableRegistry::GetInstance().AddChild(this, m_analog_input.get());
|
||||
wpi::SendableRegistry::AddChild(this, m_analog_input.get());
|
||||
}
|
||||
|
||||
AnalogPotentiometer::AnalogPotentiometer(AnalogInput* input, double fullRange,
|
||||
@@ -32,8 +32,8 @@ AnalogPotentiometer::AnalogPotentiometer(std::shared_ptr<AnalogInput> input,
|
||||
: m_analog_input(std::move(input)),
|
||||
m_fullRange(fullRange),
|
||||
m_offset(offset) {
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "AnalogPotentiometer",
|
||||
m_analog_input->GetChannel());
|
||||
wpi::SendableRegistry::AddLW(this, "AnalogPotentiometer",
|
||||
m_analog_input->GetChannel());
|
||||
}
|
||||
|
||||
double AnalogPotentiometer::Get() const {
|
||||
|
||||
@@ -20,7 +20,7 @@ using namespace frc;
|
||||
AnalogTrigger::AnalogTrigger(int channel)
|
||||
: AnalogTrigger(new AnalogInput(channel)) {
|
||||
m_ownsAnalog = true;
|
||||
wpi::SendableRegistry::GetInstance().AddChild(this, m_analogInput);
|
||||
wpi::SendableRegistry::AddChild(this, m_analogInput);
|
||||
}
|
||||
|
||||
AnalogTrigger::AnalogTrigger(AnalogInput* input) {
|
||||
@@ -31,7 +31,7 @@ AnalogTrigger::AnalogTrigger(AnalogInput* input) {
|
||||
int index = GetIndex();
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, index + 1);
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "AnalogTrigger", index);
|
||||
wpi::SendableRegistry::AddLW(this, "AnalogTrigger", index);
|
||||
}
|
||||
|
||||
AnalogTrigger::AnalogTrigger(DutyCycle* input) {
|
||||
@@ -42,7 +42,7 @@ AnalogTrigger::AnalogTrigger(DutyCycle* input) {
|
||||
int index = GetIndex();
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, index + 1);
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "AnalogTrigger", index);
|
||||
wpi::SendableRegistry::AddLW(this, "AnalogTrigger", index);
|
||||
}
|
||||
|
||||
AnalogTrigger::~AnalogTrigger() {
|
||||
|
||||
@@ -18,7 +18,7 @@ BuiltInAccelerometer::BuiltInAccelerometer(Range range) {
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Accelerometer, 0, 0,
|
||||
"Built-in accelerometer");
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "BuiltInAccel");
|
||||
wpi::SendableRegistry::AddLW(this, "BuiltInAccel");
|
||||
}
|
||||
|
||||
void BuiltInAccelerometer::SetRange(Range range) {
|
||||
|
||||
@@ -27,7 +27,7 @@ Counter::Counter(Mode mode) {
|
||||
SetMaxPeriod(0.5_s);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Counter, m_index + 1, mode + 1);
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "Counter", m_index);
|
||||
wpi::SendableRegistry::AddLW(this, "Counter", m_index);
|
||||
}
|
||||
|
||||
Counter::Counter(int channel) : Counter(kTwoPulse) {
|
||||
@@ -97,7 +97,7 @@ Counter::~Counter() {
|
||||
|
||||
void Counter::SetUpSource(int channel) {
|
||||
SetUpSource(std::make_shared<DigitalInput>(channel));
|
||||
wpi::SendableRegistry::GetInstance().AddChild(this, m_upSource.get());
|
||||
wpi::SendableRegistry::AddChild(this, m_upSource.get());
|
||||
}
|
||||
|
||||
void Counter::SetUpSource(AnalogTrigger* analogTrigger,
|
||||
@@ -152,7 +152,7 @@ void Counter::ClearUpSource() {
|
||||
|
||||
void Counter::SetDownSource(int channel) {
|
||||
SetDownSource(std::make_shared<DigitalInput>(channel));
|
||||
wpi::SendableRegistry::GetInstance().AddChild(this, m_downSource.get());
|
||||
wpi::SendableRegistry::AddChild(this, m_downSource.get());
|
||||
}
|
||||
|
||||
void Counter::SetDownSource(AnalogTrigger* analogTrigger,
|
||||
|
||||
@@ -35,8 +35,7 @@ DigitalGlitchFilter::DigitalGlitchFilter() {
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_DigitalGlitchFilter,
|
||||
m_channelIndex + 1);
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "DigitalGlitchFilter",
|
||||
m_channelIndex);
|
||||
wpi::SendableRegistry::AddLW(this, "DigitalGlitchFilter", m_channelIndex);
|
||||
}
|
||||
|
||||
DigitalGlitchFilter::~DigitalGlitchFilter() {
|
||||
|
||||
@@ -33,7 +33,7 @@ DigitalInput::DigitalInput(int channel) {
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_DigitalInput, channel + 1);
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "DigitalInput", channel);
|
||||
wpi::SendableRegistry::AddLW(this, "DigitalInput", channel);
|
||||
}
|
||||
|
||||
DigitalInput::~DigitalInput() {
|
||||
|
||||
@@ -33,7 +33,7 @@ DigitalOutput::DigitalOutput(int channel) {
|
||||
FRC_CheckErrorStatus(status, "Channel {}", channel);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_DigitalOutput, channel + 1);
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "DigitalOutput", channel);
|
||||
wpi::SendableRegistry::AddLW(this, "DigitalOutput", channel);
|
||||
}
|
||||
|
||||
DigitalOutput::~DigitalOutput() {
|
||||
|
||||
@@ -53,8 +53,9 @@ DoubleSolenoid::DoubleSolenoid(std::shared_ptr<PneumaticsBase> module,
|
||||
m_module->GetModuleNumber() + 1);
|
||||
HAL_Report(HALUsageReporting::kResourceType_Solenoid, m_reverseChannel + 1,
|
||||
m_module->GetModuleNumber() + 1);
|
||||
wpi::SendableRegistry::GetInstance().AddLW(
|
||||
this, "DoubleSolenoid", m_module->GetModuleNumber(), m_forwardChannel);
|
||||
|
||||
wpi::SendableRegistry::AddLW(this, "DoubleSolenoid",
|
||||
m_module->GetModuleNumber(), m_forwardChannel);
|
||||
}
|
||||
|
||||
DoubleSolenoid::~DoubleSolenoid() {}
|
||||
|
||||
@@ -4,23 +4,34 @@
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <hal/DriverStation.h>
|
||||
#include <hal/DriverStationTypes.h>
|
||||
#include <hal/HALBase.h>
|
||||
#include <hal/Power.h>
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <wpi/condition_variable.h>
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/MotorSafety.h"
|
||||
#include "frc/Timer.h"
|
||||
|
||||
namespace frc {
|
||||
using namespace frc;
|
||||
|
||||
namespace {
|
||||
// A simple class which caches the previous value written to an NT entry
|
||||
// Used to prevent redundant, repeated writes of the same value
|
||||
template <class T>
|
||||
@@ -60,37 +71,94 @@ class MatchDataSenderEntry {
|
||||
void SetValue(std::string_view val) { ntEntry.SetString(val); }
|
||||
};
|
||||
|
||||
class MatchDataSender {
|
||||
public:
|
||||
std::shared_ptr<nt::NetworkTable> table;
|
||||
MatchDataSenderEntry<std::string> typeMetaData;
|
||||
MatchDataSenderEntry<std::string> gameSpecificMessage;
|
||||
MatchDataSenderEntry<std::string> eventName;
|
||||
MatchDataSenderEntry<double> matchNumber;
|
||||
MatchDataSenderEntry<double> replayNumber;
|
||||
MatchDataSenderEntry<double> matchType;
|
||||
MatchDataSenderEntry<bool> alliance;
|
||||
MatchDataSenderEntry<double> station;
|
||||
MatchDataSenderEntry<double> controlWord;
|
||||
|
||||
MatchDataSender()
|
||||
: table(nt::NetworkTableInstance::GetDefault().GetTable("FMSInfo")),
|
||||
typeMetaData(table, ".type", "FMSInfo"),
|
||||
gameSpecificMessage(table, "GameSpecificMessage", ""),
|
||||
eventName(table, "EventName", ""),
|
||||
matchNumber(table, "MatchNumber", 0.0),
|
||||
replayNumber(table, "ReplayNumber", 0.0),
|
||||
matchType(table, "MatchType", 0.0),
|
||||
alliance(table, "IsRedAlliance", true),
|
||||
station(table, "StationNumber", 1.0),
|
||||
controlWord(table, "FMSControlData", 0.0) {}
|
||||
struct MatchDataSender {
|
||||
std::shared_ptr<nt::NetworkTable> table =
|
||||
nt::NetworkTableInstance::GetDefault().GetTable("FMSInfo");
|
||||
MatchDataSenderEntry<std::string> typeMetaData{table, ".type", "FMSInfo"};
|
||||
MatchDataSenderEntry<std::string> gameSpecificMessage{
|
||||
table, "GameSpecificMessage", ""};
|
||||
MatchDataSenderEntry<std::string> eventName{table, "EventName", ""};
|
||||
MatchDataSenderEntry<double> matchNumber{table, "MatchNumber", 0.0};
|
||||
MatchDataSenderEntry<double> replayNumber{table, "ReplayNumber", 0.0};
|
||||
MatchDataSenderEntry<double> matchType{table, "MatchType", 0.0};
|
||||
MatchDataSenderEntry<bool> alliance{table, "IsRedAlliance", true};
|
||||
MatchDataSenderEntry<double> station{table, "StationNumber", 1.0};
|
||||
MatchDataSenderEntry<double> controlWord{table, "FMSControlData", 0.0};
|
||||
};
|
||||
} // namespace frc
|
||||
|
||||
using namespace frc;
|
||||
struct Instance {
|
||||
Instance();
|
||||
~Instance();
|
||||
|
||||
MatchDataSender matchDataSender;
|
||||
|
||||
// Joystick button rising/falling edge flags
|
||||
wpi::mutex buttonEdgeMutex;
|
||||
std::array<HAL_JoystickButtons, DriverStation::kJoystickPorts>
|
||||
previousButtonStates;
|
||||
std::array<uint32_t, DriverStation::kJoystickPorts> joystickButtonsPressed;
|
||||
std::array<uint32_t, DriverStation::kJoystickPorts> joystickButtonsReleased;
|
||||
|
||||
// Internal Driver Station thread
|
||||
std::thread dsThread;
|
||||
std::atomic<bool> isRunning{false};
|
||||
|
||||
mutable wpi::mutex waitForDataMutex;
|
||||
wpi::condition_variable waitForDataCond;
|
||||
int waitForDataCounter = 0;
|
||||
|
||||
bool silenceJoystickWarning = false;
|
||||
|
||||
// Robot state status variables
|
||||
bool userInDisabled = false;
|
||||
bool userInAutonomous = false;
|
||||
bool userInTeleop = false;
|
||||
bool userInTest = false;
|
||||
|
||||
units::second_t nextMessageTime = 0_s;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static constexpr auto kJoystickUnpluggedMessageInterval = 1_s;
|
||||
|
||||
static Instance& GetInstance() {
|
||||
static Instance instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
static void Run();
|
||||
static void SendMatchData();
|
||||
|
||||
/**
|
||||
* Reports errors related to unplugged joysticks.
|
||||
*
|
||||
* Throttles the errors so that they don't overwhelm the DS.
|
||||
*/
|
||||
static void ReportJoystickUnpluggedErrorV(fmt::string_view format,
|
||||
fmt::format_args args);
|
||||
|
||||
template <typename S, typename... Args>
|
||||
static inline void ReportJoystickUnpluggedError(const S& format,
|
||||
Args&&... args) {
|
||||
ReportJoystickUnpluggedErrorV(
|
||||
format, fmt::make_args_checked<Args...>(format, args...));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports errors related to unplugged joysticks.
|
||||
*
|
||||
* Throttles the errors so that they don't overwhelm the DS.
|
||||
*/
|
||||
static void ReportJoystickUnpluggedWarningV(fmt::string_view format,
|
||||
fmt::format_args args);
|
||||
|
||||
template <typename S, typename... Args>
|
||||
static inline void ReportJoystickUnpluggedWarning(const S& format,
|
||||
Args&&... args) {
|
||||
ReportJoystickUnpluggedWarningV(
|
||||
format, fmt::make_args_checked<Args...>(format, args...));
|
||||
}
|
||||
|
||||
static int& GetDSLastCount() {
|
||||
// There is a rollover error condition here. At Packet# = n * (uintmax), this
|
||||
// will return false when instead it should return true. However, this at a
|
||||
@@ -100,14 +168,30 @@ static int& GetDSLastCount() {
|
||||
return lastCount;
|
||||
}
|
||||
|
||||
DriverStation::~DriverStation() {
|
||||
m_isRunning = false;
|
||||
Instance::Instance() {
|
||||
HAL_Initialize(500, 0);
|
||||
|
||||
// All joysticks should default to having zero axes, povs and buttons, so
|
||||
// uninitialized memory doesn't get sent to speed controllers.
|
||||
for (unsigned int i = 0; i < DriverStation::kJoystickPorts; i++) {
|
||||
joystickButtonsPressed[i] = 0;
|
||||
joystickButtonsReleased[i] = 0;
|
||||
previousButtonStates[i].count = 0;
|
||||
previousButtonStates[i].buttons = 0;
|
||||
}
|
||||
|
||||
dsThread = std::thread(&Run);
|
||||
}
|
||||
|
||||
Instance::~Instance() {
|
||||
isRunning = false;
|
||||
// Trigger a DS mutex release in case there is no driver station running.
|
||||
HAL_ReleaseDSMutex();
|
||||
m_dsThread.join();
|
||||
dsThread.join();
|
||||
}
|
||||
|
||||
DriverStation& DriverStation::GetInstance() {
|
||||
::GetInstance();
|
||||
static DriverStation instance;
|
||||
return instance;
|
||||
}
|
||||
@@ -158,14 +242,14 @@ bool DriverStation::GetStickButtonPressed(int stick, int button) {
|
||||
button, buttons.count);
|
||||
return false;
|
||||
}
|
||||
std::unique_lock lock(m_buttonEdgeMutex);
|
||||
auto& inst = ::GetInstance();
|
||||
std::unique_lock lock(inst.buttonEdgeMutex);
|
||||
// If button was pressed, clear flag and return true
|
||||
if (m_joystickButtonsPressed[stick] & 1 << (button - 1)) {
|
||||
m_joystickButtonsPressed[stick] &= ~(1 << (button - 1));
|
||||
if (inst.joystickButtonsPressed[stick] & 1 << (button - 1)) {
|
||||
inst.joystickButtonsPressed[stick] &= ~(1 << (button - 1));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DriverStation::GetStickButtonReleased(int stick, int button) {
|
||||
@@ -189,14 +273,14 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) {
|
||||
button, buttons.count);
|
||||
return false;
|
||||
}
|
||||
std::unique_lock lock(m_buttonEdgeMutex);
|
||||
auto& inst = ::GetInstance();
|
||||
std::unique_lock lock(inst.buttonEdgeMutex);
|
||||
// If button was released, clear flag and return true
|
||||
if (m_joystickButtonsReleased[stick] & 1 << (button - 1)) {
|
||||
m_joystickButtonsReleased[stick] &= ~(1 << (button - 1));
|
||||
if (inst.joystickButtonsReleased[stick] & 1 << (button - 1)) {
|
||||
inst.joystickButtonsReleased[stick] &= ~(1 << (button - 1));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
double DriverStation::GetStickAxis(int stick, int axis) {
|
||||
@@ -247,7 +331,7 @@ int DriverStation::GetStickPOV(int stick, int pov) {
|
||||
return povs.povs[pov];
|
||||
}
|
||||
|
||||
int DriverStation::GetStickButtons(int stick) const {
|
||||
int DriverStation::GetStickButtons(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return 0;
|
||||
@@ -259,7 +343,7 @@ int DriverStation::GetStickButtons(int stick) const {
|
||||
return buttons.buttons;
|
||||
}
|
||||
|
||||
int DriverStation::GetStickAxisCount(int stick) const {
|
||||
int DriverStation::GetStickAxisCount(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return 0;
|
||||
@@ -271,7 +355,7 @@ int DriverStation::GetStickAxisCount(int stick) const {
|
||||
return axes.count;
|
||||
}
|
||||
|
||||
int DriverStation::GetStickPOVCount(int stick) const {
|
||||
int DriverStation::GetStickPOVCount(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return 0;
|
||||
@@ -283,7 +367,7 @@ int DriverStation::GetStickPOVCount(int stick) const {
|
||||
return povs.count;
|
||||
}
|
||||
|
||||
int DriverStation::GetStickButtonCount(int stick) const {
|
||||
int DriverStation::GetStickButtonCount(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return 0;
|
||||
@@ -295,7 +379,7 @@ int DriverStation::GetStickButtonCount(int stick) const {
|
||||
return buttons.count;
|
||||
}
|
||||
|
||||
bool DriverStation::GetJoystickIsXbox(int stick) const {
|
||||
bool DriverStation::GetJoystickIsXbox(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return false;
|
||||
@@ -307,7 +391,7 @@ bool DriverStation::GetJoystickIsXbox(int stick) const {
|
||||
return static_cast<bool>(descriptor.isXbox);
|
||||
}
|
||||
|
||||
int DriverStation::GetJoystickType(int stick) const {
|
||||
int DriverStation::GetJoystickType(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return -1;
|
||||
@@ -319,7 +403,7 @@ int DriverStation::GetJoystickType(int stick) const {
|
||||
return static_cast<int>(descriptor.type);
|
||||
}
|
||||
|
||||
std::string DriverStation::GetJoystickName(int stick) const {
|
||||
std::string DriverStation::GetJoystickName(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
}
|
||||
@@ -330,7 +414,7 @@ std::string DriverStation::GetJoystickName(int stick) const {
|
||||
return descriptor.name;
|
||||
}
|
||||
|
||||
int DriverStation::GetJoystickAxisType(int stick, int axis) const {
|
||||
int DriverStation::GetJoystickAxisType(int stick, int axis) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
|
||||
return -1;
|
||||
@@ -342,69 +426,70 @@ int DriverStation::GetJoystickAxisType(int stick, int axis) const {
|
||||
return static_cast<bool>(descriptor.axisTypes);
|
||||
}
|
||||
|
||||
bool DriverStation::IsJoystickConnected(int stick) const {
|
||||
bool DriverStation::IsJoystickConnected(int stick) {
|
||||
return GetStickAxisCount(stick) > 0 || GetStickButtonCount(stick) > 0 ||
|
||||
GetStickPOVCount(stick) > 0;
|
||||
}
|
||||
|
||||
bool DriverStation::IsEnabled() const {
|
||||
bool DriverStation::IsEnabled() {
|
||||
HAL_ControlWord controlWord;
|
||||
HAL_GetControlWord(&controlWord);
|
||||
return controlWord.enabled && controlWord.dsAttached;
|
||||
}
|
||||
|
||||
bool DriverStation::IsDisabled() const {
|
||||
bool DriverStation::IsDisabled() {
|
||||
HAL_ControlWord controlWord;
|
||||
HAL_GetControlWord(&controlWord);
|
||||
return !(controlWord.enabled && controlWord.dsAttached);
|
||||
}
|
||||
|
||||
bool DriverStation::IsEStopped() const {
|
||||
bool DriverStation::IsEStopped() {
|
||||
HAL_ControlWord controlWord;
|
||||
HAL_GetControlWord(&controlWord);
|
||||
return controlWord.eStop;
|
||||
}
|
||||
|
||||
bool DriverStation::IsAutonomous() const {
|
||||
bool DriverStation::IsAutonomous() {
|
||||
HAL_ControlWord controlWord;
|
||||
HAL_GetControlWord(&controlWord);
|
||||
return controlWord.autonomous;
|
||||
}
|
||||
|
||||
bool DriverStation::IsAutonomousEnabled() const {
|
||||
bool DriverStation::IsAutonomousEnabled() {
|
||||
HAL_ControlWord controlWord;
|
||||
HAL_GetControlWord(&controlWord);
|
||||
return controlWord.autonomous && controlWord.enabled;
|
||||
}
|
||||
|
||||
bool DriverStation::IsOperatorControl() const {
|
||||
bool DriverStation::IsOperatorControl() {
|
||||
HAL_ControlWord controlWord;
|
||||
HAL_GetControlWord(&controlWord);
|
||||
return !(controlWord.autonomous || controlWord.test);
|
||||
}
|
||||
|
||||
bool DriverStation::IsOperatorControlEnabled() const {
|
||||
bool DriverStation::IsOperatorControlEnabled() {
|
||||
HAL_ControlWord controlWord;
|
||||
HAL_GetControlWord(&controlWord);
|
||||
return !controlWord.autonomous && !controlWord.test && controlWord.enabled;
|
||||
}
|
||||
|
||||
bool DriverStation::IsTest() const {
|
||||
bool DriverStation::IsTest() {
|
||||
HAL_ControlWord controlWord;
|
||||
HAL_GetControlWord(&controlWord);
|
||||
return controlWord.test;
|
||||
}
|
||||
|
||||
bool DriverStation::IsDSAttached() const {
|
||||
bool DriverStation::IsDSAttached() {
|
||||
HAL_ControlWord controlWord;
|
||||
HAL_GetControlWord(&controlWord);
|
||||
return controlWord.dsAttached;
|
||||
}
|
||||
|
||||
bool DriverStation::IsNewControlData() const {
|
||||
std::unique_lock lock(m_waitForDataMutex);
|
||||
bool DriverStation::IsNewControlData() {
|
||||
auto& inst = ::GetInstance();
|
||||
std::unique_lock lock(inst.waitForDataMutex);
|
||||
int& lastCount = GetDSLastCount();
|
||||
int currentCount = m_waitForDataCounter;
|
||||
int currentCount = inst.waitForDataCounter;
|
||||
if (lastCount == currentCount) {
|
||||
return false;
|
||||
}
|
||||
@@ -412,44 +497,44 @@ bool DriverStation::IsNewControlData() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DriverStation::IsFMSAttached() const {
|
||||
bool DriverStation::IsFMSAttached() {
|
||||
HAL_ControlWord controlWord;
|
||||
HAL_GetControlWord(&controlWord);
|
||||
return controlWord.fmsAttached;
|
||||
}
|
||||
|
||||
std::string DriverStation::GetGameSpecificMessage() const {
|
||||
std::string DriverStation::GetGameSpecificMessage() {
|
||||
HAL_MatchInfo info;
|
||||
HAL_GetMatchInfo(&info);
|
||||
return std::string(reinterpret_cast<char*>(info.gameSpecificMessage),
|
||||
info.gameSpecificMessageSize);
|
||||
}
|
||||
|
||||
std::string DriverStation::GetEventName() const {
|
||||
std::string DriverStation::GetEventName() {
|
||||
HAL_MatchInfo info;
|
||||
HAL_GetMatchInfo(&info);
|
||||
return info.eventName;
|
||||
}
|
||||
|
||||
DriverStation::MatchType DriverStation::GetMatchType() const {
|
||||
DriverStation::MatchType DriverStation::GetMatchType() {
|
||||
HAL_MatchInfo info;
|
||||
HAL_GetMatchInfo(&info);
|
||||
return static_cast<DriverStation::MatchType>(info.matchType);
|
||||
}
|
||||
|
||||
int DriverStation::GetMatchNumber() const {
|
||||
int DriverStation::GetMatchNumber() {
|
||||
HAL_MatchInfo info;
|
||||
HAL_GetMatchInfo(&info);
|
||||
return info.matchNumber;
|
||||
}
|
||||
|
||||
int DriverStation::GetReplayNumber() const {
|
||||
int DriverStation::GetReplayNumber() {
|
||||
HAL_MatchInfo info;
|
||||
HAL_GetMatchInfo(&info);
|
||||
return info.replayNumber;
|
||||
}
|
||||
|
||||
DriverStation::Alliance DriverStation::GetAlliance() const {
|
||||
DriverStation::Alliance DriverStation::GetAlliance() {
|
||||
int32_t status = 0;
|
||||
auto allianceStationID = HAL_GetAllianceStation(&status);
|
||||
switch (allianceStationID) {
|
||||
@@ -466,7 +551,7 @@ DriverStation::Alliance DriverStation::GetAlliance() const {
|
||||
}
|
||||
}
|
||||
|
||||
int DriverStation::GetLocation() const {
|
||||
int DriverStation::GetLocation() {
|
||||
int32_t status = 0;
|
||||
auto allianceStationID = HAL_GetAllianceStation(&status);
|
||||
switch (allianceStationID) {
|
||||
@@ -489,36 +574,37 @@ void DriverStation::WaitForData() {
|
||||
}
|
||||
|
||||
bool DriverStation::WaitForData(units::second_t timeout) {
|
||||
auto& inst = ::GetInstance();
|
||||
auto timeoutTime = std::chrono::steady_clock::now() +
|
||||
std::chrono::steady_clock::duration{timeout};
|
||||
|
||||
std::unique_lock lock(m_waitForDataMutex);
|
||||
std::unique_lock lock(inst.waitForDataMutex);
|
||||
int& lastCount = GetDSLastCount();
|
||||
int currentCount = m_waitForDataCounter;
|
||||
int currentCount = inst.waitForDataCounter;
|
||||
if (lastCount != currentCount) {
|
||||
lastCount = currentCount;
|
||||
return true;
|
||||
}
|
||||
while (m_waitForDataCounter == currentCount) {
|
||||
while (inst.waitForDataCounter == currentCount) {
|
||||
if (timeout > 0_s) {
|
||||
auto timedOut = m_waitForDataCond.wait_until(lock, timeoutTime);
|
||||
auto timedOut = inst.waitForDataCond.wait_until(lock, timeoutTime);
|
||||
if (timedOut == std::cv_status::timeout) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
m_waitForDataCond.wait(lock);
|
||||
inst.waitForDataCond.wait(lock);
|
||||
}
|
||||
}
|
||||
lastCount = m_waitForDataCounter;
|
||||
lastCount = inst.waitForDataCounter;
|
||||
return true;
|
||||
}
|
||||
|
||||
double DriverStation::GetMatchTime() const {
|
||||
double DriverStation::GetMatchTime() {
|
||||
int32_t status = 0;
|
||||
return HAL_GetMatchTime(&status);
|
||||
}
|
||||
|
||||
double DriverStation::GetBatteryVoltage() const {
|
||||
double DriverStation::GetBatteryVoltage() {
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetVinVoltage(&status);
|
||||
FRC_CheckErrorStatus(status, "{}", "getVinVoltage");
|
||||
@@ -526,92 +612,101 @@ double DriverStation::GetBatteryVoltage() const {
|
||||
return voltage;
|
||||
}
|
||||
|
||||
void DriverStation::WakeupWaitForData() {
|
||||
std::scoped_lock waitLock(m_waitForDataMutex);
|
||||
// Nofify all threads
|
||||
m_waitForDataCounter++;
|
||||
m_waitForDataCond.notify_all();
|
||||
void DriverStation::InDisabled(bool entering) {
|
||||
::GetInstance().userInDisabled = entering;
|
||||
}
|
||||
|
||||
void DriverStation::GetData() {
|
||||
void DriverStation::InAutonomous(bool entering) {
|
||||
::GetInstance().userInAutonomous = entering;
|
||||
}
|
||||
|
||||
void DriverStation::InOperatorControl(bool entering) {
|
||||
::GetInstance().userInTeleop = entering;
|
||||
}
|
||||
|
||||
void DriverStation::InTest(bool entering) {
|
||||
::GetInstance().userInTest = entering;
|
||||
}
|
||||
|
||||
void DriverStation::WakeupWaitForData() {
|
||||
auto& inst = ::GetInstance();
|
||||
std::scoped_lock waitLock(inst.waitForDataMutex);
|
||||
// Nofify all threads
|
||||
inst.waitForDataCounter++;
|
||||
inst.waitForDataCond.notify_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy data from the DS task for the user.
|
||||
*
|
||||
* If no new data exists, it will just be returned, otherwise
|
||||
* the data will be copied from the DS polling loop.
|
||||
*/
|
||||
void GetData() {
|
||||
auto& inst = ::GetInstance();
|
||||
{
|
||||
// Compute the pressed and released buttons
|
||||
HAL_JoystickButtons currentButtons;
|
||||
std::unique_lock lock(m_buttonEdgeMutex);
|
||||
std::unique_lock lock(inst.buttonEdgeMutex);
|
||||
|
||||
for (int32_t i = 0; i < kJoystickPorts; i++) {
|
||||
for (int32_t i = 0; i < DriverStation::kJoystickPorts; i++) {
|
||||
HAL_GetJoystickButtons(i, ¤tButtons);
|
||||
|
||||
// If buttons weren't pressed and are now, set flags in m_buttonsPressed
|
||||
m_joystickButtonsPressed[i] |=
|
||||
~m_previousButtonStates[i].buttons & currentButtons.buttons;
|
||||
inst.joystickButtonsPressed[i] |=
|
||||
~inst.previousButtonStates[i].buttons & currentButtons.buttons;
|
||||
|
||||
// If buttons were pressed and aren't now, set flags in m_buttonsReleased
|
||||
m_joystickButtonsReleased[i] |=
|
||||
m_previousButtonStates[i].buttons & ~currentButtons.buttons;
|
||||
inst.joystickButtonsReleased[i] |=
|
||||
inst.previousButtonStates[i].buttons & ~currentButtons.buttons;
|
||||
|
||||
m_previousButtonStates[i] = currentButtons;
|
||||
inst.previousButtonStates[i] = currentButtons;
|
||||
}
|
||||
}
|
||||
|
||||
WakeupWaitForData();
|
||||
DriverStation::WakeupWaitForData();
|
||||
SendMatchData();
|
||||
}
|
||||
|
||||
void DriverStation::SilenceJoystickConnectionWarning(bool silence) {
|
||||
m_silenceJoystickWarning = silence;
|
||||
::GetInstance().silenceJoystickWarning = silence;
|
||||
}
|
||||
|
||||
bool DriverStation::IsJoystickConnectionWarningSilenced() const {
|
||||
return !IsFMSAttached() && m_silenceJoystickWarning;
|
||||
bool DriverStation::IsJoystickConnectionWarningSilenced() {
|
||||
return !IsFMSAttached() && ::GetInstance().silenceJoystickWarning;
|
||||
}
|
||||
|
||||
DriverStation::DriverStation() {
|
||||
HAL_Initialize(500, 0);
|
||||
m_waitForDataCounter = 0;
|
||||
|
||||
m_matchDataSender = std::make_unique<MatchDataSender>();
|
||||
|
||||
// All joysticks should default to having zero axes, povs and buttons, so
|
||||
// uninitialized memory doesn't get sent to speed controllers.
|
||||
for (unsigned int i = 0; i < kJoystickPorts; i++) {
|
||||
m_joystickButtonsPressed[i] = 0;
|
||||
m_joystickButtonsReleased[i] = 0;
|
||||
m_previousButtonStates[i].count = 0;
|
||||
m_previousButtonStates[i].buttons = 0;
|
||||
}
|
||||
|
||||
m_dsThread = std::thread(&DriverStation::Run, this);
|
||||
}
|
||||
|
||||
void DriverStation::ReportJoystickUnpluggedErrorV(fmt::string_view format,
|
||||
fmt::format_args args) {
|
||||
void ReportJoystickUnpluggedErrorV(fmt::string_view format,
|
||||
fmt::format_args args) {
|
||||
auto& inst = GetInstance();
|
||||
auto currentTime = Timer::GetFPGATimestamp();
|
||||
if (currentTime > m_nextMessageTime) {
|
||||
if (currentTime > inst.nextMessageTime) {
|
||||
ReportErrorV(err::Error, "", 0, "", format, args);
|
||||
m_nextMessageTime = currentTime + kJoystickUnpluggedMessageInterval;
|
||||
inst.nextMessageTime = currentTime + kJoystickUnpluggedMessageInterval;
|
||||
}
|
||||
}
|
||||
|
||||
void DriverStation::ReportJoystickUnpluggedWarningV(fmt::string_view format,
|
||||
fmt::format_args args) {
|
||||
if (IsFMSAttached() || !m_silenceJoystickWarning) {
|
||||
void ReportJoystickUnpluggedWarningV(fmt::string_view format,
|
||||
fmt::format_args args) {
|
||||
auto& inst = GetInstance();
|
||||
if (DriverStation::IsFMSAttached() || !inst.silenceJoystickWarning) {
|
||||
auto currentTime = Timer::GetFPGATimestamp();
|
||||
if (currentTime > m_nextMessageTime) {
|
||||
if (currentTime > inst.nextMessageTime) {
|
||||
ReportErrorV(warn::Warning, "", 0, "", format, args);
|
||||
m_nextMessageTime = currentTime + kJoystickUnpluggedMessageInterval;
|
||||
inst.nextMessageTime = currentTime + kJoystickUnpluggedMessageInterval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DriverStation::Run() {
|
||||
m_isRunning = true;
|
||||
void Run() {
|
||||
auto& inst = GetInstance();
|
||||
inst.isRunning = true;
|
||||
int safetyCounter = 0;
|
||||
while (m_isRunning) {
|
||||
while (inst.isRunning) {
|
||||
HAL_WaitForDSData();
|
||||
GetData();
|
||||
|
||||
if (IsDisabled()) {
|
||||
if (DriverStation::IsDisabled()) {
|
||||
safetyCounter = 0;
|
||||
}
|
||||
|
||||
@@ -619,22 +714,22 @@ void DriverStation::Run() {
|
||||
MotorSafety::CheckMotors();
|
||||
safetyCounter = 0;
|
||||
}
|
||||
if (m_userInDisabled) {
|
||||
if (inst.userInDisabled) {
|
||||
HAL_ObserveUserProgramDisabled();
|
||||
}
|
||||
if (m_userInAutonomous) {
|
||||
if (inst.userInAutonomous) {
|
||||
HAL_ObserveUserProgramAutonomous();
|
||||
}
|
||||
if (m_userInTeleop) {
|
||||
if (inst.userInTeleop) {
|
||||
HAL_ObserveUserProgramTeleop();
|
||||
}
|
||||
if (m_userInTest) {
|
||||
if (inst.userInTest) {
|
||||
HAL_ObserveUserProgramTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DriverStation::SendMatchData() {
|
||||
void SendMatchData() {
|
||||
int32_t status = 0;
|
||||
HAL_AllianceStationID alliance = HAL_GetAllianceStation(&status);
|
||||
bool isRedAlliance = false;
|
||||
@@ -669,19 +764,20 @@ void DriverStation::SendMatchData() {
|
||||
HAL_MatchInfo tmpDataStore;
|
||||
HAL_GetMatchInfo(&tmpDataStore);
|
||||
|
||||
m_matchDataSender->alliance.Set(isRedAlliance);
|
||||
m_matchDataSender->station.Set(stationNumber);
|
||||
m_matchDataSender->eventName.Set(tmpDataStore.eventName);
|
||||
m_matchDataSender->gameSpecificMessage.Set(
|
||||
auto& inst = GetInstance();
|
||||
inst.matchDataSender.alliance.Set(isRedAlliance);
|
||||
inst.matchDataSender.station.Set(stationNumber);
|
||||
inst.matchDataSender.eventName.Set(tmpDataStore.eventName);
|
||||
inst.matchDataSender.gameSpecificMessage.Set(
|
||||
std::string(reinterpret_cast<char*>(tmpDataStore.gameSpecificMessage),
|
||||
tmpDataStore.gameSpecificMessageSize));
|
||||
m_matchDataSender->matchNumber.Set(tmpDataStore.matchNumber);
|
||||
m_matchDataSender->replayNumber.Set(tmpDataStore.replayNumber);
|
||||
m_matchDataSender->matchType.Set(static_cast<int>(tmpDataStore.matchType));
|
||||
inst.matchDataSender.matchNumber.Set(tmpDataStore.matchNumber);
|
||||
inst.matchDataSender.replayNumber.Set(tmpDataStore.replayNumber);
|
||||
inst.matchDataSender.matchType.Set(static_cast<int>(tmpDataStore.matchType));
|
||||
|
||||
HAL_ControlWord ctlWord;
|
||||
HAL_GetControlWord(&ctlWord);
|
||||
int32_t wordInt = 0;
|
||||
std::memcpy(&wordInt, &ctlWord, sizeof(wordInt));
|
||||
m_matchDataSender->controlWord.Set(wordInt);
|
||||
inst.matchDataSender.controlWord.Set(wordInt);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ void DutyCycle::InitDutyCycle() {
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
int index = GetFPGAIndex();
|
||||
HAL_Report(HALUsageReporting::kResourceType_DutyCycle, index + 1);
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "Duty Cycle", index);
|
||||
wpi::SendableRegistry::AddLW(this, "Duty Cycle", index);
|
||||
}
|
||||
|
||||
int DutyCycle::GetFPGAIndex() const {
|
||||
|
||||
@@ -72,8 +72,8 @@ void DutyCycleEncoder::Init() {
|
||||
m_analogTrigger->CreateOutput(AnalogTriggerType::kFallingPulse));
|
||||
}
|
||||
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "DutyCycle Encoder",
|
||||
m_dutyCycle->GetSourceChannel());
|
||||
wpi::SendableRegistry::AddLW(this, "DutyCycle Encoder",
|
||||
m_dutyCycle->GetSourceChannel());
|
||||
}
|
||||
|
||||
units::turn_t DutyCycleEncoder::Get() const {
|
||||
|
||||
@@ -22,9 +22,8 @@ Encoder::Encoder(int aChannel, int bChannel, bool reverseDirection,
|
||||
m_aSource = std::make_shared<DigitalInput>(aChannel);
|
||||
m_bSource = std::make_shared<DigitalInput>(bChannel);
|
||||
InitEncoder(reverseDirection, encodingType);
|
||||
auto& registry = wpi::SendableRegistry::GetInstance();
|
||||
registry.AddChild(this, m_aSource.get());
|
||||
registry.AddChild(this, m_bSource.get());
|
||||
wpi::SendableRegistry::AddChild(this, m_aSource.get());
|
||||
wpi::SendableRegistry::AddChild(this, m_bSource.get());
|
||||
}
|
||||
|
||||
Encoder::Encoder(DigitalSource* aSource, DigitalSource* bSource,
|
||||
@@ -181,7 +180,7 @@ int Encoder::GetSamplesToAverage() const {
|
||||
void Encoder::SetIndexSource(int channel, Encoder::IndexingType type) {
|
||||
// Force digital input if just given an index
|
||||
m_indexSource = std::make_shared<DigitalInput>(channel);
|
||||
wpi::SendableRegistry::GetInstance().AddChild(this, m_indexSource.get());
|
||||
wpi::SendableRegistry::AddChild(this, m_indexSource.get());
|
||||
SetIndexSource(*m_indexSource.get(), type);
|
||||
}
|
||||
|
||||
@@ -240,8 +239,7 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) {
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Encoder, GetFPGAIndex() + 1,
|
||||
encodingType);
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "Encoder",
|
||||
m_aSource->GetChannel());
|
||||
wpi::SendableRegistry::AddLW(this, "Encoder", m_aSource->GetChannel());
|
||||
}
|
||||
|
||||
double Encoder::DecodingScaleFactor() const {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
GenericHID::GenericHID(int port) : m_ds(&DriverStation::GetInstance()) {
|
||||
GenericHID::GenericHID(int port) {
|
||||
if (port < 0 || port >= DriverStation::kJoystickPorts) {
|
||||
throw FRC_MakeError(warn::BadJoystickIndex, "port {} out of range", port);
|
||||
}
|
||||
@@ -19,51 +19,51 @@ GenericHID::GenericHID(int port) : m_ds(&DriverStation::GetInstance()) {
|
||||
}
|
||||
|
||||
bool GenericHID::GetRawButton(int button) const {
|
||||
return m_ds->GetStickButton(m_port, button);
|
||||
return DriverStation::GetStickButton(m_port, button);
|
||||
}
|
||||
|
||||
bool GenericHID::GetRawButtonPressed(int button) {
|
||||
return m_ds->GetStickButtonPressed(m_port, button);
|
||||
return DriverStation::GetStickButtonPressed(m_port, button);
|
||||
}
|
||||
|
||||
bool GenericHID::GetRawButtonReleased(int button) {
|
||||
return m_ds->GetStickButtonReleased(m_port, button);
|
||||
return DriverStation::GetStickButtonReleased(m_port, button);
|
||||
}
|
||||
|
||||
double GenericHID::GetRawAxis(int axis) const {
|
||||
return m_ds->GetStickAxis(m_port, axis);
|
||||
return DriverStation::GetStickAxis(m_port, axis);
|
||||
}
|
||||
|
||||
int GenericHID::GetPOV(int pov) const {
|
||||
return m_ds->GetStickPOV(m_port, pov);
|
||||
return DriverStation::GetStickPOV(m_port, pov);
|
||||
}
|
||||
|
||||
int GenericHID::GetAxisCount() const {
|
||||
return m_ds->GetStickAxisCount(m_port);
|
||||
return DriverStation::GetStickAxisCount(m_port);
|
||||
}
|
||||
|
||||
int GenericHID::GetPOVCount() const {
|
||||
return m_ds->GetStickPOVCount(m_port);
|
||||
return DriverStation::GetStickPOVCount(m_port);
|
||||
}
|
||||
|
||||
int GenericHID::GetButtonCount() const {
|
||||
return m_ds->GetStickButtonCount(m_port);
|
||||
return DriverStation::GetStickButtonCount(m_port);
|
||||
}
|
||||
|
||||
bool GenericHID::IsConnected() const {
|
||||
return m_ds->IsJoystickConnected(m_port);
|
||||
return DriverStation::IsJoystickConnected(m_port);
|
||||
}
|
||||
|
||||
GenericHID::HIDType GenericHID::GetType() const {
|
||||
return static_cast<HIDType>(m_ds->GetJoystickType(m_port));
|
||||
return static_cast<HIDType>(DriverStation::GetJoystickType(m_port));
|
||||
}
|
||||
|
||||
std::string GenericHID::GetName() const {
|
||||
return m_ds->GetJoystickName(m_port);
|
||||
return DriverStation::GetJoystickName(m_port);
|
||||
}
|
||||
|
||||
int GenericHID::GetAxisType(int axis) const {
|
||||
return m_ds->GetJoystickAxisType(m_port, axis);
|
||||
return DriverStation::GetJoystickAxisType(m_port, axis);
|
||||
}
|
||||
|
||||
int GenericHID::GetPort() const {
|
||||
|
||||
@@ -110,7 +110,7 @@ void IterativeRobotBase::LoopFunc() {
|
||||
// Call DisabledInit() if we are now just entering disabled mode from
|
||||
// either a different mode or from power-on.
|
||||
if (m_lastMode != Mode::kDisabled) {
|
||||
LiveWindow::GetInstance()->SetEnabled(false);
|
||||
LiveWindow::SetEnabled(false);
|
||||
Shuffleboard::DisableActuatorWidgets();
|
||||
DisabledInit();
|
||||
m_watchdog.AddEpoch("DisabledInit()");
|
||||
@@ -124,7 +124,7 @@ void IterativeRobotBase::LoopFunc() {
|
||||
// Call AutonomousInit() if we are now just entering autonomous mode from
|
||||
// either a different mode or from power-on.
|
||||
if (m_lastMode != Mode::kAutonomous) {
|
||||
LiveWindow::GetInstance()->SetEnabled(false);
|
||||
LiveWindow::SetEnabled(false);
|
||||
Shuffleboard::DisableActuatorWidgets();
|
||||
AutonomousInit();
|
||||
m_watchdog.AddEpoch("AutonomousInit()");
|
||||
@@ -138,7 +138,7 @@ void IterativeRobotBase::LoopFunc() {
|
||||
// Call TeleopInit() if we are now just entering teleop mode from
|
||||
// either a different mode or from power-on.
|
||||
if (m_lastMode != Mode::kTeleop) {
|
||||
LiveWindow::GetInstance()->SetEnabled(false);
|
||||
LiveWindow::SetEnabled(false);
|
||||
Shuffleboard::DisableActuatorWidgets();
|
||||
TeleopInit();
|
||||
m_watchdog.AddEpoch("TeleopInit()");
|
||||
@@ -152,7 +152,7 @@ void IterativeRobotBase::LoopFunc() {
|
||||
// Call TestInit() if we are now just entering test mode from
|
||||
// either a different mode or from power-on.
|
||||
if (m_lastMode != Mode::kTest) {
|
||||
LiveWindow::GetInstance()->SetEnabled(true);
|
||||
LiveWindow::SetEnabled(true);
|
||||
Shuffleboard::EnableActuatorWidgets();
|
||||
TestInit();
|
||||
m_watchdog.AddEpoch("TestInit()");
|
||||
@@ -169,7 +169,7 @@ void IterativeRobotBase::LoopFunc() {
|
||||
|
||||
SmartDashboard::UpdateValues();
|
||||
m_watchdog.AddEpoch("SmartDashboard::UpdateValues()");
|
||||
LiveWindow::GetInstance()->UpdateValues();
|
||||
LiveWindow::UpdateValues();
|
||||
m_watchdog.AddEpoch("LiveWindow::UpdateValues()");
|
||||
Shuffleboard::Update();
|
||||
m_watchdog.AddEpoch("Shuffleboard::Update()");
|
||||
|
||||
@@ -82,8 +82,7 @@ void MotorSafety::Check() {
|
||||
stopTime = m_stopTime;
|
||||
}
|
||||
|
||||
DriverStation& ds = DriverStation::GetInstance();
|
||||
if (!enabled || ds.IsDisabled() || ds.IsTest()) {
|
||||
if (!enabled || DriverStation::IsDisabled() || DriverStation::IsTest()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ PWM::PWM(int channel, bool registerSendable) {
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_PWM, channel + 1);
|
||||
if (registerSendable) {
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "PWM", channel);
|
||||
wpi::SendableRegistry::AddLW(this, "PWM", channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@ PowerDistributionPanel::PowerDistributionPanel(int module) : m_module(module) {
|
||||
FRC_CheckErrorStatus(status, "Module {}", module);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_PDP, module + 1);
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "PowerDistributionPanel",
|
||||
module);
|
||||
wpi::SendableRegistry::AddLW(this, "PowerDistributionPanel", module);
|
||||
}
|
||||
|
||||
double PowerDistributionPanel::GetVoltage() const {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
|
||||
using namespace frc;
|
||||
@@ -14,42 +15,59 @@ using namespace frc;
|
||||
// The Preferences table name
|
||||
static constexpr std::string_view kTableName{"Preferences"};
|
||||
|
||||
namespace {
|
||||
struct Instance {
|
||||
Instance();
|
||||
|
||||
std::shared_ptr<nt::NetworkTable> table{
|
||||
nt::NetworkTableInstance::GetDefault().GetTable(kTableName)};
|
||||
NT_EntryListener listener;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static Instance& GetInstance() {
|
||||
static Instance instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
Preferences* Preferences::GetInstance() {
|
||||
::GetInstance();
|
||||
static Preferences instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
std::vector<std::string> Preferences::GetKeys() {
|
||||
return m_table->GetKeys();
|
||||
return ::GetInstance().table->GetKeys();
|
||||
}
|
||||
|
||||
std::string Preferences::GetString(std::string_view key,
|
||||
std::string_view defaultValue) {
|
||||
return m_table->GetString(key, defaultValue);
|
||||
return ::GetInstance().table->GetString(key, defaultValue);
|
||||
}
|
||||
|
||||
int Preferences::GetInt(std::string_view key, int defaultValue) {
|
||||
return static_cast<int>(m_table->GetNumber(key, defaultValue));
|
||||
return static_cast<int>(::GetInstance().table->GetNumber(key, defaultValue));
|
||||
}
|
||||
|
||||
double Preferences::GetDouble(std::string_view key, double defaultValue) {
|
||||
return m_table->GetNumber(key, defaultValue);
|
||||
return ::GetInstance().table->GetNumber(key, defaultValue);
|
||||
}
|
||||
|
||||
float Preferences::GetFloat(std::string_view key, float defaultValue) {
|
||||
return m_table->GetNumber(key, defaultValue);
|
||||
return ::GetInstance().table->GetNumber(key, defaultValue);
|
||||
}
|
||||
|
||||
bool Preferences::GetBoolean(std::string_view key, bool defaultValue) {
|
||||
return m_table->GetBoolean(key, defaultValue);
|
||||
return ::GetInstance().table->GetBoolean(key, defaultValue);
|
||||
}
|
||||
|
||||
int64_t Preferences::GetLong(std::string_view key, int64_t defaultValue) {
|
||||
return static_cast<int64_t>(m_table->GetNumber(key, defaultValue));
|
||||
return static_cast<int64_t>(
|
||||
::GetInstance().table->GetNumber(key, defaultValue));
|
||||
}
|
||||
|
||||
void Preferences::SetString(std::string_view key, std::string_view value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
auto entry = ::GetInstance().table->GetEntry(key);
|
||||
entry.SetString(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
@@ -59,12 +77,12 @@ void Preferences::PutString(std::string_view key, std::string_view value) {
|
||||
}
|
||||
|
||||
void Preferences::InitString(std::string_view key, std::string_view value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
auto entry = ::GetInstance().table->GetEntry(key);
|
||||
entry.SetDefaultString(value);
|
||||
}
|
||||
|
||||
void Preferences::SetInt(std::string_view key, int value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
auto entry = ::GetInstance().table->GetEntry(key);
|
||||
entry.SetDouble(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
@@ -74,12 +92,12 @@ void Preferences::PutInt(std::string_view key, int value) {
|
||||
}
|
||||
|
||||
void Preferences::InitInt(std::string_view key, int value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
auto entry = ::GetInstance().table->GetEntry(key);
|
||||
entry.SetDefaultDouble(value);
|
||||
}
|
||||
|
||||
void Preferences::SetDouble(std::string_view key, double value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
auto entry = ::GetInstance().table->GetEntry(key);
|
||||
entry.SetDouble(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
@@ -89,12 +107,12 @@ void Preferences::PutDouble(std::string_view key, double value) {
|
||||
}
|
||||
|
||||
void Preferences::InitDouble(std::string_view key, double value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
auto entry = ::GetInstance().table->GetEntry(key);
|
||||
entry.SetDefaultDouble(value);
|
||||
}
|
||||
|
||||
void Preferences::SetFloat(std::string_view key, float value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
auto entry = ::GetInstance().table->GetEntry(key);
|
||||
entry.SetDouble(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
@@ -104,12 +122,12 @@ void Preferences::PutFloat(std::string_view key, float value) {
|
||||
}
|
||||
|
||||
void Preferences::InitFloat(std::string_view key, float value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
auto entry = ::GetInstance().table->GetEntry(key);
|
||||
entry.SetDefaultDouble(value);
|
||||
}
|
||||
|
||||
void Preferences::SetBoolean(std::string_view key, bool value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
auto entry = ::GetInstance().table->GetEntry(key);
|
||||
entry.SetBoolean(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
@@ -119,12 +137,12 @@ void Preferences::PutBoolean(std::string_view key, bool value) {
|
||||
}
|
||||
|
||||
void Preferences::InitBoolean(std::string_view key, bool value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
auto entry = ::GetInstance().table->GetEntry(key);
|
||||
entry.SetDefaultBoolean(value);
|
||||
}
|
||||
|
||||
void Preferences::SetLong(std::string_view key, int64_t value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
auto entry = ::GetInstance().table->GetEntry(key);
|
||||
entry.SetDouble(value);
|
||||
entry.SetPersistent();
|
||||
}
|
||||
@@ -134,16 +152,16 @@ void Preferences::PutLong(std::string_view key, int64_t value) {
|
||||
}
|
||||
|
||||
void Preferences::InitLong(std::string_view key, int64_t value) {
|
||||
auto entry = m_table->GetEntry(key);
|
||||
auto entry = ::GetInstance().table->GetEntry(key);
|
||||
entry.SetDefaultDouble(value);
|
||||
}
|
||||
|
||||
bool Preferences::ContainsKey(std::string_view key) {
|
||||
return m_table->ContainsKey(key);
|
||||
return ::GetInstance().table->ContainsKey(key);
|
||||
}
|
||||
|
||||
void Preferences::Remove(std::string_view key) {
|
||||
m_table->Delete(key);
|
||||
::GetInstance().table->Delete(key);
|
||||
}
|
||||
|
||||
void Preferences::RemoveAll() {
|
||||
@@ -154,10 +172,9 @@ void Preferences::RemoveAll() {
|
||||
}
|
||||
}
|
||||
|
||||
Preferences::Preferences()
|
||||
: m_table(nt::NetworkTableInstance::GetDefault().GetTable(kTableName)) {
|
||||
m_table->GetEntry(".type").SetString("RobotPreferences");
|
||||
m_listener = m_table->AddEntryListener(
|
||||
Instance::Instance() {
|
||||
table->GetEntry(".type").SetString("RobotPreferences");
|
||||
listener = table->AddEntryListener(
|
||||
[=](nt::NetworkTable* table, std::string_view name,
|
||||
nt::NetworkTableEntry entry, std::shared_ptr<nt::Value> value,
|
||||
int flags) { entry.SetPersistent(); },
|
||||
|
||||
@@ -56,7 +56,7 @@ Relay::Relay(int channel, Relay::Direction direction)
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "Relay", m_channel);
|
||||
wpi::SendableRegistry::AddLW(this, "Relay", m_channel);
|
||||
}
|
||||
|
||||
Relay::~Relay() {
|
||||
|
||||
@@ -9,25 +9,25 @@
|
||||
using namespace frc;
|
||||
|
||||
bool RobotState::IsDisabled() {
|
||||
return DriverStation::GetInstance().IsDisabled();
|
||||
return DriverStation::IsDisabled();
|
||||
}
|
||||
|
||||
bool RobotState::IsEnabled() {
|
||||
return DriverStation::GetInstance().IsEnabled();
|
||||
return DriverStation::IsEnabled();
|
||||
}
|
||||
|
||||
bool RobotState::IsEStopped() {
|
||||
return DriverStation::GetInstance().IsEStopped();
|
||||
return DriverStation::IsEStopped();
|
||||
}
|
||||
|
||||
bool RobotState::IsOperatorControl() {
|
||||
return DriverStation::GetInstance().IsOperatorControl();
|
||||
return DriverStation::IsOperatorControl();
|
||||
}
|
||||
|
||||
bool RobotState::IsAutonomous() {
|
||||
return DriverStation::GetInstance().IsAutonomous();
|
||||
return DriverStation::IsAutonomous();
|
||||
}
|
||||
|
||||
bool RobotState::IsTest() {
|
||||
return DriverStation::GetInstance().IsTest();
|
||||
return DriverStation::IsTest();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ Servo::Servo(int channel) : PWM(channel) {
|
||||
SetPeriodMultiplier(kPeriodMultiplier_4X);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Servo, channel + 1);
|
||||
wpi::SendableRegistry::GetInstance().SetName(this, "Servo", channel);
|
||||
wpi::SendableRegistry::SetName(this, "Servo", channel);
|
||||
}
|
||||
|
||||
void Servo::Set(double value) {
|
||||
|
||||
@@ -36,8 +36,8 @@ Solenoid::Solenoid(std::shared_ptr<PneumaticsBase> module, int channel)
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Solenoid, m_channel + 1,
|
||||
m_module->GetModuleNumber() + 1);
|
||||
wpi::SendableRegistry::GetInstance().AddLW(
|
||||
this, "Solenoid", m_module->GetModuleNumber(), m_channel);
|
||||
wpi::SendableRegistry::AddLW(this, "Solenoid", m_module->GetModuleNumber(),
|
||||
m_channel);
|
||||
}
|
||||
|
||||
Solenoid::~Solenoid() {}
|
||||
|
||||
@@ -20,12 +20,11 @@ SpeedControllerGroup::SpeedControllerGroup(
|
||||
|
||||
void SpeedControllerGroup::Initialize() {
|
||||
for (auto& speedController : m_speedControllers) {
|
||||
wpi::SendableRegistry::GetInstance().AddChild(this, &speedController.get());
|
||||
wpi::SendableRegistry::AddChild(this, &speedController.get());
|
||||
}
|
||||
static int instances = 0;
|
||||
++instances;
|
||||
wpi::SendableRegistry::GetInstance().Add(this, "SpeedControllerGroup",
|
||||
instances);
|
||||
wpi::SendableRegistry::Add(this, "SpeedControllerGroup", instances);
|
||||
}
|
||||
|
||||
void SpeedControllerGroup::Set(double speed) {
|
||||
|
||||
@@ -30,9 +30,8 @@ Ultrasonic::Ultrasonic(int pingChannel, int echoChannel)
|
||||
m_echoChannel(std::make_shared<DigitalInput>(echoChannel)),
|
||||
m_counter(m_echoChannel) {
|
||||
Initialize();
|
||||
auto& registry = wpi::SendableRegistry::GetInstance();
|
||||
registry.AddChild(this, m_pingChannel.get());
|
||||
registry.AddChild(this, m_echoChannel.get());
|
||||
wpi::SendableRegistry::AddChild(this, m_pingChannel.get());
|
||||
wpi::SendableRegistry::AddChild(this, m_echoChannel.get());
|
||||
}
|
||||
|
||||
Ultrasonic::Ultrasonic(DigitalOutput* pingChannel, DigitalInput* echoChannel)
|
||||
@@ -185,8 +184,7 @@ void Ultrasonic::Initialize() {
|
||||
static int instances = 0;
|
||||
instances++;
|
||||
HAL_Report(HALUsageReporting::kResourceType_Ultrasonic, instances);
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, "Ultrasonic",
|
||||
m_echoChannel->GetChannel());
|
||||
wpi::SendableRegistry::AddLW(this, "Ultrasonic", m_echoChannel->GetChannel());
|
||||
}
|
||||
|
||||
void Ultrasonic::UltrasonicChecker() {
|
||||
|
||||
@@ -31,7 +31,7 @@ PIDController::PIDController(double Kp, double Ki, double Kd,
|
||||
static int instances = 0;
|
||||
instances++;
|
||||
HAL_Report(HALUsageReporting::kResourceType_PIDController2, instances);
|
||||
wpi::SendableRegistry::GetInstance().Add(this, "PIDController", instances);
|
||||
wpi::SendableRegistry::Add(this, "PIDController", instances);
|
||||
}
|
||||
|
||||
void PIDController::SetPID(double Kp, double Ki, double Kd) {
|
||||
|
||||
@@ -26,12 +26,11 @@ using namespace frc;
|
||||
DifferentialDrive::DifferentialDrive(SpeedController& leftMotor,
|
||||
SpeedController& rightMotor)
|
||||
: m_leftMotor(&leftMotor), m_rightMotor(&rightMotor) {
|
||||
auto& registry = wpi::SendableRegistry::GetInstance();
|
||||
registry.AddChild(this, m_leftMotor);
|
||||
registry.AddChild(this, m_rightMotor);
|
||||
wpi::SendableRegistry::AddChild(this, m_leftMotor);
|
||||
wpi::SendableRegistry::AddChild(this, m_rightMotor);
|
||||
static int instances = 0;
|
||||
++instances;
|
||||
registry.AddLW(this, "DifferentialDrive", instances);
|
||||
wpi::SendableRegistry::AddLW(this, "DifferentialDrive", instances);
|
||||
}
|
||||
|
||||
void DifferentialDrive::ArcadeDrive(double xSpeed, double zRotation,
|
||||
|
||||
@@ -43,13 +43,12 @@ KilloughDrive::KilloughDrive(SpeedController& leftMotor,
|
||||
std::sin(rightMotorAngle * (wpi::numbers::pi / 180.0))};
|
||||
m_backVec = {std::cos(backMotorAngle * (wpi::numbers::pi / 180.0)),
|
||||
std::sin(backMotorAngle * (wpi::numbers::pi / 180.0))};
|
||||
auto& registry = wpi::SendableRegistry::GetInstance();
|
||||
registry.AddChild(this, m_leftMotor);
|
||||
registry.AddChild(this, m_rightMotor);
|
||||
registry.AddChild(this, m_backMotor);
|
||||
wpi::SendableRegistry::AddChild(this, m_leftMotor);
|
||||
wpi::SendableRegistry::AddChild(this, m_rightMotor);
|
||||
wpi::SendableRegistry::AddChild(this, m_backMotor);
|
||||
static int instances = 0;
|
||||
++instances;
|
||||
registry.AddLW(this, "KilloughDrive", instances);
|
||||
wpi::SendableRegistry::AddLW(this, "KilloughDrive", instances);
|
||||
}
|
||||
|
||||
void KilloughDrive::DriveCartesian(double ySpeed, double xSpeed,
|
||||
|
||||
@@ -33,14 +33,13 @@ MecanumDrive::MecanumDrive(SpeedController& frontLeftMotor,
|
||||
m_rearLeftMotor(&rearLeftMotor),
|
||||
m_frontRightMotor(&frontRightMotor),
|
||||
m_rearRightMotor(&rearRightMotor) {
|
||||
auto& registry = wpi::SendableRegistry::GetInstance();
|
||||
registry.AddChild(this, m_frontLeftMotor);
|
||||
registry.AddChild(this, m_rearLeftMotor);
|
||||
registry.AddChild(this, m_frontRightMotor);
|
||||
registry.AddChild(this, m_rearRightMotor);
|
||||
wpi::SendableRegistry::AddChild(this, m_frontLeftMotor);
|
||||
wpi::SendableRegistry::AddChild(this, m_rearLeftMotor);
|
||||
wpi::SendableRegistry::AddChild(this, m_frontRightMotor);
|
||||
wpi::SendableRegistry::AddChild(this, m_rearRightMotor);
|
||||
static int instances = 0;
|
||||
++instances;
|
||||
registry.AddLW(this, "MecanumDrive", instances);
|
||||
wpi::SendableRegistry::AddLW(this, "MecanumDrive", instances);
|
||||
}
|
||||
|
||||
void MecanumDrive::DriveCartesian(double ySpeed, double xSpeed,
|
||||
|
||||
@@ -15,133 +15,152 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
struct LiveWindow::Impl {
|
||||
Impl();
|
||||
namespace {
|
||||
struct Component {
|
||||
bool firstTime = true;
|
||||
bool telemetryEnabled = true;
|
||||
};
|
||||
|
||||
struct Component {
|
||||
bool firstTime = true;
|
||||
bool telemetryEnabled = true;
|
||||
};
|
||||
struct Instance {
|
||||
Instance() {
|
||||
wpi::SendableRegistry::SetLiveWindowBuilderFactory(
|
||||
[] { return std::make_unique<SendableBuilderImpl>(); });
|
||||
}
|
||||
|
||||
wpi::mutex mutex;
|
||||
|
||||
wpi::SendableRegistry& registry;
|
||||
int dataHandle;
|
||||
int dataHandle = wpi::SendableRegistry::GetDataHandle();
|
||||
|
||||
std::shared_ptr<nt::NetworkTable> liveWindowTable;
|
||||
std::shared_ptr<nt::NetworkTable> statusTable;
|
||||
nt::NetworkTableEntry enabledEntry;
|
||||
std::shared_ptr<nt::NetworkTable> liveWindowTable =
|
||||
nt::NetworkTableInstance::GetDefault().GetTable("LiveWindow");
|
||||
std::shared_ptr<nt::NetworkTable> statusTable =
|
||||
liveWindowTable->GetSubTable(".status");
|
||||
nt::NetworkTableEntry enabledEntry = statusTable->GetEntry("LW Enabled");
|
||||
|
||||
bool startLiveWindow = false;
|
||||
bool liveWindowEnabled = false;
|
||||
bool telemetryEnabled = true;
|
||||
|
||||
std::function<void()> enabled;
|
||||
std::function<void()> disabled;
|
||||
|
||||
std::shared_ptr<Component> GetOrAdd(wpi::Sendable* sendable);
|
||||
};
|
||||
} // namespace
|
||||
|
||||
LiveWindow::Impl::Impl()
|
||||
: registry(wpi::SendableRegistry::GetInstance()),
|
||||
dataHandle(registry.GetDataHandle()),
|
||||
liveWindowTable(
|
||||
nt::NetworkTableInstance::GetDefault().GetTable("LiveWindow")) {
|
||||
registry.SetLiveWindowBuilderFactory(
|
||||
[] { return std::make_unique<SendableBuilderImpl>(); });
|
||||
statusTable = liveWindowTable->GetSubTable(".status");
|
||||
enabledEntry = statusTable->GetEntry("LW Enabled");
|
||||
static Instance& GetInstance() {
|
||||
static Instance instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
std::shared_ptr<LiveWindow::Impl::Component> LiveWindow::Impl::GetOrAdd(
|
||||
wpi::Sendable* sendable) {
|
||||
std::shared_ptr<Component> Instance::GetOrAdd(wpi::Sendable* sendable) {
|
||||
auto data = std::static_pointer_cast<Component>(
|
||||
registry.GetData(sendable, dataHandle));
|
||||
wpi::SendableRegistry::GetData(sendable, dataHandle));
|
||||
if (!data) {
|
||||
data = std::make_shared<Component>();
|
||||
registry.SetData(sendable, dataHandle, data);
|
||||
wpi::SendableRegistry::SetData(sendable, dataHandle, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
LiveWindow* LiveWindow::GetInstance() {
|
||||
::GetInstance();
|
||||
static LiveWindow instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
void LiveWindow::SetEnabledCallback(std::function<void()> func) {
|
||||
::GetInstance().enabled = func;
|
||||
}
|
||||
|
||||
void LiveWindow::SetDisabledCallback(std::function<void()> func) {
|
||||
::GetInstance().disabled = func;
|
||||
}
|
||||
|
||||
void LiveWindow::EnableTelemetry(wpi::Sendable* sendable) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto& inst = ::GetInstance();
|
||||
std::scoped_lock lock(inst.mutex);
|
||||
// Re-enable global setting in case DisableAllTelemetry() was called.
|
||||
m_impl->telemetryEnabled = true;
|
||||
m_impl->GetOrAdd(sendable)->telemetryEnabled = true;
|
||||
inst.telemetryEnabled = true;
|
||||
inst.GetOrAdd(sendable)->telemetryEnabled = true;
|
||||
}
|
||||
|
||||
void LiveWindow::DisableTelemetry(wpi::Sendable* sendable) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
m_impl->GetOrAdd(sendable)->telemetryEnabled = false;
|
||||
auto& inst = ::GetInstance();
|
||||
std::scoped_lock lock(inst.mutex);
|
||||
inst.GetOrAdd(sendable)->telemetryEnabled = false;
|
||||
}
|
||||
|
||||
void LiveWindow::DisableAllTelemetry() {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
m_impl->telemetryEnabled = false;
|
||||
m_impl->registry.ForeachLiveWindow(m_impl->dataHandle, [&](auto& cbdata) {
|
||||
auto& inst = ::GetInstance();
|
||||
std::scoped_lock lock(inst.mutex);
|
||||
inst.telemetryEnabled = false;
|
||||
wpi::SendableRegistry::ForeachLiveWindow(inst.dataHandle, [&](auto& cbdata) {
|
||||
if (!cbdata.data) {
|
||||
cbdata.data = std::make_shared<Impl::Component>();
|
||||
cbdata.data = std::make_shared<Component>();
|
||||
}
|
||||
std::static_pointer_cast<Impl::Component>(cbdata.data)->telemetryEnabled =
|
||||
false;
|
||||
std::static_pointer_cast<Component>(cbdata.data)->telemetryEnabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
bool LiveWindow::IsEnabled() const {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
return m_impl->liveWindowEnabled;
|
||||
bool LiveWindow::IsEnabled() {
|
||||
auto& inst = ::GetInstance();
|
||||
std::scoped_lock lock(inst.mutex);
|
||||
return inst.liveWindowEnabled;
|
||||
}
|
||||
|
||||
void LiveWindow::SetEnabled(bool enabled) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
if (m_impl->liveWindowEnabled == enabled) {
|
||||
auto& inst = ::GetInstance();
|
||||
std::scoped_lock lock(inst.mutex);
|
||||
if (inst.liveWindowEnabled == enabled) {
|
||||
return;
|
||||
}
|
||||
m_impl->startLiveWindow = enabled;
|
||||
m_impl->liveWindowEnabled = enabled;
|
||||
inst.startLiveWindow = enabled;
|
||||
inst.liveWindowEnabled = enabled;
|
||||
// Force table generation now to make sure everything is defined
|
||||
UpdateValuesUnsafe();
|
||||
if (enabled) {
|
||||
if (this->enabled) {
|
||||
this->enabled();
|
||||
if (inst.enabled) {
|
||||
inst.enabled();
|
||||
}
|
||||
} else {
|
||||
m_impl->registry.ForeachLiveWindow(m_impl->dataHandle, [&](auto& cbdata) {
|
||||
static_cast<SendableBuilderImpl&>(cbdata.builder).StopLiveWindowMode();
|
||||
});
|
||||
if (this->disabled) {
|
||||
this->disabled();
|
||||
wpi::SendableRegistry::ForeachLiveWindow(
|
||||
inst.dataHandle, [&](auto& cbdata) {
|
||||
static_cast<SendableBuilderImpl&>(cbdata.builder)
|
||||
.StopLiveWindowMode();
|
||||
});
|
||||
if (inst.disabled) {
|
||||
inst.disabled();
|
||||
}
|
||||
}
|
||||
m_impl->enabledEntry.SetBoolean(enabled);
|
||||
inst.enabledEntry.SetBoolean(enabled);
|
||||
}
|
||||
|
||||
void LiveWindow::UpdateValues() {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto& inst = ::GetInstance();
|
||||
std::scoped_lock lock(inst.mutex);
|
||||
UpdateValuesUnsafe();
|
||||
}
|
||||
|
||||
void LiveWindow::UpdateValuesUnsafe() {
|
||||
auto& inst = ::GetInstance();
|
||||
// Only do this if either LiveWindow mode or telemetry is enabled.
|
||||
if (!m_impl->liveWindowEnabled && !m_impl->telemetryEnabled) {
|
||||
if (!inst.liveWindowEnabled && !inst.telemetryEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_impl->registry.ForeachLiveWindow(m_impl->dataHandle, [&](auto& cbdata) {
|
||||
wpi::SendableRegistry::ForeachLiveWindow(inst.dataHandle, [&](auto& cbdata) {
|
||||
if (!cbdata.sendable || cbdata.parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cbdata.data) {
|
||||
cbdata.data = std::make_shared<Impl::Component>();
|
||||
cbdata.data = std::make_shared<Component>();
|
||||
}
|
||||
|
||||
auto& comp = *std::static_pointer_cast<Impl::Component>(cbdata.data);
|
||||
auto& comp = *std::static_pointer_cast<Component>(cbdata.data);
|
||||
|
||||
if (!m_impl->liveWindowEnabled && !comp.telemetryEnabled) {
|
||||
if (!inst.liveWindowEnabled && !comp.telemetryEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -153,7 +172,7 @@ void LiveWindow::UpdateValuesUnsafe() {
|
||||
if (cbdata.name.empty()) {
|
||||
return;
|
||||
}
|
||||
auto ssTable = m_impl->liveWindowTable->GetSubTable(cbdata.subsystem);
|
||||
auto ssTable = inst.liveWindowTable->GetSubTable(cbdata.subsystem);
|
||||
std::shared_ptr<nt::NetworkTable> table;
|
||||
// Treat name==subsystem as top level of subsystem
|
||||
if (cbdata.name == cbdata.subsystem) {
|
||||
@@ -169,13 +188,11 @@ void LiveWindow::UpdateValuesUnsafe() {
|
||||
comp.firstTime = false;
|
||||
}
|
||||
|
||||
if (m_impl->startLiveWindow) {
|
||||
if (inst.startLiveWindow) {
|
||||
static_cast<SendableBuilderImpl&>(cbdata.builder).StartLiveWindowMode();
|
||||
}
|
||||
cbdata.builder.Update();
|
||||
});
|
||||
|
||||
m_impl->startLiveWindow = false;
|
||||
inst.startLiveWindow = false;
|
||||
}
|
||||
|
||||
LiveWindow::LiveWindow() : m_impl(new Impl) {}
|
||||
|
||||
@@ -20,12 +20,11 @@ MotorControllerGroup::MotorControllerGroup(
|
||||
|
||||
void MotorControllerGroup::Initialize() {
|
||||
for (auto& motorController : m_motorControllers) {
|
||||
wpi::SendableRegistry::GetInstance().AddChild(this, &motorController.get());
|
||||
wpi::SendableRegistry::AddChild(this, &motorController.get());
|
||||
}
|
||||
static int instances = 0;
|
||||
++instances;
|
||||
wpi::SendableRegistry::GetInstance().Add(this, "MotorControllerGroup",
|
||||
instances);
|
||||
wpi::SendableRegistry::Add(this, "MotorControllerGroup", instances);
|
||||
}
|
||||
|
||||
void MotorControllerGroup::Set(double speed) {
|
||||
|
||||
@@ -13,9 +13,8 @@ using namespace frc;
|
||||
|
||||
NidecBrushless::NidecBrushless(int pwmChannel, int dioChannel)
|
||||
: m_dio(dioChannel), m_pwm(pwmChannel) {
|
||||
auto& registry = wpi::SendableRegistry::GetInstance();
|
||||
registry.AddChild(this, &m_dio);
|
||||
registry.AddChild(this, &m_pwm);
|
||||
wpi::SendableRegistry::AddChild(this, &m_dio);
|
||||
wpi::SendableRegistry::AddChild(this, &m_pwm);
|
||||
SetExpiration(0_s);
|
||||
SetSafetyEnabled(false);
|
||||
|
||||
@@ -24,7 +23,7 @@ NidecBrushless::NidecBrushless(int pwmChannel, int dioChannel)
|
||||
m_dio.EnablePWM(0.5);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_NidecBrushless, pwmChannel + 1);
|
||||
registry.AddLW(this, "Nidec Brushless", pwmChannel);
|
||||
wpi::SendableRegistry::AddLW(this, "Nidec Brushless", pwmChannel);
|
||||
}
|
||||
|
||||
void NidecBrushless::Set(double speed) {
|
||||
|
||||
@@ -44,7 +44,7 @@ int PWMMotorController::GetChannel() const {
|
||||
|
||||
PWMMotorController::PWMMotorController(std::string_view name, int channel)
|
||||
: m_pwm(channel, false) {
|
||||
wpi::SendableRegistry::GetInstance().AddLW(this, name, channel);
|
||||
wpi::SendableRegistry::AddLW(this, name, channel);
|
||||
}
|
||||
|
||||
void PWMMotorController::InitSendable(wpi::SendableBuilder& builder) {
|
||||
|
||||
@@ -21,7 +21,7 @@ std::shared_ptr<SendableCameraWrapper>& GetSendableCameraWrapper(
|
||||
}
|
||||
|
||||
void AddToSendableRegistry(wpi::Sendable* sendable, std::string name) {
|
||||
wpi::SendableRegistry::GetInstance().Add(sendable, name);
|
||||
wpi::SendableRegistry::Add(sendable, name);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ ComplexWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
}
|
||||
|
||||
ComplexWidget& ShuffleboardContainer::Add(wpi::Sendable& sendable) {
|
||||
auto name = wpi::SendableRegistry::GetInstance().GetName(&sendable);
|
||||
auto name = wpi::SendableRegistry::GetName(&sendable);
|
||||
if (name.empty()) {
|
||||
FRC_ReportError(err::Error, "{}", "Sendable must have a name");
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ void DriverStationSim::SetMatchTime(double matchTime) {
|
||||
|
||||
void DriverStationSim::NotifyNewData() {
|
||||
HALSIM_NotifyDriverStationNewData();
|
||||
DriverStation::GetInstance().WaitForData();
|
||||
DriverStation::WaitForData();
|
||||
}
|
||||
|
||||
void DriverStationSim::SetSendError(bool shouldSend) {
|
||||
|
||||
@@ -13,7 +13,7 @@ Field2d::Field2d() {
|
||||
m_objects.emplace_back(
|
||||
std::make_unique<FieldObject2d>("Robot", FieldObject2d::private_init{}));
|
||||
m_objects[0]->SetPose(Pose2d{});
|
||||
wpi::SendableRegistry::GetInstance().Add(this, "Field");
|
||||
wpi::SendableRegistry::Add(this, "Field");
|
||||
}
|
||||
|
||||
Field2d::Field2d(Field2d&& rhs) : SendableHelper(std::move(rhs)) {
|
||||
|
||||
@@ -11,7 +11,7 @@ using namespace frc;
|
||||
std::atomic_int SendableChooserBase::s_instances{0};
|
||||
|
||||
SendableChooserBase::SendableChooserBase() : m_instance{s_instances++} {
|
||||
wpi::SendableRegistry::GetInstance().Add(this, "SendableChooser", m_instance);
|
||||
wpi::SendableRegistry::Add(this, "SendableChooser", m_instance);
|
||||
}
|
||||
|
||||
SendableChooserBase::SendableChooserBase(SendableChooserBase&& oth)
|
||||
|
||||
@@ -12,95 +12,86 @@
|
||||
#include <wpi/sendable/SendableRegistry.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/smartdashboard/ListenerExecutor.h"
|
||||
#include "frc/smartdashboard/SendableBuilderImpl.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
namespace {
|
||||
class Singleton {
|
||||
public:
|
||||
static Singleton& GetInstance();
|
||||
|
||||
std::shared_ptr<nt::NetworkTable> table;
|
||||
struct Instance {
|
||||
detail::ListenerExecutor listenerExecutor;
|
||||
std::shared_ptr<nt::NetworkTable> table =
|
||||
nt::NetworkTableInstance::GetDefault().GetTable("SmartDashboard");
|
||||
wpi::StringMap<wpi::SendableRegistry::UID> tablesToData;
|
||||
wpi::mutex tablesToDataMutex;
|
||||
|
||||
private:
|
||||
Singleton() {
|
||||
table = nt::NetworkTableInstance::GetDefault().GetTable("SmartDashboard");
|
||||
HAL_Report(HALUsageReporting::kResourceType_SmartDashboard, 0);
|
||||
}
|
||||
Singleton(const Singleton&) = delete;
|
||||
Singleton& operator=(const Singleton&) = delete;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Singleton& Singleton::GetInstance() {
|
||||
static Singleton instance;
|
||||
static Instance& GetInstance() {
|
||||
HAL_Report(HALUsageReporting::kResourceType_SmartDashboard, 0);
|
||||
static Instance instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void SmartDashboard::init() {
|
||||
Singleton::GetInstance();
|
||||
GetInstance();
|
||||
}
|
||||
|
||||
bool SmartDashboard::ContainsKey(std::string_view key) {
|
||||
return Singleton::GetInstance().table->ContainsKey(key);
|
||||
return GetInstance().table->ContainsKey(key);
|
||||
}
|
||||
|
||||
std::vector<std::string> SmartDashboard::GetKeys(int types) {
|
||||
return Singleton::GetInstance().table->GetKeys(types);
|
||||
return GetInstance().table->GetKeys(types);
|
||||
}
|
||||
|
||||
void SmartDashboard::SetPersistent(std::string_view key) {
|
||||
Singleton::GetInstance().table->GetEntry(key).SetPersistent();
|
||||
GetInstance().table->GetEntry(key).SetPersistent();
|
||||
}
|
||||
|
||||
void SmartDashboard::ClearPersistent(std::string_view key) {
|
||||
Singleton::GetInstance().table->GetEntry(key).ClearPersistent();
|
||||
GetInstance().table->GetEntry(key).ClearPersistent();
|
||||
}
|
||||
|
||||
bool SmartDashboard::IsPersistent(std::string_view key) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).IsPersistent();
|
||||
return GetInstance().table->GetEntry(key).IsPersistent();
|
||||
}
|
||||
|
||||
void SmartDashboard::SetFlags(std::string_view key, unsigned int flags) {
|
||||
Singleton::GetInstance().table->GetEntry(key).SetFlags(flags);
|
||||
GetInstance().table->GetEntry(key).SetFlags(flags);
|
||||
}
|
||||
|
||||
void SmartDashboard::ClearFlags(std::string_view key, unsigned int flags) {
|
||||
Singleton::GetInstance().table->GetEntry(key).ClearFlags(flags);
|
||||
GetInstance().table->GetEntry(key).ClearFlags(flags);
|
||||
}
|
||||
|
||||
unsigned int SmartDashboard::GetFlags(std::string_view key) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).GetFlags();
|
||||
return GetInstance().table->GetEntry(key).GetFlags();
|
||||
}
|
||||
|
||||
void SmartDashboard::Delete(std::string_view key) {
|
||||
Singleton::GetInstance().table->Delete(key);
|
||||
GetInstance().table->Delete(key);
|
||||
}
|
||||
|
||||
nt::NetworkTableEntry SmartDashboard::GetEntry(std::string_view key) {
|
||||
return Singleton::GetInstance().table->GetEntry(key);
|
||||
return GetInstance().table->GetEntry(key);
|
||||
}
|
||||
|
||||
void SmartDashboard::PutData(std::string_view key, wpi::Sendable* data) {
|
||||
if (!data) {
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "value");
|
||||
}
|
||||
auto& inst = Singleton::GetInstance();
|
||||
auto& inst = GetInstance();
|
||||
std::scoped_lock lock(inst.tablesToDataMutex);
|
||||
auto& uid = inst.tablesToData[key];
|
||||
auto& registry = wpi::SendableRegistry::GetInstance();
|
||||
wpi::Sendable* sddata = registry.GetSendable(uid);
|
||||
wpi::Sendable* sddata = wpi::SendableRegistry::GetSendable(uid);
|
||||
if (sddata != data) {
|
||||
uid = registry.GetUniqueId(data);
|
||||
uid = wpi::SendableRegistry::GetUniqueId(data);
|
||||
auto dataTable = inst.table->GetSubTable(key);
|
||||
auto builder = std::make_unique<SendableBuilderImpl>();
|
||||
auto builderPtr = builder.get();
|
||||
builderPtr->SetTable(dataTable);
|
||||
registry.Publish(uid, std::move(builder));
|
||||
wpi::SendableRegistry::Publish(uid, std::move(builder));
|
||||
builderPtr->StartListeners();
|
||||
dataTable->GetEntry(".name").SetString(key);
|
||||
}
|
||||
@@ -110,163 +101,147 @@ void SmartDashboard::PutData(wpi::Sendable* value) {
|
||||
if (!value) {
|
||||
throw FRC_MakeError(err::NullParameter, "{}", "value");
|
||||
}
|
||||
auto name = wpi::SendableRegistry::GetInstance().GetName(value);
|
||||
auto name = wpi::SendableRegistry::GetName(value);
|
||||
if (!name.empty()) {
|
||||
PutData(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
wpi::Sendable* SmartDashboard::GetData(std::string_view key) {
|
||||
auto& inst = Singleton::GetInstance();
|
||||
auto& inst = GetInstance();
|
||||
std::scoped_lock lock(inst.tablesToDataMutex);
|
||||
auto it = inst.tablesToData.find(key);
|
||||
if (it == inst.tablesToData.end()) {
|
||||
throw FRC_MakeError(err::SmartDashboardMissingKey, "{}", key);
|
||||
}
|
||||
return wpi::SendableRegistry::GetInstance().GetSendable(it->getValue());
|
||||
return wpi::SendableRegistry::GetSendable(it->getValue());
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutBoolean(std::string_view keyName, bool value) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).SetBoolean(value);
|
||||
return GetInstance().table->GetEntry(keyName).SetBoolean(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultBoolean(std::string_view key,
|
||||
bool defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultBoolean(
|
||||
defaultValue);
|
||||
return GetInstance().table->GetEntry(key).SetDefaultBoolean(defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::GetBoolean(std::string_view keyName, bool defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).GetBoolean(
|
||||
defaultValue);
|
||||
return GetInstance().table->GetEntry(keyName).GetBoolean(defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutNumber(std::string_view keyName, double value) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).SetDouble(value);
|
||||
return GetInstance().table->GetEntry(keyName).SetDouble(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultNumber(std::string_view key,
|
||||
double defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultDouble(
|
||||
defaultValue);
|
||||
return GetInstance().table->GetEntry(key).SetDefaultDouble(defaultValue);
|
||||
}
|
||||
|
||||
double SmartDashboard::GetNumber(std::string_view keyName,
|
||||
double defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).GetDouble(
|
||||
defaultValue);
|
||||
return GetInstance().table->GetEntry(keyName).GetDouble(defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutString(std::string_view keyName,
|
||||
std::string_view value) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).SetString(value);
|
||||
return GetInstance().table->GetEntry(keyName).SetString(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultString(std::string_view key,
|
||||
std::string_view defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultString(
|
||||
defaultValue);
|
||||
return GetInstance().table->GetEntry(key).SetDefaultString(defaultValue);
|
||||
}
|
||||
|
||||
std::string SmartDashboard::GetString(std::string_view keyName,
|
||||
std::string_view defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).GetString(
|
||||
defaultValue);
|
||||
return GetInstance().table->GetEntry(keyName).GetString(defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutBooleanArray(std::string_view key,
|
||||
wpi::span<const int> value) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetBooleanArray(value);
|
||||
return GetInstance().table->GetEntry(key).SetBooleanArray(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultBooleanArray(std::string_view key,
|
||||
wpi::span<const int> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultBooleanArray(
|
||||
return GetInstance().table->GetEntry(key).SetDefaultBooleanArray(
|
||||
defaultValue);
|
||||
}
|
||||
|
||||
std::vector<int> SmartDashboard::GetBooleanArray(
|
||||
std::string_view key, wpi::span<const int> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).GetBooleanArray(
|
||||
defaultValue);
|
||||
return GetInstance().table->GetEntry(key).GetBooleanArray(defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutNumberArray(std::string_view key,
|
||||
wpi::span<const double> value) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDoubleArray(value);
|
||||
return GetInstance().table->GetEntry(key).SetDoubleArray(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultNumberArray(
|
||||
std::string_view key, wpi::span<const double> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultDoubleArray(
|
||||
defaultValue);
|
||||
return GetInstance().table->GetEntry(key).SetDefaultDoubleArray(defaultValue);
|
||||
}
|
||||
|
||||
std::vector<double> SmartDashboard::GetNumberArray(
|
||||
std::string_view key, wpi::span<const double> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).GetDoubleArray(
|
||||
defaultValue);
|
||||
return GetInstance().table->GetEntry(key).GetDoubleArray(defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutStringArray(std::string_view key,
|
||||
wpi::span<const std::string> value) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetStringArray(value);
|
||||
return GetInstance().table->GetEntry(key).SetStringArray(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultStringArray(
|
||||
std::string_view key, wpi::span<const std::string> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultStringArray(
|
||||
defaultValue);
|
||||
return GetInstance().table->GetEntry(key).SetDefaultStringArray(defaultValue);
|
||||
}
|
||||
|
||||
std::vector<std::string> SmartDashboard::GetStringArray(
|
||||
std::string_view key, wpi::span<const std::string> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).GetStringArray(
|
||||
defaultValue);
|
||||
return GetInstance().table->GetEntry(key).GetStringArray(defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutRaw(std::string_view key, std::string_view value) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetRaw(value);
|
||||
return GetInstance().table->GetEntry(key).SetRaw(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultRaw(std::string_view key,
|
||||
std::string_view defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultRaw(
|
||||
defaultValue);
|
||||
return GetInstance().table->GetEntry(key).SetDefaultRaw(defaultValue);
|
||||
}
|
||||
|
||||
std::string SmartDashboard::GetRaw(std::string_view key,
|
||||
std::string_view defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).GetRaw(defaultValue);
|
||||
return GetInstance().table->GetEntry(key).GetRaw(defaultValue);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutValue(std::string_view keyName,
|
||||
std::shared_ptr<nt::Value> value) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).SetValue(value);
|
||||
return GetInstance().table->GetEntry(keyName).SetValue(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultValue(std::string_view key,
|
||||
std::shared_ptr<nt::Value> defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).SetDefaultValue(
|
||||
defaultValue);
|
||||
return GetInstance().table->GetEntry(key).SetDefaultValue(defaultValue);
|
||||
}
|
||||
|
||||
std::shared_ptr<nt::Value> SmartDashboard::GetValue(std::string_view keyName) {
|
||||
return Singleton::GetInstance().table->GetEntry(keyName).GetValue();
|
||||
return GetInstance().table->GetEntry(keyName).GetValue();
|
||||
}
|
||||
|
||||
detail::ListenerExecutor SmartDashboard::listenerExecutor;
|
||||
|
||||
void SmartDashboard::PostListenerTask(std::function<void()> task) {
|
||||
listenerExecutor.Execute(task);
|
||||
GetInstance().listenerExecutor.Execute(task);
|
||||
}
|
||||
|
||||
void SmartDashboard::UpdateValues() {
|
||||
auto& registry = wpi::SendableRegistry::GetInstance();
|
||||
auto& inst = Singleton::GetInstance();
|
||||
listenerExecutor.RunListenerTasks();
|
||||
auto& inst = GetInstance();
|
||||
inst.listenerExecutor.RunListenerTasks();
|
||||
std::scoped_lock lock(inst.tablesToDataMutex);
|
||||
for (auto& i : inst.tablesToData) {
|
||||
registry.Update(i.getValue());
|
||||
wpi::SendableRegistry::Update(i.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user