Update LiveWindow to provide continuous telemetry. (#771)

LiveWindow.updateValues() is now called from IterativeRobotBase on every
loop iteration.  Telemetry for all WPILib classes is enabled by default;
it can be disabled for specific classes using LiveWindow.disableTelemetry(),
or all telemetry can be disabled using LiveWindow.disableAllTelemetry().

This necessitated changing the hook methodology into other classes to
be more property-based rather than each class providing multiple functions.
This had the benefit of reducing boilerplate and increasing consistency.

- Remove NamedSendable, add name to Sendable.

- Provide SendableBase abstract class.

- Deprecate LiveWindow addSensor/addActuator interfaces.

- Add LiveWindow support to drive classes.

- Add addChild() helper functions to Subsystem.

- Fix inheritance hierarchy.  Now only sensors inherit from SensorBase.
  Other devices inherit from some combination of SendableBase, ErrorBase, or
  nothing.
This commit is contained in:
Peter Johnson
2017-12-04 23:28:33 -08:00
committed by GitHub
parent 3befc7015b
commit f9bece2ffb
213 changed files with 3704 additions and 3758 deletions

View File

@@ -13,7 +13,7 @@
#include <llvm/SmallString.h>
#include <llvm/raw_ostream.h>
#include "LiveWindow/LiveWindow.h"
#include "SmartDashboard/SendableBuilder.h"
#include "WPIErrors.h"
using namespace frc;
@@ -32,6 +32,7 @@ PowerDistributionPanel::PowerDistributionPanel(int module) : m_module(module) {
m_module = -1;
return;
}
SetName("PowerDistributionPanel", module);
}
/**
@@ -171,39 +172,13 @@ void PowerDistributionPanel::ClearStickyFaults() {
}
}
void PowerDistributionPanel::UpdateTable() {
for (size_t i = 0; i < sizeof(m_chanEntry) / sizeof(m_chanEntry[0]); ++i) {
if (m_chanEntry[i]) m_chanEntry[i].SetDouble(GetCurrent(i));
}
if (m_voltageEntry) m_voltageEntry.SetDouble(GetVoltage());
if (m_totalCurrentEntry) m_totalCurrentEntry.SetDouble(GetTotalCurrent());
}
void PowerDistributionPanel::StartLiveWindowMode() {}
void PowerDistributionPanel::StopLiveWindowMode() {}
std::string PowerDistributionPanel::GetSmartDashboardType() const {
return "PowerDistributionPanel";
}
void PowerDistributionPanel::InitTable(
std::shared_ptr<nt::NetworkTable> subTable) {
if (subTable != nullptr) {
for (size_t i = 0; i < sizeof(m_chanEntry) / sizeof(m_chanEntry[0]); ++i) {
llvm::SmallString<32> buf;
llvm::raw_svector_ostream oss(buf);
oss << "Chan" << i;
m_chanEntry[i] = subTable->GetEntry(oss.str());
}
m_voltageEntry = subTable->GetEntry("Voltage");
m_totalCurrentEntry = subTable->GetEntry("TotalCurrent");
UpdateTable();
} else {
for (size_t i = 0; i < sizeof(m_chanEntry) / sizeof(m_chanEntry[0]); ++i) {
m_chanEntry[i] = nt::NetworkTableEntry();
}
m_voltageEntry = nt::NetworkTableEntry();
m_totalCurrentEntry = nt::NetworkTableEntry();
void PowerDistributionPanel::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("PowerDistributionPanel");
for (int i = 0; i < kPDPChannels; ++i) {
builder.AddDoubleProperty("Chan" + llvm::Twine(i),
[=]() { return GetCurrent(i); }, nullptr);
}
builder.AddDoubleProperty("Voltage", [=]() { return GetVoltage(); }, nullptr);
builder.AddDoubleProperty("TotalCurrent", [=]() { return GetTotalCurrent(); },
nullptr);
}