Split Sendable into NT and non-NT portions (#3432)

The non-NT portion has been moved to wpiutil.
The NT portion has been moved to ntcore (as NTSendable).

SendableBuilder similarly split and moved.

SendableRegistry moved to wpiutil.

In C++, SendableHelper also moved to wpiutil.

This enables use of Sendable from wpimath and also enables
moving several classes from wpilib to wpimath.
This commit is contained in:
Peter Johnson
2021-06-13 16:38:05 -07:00
committed by GitHub
parent ef4ea84cb5
commit b417d961ec
196 changed files with 1147 additions and 891 deletions

View File

@@ -8,10 +8,10 @@
#include <cmath>
#include <hal/FRCUsageReporting.h>
#include <wpi/sendable/SendableBuilder.h>
#include <wpi/sendable/SendableRegistry.h>
#include "frc/PIDOutput.h"
#include "frc/smartdashboard/SendableBuilder.h"
#include "frc/smartdashboard/SendableRegistry.h"
using namespace frc;
@@ -41,7 +41,7 @@ PIDBase::PIDBase(double Kp, double Ki, double Kd, double Kf, PIDSource& source,
static int instances = 0;
instances++;
HAL_Report(HALUsageReporting::kResourceType_PIDController, instances);
SendableRegistry::GetInstance().Add(this, "PIDController", instances);
wpi::SendableRegistry::GetInstance().Add(this, "PIDController", instances);
}
double PIDBase::Get() const {
@@ -228,7 +228,7 @@ void PIDBase::PIDWrite(double output) {
SetSetpoint(output);
}
void PIDBase::InitSendable(SendableBuilder& builder) {
void PIDBase::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("PIDController");
builder.SetSafeState([=] { Reset(); });
builder.AddDoubleProperty(

View File

@@ -4,9 +4,10 @@
#include "frc/PIDController.h"
#include <wpi/sendable/SendableBuilder.h>
#include "frc/Notifier.h"
#include "frc/PIDOutput.h"
#include "frc/smartdashboard/SendableBuilder.h"
using namespace frc;
@@ -75,7 +76,7 @@ void PIDController::Reset() {
PIDBase::Reset();
}
void PIDController::InitSendable(SendableBuilder& builder) {
void PIDController::InitSendable(wpi::SendableBuilder& builder) {
PIDBase::InitSendable(builder);
builder.AddBooleanProperty(
"enabled", [=] { return IsEnabled(); },

View File

@@ -2,13 +2,14 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <wpi/sendable/SendableBuilder.h>
#include "frc/buttons/Button.h"
#include "frc/buttons/CancelButtonScheduler.h"
#include "frc/buttons/HeldButtonScheduler.h"
#include "frc/buttons/PressedButtonScheduler.h"
#include "frc/buttons/ReleasedButtonScheduler.h"
#include "frc/buttons/ToggleButtonScheduler.h"
#include "frc/smartdashboard/SendableBuilder.h"
using namespace frc;
@@ -62,7 +63,7 @@ void Trigger::ToggleWhenActive(Command* command) {
tbs->Start();
}
void Trigger::InitSendable(SendableBuilder& builder) {
void Trigger::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Button");
builder.SetSafeState([=] { m_sendablePressed = false; });
builder.AddBooleanProperty(

View File

@@ -6,14 +6,15 @@
#include <typeinfo>
#include <wpi/sendable/SendableBuilder.h>
#include <wpi/sendable/SendableRegistry.h>
#include "frc/Errors.h"
#include "frc/RobotState.h"
#include "frc/Timer.h"
#include "frc/commands/CommandGroup.h"
#include "frc/commands/Scheduler.h"
#include "frc/livewindow/LiveWindow.h"
#include "frc/smartdashboard/SendableBuilder.h"
#include "frc/smartdashboard/SendableRegistry.h"
using namespace frc;
@@ -40,10 +41,10 @@ Command::Command(std::string_view name, units::second_t timeout) {
// If name contains an empty string
if (name.empty()) {
SendableRegistry::GetInstance().Add(
wpi::SendableRegistry::GetInstance().Add(
this, fmt::format("Command_{}", typeid(*this).name()));
} else {
SendableRegistry::GetInstance().Add(this, name);
wpi::SendableRegistry::GetInstance().Add(this, name);
}
}
@@ -277,25 +278,26 @@ void Command::StartTiming() {
}
std::string Command::GetName() const {
return SendableRegistry::GetInstance().GetName(this);
return wpi::SendableRegistry::GetInstance().GetName(this);
}
void Command::SetName(std::string_view name) {
SendableRegistry::GetInstance().SetName(this, name);
wpi::SendableRegistry::GetInstance().SetName(this, name);
}
std::string Command::GetSubsystem() const {
return SendableRegistry::GetInstance().GetSubsystem(this);
return wpi::SendableRegistry::GetInstance().GetSubsystem(this);
}
void Command::SetSubsystem(std::string_view name) {
SendableRegistry::GetInstance().SetSubsystem(this, name);
wpi::SendableRegistry::GetInstance().SetSubsystem(this, name);
}
void Command::InitSendable(SendableBuilder& builder) {
void Command::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Command");
builder.AddStringProperty(
".name", [=] { return SendableRegistry::GetInstance().GetName(this); },
".name",
[=] { return wpi::SendableRegistry::GetInstance().GetName(this); },
nullptr);
builder.AddBooleanProperty(
"running", [=] { return IsRunning(); },

View File

@@ -4,7 +4,7 @@
#include "frc/commands/PIDCommand.h"
#include "frc/smartdashboard/SendableBuilder.h"
#include <wpi/sendable/SendableBuilder.h>
using namespace frc;
@@ -112,7 +112,7 @@ double PIDCommand::GetPosition() {
return ReturnPIDInput();
}
void PIDCommand::InitSendable(SendableBuilder& builder) {
void PIDCommand::InitSendable(wpi::SendableBuilder& builder) {
m_controller->InitSendable(builder);
Command::InitSendable(builder);
builder.SetSmartDashboardType("PIDCommand");

View File

@@ -10,16 +10,16 @@
#include <vector>
#include <hal/FRCUsageReporting.h>
#include <networktables/NTSendableBuilder.h>
#include <networktables/NetworkTableEntry.h>
#include <wpi/mutex.h>
#include <wpi/sendable/SendableRegistry.h>
#include "frc/Errors.h"
#include "frc/buttons/ButtonScheduler.h"
#include "frc/commands/Command.h"
#include "frc/commands/Subsystem.h"
#include "frc/livewindow/LiveWindow.h"
#include "frc/smartdashboard/SendableBuilder.h"
#include "frc/smartdashboard/SendableRegistry.h"
using namespace frc;
@@ -157,7 +157,7 @@ void Scheduler::SetEnabled(bool enabled) {
m_impl->enabled = enabled;
}
void Scheduler::InitSendable(SendableBuilder& builder) {
void Scheduler::InitSendable(nt::NTSendableBuilder& builder) {
builder.SetSmartDashboardType("Scheduler");
auto namesEntry = builder.GetEntry("Names");
auto idsEntry = builder.GetEntry("Ids");
@@ -186,7 +186,7 @@ void Scheduler::InitSendable(SendableBuilder& builder) {
if (m_impl->runningCommandsChanged) {
m_impl->commandsBuf.resize(0);
m_impl->idsBuf.resize(0);
auto& registry = SendableRegistry::GetInstance();
auto& registry = wpi::SendableRegistry::GetInstance();
for (const auto& command : m_impl->commands) {
m_impl->commandsBuf.emplace_back(registry.GetName(command));
m_impl->idsBuf.emplace_back(command->GetID());
@@ -200,7 +200,7 @@ void Scheduler::InitSendable(SendableBuilder& builder) {
Scheduler::Scheduler() : m_impl(new Impl) {
HAL_Report(HALUsageReporting::kResourceType_Command,
HALUsageReporting::kCommand_Scheduler);
SendableRegistry::GetInstance().AddLW(this, "Scheduler");
wpi::SendableRegistry::GetInstance().AddLW(this, "Scheduler");
auto scheduler = frc::LiveWindow::GetInstance();
scheduler->enabled = [this] {
this->SetEnabled(false);
@@ -210,7 +210,7 @@ Scheduler::Scheduler() : m_impl(new Impl) {
}
Scheduler::~Scheduler() {
SendableRegistry::GetInstance().Remove(this);
wpi::SendableRegistry::GetInstance().Remove(this);
auto scheduler = frc::LiveWindow::GetInstance();
scheduler->enabled = nullptr;
scheduler->disabled = nullptr;

View File

@@ -4,17 +4,18 @@
#include "frc/commands/Subsystem.h"
#include <wpi/sendable/SendableBuilder.h>
#include <wpi/sendable/SendableRegistry.h>
#include "frc/Errors.h"
#include "frc/commands/Command.h"
#include "frc/commands/Scheduler.h"
#include "frc/livewindow/LiveWindow.h"
#include "frc/smartdashboard/SendableBuilder.h"
#include "frc/smartdashboard/SendableRegistry.h"
using namespace frc;
Subsystem::Subsystem(std::string_view name) {
SendableRegistry::GetInstance().AddLW(this, name, name);
wpi::SendableRegistry::GetInstance().AddLW(this, name, name);
Scheduler::GetInstance()->RegisterSubsystem(this);
}
@@ -43,7 +44,7 @@ Command* Subsystem::GetDefaultCommand() {
std::string Subsystem::GetDefaultCommandName() {
Command* defaultCommand = GetDefaultCommand();
if (defaultCommand) {
return SendableRegistry::GetInstance().GetName(defaultCommand);
return wpi::SendableRegistry::GetInstance().GetName(defaultCommand);
} else {
return {};
}
@@ -61,7 +62,7 @@ Command* Subsystem::GetCurrentCommand() const {
std::string Subsystem::GetCurrentCommandName() const {
Command* currentCommand = GetCurrentCommand();
if (currentCommand) {
return SendableRegistry::GetInstance().GetName(currentCommand);
return wpi::SendableRegistry::GetInstance().GetName(currentCommand);
} else {
return {};
}
@@ -72,19 +73,19 @@ void Subsystem::Periodic() {}
void Subsystem::InitDefaultCommand() {}
std::string Subsystem::GetName() const {
return SendableRegistry::GetInstance().GetName(this);
return wpi::SendableRegistry::GetInstance().GetName(this);
}
void Subsystem::SetName(std::string_view name) {
SendableRegistry::GetInstance().SetName(this, name);
wpi::SendableRegistry::GetInstance().SetName(this, name);
}
std::string Subsystem::GetSubsystem() const {
return SendableRegistry::GetInstance().GetSubsystem(this);
return wpi::SendableRegistry::GetInstance().GetSubsystem(this);
}
void Subsystem::SetSubsystem(std::string_view name) {
SendableRegistry::GetInstance().SetSubsystem(this, name);
wpi::SendableRegistry::GetInstance().SetSubsystem(this, name);
}
void Subsystem::AddChild(std::string_view name,
@@ -92,25 +93,25 @@ void Subsystem::AddChild(std::string_view name,
AddChild(name, *child);
}
void Subsystem::AddChild(std::string_view name, Sendable* child) {
void Subsystem::AddChild(std::string_view name, wpi::Sendable* child) {
AddChild(name, *child);
}
void Subsystem::AddChild(std::string_view name, Sendable& child) {
auto& registry = SendableRegistry::GetInstance();
void Subsystem::AddChild(std::string_view name, wpi::Sendable& child) {
auto& registry = wpi::SendableRegistry::GetInstance();
registry.AddLW(&child, registry.GetSubsystem(this), name);
}
void Subsystem::AddChild(std::shared_ptr<Sendable> child) {
void Subsystem::AddChild(std::shared_ptr<wpi::Sendable> child) {
AddChild(*child);
}
void Subsystem::AddChild(Sendable* child) {
void Subsystem::AddChild(wpi::Sendable* child) {
AddChild(*child);
}
void Subsystem::AddChild(Sendable& child) {
auto& registry = SendableRegistry::GetInstance();
void Subsystem::AddChild(wpi::Sendable& child) {
auto& registry = wpi::SendableRegistry::GetInstance();
registry.SetSubsystem(&child, registry.GetSubsystem(this));
registry.EnableLiveWindow(&child);
}
@@ -121,7 +122,7 @@ void Subsystem::ConfirmCommand() {
}
}
void Subsystem::InitSendable(SendableBuilder& builder) {
void Subsystem::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Subsystem");
builder.AddBooleanProperty(

View File

@@ -9,19 +9,17 @@
#include <wpi/deprecated.h>
#include <wpi/mutex.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/PIDInterface.h"
#include "frc/PIDOutput.h"
#include "frc/PIDSource.h"
#include "frc/Timer.h"
#include "frc/filter/LinearFilter.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* Class implements a PID Control Loop.
*
@@ -36,8 +34,8 @@ class SendableBuilder;
*/
class PIDBase : public PIDInterface,
public PIDOutput,
public Sendable,
public SendableHelper<PIDBase> {
public wpi::Sendable,
public wpi::SendableHelper<PIDBase> {
public:
/**
* Allocate a PID object with the given constants for P, I, D.
@@ -301,7 +299,7 @@ class PIDBase : public PIDInterface,
*/
void PIDWrite(double output) override;
void InitSendable(SendableBuilder& builder) override;
void InitSendable(wpi::SendableBuilder& builder) override;
protected:
// Is the pid controller enabled

View File

@@ -126,7 +126,7 @@ class PIDController : public PIDBase, public Controller {
*/
void Reset() override;
void InitSendable(SendableBuilder& builder) override;
void InitSendable(wpi::SendableBuilder& builder) override;
private:
std::unique_ptr<Notifier> m_controlLoop;

View File

@@ -6,8 +6,8 @@
#include <atomic>
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
namespace frc {
@@ -26,7 +26,7 @@ class Command;
* only have to write the {@link Trigger#Get()} method to get the full
* functionality of the Trigger class.
*/
class Trigger : public Sendable, public SendableHelper<Trigger> {
class Trigger : public wpi::Sendable, public wpi::SendableHelper<Trigger> {
public:
Trigger() = default;
~Trigger() override = default;
@@ -44,7 +44,7 @@ class Trigger : public Sendable, public SendableHelper<Trigger> {
void CancelWhenActive(Command* command);
void ToggleWhenActive(Command* command);
void InitSendable(SendableBuilder& builder) override;
void InitSendable(wpi::SendableBuilder& builder) override;
private:
std::atomic_bool m_sendablePressed{false};

View File

@@ -10,10 +10,10 @@
#include <units/time.h>
#include <wpi/SmallPtrSet.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/commands/Subsystem.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -43,7 +43,7 @@ class CommandGroup;
* @see CommandGroup
* @see Subsystem
*/
class Command : public Sendable, public SendableHelper<Command> {
class Command : public wpi::Sendable, public wpi::SendableHelper<Command> {
friend class CommandGroup;
friend class Scheduler;
@@ -482,7 +482,7 @@ class Command : public Sendable, public SendableHelper<Command> {
static int m_commandCounter;
public:
void InitSendable(SendableBuilder& builder) override;
void InitSendable(wpi::SendableBuilder& builder) override;
};
} // namespace frc

View File

@@ -64,7 +64,7 @@ class PIDCommand : public Command, public PIDOutput, public PIDSource {
std::shared_ptr<PIDController> m_controller;
public:
void InitSendable(SendableBuilder& builder) override;
void InitSendable(wpi::SendableBuilder& builder) override;
};
} // namespace frc

View File

@@ -6,8 +6,8 @@
#include <memory>
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
#include <networktables/NTSendable.h>
#include <wpi/sendable/SendableHelper.h>
namespace frc {
@@ -15,7 +15,7 @@ class ButtonScheduler;
class Command;
class Subsystem;
class Scheduler : public Sendable, public SendableHelper<Scheduler> {
class Scheduler : public nt::NTSendable, public wpi::SendableHelper<Scheduler> {
public:
/**
* Returns the Scheduler, creating it if one does not exist.
@@ -78,7 +78,7 @@ class Scheduler : public Sendable, public SendableHelper<Scheduler> {
void SetEnabled(bool enabled);
void InitSendable(SendableBuilder& builder) override;
void InitSendable(nt::NTSendableBuilder& builder) override;
private:
Scheduler();

View File

@@ -8,14 +8,14 @@
#include <string>
#include <string_view>
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
namespace frc {
class Command;
class Subsystem : public Sendable, public SendableHelper<Subsystem> {
class Subsystem : public wpi::Sendable, public wpi::SendableHelper<Subsystem> {
friend class Scheduler;
public:
@@ -127,7 +127,7 @@ class Subsystem : public Sendable, public SendableHelper<Subsystem> {
* @param name name to give child
* @param child sendable
*/
void AddChild(std::string_view name, std::shared_ptr<Sendable> child);
void AddChild(std::string_view name, std::shared_ptr<wpi::Sendable> child);
/**
* Associate a Sendable with this Subsystem.
@@ -136,7 +136,7 @@ class Subsystem : public Sendable, public SendableHelper<Subsystem> {
* @param name name to give child
* @param child sendable
*/
void AddChild(std::string_view name, Sendable* child);
void AddChild(std::string_view name, wpi::Sendable* child);
/**
* Associate a Sendable with this Subsystem.
@@ -145,28 +145,28 @@ class Subsystem : public Sendable, public SendableHelper<Subsystem> {
* @param name name to give child
* @param child sendable
*/
void AddChild(std::string_view name, Sendable& child);
void AddChild(std::string_view name, wpi::Sendable& child);
/**
* Associate a {@link Sendable} with this Subsystem.
*
* @param child sendable
*/
void AddChild(std::shared_ptr<Sendable> child);
void AddChild(std::shared_ptr<wpi::Sendable> child);
/**
* Associate a {@link Sendable} with this Subsystem.
*
* @param child sendable
*/
void AddChild(Sendable* child);
void AddChild(wpi::Sendable* child);
/**
* Associate a {@link Sendable} with this Subsystem.
*
* @param child sendable
*/
void AddChild(Sendable& child);
void AddChild(wpi::Sendable& child);
private:
/**
@@ -185,7 +185,7 @@ class Subsystem : public Sendable, public SendableHelper<Subsystem> {
bool m_initializedDefaultCommand = false;
public:
void InitSendable(SendableBuilder& builder) override;
void InitSendable(wpi::SendableBuilder& builder) override;
};
} // namespace frc