mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +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:
91
wpilibc/src/main/native/cpp/SmartDashboard/SendableBase.cpp
Normal file
91
wpilibc/src/main/native/cpp/SmartDashboard/SendableBase.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
/**
|
||||
* Creates an instance of the sensor base.
|
||||
*
|
||||
* @param addLiveWindow if true, add this Sendable to LiveWindow
|
||||
*/
|
||||
SendableBase::SendableBase(bool addLiveWindow) {
|
||||
if (addLiveWindow) LiveWindow::GetInstance()->Add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the resources used by this object.
|
||||
*/
|
||||
SendableBase::~SendableBase() { LiveWindow::GetInstance()->Remove(this); }
|
||||
|
||||
std::string SendableBase::GetName() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void SendableBase::SetName(const llvm::Twine& name) {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_name = name.str();
|
||||
}
|
||||
|
||||
std::string SendableBase::GetSubsystem() const {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_subsystem;
|
||||
}
|
||||
|
||||
void SendableBase::SetSubsystem(const llvm::Twine& subsystem) {
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_subsystem = subsystem.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a child component.
|
||||
*
|
||||
* @param child child component
|
||||
*/
|
||||
void SendableBase::AddChild(std::shared_ptr<Sendable> child) {
|
||||
LiveWindow::GetInstance()->AddChild(this, child);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a child component.
|
||||
*
|
||||
* @param child child component
|
||||
*/
|
||||
void SendableBase::AddChild(void* child) {
|
||||
LiveWindow::GetInstance()->AddChild(this, child);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the sensor with a channel number.
|
||||
*
|
||||
* @param moduleType A string that defines the module name in the label for the
|
||||
* value
|
||||
* @param channel The channel number the device is plugged into
|
||||
*/
|
||||
void SendableBase::SetName(const llvm::Twine& moduleType, int channel) {
|
||||
SetName(moduleType + llvm::Twine('[') + llvm::Twine(channel) +
|
||||
llvm::Twine(']'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the sensor with a module and channel number.
|
||||
*
|
||||
* @param moduleType A string that defines the module name in the label for
|
||||
* the value
|
||||
* @param moduleNumber The number of the particular module type
|
||||
* @param channel The channel number the device is plugged into (usually
|
||||
* PWM)
|
||||
*/
|
||||
void SendableBase::SetName(const llvm::Twine& moduleType, int moduleNumber,
|
||||
int channel) {
|
||||
SetName(moduleType + llvm::Twine('[') + llvm::Twine(moduleNumber) +
|
||||
llvm::Twine(',') + llvm::Twine(channel) + llvm::Twine(']'));
|
||||
}
|
||||
Reference in New Issue
Block a user