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

@@ -10,7 +10,7 @@
#include <HAL/HAL.h>
#include "DigitalInput.h"
#include "LiveWindow/LiveWindow.h"
#include "SmartDashboard/SendableBuilder.h"
#include "WPIErrors.h"
using namespace frc;
@@ -45,8 +45,7 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) {
HAL_Report(HALUsageReporting::kResourceType_Encoder, GetFPGAIndex(),
encodingType);
LiveWindow::GetInstance()->AddSensor("Encoder", m_aSource->GetChannel(),
this);
SetName("Encoder", m_aSource->GetChannel());
}
/**
@@ -77,6 +76,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);
AddChild(m_aSource);
AddChild(m_bSource);
}
/**
@@ -371,6 +372,19 @@ void Encoder::SetDistancePerPulse(double distancePerPulse) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
/**
* Get the distance per pulse for this encoder.
*
* @return The scale factor that will be used to convert pulses to useful units.
*/
double Encoder::GetDistancePerPulse() const {
if (StatusIsFatal()) return 0.0;
int32_t status = 0;
double distancePerPulse = HAL_GetEncoderDistancePerPulse(m_encoder, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return distancePerPulse;
}
/**
* Set the direction sensing for this encoder.
*
@@ -479,41 +493,18 @@ int Encoder::GetFPGAIndex() const {
return val;
}
void Encoder::UpdateTable() {
if (m_speedEntry) m_speedEntry.SetDouble(GetRate());
if (m_distanceEntry) m_distanceEntry.SetDouble(GetDistance());
if (m_distancePerTickEntry) {
int32_t status = 0;
double distancePerPulse =
HAL_GetEncoderDistancePerPulse(m_encoder, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
m_distancePerTickEntry.SetDouble(distancePerPulse);
}
}
void Encoder::StartLiveWindowMode() {}
void Encoder::StopLiveWindowMode() {}
std::string Encoder::GetSmartDashboardType() const {
void Encoder::InitSendable(SendableBuilder& builder) {
int32_t status = 0;
HAL_EncoderEncodingType type = HAL_GetEncoderEncodingType(m_encoder, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
if (type == HAL_EncoderEncodingType::HAL_Encoder_k4X)
return "Quadrature Encoder";
builder.SetSmartDashboardType("Quadrature Encoder");
else
return "Encoder";
}
builder.SetSmartDashboardType("Encoder");
void Encoder::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
if (subTable) {
m_speedEntry = subTable->GetEntry("Speed");
m_distanceEntry = subTable->GetEntry("Distance");
m_distancePerTickEntry = subTable->GetEntry("Distance per Tick");
UpdateTable();
} else {
m_speedEntry = nt::NetworkTableEntry();
m_distanceEntry = nt::NetworkTableEntry();
m_distancePerTickEntry = nt::NetworkTableEntry();
}
builder.AddDoubleProperty("Speed", [=]() { return GetRate(); }, nullptr);
builder.AddDoubleProperty("Distance", [=]() { return GetDistance(); },
nullptr);
builder.AddDoubleProperty("Distance per Tick",
[=]() { return GetDistancePerPulse(); }, nullptr);
}