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,82 +7,76 @@
#pragma once
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "Commands/Scheduler.h"
#include "LiveWindow/LiveWindowSendable.h"
#include "networktables/NetworkTable.h"
#include "networktables/NetworkTableEntry.h"
#include <llvm/Twine.h>
#include <support/deprecated.h>
#include "SmartDashboard/Sendable.h"
namespace frc {
struct LiveWindowComponent {
std::string subsystem;
std::string name;
bool isSensor = false;
LiveWindowComponent() = default;
LiveWindowComponent(std::string subsystem, std::string name, bool isSensor) {
this->subsystem = subsystem;
this->name = name;
this->isSensor = isSensor;
}
};
/**
* The LiveWindow class is the public interface for putting sensors and
* actuators on the LiveWindow.
*/
class LiveWindow {
public:
LiveWindow(const LiveWindow&) = delete;
LiveWindow& operator=(const LiveWindow&) = delete;
static LiveWindow* GetInstance();
void Run();
void AddSensor(const std::string& subsystem, const std::string& name,
LiveWindowSendable* component);
void AddSensor(const std::string& subsystem, const std::string& name,
LiveWindowSendable& component);
void AddSensor(const std::string& subsystem, const std::string& name,
std::shared_ptr<LiveWindowSendable> component);
void AddActuator(const std::string& subsystem, const std::string& name,
LiveWindowSendable* component);
void AddActuator(const std::string& subsystem, const std::string& name,
LiveWindowSendable& component);
void AddActuator(const std::string& subsystem, const std::string& name,
std::shared_ptr<LiveWindowSendable> component);
void AddSensor(std::string type, int channel, LiveWindowSendable* component);
void AddActuator(std::string type, int channel,
LiveWindowSendable* component);
void AddActuator(std::string type, int module, int channel,
LiveWindowSendable* component);
WPI_DEPRECATED("no longer required")
void Run() { UpdateValues(); }
bool IsEnabled() const { return m_enabled; }
WPI_DEPRECATED("use Sendable::SetName() instead")
void AddSensor(const llvm::Twine& subsystem, const llvm::Twine& name,
Sendable* component);
WPI_DEPRECATED("use Sendable::SetName() instead")
void AddSensor(const llvm::Twine& subsystem, const llvm::Twine& name,
Sendable& component);
WPI_DEPRECATED("use Sendable::SetName() instead")
void AddSensor(const llvm::Twine& subsystem, const llvm::Twine& name,
std::shared_ptr<Sendable> component);
WPI_DEPRECATED("use Sendable::SetName() instead")
void AddActuator(const llvm::Twine& subsystem, const llvm::Twine& name,
Sendable* component);
WPI_DEPRECATED("use Sendable::SetName() instead")
void AddActuator(const llvm::Twine& subsystem, const llvm::Twine& name,
Sendable& component);
WPI_DEPRECATED("use Sendable::SetName() instead")
void AddActuator(const llvm::Twine& subsystem, const llvm::Twine& name,
std::shared_ptr<Sendable> component);
WPI_DEPRECATED("use SensorBase::SetName() instead")
void AddSensor(const llvm::Twine& type, int channel, Sendable* component);
WPI_DEPRECATED("use SensorBase::SetName() instead")
void AddActuator(const llvm::Twine& type, int channel, Sendable* component);
WPI_DEPRECATED("use SensorBase::SetName() instead")
void AddActuator(const llvm::Twine& type, int module, int channel,
Sendable* component);
void Add(std::shared_ptr<Sendable> component);
void Add(Sendable* component);
void AddChild(Sendable* parent, std::shared_ptr<Sendable> component);
void AddChild(Sendable* parent, void* component);
void Remove(Sendable* component);
void EnableTelemetry(Sendable* component);
void DisableTelemetry(Sendable* component);
void DisableAllTelemetry();
bool IsEnabled() const;
void SetEnabled(bool enabled);
protected:
LiveWindow();
virtual ~LiveWindow() = default;
void UpdateValues();
private:
void UpdateValues();
void Initialize();
void InitializeLiveWindowComponents();
LiveWindow();
std::vector<std::shared_ptr<LiveWindowSendable>> m_sensors;
std::map<std::shared_ptr<LiveWindowSendable>, LiveWindowComponent>
m_components;
std::shared_ptr<nt::NetworkTable> m_liveWindowTable;
std::shared_ptr<nt::NetworkTable> m_statusTable;
nt::NetworkTableEntry m_enabledEntry;
Scheduler* m_scheduler;
bool m_enabled = false;
bool m_firstTime = true;
struct Impl;
std::unique_ptr<Impl> m_impl;
};
} // namespace frc

View File

@@ -1,36 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2012-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. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "SmartDashboard/Sendable.h"
namespace frc {
/**
* Live Window Sendable is a special type of object sendable to the live window.
*/
class LiveWindowSendable : public Sendable {
public:
/**
* Update the table for this sendable object with the latest values.
*/
virtual void UpdateTable() = 0;
/**
* Start having this sendable object automatically respond to value changes
* reflect the value on the table.
*/
virtual void StartLiveWindowMode() = 0;
/**
* Stop having this sendable object automatically respond to value changes.
*/
virtual void StopLiveWindowMode() = 0;
};
} // namespace frc