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

@@ -15,6 +15,8 @@
#include <llvm/SmallString.h>
#include <llvm/raw_ostream.h>
#include "SensorBase.h"
#include "SmartDashboard/SendableBuilder.h"
#include "WPIErrors.h"
using namespace frc;
@@ -32,7 +34,7 @@ DigitalOutput::DigitalOutput(int channel) {
llvm::raw_svector_ostream buf(str);
m_pwmGenerator = HAL_kInvalidHandle;
if (!CheckDigitalChannel(channel)) {
if (!SensorBase::CheckDigitalChannel(channel)) {
buf << "Digital Channel " << channel;
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
m_channel = std::numeric_limits<int>::max();
@@ -51,13 +53,13 @@ DigitalOutput::DigitalOutput(int channel) {
}
HAL_Report(HALUsageReporting::kResourceType_DigitalOutput, channel);
SetName("DigitalOutput", channel);
}
/**
* Free the resources associated with a digital output.
*/
DigitalOutput::~DigitalOutput() {
if (m_valueListener != 0) m_valueEntry.RemoveListener(m_valueListener);
if (StatusIsFatal()) return;
// Disable the PWM in case it was running.
DisablePWM();
@@ -190,7 +192,8 @@ void DigitalOutput::DisablePWM() {
int32_t status = 0;
// Disable the output by routing to a dead bit.
HAL_SetDigitalPWMOutputChannel(m_pwmGenerator, kDigitalChannels, &status);
HAL_SetDigitalPWMOutputChannel(m_pwmGenerator, SensorBase::kDigitalChannels,
&status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
HAL_FreeDigitalPWM(m_pwmGenerator, &status);
@@ -215,52 +218,8 @@ void DigitalOutput::UpdateDutyCycle(double dutyCycle) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
* @return The HAL Handle to the specified source.
*/
HAL_Handle DigitalOutput::GetPortHandleForRouting() const { return m_handle; }
/**
* Is source an AnalogTrigger
*/
bool DigitalOutput::IsAnalogTrigger() const { return false; }
/**
* @return The type of analog trigger output to be used. 0 for Digitals
*/
AnalogTriggerType DigitalOutput::GetAnalogTriggerTypeForRouting() const {
return (AnalogTriggerType)0;
}
void DigitalOutput::UpdateTable() {}
void DigitalOutput::StartLiveWindowMode() {
if (m_valueEntry) {
m_valueListener = m_valueEntry.AddListener(
[=](const nt::EntryNotification& event) {
if (!event.value->IsBoolean()) return;
Set(event.value->GetBoolean());
},
NT_NOTIFY_IMMEDIATE | NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
}
}
void DigitalOutput::StopLiveWindowMode() {
if (m_valueListener != 0) {
m_valueEntry.RemoveListener(m_valueListener);
m_valueListener = 0;
}
}
std::string DigitalOutput::GetSmartDashboardType() const {
return "Digital Output";
}
void DigitalOutput::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
if (subTable) {
m_valueEntry = subTable->GetEntry("Value");
UpdateTable();
} else {
m_valueEntry = nt::NetworkTableEntry();
}
void DigitalOutput::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Digital Output");
builder.AddBooleanProperty("Value", [=]() { return Get(); },
[=](bool value) { Set(value); });
}