mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
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:
@@ -9,9 +9,7 @@
|
||||
|
||||
#include <HAL/HAL.h>
|
||||
|
||||
#include "DigitalInput.h"
|
||||
#include "DigitalOutput.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "SmartDashboard/SendableBuilder.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -40,7 +38,7 @@ ADXL345_SPI::ADXL345_SPI(SPI::Port port, ADXL345_SPI::Range range)
|
||||
HAL_Report(HALUsageReporting::kResourceType_ADXL345,
|
||||
HALUsageReporting::kADXL345_SPI);
|
||||
|
||||
LiveWindow::GetInstance()->AddSensor("ADXL345_SPI", port, this);
|
||||
SetName("ADXL345_SPI", port);
|
||||
}
|
||||
|
||||
void ADXL345_SPI::SetRange(Range range) {
|
||||
@@ -103,25 +101,15 @@ ADXL345_SPI::AllAxes ADXL345_SPI::GetAccelerations() {
|
||||
return data;
|
||||
}
|
||||
|
||||
std::string ADXL345_SPI::GetSmartDashboardType() const {
|
||||
return "3AxisAccelerometer";
|
||||
}
|
||||
|
||||
void ADXL345_SPI::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
|
||||
if (subtable) {
|
||||
m_xEntry = subtable->GetEntry("X");
|
||||
m_yEntry = subtable->GetEntry("Y");
|
||||
m_zEntry = subtable->GetEntry("Z");
|
||||
UpdateTable();
|
||||
} else {
|
||||
m_xEntry = nt::NetworkTableEntry();
|
||||
m_yEntry = nt::NetworkTableEntry();
|
||||
m_zEntry = nt::NetworkTableEntry();
|
||||
}
|
||||
}
|
||||
|
||||
void ADXL345_SPI::UpdateTable() {
|
||||
if (m_xEntry) m_xEntry.SetDouble(GetX());
|
||||
if (m_yEntry) m_yEntry.SetDouble(GetY());
|
||||
if (m_zEntry) m_zEntry.SetDouble(GetZ());
|
||||
void ADXL345_SPI::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("3AxisAccelerometer");
|
||||
auto x = builder.GetEntry("X").GetHandle();
|
||||
auto y = builder.GetEntry("Y").GetHandle();
|
||||
auto z = builder.GetEntry("Z").GetHandle();
|
||||
builder.SetUpdateTable([=]() {
|
||||
auto data = GetAccelerations();
|
||||
nt::NetworkTableEntry(x).SetDouble(data.XAxis);
|
||||
nt::NetworkTableEntry(y).SetDouble(data.YAxis);
|
||||
nt::NetworkTableEntry(z).SetDouble(data.ZAxis);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user