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

@@ -7,18 +7,28 @@
#include "SmartDashboard/SmartDashboard.h"
#include <map>
#include <llvm/StringMap.h>
#include <support/mutex.h>
#include "HLUsageReporting.h"
#include "SmartDashboard/NamedSendable.h"
#include "SmartDashboard/Sendable.h"
#include "SmartDashboard/SendableBuilderImpl.h"
#include "WPIErrors.h"
#include "networktables/NetworkTable.h"
#include "networktables/NetworkTableInstance.h"
using namespace frc;
namespace {
struct SmartDashboardData {
Sendable* sendable = nullptr;
SendableBuilderImpl builder;
};
} // namespace
static std::shared_ptr<nt::NetworkTable> s_table;
static std::map<std::shared_ptr<nt::NetworkTable>, Sendable*> s_tablesToData;
static llvm::StringMap<SmartDashboardData> s_tablesToData;
static wpi::mutex s_tablesToDataMutex;
void SmartDashboard::init() {
s_table = nt::NetworkTableInstance::GetDefault().GetTable("SmartDashboard");
@@ -126,22 +136,26 @@ void SmartDashboard::PutData(llvm::StringRef key, Sendable* data) {
wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
return;
}
std::shared_ptr<nt::NetworkTable> dataTable(s_table->GetSubTable(key));
dataTable->GetEntry(".type").SetString(data->GetSmartDashboardType());
data->InitTable(dataTable);
s_tablesToData[dataTable] = data;
std::lock_guard<wpi::mutex> lock(s_tablesToDataMutex);
auto& sddata = s_tablesToData[key];
if (!sddata.sendable || sddata.sendable != data) {
sddata.sendable = data;
sddata.builder.SetTable(s_table->GetSubTable(key));
data->InitSendable(sddata.builder);
}
sddata.builder.UpdateTable();
}
/**
* Maps the specified key (where the key is the name of the
* {@link SmartDashboardNamedData} to the specified value in this table.
* Maps the specified key (where the key is the name of the Sendable)
* to the specified value in this table.
*
* The value can be retrieved by calling the get method with a key that is equal
* to the original key.
*
* @param value the value
*/
void SmartDashboard::PutData(NamedSendable* value) {
void SmartDashboard::PutData(Sendable* value) {
if (value == nullptr) {
wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
return;
@@ -156,13 +170,13 @@ void SmartDashboard::PutData(NamedSendable* value) {
* @return the value
*/
Sendable* SmartDashboard::GetData(llvm::StringRef key) {
std::shared_ptr<nt::NetworkTable> subtable(s_table->GetSubTable(key));
Sendable* data = s_tablesToData[subtable];
if (data == nullptr) {
std::lock_guard<wpi::mutex> lock(s_tablesToDataMutex);
auto data = s_tablesToData.find(key);
if (data == s_tablesToData.end()) {
wpi_setGlobalWPIErrorWithContext(SmartDashboardMissingKey, key);
return nullptr;
}
return data;
return data->getValue().sendable;
}
/**