mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01: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:
@@ -7,13 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "I2C.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SensorBase.h"
|
||||
#include "interfaces/Accelerometer.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -24,7 +20,7 @@ namespace frc {
|
||||
* an I2C bus. This class assumes the default (not alternate) sensor address of
|
||||
* 0x1D (7-bit address).
|
||||
*/
|
||||
class ADXL345_I2C : public Accelerometer, public LiveWindowSendable {
|
||||
class ADXL345_I2C : public SensorBase, public Accelerometer {
|
||||
public:
|
||||
enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
|
||||
|
||||
@@ -36,7 +32,7 @@ class ADXL345_I2C : public Accelerometer, public LiveWindowSendable {
|
||||
|
||||
explicit ADXL345_I2C(I2C::Port port, Range range = kRange_2G,
|
||||
int deviceAddress = kAddress);
|
||||
virtual ~ADXL345_I2C() = default;
|
||||
~ADXL345_I2C() override = default;
|
||||
|
||||
ADXL345_I2C(const ADXL345_I2C&) = delete;
|
||||
ADXL345_I2C& operator=(const ADXL345_I2C&) = delete;
|
||||
@@ -50,11 +46,7 @@ class ADXL345_I2C : public Accelerometer, public LiveWindowSendable {
|
||||
virtual double GetAcceleration(Axes axis);
|
||||
virtual AllAxes GetAccelerations();
|
||||
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override {}
|
||||
void StopLiveWindowMode() override {}
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
protected:
|
||||
I2C m_i2c;
|
||||
@@ -79,11 +71,6 @@ class ADXL345_I2C : public Accelerometer, public LiveWindowSendable {
|
||||
kDataFormat_FullRes = 0x08,
|
||||
kDataFormat_Justify = 0x04
|
||||
};
|
||||
|
||||
private:
|
||||
nt::NetworkTableEntry m_xEntry;
|
||||
nt::NetworkTableEntry m_yEntry;
|
||||
nt::NetworkTableEntry m_zEntry;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -7,27 +7,19 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SPI.h"
|
||||
#include "SensorBase.h"
|
||||
#include "interfaces/Accelerometer.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class DigitalInput;
|
||||
class DigitalOutput;
|
||||
|
||||
/**
|
||||
* ADXL345 Accelerometer on SPI.
|
||||
*
|
||||
* This class allows access to an Analog Devices ADXL345 3-axis accelerometer
|
||||
* via SPI. This class assumes the sensor is wired in 4-wire SPI mode.
|
||||
*/
|
||||
class ADXL345_SPI : public Accelerometer, public LiveWindowSendable {
|
||||
class ADXL345_SPI : public SensorBase, public Accelerometer {
|
||||
public:
|
||||
enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
|
||||
|
||||
@@ -38,7 +30,7 @@ class ADXL345_SPI : public Accelerometer, public LiveWindowSendable {
|
||||
};
|
||||
|
||||
explicit ADXL345_SPI(SPI::Port port, Range range = kRange_2G);
|
||||
virtual ~ADXL345_SPI() = default;
|
||||
~ADXL345_SPI() override = default;
|
||||
|
||||
ADXL345_SPI(const ADXL345_SPI&) = delete;
|
||||
ADXL345_SPI& operator=(const ADXL345_SPI&) = delete;
|
||||
@@ -52,11 +44,7 @@ class ADXL345_SPI : public Accelerometer, public LiveWindowSendable {
|
||||
virtual double GetAcceleration(Axes axis);
|
||||
virtual AllAxes GetAccelerations();
|
||||
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override {}
|
||||
void StopLiveWindowMode() override {}
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
protected:
|
||||
SPI m_spi;
|
||||
@@ -82,11 +70,6 @@ class ADXL345_SPI : public Accelerometer, public LiveWindowSendable {
|
||||
kDataFormat_FullRes = 0x08,
|
||||
kDataFormat_Justify = 0x04
|
||||
};
|
||||
|
||||
private:
|
||||
nt::NetworkTableEntry m_xEntry;
|
||||
nt::NetworkTableEntry m_yEntry;
|
||||
nt::NetworkTableEntry m_zEntry;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -7,26 +7,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SPI.h"
|
||||
#include "SensorBase.h"
|
||||
#include "interfaces/Accelerometer.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class DigitalInput;
|
||||
class DigitalOutput;
|
||||
|
||||
/**
|
||||
* ADXL362 SPI Accelerometer.
|
||||
*
|
||||
* This class allows access to an Analog Devices ADXL362 3-axis accelerometer.
|
||||
*/
|
||||
class ADXL362 : public Accelerometer, public LiveWindowSendable {
|
||||
class ADXL362 : public SensorBase, public Accelerometer {
|
||||
public:
|
||||
enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
|
||||
struct AllAxes {
|
||||
@@ -52,19 +44,11 @@ class ADXL362 : public Accelerometer, public LiveWindowSendable {
|
||||
virtual double GetAcceleration(Axes axis);
|
||||
virtual AllAxes GetAccelerations();
|
||||
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override {}
|
||||
void StopLiveWindowMode() override {}
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
SPI m_spi;
|
||||
double m_gsPerLSB = 0.001;
|
||||
|
||||
nt::NetworkTableEntry m_xEntry;
|
||||
nt::NetworkTableEntry m_yEntry;
|
||||
nt::NetworkTableEntry m_zEntry;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -8,13 +8,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "AnalogInput.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "PIDSource.h"
|
||||
#include "SensorBase.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -25,25 +22,19 @@ namespace frc {
|
||||
* sensors have multiple axis and can be treated as multiple devices. Each is
|
||||
* calibrated by finding the center value over a period of time.
|
||||
*/
|
||||
class AnalogAccelerometer : public SensorBase,
|
||||
public PIDSource,
|
||||
public LiveWindowSendable {
|
||||
class AnalogAccelerometer : public SensorBase, public PIDSource {
|
||||
public:
|
||||
explicit AnalogAccelerometer(int channel);
|
||||
explicit AnalogAccelerometer(AnalogInput* channel);
|
||||
explicit AnalogAccelerometer(std::shared_ptr<AnalogInput> channel);
|
||||
virtual ~AnalogAccelerometer() = default;
|
||||
~AnalogAccelerometer() override = default;
|
||||
|
||||
double GetAcceleration() const;
|
||||
void SetSensitivity(double sensitivity);
|
||||
void SetZero(double zero);
|
||||
double PIDGet() override;
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
void InitAccelerometer();
|
||||
@@ -51,8 +42,6 @@ class AnalogAccelerometer : public SensorBase,
|
||||
std::shared_ptr<AnalogInput> m_analogInput;
|
||||
double m_voltsPerG = 1.0;
|
||||
double m_zeroGVoltage = 2.5;
|
||||
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -9,15 +9,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <HAL/Types.h>
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "PIDSource.h"
|
||||
#include "SensorBase.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -33,9 +28,7 @@ namespace frc {
|
||||
* are divided by the number of samples to retain the resolution, but get more
|
||||
* stable values.
|
||||
*/
|
||||
class AnalogInput : public SensorBase,
|
||||
public PIDSource,
|
||||
public LiveWindowSendable {
|
||||
class AnalogInput : public SensorBase, public PIDSource {
|
||||
friend class AnalogTrigger;
|
||||
friend class AnalogGyro;
|
||||
|
||||
@@ -45,7 +38,7 @@ class AnalogInput : public SensorBase,
|
||||
static constexpr int kAccumulatorChannels[kAccumulatorNumChannels] = {0, 1};
|
||||
|
||||
explicit AnalogInput(int channel);
|
||||
virtual ~AnalogInput();
|
||||
~AnalogInput() override;
|
||||
|
||||
int GetValue() const;
|
||||
int GetAverageValue() const;
|
||||
@@ -78,19 +71,13 @@ class AnalogInput : public SensorBase,
|
||||
|
||||
double PIDGet() override;
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
int m_channel;
|
||||
// TODO: Adjust HAL to avoid use of raw pointers.
|
||||
HAL_AnalogInputHandle m_port;
|
||||
int64_t m_accumulatorOffset;
|
||||
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -7,40 +7,30 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <HAL/AnalogOutput.h>
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SensorBase.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* MXP analog output class.
|
||||
*/
|
||||
class AnalogOutput : public SensorBase, public LiveWindowSendable {
|
||||
class AnalogOutput : public ErrorBase, public SendableBase {
|
||||
public:
|
||||
explicit AnalogOutput(int channel);
|
||||
virtual ~AnalogOutput();
|
||||
~AnalogOutput() override;
|
||||
|
||||
void SetVoltage(double voltage);
|
||||
double GetVoltage() const;
|
||||
int GetChannel();
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
protected:
|
||||
int m_channel;
|
||||
HAL_AnalogOutputHandle m_port;
|
||||
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -8,12 +8,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "AnalogInput.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SensorBase.h"
|
||||
#include "interfaces/Potentiometer.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -23,7 +21,7 @@ namespace frc {
|
||||
* units you choose, by way of the scaling and offset constants passed to the
|
||||
* constructor.
|
||||
*/
|
||||
class AnalogPotentiometer : public Potentiometer, public LiveWindowSendable {
|
||||
class AnalogPotentiometer : public SensorBase, public Potentiometer {
|
||||
public:
|
||||
/**
|
||||
* AnalogPotentiometer constructor.
|
||||
@@ -52,7 +50,7 @@ class AnalogPotentiometer : public Potentiometer, public LiveWindowSendable {
|
||||
explicit AnalogPotentiometer(std::shared_ptr<AnalogInput> input,
|
||||
double fullRange = 1.0, double offset = 0.0);
|
||||
|
||||
virtual ~AnalogPotentiometer() = default;
|
||||
~AnalogPotentiometer() override = default;
|
||||
|
||||
/**
|
||||
* Get the current reading of the potentiomer.
|
||||
@@ -68,29 +66,11 @@ class AnalogPotentiometer : public Potentiometer, public LiveWindowSendable {
|
||||
*/
|
||||
double PIDGet() override;
|
||||
|
||||
/*
|
||||
* Live Window code, only does anything if live window is activated.
|
||||
*/
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
|
||||
void UpdateTable() override;
|
||||
|
||||
/**
|
||||
* AnalogPotentiometers don't have to do anything special when entering the
|
||||
* LiveWindow.
|
||||
*/
|
||||
void StartLiveWindowMode() override {}
|
||||
|
||||
/**
|
||||
* AnalogPotentiometers don't have to do anything special when exiting the
|
||||
* LiveWindow.
|
||||
*/
|
||||
void StopLiveWindowMode() override {}
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<AnalogInput> m_analog_input;
|
||||
double m_fullRange, m_offset;
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -24,7 +24,7 @@ class AnalogTrigger : public SensorBase {
|
||||
public:
|
||||
explicit AnalogTrigger(int channel);
|
||||
explicit AnalogTrigger(AnalogInput* channel);
|
||||
virtual ~AnalogTrigger();
|
||||
~AnalogTrigger() override;
|
||||
|
||||
void SetLimitsVoltage(double lower, double upper);
|
||||
void SetLimitsRaw(int lower, int upper);
|
||||
@@ -36,6 +36,8 @@ class AnalogTrigger : public SensorBase {
|
||||
std::shared_ptr<AnalogTriggerOutput> CreateOutput(
|
||||
AnalogTriggerType type) const;
|
||||
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
int m_index;
|
||||
HAL_AnalogTriggerHandle m_trigger;
|
||||
|
||||
@@ -50,7 +50,7 @@ class AnalogTriggerOutput : public DigitalSource {
|
||||
friend class AnalogTrigger;
|
||||
|
||||
public:
|
||||
virtual ~AnalogTriggerOutput();
|
||||
~AnalogTriggerOutput() override;
|
||||
bool Get() const;
|
||||
|
||||
// DigitalSource interface
|
||||
@@ -59,6 +59,8 @@ class AnalogTriggerOutput : public DigitalSource {
|
||||
bool IsAnalogTrigger() const override;
|
||||
int GetChannel() const override;
|
||||
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
protected:
|
||||
AnalogTriggerOutput(const AnalogTrigger& trigger,
|
||||
AnalogTriggerType outputType);
|
||||
|
||||
@@ -7,13 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SensorBase.h"
|
||||
#include "interfaces/Accelerometer.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -22,12 +17,9 @@ namespace frc {
|
||||
*
|
||||
* This class allows access to the roboRIO's internal accelerometer.
|
||||
*/
|
||||
class BuiltInAccelerometer : public Accelerometer,
|
||||
public SensorBase,
|
||||
public LiveWindowSendable {
|
||||
class BuiltInAccelerometer : public SensorBase, public Accelerometer {
|
||||
public:
|
||||
explicit BuiltInAccelerometer(Range range = kRange_8G);
|
||||
virtual ~BuiltInAccelerometer() = default;
|
||||
|
||||
// Accelerometer interface
|
||||
void SetRange(Range range) override;
|
||||
@@ -35,16 +27,7 @@ class BuiltInAccelerometer : public Accelerometer,
|
||||
double GetY() override;
|
||||
double GetZ() override;
|
||||
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<NetworkTable> subtable) override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override {}
|
||||
void StopLiveWindowMode() override {}
|
||||
|
||||
private:
|
||||
nt::NetworkTableEntry m_xEntry;
|
||||
nt::NetworkTableEntry m_yEntry;
|
||||
nt::NetworkTableEntry m_zEntry;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -7,11 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
|
||||
#include "SmartDashboard/Sendable.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -30,10 +28,10 @@ class Command;
|
||||
* only have to write the {@link Trigger#Get()} method to get the full
|
||||
* functionality of the Trigger class.
|
||||
*/
|
||||
class Trigger : public Sendable {
|
||||
class Trigger : public SendableBase {
|
||||
public:
|
||||
Trigger() = default;
|
||||
virtual ~Trigger() = default;
|
||||
~Trigger() override = default;
|
||||
bool Grab();
|
||||
virtual bool Get() = 0;
|
||||
void WhenActive(Command* command);
|
||||
@@ -42,11 +40,10 @@ class Trigger : public Sendable {
|
||||
void CancelWhenActive(Command* command);
|
||||
void ToggleWhenActive(Command* command);
|
||||
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
protected:
|
||||
nt::NetworkTableEntry m_pressedEntry;
|
||||
private:
|
||||
std::atomic_bool m_sendablePressed{false};
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include <llvm/Twine.h>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/NamedSendable.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -44,16 +45,16 @@ class Subsystem;
|
||||
* @see CommandGroup
|
||||
* @see Subsystem
|
||||
*/
|
||||
class Command : public ErrorBase, public NamedSendable {
|
||||
class Command : public ErrorBase, public SendableBase {
|
||||
friend class CommandGroup;
|
||||
friend class Scheduler;
|
||||
|
||||
public:
|
||||
Command();
|
||||
explicit Command(const std::string& name);
|
||||
explicit Command(const llvm::Twine& name);
|
||||
explicit Command(double timeout);
|
||||
Command(const std::string& name, double timeout);
|
||||
virtual ~Command();
|
||||
Command(const llvm::Twine& name, double timeout);
|
||||
~Command() override = default;
|
||||
double TimeSinceInitialized() const;
|
||||
void Requires(Subsystem* s);
|
||||
bool IsCanceled() const;
|
||||
@@ -76,6 +77,7 @@ class Command : public ErrorBase, public NamedSendable {
|
||||
bool IsTimedOut() const;
|
||||
bool AssertUnlocked(const std::string& message);
|
||||
void SetParent(CommandGroup* parent);
|
||||
bool IsParented() const;
|
||||
void ClearRequirements();
|
||||
|
||||
virtual void Initialize();
|
||||
@@ -116,9 +118,6 @@ class Command : public ErrorBase, public NamedSendable {
|
||||
void StartRunning();
|
||||
void StartTiming();
|
||||
|
||||
// The name of this command
|
||||
std::string m_name;
|
||||
|
||||
// The time since this command was initialized
|
||||
double m_startTime = -1;
|
||||
|
||||
@@ -153,14 +152,7 @@ class Command : public ErrorBase, public NamedSendable {
|
||||
static int m_commandCounter;
|
||||
|
||||
public:
|
||||
std::string GetName() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
|
||||
private:
|
||||
nt::NetworkTableEntry m_runningEntry;
|
||||
nt::NetworkTableEntry m_isParentedEntry;
|
||||
NT_EntryListener m_runningListener = 0;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -54,8 +54,7 @@ class PIDCommand : public Command, public PIDOutput, public PIDSource {
|
||||
std::shared_ptr<PIDController> m_controller;
|
||||
|
||||
public:
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -35,7 +35,7 @@ class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource {
|
||||
PIDSubsystem(double p, double i, double d);
|
||||
PIDSubsystem(double p, double i, double d, double f);
|
||||
PIDSubsystem(double p, double i, double d, double f, double period);
|
||||
virtual ~PIDSubsystem() = default;
|
||||
~PIDSubsystem() override = default;
|
||||
|
||||
void Enable();
|
||||
void Disable();
|
||||
@@ -66,10 +66,6 @@ class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource {
|
||||
private:
|
||||
// The internal PIDController
|
||||
std::shared_ptr<PIDController> m_controller;
|
||||
|
||||
public:
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
#include "Commands/Command.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/NamedSendable.h"
|
||||
#include "SmartDashboard/SmartDashboard.h"
|
||||
#include "networktables/NetworkTable.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -26,7 +24,7 @@ namespace frc {
|
||||
class ButtonScheduler;
|
||||
class Subsystem;
|
||||
|
||||
class Scheduler : public ErrorBase, public NamedSendable {
|
||||
class Scheduler : public ErrorBase, public SendableBase {
|
||||
public:
|
||||
static Scheduler* GetInstance();
|
||||
|
||||
@@ -39,15 +37,11 @@ class Scheduler : public ErrorBase, public NamedSendable {
|
||||
void ResetAll();
|
||||
void SetEnabled(bool enabled);
|
||||
|
||||
void UpdateTable();
|
||||
std::string GetSmartDashboardType() const;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable);
|
||||
std::string GetName() const;
|
||||
std::string GetType() const;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
Scheduler();
|
||||
virtual ~Scheduler() = default;
|
||||
~Scheduler() override = default;
|
||||
|
||||
void ProcessCommandAddition(Command* command);
|
||||
|
||||
|
||||
@@ -8,49 +8,50 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <llvm/StringRef.h>
|
||||
#include <llvm/Twine.h>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/NamedSendable.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
#include "SmartDashboard/Sendable.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class Command;
|
||||
|
||||
class Subsystem : public ErrorBase, public NamedSendable {
|
||||
class Subsystem : public ErrorBase, public SendableBase {
|
||||
friend class Scheduler;
|
||||
|
||||
public:
|
||||
explicit Subsystem(const std::string& name);
|
||||
virtual ~Subsystem() = default;
|
||||
explicit Subsystem(const llvm::Twine& name);
|
||||
|
||||
void SetDefaultCommand(Command* command);
|
||||
Command* GetDefaultCommand();
|
||||
llvm::StringRef GetDefaultCommandName();
|
||||
void SetCurrentCommand(Command* command);
|
||||
Command* GetCurrentCommand() const;
|
||||
llvm::StringRef GetCurrentCommandName() const;
|
||||
virtual void Periodic();
|
||||
virtual void InitDefaultCommand();
|
||||
|
||||
void AddChild(const llvm::Twine& name, std::shared_ptr<Sendable> child);
|
||||
void AddChild(const llvm::Twine& name, Sendable* child);
|
||||
void AddChild(const llvm::Twine& name, Sendable& child);
|
||||
void AddChild(std::shared_ptr<Sendable> child);
|
||||
void AddChild(Sendable* child);
|
||||
void AddChild(Sendable& child);
|
||||
|
||||
private:
|
||||
void ConfirmCommand();
|
||||
|
||||
Command* m_currentCommand = nullptr;
|
||||
bool m_currentCommandChanged = true;
|
||||
Command* m_defaultCommand = nullptr;
|
||||
std::string m_name;
|
||||
bool m_initializedDefaultCommand = false;
|
||||
|
||||
public:
|
||||
std::string GetName() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
|
||||
protected:
|
||||
nt::NetworkTableEntry m_hasDefaultEntry;
|
||||
nt::NetworkTableEntry m_defaultEntry;
|
||||
nt::NetworkTableEntry m_hasCommandEntry;
|
||||
nt::NetworkTableEntry m_commandEntry;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -7,14 +7,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <HAL/Types.h>
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SensorBase.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -33,11 +30,11 @@ namespace frc {
|
||||
* loop control. You can only turn off closed loop control, thereby stopping
|
||||
* the compressor from operating.
|
||||
*/
|
||||
class Compressor : public SensorBase, public LiveWindowSendable {
|
||||
class Compressor : public ErrorBase, public SendableBase {
|
||||
public:
|
||||
// Default PCM ID is 0
|
||||
explicit Compressor(int pcmID = GetDefaultSolenoidModule());
|
||||
virtual ~Compressor();
|
||||
explicit Compressor(int pcmID = SensorBase::GetDefaultSolenoidModule());
|
||||
~Compressor() override = default;
|
||||
|
||||
void Start();
|
||||
void Stop();
|
||||
@@ -58,11 +55,7 @@ class Compressor : public SensorBase, public LiveWindowSendable {
|
||||
bool GetCompressorNotConnectedFault() const;
|
||||
void ClearAllPCMStickyFaults();
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
protected:
|
||||
HAL_CompressorHandle m_compressorHandle;
|
||||
@@ -70,10 +63,6 @@ class Compressor : public SensorBase, public LiveWindowSendable {
|
||||
private:
|
||||
void SetCompressor(bool on);
|
||||
int m_module;
|
||||
|
||||
nt::NetworkTableEntry m_enabledEntry;
|
||||
nt::NetworkTableEntry m_pressureSwitchEntry;
|
||||
NT_EntryListener m_enabledListener = 0;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -8,16 +8,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <HAL/Counter.h>
|
||||
#include <HAL/Types.h>
|
||||
|
||||
#include "AnalogTrigger.h"
|
||||
#include "CounterBase.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SensorBase.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -33,9 +30,7 @@ class DigitalGlitchFilter;
|
||||
* All counters will immediately start counting - Reset() them if you need them
|
||||
* to be zeroed before use.
|
||||
*/
|
||||
class Counter : public SensorBase,
|
||||
public CounterBase,
|
||||
public LiveWindowSendable {
|
||||
class Counter : public SensorBase, public CounterBase {
|
||||
public:
|
||||
enum Mode {
|
||||
kTwoPulse = 0,
|
||||
@@ -53,7 +48,7 @@ class Counter : public SensorBase,
|
||||
DigitalSource* downSource, bool inverted);
|
||||
Counter(EncodingType encodingType, std::shared_ptr<DigitalSource> upSource,
|
||||
std::shared_ptr<DigitalSource> downSource, bool inverted);
|
||||
virtual ~Counter();
|
||||
~Counter() override;
|
||||
|
||||
void SetUpSource(int channel);
|
||||
void SetUpSource(AnalogTrigger* analogTrigger, AnalogTriggerType triggerType);
|
||||
@@ -96,11 +91,7 @@ class Counter : public SensorBase,
|
||||
int GetSamplesToAverage() const;
|
||||
int GetFPGAIndex() const { return m_index; }
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
protected:
|
||||
// Makes the counter count up.
|
||||
@@ -115,7 +106,6 @@ class Counter : public SensorBase,
|
||||
private:
|
||||
int m_index = 0; // The index of this counter.
|
||||
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
friend class DigitalGlitchFilter;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "DigitalSource.h"
|
||||
#include "SensorBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -30,7 +31,7 @@ class Counter;
|
||||
class DigitalGlitchFilter : public SensorBase {
|
||||
public:
|
||||
DigitalGlitchFilter();
|
||||
~DigitalGlitchFilter();
|
||||
~DigitalGlitchFilter() override;
|
||||
|
||||
void Add(DigitalSource* input);
|
||||
void Add(Encoder* input);
|
||||
@@ -46,6 +47,8 @@ class DigitalGlitchFilter : public SensorBase {
|
||||
int GetPeriodCycles();
|
||||
uint64_t GetPeriodNanoSeconds();
|
||||
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
// Sets the filter for the input to be the requested index. A value of 0
|
||||
// disables the filter, and the filter value must be between 1 and 3,
|
||||
|
||||
@@ -7,12 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "DigitalSource.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -27,10 +22,10 @@ class DigitalGlitchFilter;
|
||||
* as required. This class is only for devices like switches etc. that aren't
|
||||
* implemented anywhere else.
|
||||
*/
|
||||
class DigitalInput : public DigitalSource, public LiveWindowSendable {
|
||||
class DigitalInput : public DigitalSource {
|
||||
public:
|
||||
explicit DigitalInput(int channel);
|
||||
virtual ~DigitalInput();
|
||||
~DigitalInput() override;
|
||||
bool Get() const;
|
||||
int GetChannel() const override;
|
||||
|
||||
@@ -39,17 +34,12 @@ class DigitalInput : public DigitalSource, public LiveWindowSendable {
|
||||
AnalogTriggerType GetAnalogTriggerTypeForRouting() const override;
|
||||
bool IsAnalogTrigger() const override;
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
int m_channel;
|
||||
HAL_DigitalHandle m_handle;
|
||||
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
friend class DigitalGlitchFilter;
|
||||
};
|
||||
|
||||
|
||||
@@ -7,14 +7,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <HAL/Types.h>
|
||||
|
||||
#include "DigitalSource.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -25,13 +21,13 @@ namespace frc {
|
||||
* elsewhere will allocate channels automatically so for those devices it
|
||||
* shouldn't be done here.
|
||||
*/
|
||||
class DigitalOutput : public DigitalSource, public LiveWindowSendable {
|
||||
class DigitalOutput : public ErrorBase, public SendableBase {
|
||||
public:
|
||||
explicit DigitalOutput(int channel);
|
||||
virtual ~DigitalOutput();
|
||||
~DigitalOutput() override;
|
||||
void Set(bool value);
|
||||
bool Get() const;
|
||||
int GetChannel() const override;
|
||||
int GetChannel() const;
|
||||
void Pulse(double length);
|
||||
bool IsPulsing() const;
|
||||
void SetPWMRate(double rate);
|
||||
@@ -39,24 +35,12 @@ class DigitalOutput : public DigitalSource, public LiveWindowSendable {
|
||||
void DisablePWM();
|
||||
void UpdateDutyCycle(double dutyCycle);
|
||||
|
||||
// Digital Source Interface
|
||||
HAL_Handle GetPortHandleForRouting() const override;
|
||||
AnalogTriggerType GetAnalogTriggerTypeForRouting() const override;
|
||||
bool IsAnalogTrigger() const override;
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
int m_channel;
|
||||
HAL_DigitalHandle m_handle;
|
||||
HAL_DigitalPWMHandle m_pwmGenerator;
|
||||
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
NT_EntryListener m_valueListener = 0;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -24,7 +24,6 @@ namespace frc {
|
||||
*/
|
||||
class DigitalSource : public InterruptableSensorBase {
|
||||
public:
|
||||
virtual ~DigitalSource() = default;
|
||||
virtual HAL_Handle GetPortHandleForRouting() const = 0;
|
||||
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
|
||||
virtual bool IsAnalogTrigger() const = 0;
|
||||
|
||||
@@ -7,14 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <HAL/Types.h>
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SolenoidBase.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -25,23 +20,19 @@ namespace frc {
|
||||
* The DoubleSolenoid class is typically used for pneumatics solenoids that
|
||||
* have two positions controlled by two separate channels.
|
||||
*/
|
||||
class DoubleSolenoid : public SolenoidBase, public LiveWindowSendable {
|
||||
class DoubleSolenoid : public SolenoidBase {
|
||||
public:
|
||||
enum Value { kOff, kForward, kReverse };
|
||||
|
||||
explicit DoubleSolenoid(int forwardChannel, int reverseChannel);
|
||||
DoubleSolenoid(int moduleNumber, int forwardChannel, int reverseChannel);
|
||||
virtual ~DoubleSolenoid();
|
||||
~DoubleSolenoid() override;
|
||||
virtual void Set(Value value);
|
||||
virtual Value Get() const;
|
||||
bool IsFwdSolenoidBlackListed() const;
|
||||
bool IsRevSolenoidBlackListed() const;
|
||||
|
||||
void UpdateTable();
|
||||
void StartLiveWindowMode();
|
||||
void StopLiveWindowMode();
|
||||
std::string GetSmartDashboardType() const;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable);
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
int m_forwardChannel; // The forward channel on the module to control.
|
||||
@@ -50,9 +41,6 @@ class DoubleSolenoid : public SolenoidBase, public LiveWindowSendable {
|
||||
int m_reverseMask; // The mask for the reverse channel.
|
||||
HAL_SolenoidHandle m_forwardHandle = HAL_kInvalidHandle;
|
||||
HAL_SolenoidHandle m_reverseHandle = HAL_kInvalidHandle;
|
||||
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
NT_EntryListener m_valueListener = 0;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -102,7 +102,7 @@ class DifferentialDrive : public RobotDriveBase {
|
||||
static constexpr double kDefaultQuickStopAlpha = 0.1;
|
||||
|
||||
DifferentialDrive(SpeedController& leftMotor, SpeedController& rightMotor);
|
||||
virtual ~DifferentialDrive() = default;
|
||||
~DifferentialDrive() override = default;
|
||||
|
||||
DifferentialDrive(const DifferentialDrive&) = delete;
|
||||
DifferentialDrive& operator=(const DifferentialDrive&) = delete;
|
||||
@@ -118,6 +118,8 @@ class DifferentialDrive : public RobotDriveBase {
|
||||
void StopMotor() override;
|
||||
void GetDescription(llvm::raw_ostream& desc) const override;
|
||||
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
SpeedController& m_leftMotor;
|
||||
SpeedController& m_rightMotor;
|
||||
|
||||
@@ -55,7 +55,7 @@ class KilloughDrive : public RobotDriveBase {
|
||||
KilloughDrive(SpeedController& leftMotor, SpeedController& rightMotor,
|
||||
SpeedController& backMotor, double leftMotorAngle,
|
||||
double rightMotorAngle, double backMotorAngle);
|
||||
virtual ~KilloughDrive() = default;
|
||||
~KilloughDrive() override = default;
|
||||
|
||||
KilloughDrive(const KilloughDrive&) = delete;
|
||||
KilloughDrive& operator=(const KilloughDrive&) = delete;
|
||||
@@ -67,6 +67,8 @@ class KilloughDrive : public RobotDriveBase {
|
||||
void StopMotor() override;
|
||||
void GetDescription(llvm::raw_ostream& desc) const override;
|
||||
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
SpeedController& m_leftMotor;
|
||||
SpeedController& m_rightMotor;
|
||||
|
||||
@@ -67,7 +67,7 @@ class MecanumDrive : public RobotDriveBase {
|
||||
MecanumDrive(SpeedController& frontLeftMotor, SpeedController& rearLeftMotor,
|
||||
SpeedController& frontRightMotor,
|
||||
SpeedController& rearRightMotor);
|
||||
virtual ~MecanumDrive() = default;
|
||||
~MecanumDrive() override = default;
|
||||
|
||||
MecanumDrive(const MecanumDrive&) = delete;
|
||||
MecanumDrive& operator=(const MecanumDrive&) = delete;
|
||||
@@ -79,6 +79,8 @@ class MecanumDrive : public RobotDriveBase {
|
||||
void StopMotor() override;
|
||||
void GetDescription(llvm::raw_ostream& desc) const override;
|
||||
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
SpeedController& m_frontLeftMotor;
|
||||
SpeedController& m_rearLeftMotor;
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#include <llvm/ArrayRef.h>
|
||||
#include <llvm/raw_ostream.h>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "MotorSafety.h"
|
||||
#include "MotorSafetyHelper.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -23,7 +23,7 @@ class SpeedController;
|
||||
/**
|
||||
* Common base class for drive platforms.
|
||||
*/
|
||||
class RobotDriveBase : public MotorSafety, public ErrorBase {
|
||||
class RobotDriveBase : public MotorSafety, public SendableBase {
|
||||
public:
|
||||
/**
|
||||
* The location of a motor on the robot for the purpose of driving.
|
||||
@@ -39,7 +39,7 @@ class RobotDriveBase : public MotorSafety, public ErrorBase {
|
||||
};
|
||||
|
||||
RobotDriveBase();
|
||||
virtual ~RobotDriveBase() = default;
|
||||
~RobotDriveBase() override = default;
|
||||
|
||||
RobotDriveBase(const RobotDriveBase&) = delete;
|
||||
RobotDriveBase& operator=(const RobotDriveBase&) = delete;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
#include <llvm/StringRef.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "RobotState.h"
|
||||
#include "SensorBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -28,12 +28,12 @@ struct MatchInfoData;
|
||||
* Provide access to the network communication data to / from the Driver
|
||||
* Station.
|
||||
*/
|
||||
class DriverStation : public SensorBase, public RobotStateInterface {
|
||||
class DriverStation : public ErrorBase, public RobotStateInterface {
|
||||
public:
|
||||
enum Alliance { kRed, kBlue, kInvalid };
|
||||
enum MatchType { kNone, kPractice, kQualification, kElimination };
|
||||
|
||||
virtual ~DriverStation();
|
||||
~DriverStation() override;
|
||||
static DriverStation& GetInstance();
|
||||
static void ReportError(llvm::StringRef error);
|
||||
static void ReportWarning(llvm::StringRef error);
|
||||
|
||||
@@ -8,16 +8,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <HAL/Encoder.h>
|
||||
|
||||
#include "Counter.h"
|
||||
#include "CounterBase.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "PIDSource.h"
|
||||
#include "SensorBase.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -39,10 +36,7 @@ class DigitalGlitchFilter;
|
||||
* All encoders will immediately start counting - Reset() them if you need them
|
||||
* to be zeroed before use.
|
||||
*/
|
||||
class Encoder : public SensorBase,
|
||||
public CounterBase,
|
||||
public PIDSource,
|
||||
public LiveWindowSendable {
|
||||
class Encoder : public SensorBase, public CounterBase, public PIDSource {
|
||||
public:
|
||||
enum IndexingType {
|
||||
kResetWhileHigh,
|
||||
@@ -60,7 +54,7 @@ class Encoder : public SensorBase,
|
||||
bool reverseDirection = false, EncodingType encodingType = k4X);
|
||||
Encoder(DigitalSource& aSource, DigitalSource& bSource,
|
||||
bool reverseDirection = false, EncodingType encodingType = k4X);
|
||||
virtual ~Encoder();
|
||||
~Encoder() override;
|
||||
|
||||
// CounterBase interface
|
||||
int Get() const override;
|
||||
@@ -76,6 +70,7 @@ class Encoder : public SensorBase,
|
||||
double GetRate() const;
|
||||
void SetMinRate(double minRate);
|
||||
void SetDistancePerPulse(double distancePerPulse);
|
||||
double GetDistancePerPulse() const;
|
||||
void SetReverseDirection(bool reverseDirection);
|
||||
void SetSamplesToAverage(int samplesToAverage);
|
||||
int GetSamplesToAverage() const;
|
||||
@@ -85,11 +80,7 @@ class Encoder : public SensorBase,
|
||||
void SetIndexSource(const DigitalSource& source,
|
||||
IndexingType type = kResetOnRisingEdge);
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
int GetFPGAIndex() const;
|
||||
|
||||
@@ -103,9 +94,6 @@ class Encoder : public SensorBase,
|
||||
std::unique_ptr<DigitalSource> m_indexSource = nullptr;
|
||||
HAL_EncoderHandle m_encoder = HAL_kInvalidHandle;
|
||||
|
||||
nt::NetworkTableEntry m_speedEntry;
|
||||
nt::NetworkTableEntry m_distanceEntry;
|
||||
nt::NetworkTableEntry m_distancePerTickEntry;
|
||||
friend class DigitalGlitchFilter;
|
||||
};
|
||||
|
||||
|
||||
@@ -30,11 +30,10 @@ class GearTooth : public Counter {
|
||||
explicit GearTooth(DigitalSource* source, bool directionSensitive = false);
|
||||
explicit GearTooth(std::shared_ptr<DigitalSource> source,
|
||||
bool directionSensitive = false);
|
||||
virtual ~GearTooth() = default;
|
||||
|
||||
void EnableDirectionSensing(bool directionSensitive);
|
||||
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -7,14 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "PIDSource.h"
|
||||
#include "SensorBase.h"
|
||||
#include "interfaces/Gyro.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -22,24 +17,12 @@ namespace frc {
|
||||
* GyroBase is the common base class for Gyro implementations such as
|
||||
* AnalogGyro.
|
||||
*/
|
||||
class GyroBase : public Gyro,
|
||||
public SensorBase,
|
||||
public PIDSource,
|
||||
public LiveWindowSendable {
|
||||
class GyroBase : public Gyro, public SensorBase, public PIDSource {
|
||||
public:
|
||||
virtual ~GyroBase() = default;
|
||||
|
||||
// PIDSource interface
|
||||
double PIDGet() override;
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
|
||||
|
||||
private:
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "SensorBase.h"
|
||||
#include "ErrorBase.h"
|
||||
|
||||
enum HAL_I2CPort : int32_t;
|
||||
|
||||
@@ -21,12 +21,12 @@ namespace frc {
|
||||
* This class is intended to be used by sensor (and other I2C device) drivers.
|
||||
* It probably should not be used directly.
|
||||
*/
|
||||
class I2C : SensorBase {
|
||||
class I2C : public ErrorBase {
|
||||
public:
|
||||
enum Port { kOnboard = 0, kMXP };
|
||||
|
||||
I2C(Port port, int deviceAddress);
|
||||
virtual ~I2C();
|
||||
~I2C() override;
|
||||
|
||||
I2C(const I2C&) = delete;
|
||||
I2C& operator=(const I2C&) = delete;
|
||||
|
||||
@@ -24,7 +24,6 @@ class InterruptableSensorBase : public SensorBase {
|
||||
};
|
||||
|
||||
InterruptableSensorBase() = default;
|
||||
virtual ~InterruptableSensorBase() = default;
|
||||
|
||||
virtual HAL_Handle GetPortHandleForRouting() const = 0;
|
||||
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace frc {
|
||||
class Jaguar : public PWMSpeedController {
|
||||
public:
|
||||
explicit Jaguar(int channel);
|
||||
virtual ~Jaguar() = default;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -8,28 +8,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "DigitalOutput.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "MotorSafety.h"
|
||||
#include "MotorSafetyHelper.h"
|
||||
#include "PWM.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
#include "SpeedController.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Nidec Brushless Motor.
|
||||
*/
|
||||
class NidecBrushless : public SpeedController,
|
||||
public MotorSafety,
|
||||
public LiveWindowSendable {
|
||||
class NidecBrushless : public ErrorBase,
|
||||
public SendableBase,
|
||||
public SpeedController,
|
||||
public MotorSafety {
|
||||
public:
|
||||
NidecBrushless(int pwmChannel, int dioChannel);
|
||||
~NidecBrushless() = default;
|
||||
~NidecBrushless() override = default;
|
||||
|
||||
// SpeedController interface
|
||||
void Set(double speed) override;
|
||||
@@ -55,13 +54,7 @@ class NidecBrushless : public SpeedController,
|
||||
int GetChannel() const;
|
||||
|
||||
// Sendable interface
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
|
||||
// LiveWindowSendable interface
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
MotorSafetyHelper m_safetyHelper;
|
||||
@@ -70,8 +63,6 @@ class NidecBrushless : public SpeedController,
|
||||
DigitalOutput m_dio;
|
||||
PWM m_pwm;
|
||||
double m_speed = 0.0;
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
int m_valueListener;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -7,21 +7,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <support/deprecated.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "Base.h"
|
||||
#include "Controller.h"
|
||||
#include "Filters/LinearDigitalFilter.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "Notifier.h"
|
||||
#include "PIDInterface.h"
|
||||
#include "PIDSource.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
#include "Timer.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -37,7 +36,7 @@ class PIDOutput;
|
||||
* in the integral and derivative calculations. Therefore, the sample rate
|
||||
* affects the controller's behavior for a given set of PID constants.
|
||||
*/
|
||||
class PIDController : public LiveWindowSendable, public PIDInterface {
|
||||
class PIDController : public SendableBase, public PIDInterface {
|
||||
public:
|
||||
PIDController(double p, double i, double d, PIDSource* source,
|
||||
PIDOutput* output, double period = 0.05);
|
||||
@@ -47,7 +46,7 @@ class PIDController : public LiveWindowSendable, public PIDInterface {
|
||||
PIDOutput& output, double period = 0.05);
|
||||
PIDController(double p, double i, double d, double f, PIDSource& source,
|
||||
PIDOutput& output, double period = 0.05);
|
||||
virtual ~PIDController();
|
||||
~PIDController() override;
|
||||
|
||||
PIDController(const PIDController&) = delete;
|
||||
PIDController& operator=(const PIDController) = delete;
|
||||
@@ -58,6 +57,10 @@ class PIDController : public LiveWindowSendable, public PIDInterface {
|
||||
virtual void SetOutputRange(double minimumOutput, double maximumOutput);
|
||||
void SetPID(double p, double i, double d) override;
|
||||
virtual void SetPID(double p, double i, double d, double f);
|
||||
void SetP(double p);
|
||||
void SetI(double i);
|
||||
void SetD(double d);
|
||||
void SetF(double f);
|
||||
double GetP() const override;
|
||||
double GetI() const override;
|
||||
double GetD() const override;
|
||||
@@ -87,29 +90,17 @@ class PIDController : public LiveWindowSendable, public PIDInterface {
|
||||
|
||||
void Enable() override;
|
||||
void Disable() override;
|
||||
void SetEnabled(bool enable);
|
||||
bool IsEnabled() const override;
|
||||
|
||||
void Reset() override;
|
||||
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
protected:
|
||||
PIDSource* m_pidInput;
|
||||
PIDOutput* m_pidOutput;
|
||||
|
||||
nt::NetworkTableEntry m_pEntry;
|
||||
nt::NetworkTableEntry m_iEntry;
|
||||
nt::NetworkTableEntry m_dEntry;
|
||||
nt::NetworkTableEntry m_fEntry;
|
||||
nt::NetworkTableEntry m_setpointEntry;
|
||||
nt::NetworkTableEntry m_enabledEntry;
|
||||
NT_EntryListener m_pListener = 0;
|
||||
NT_EntryListener m_iListener = 0;
|
||||
NT_EntryListener m_dListener = 0;
|
||||
NT_EntryListener m_fListener = 0;
|
||||
NT_EntryListener m_setpointListener = 0;
|
||||
NT_EntryListener m_enabledListener = 0;
|
||||
|
||||
virtual void Calculate();
|
||||
virtual double CalculateFeedForward();
|
||||
double GetContinuousError(double error) const;
|
||||
@@ -180,12 +171,6 @@ class PIDController : public LiveWindowSendable, public PIDInterface {
|
||||
|
||||
std::unique_ptr<Notifier> m_controlLoop;
|
||||
Timer m_setpointTimer;
|
||||
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
void RemoveListeners();
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include "Base.h"
|
||||
#include "Controller.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
|
||||
@@ -9,14 +9,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <HAL/Types.h>
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SensorBase.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -37,7 +33,7 @@ namespace frc {
|
||||
* - 1 = minimum pulse width (currently .5ms)
|
||||
* - 0 = disabled (i.e. PWM output is held low)
|
||||
*/
|
||||
class PWM : public SensorBase, public LiveWindowSendable {
|
||||
class PWM : public ErrorBase, public SendableBase {
|
||||
public:
|
||||
/**
|
||||
* Represents the amount to multiply the minimum servo-pulse pwm period by.
|
||||
@@ -58,7 +54,7 @@ class PWM : public SensorBase, public LiveWindowSendable {
|
||||
};
|
||||
|
||||
explicit PWM(int channel);
|
||||
virtual ~PWM();
|
||||
~PWM() override;
|
||||
virtual void SetRaw(uint16_t value);
|
||||
virtual uint16_t GetRaw() const;
|
||||
virtual void SetPosition(double pos);
|
||||
@@ -78,14 +74,7 @@ class PWM : public SensorBase, public LiveWindowSendable {
|
||||
int GetChannel() const { return m_channel; }
|
||||
|
||||
protected:
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
|
||||
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
NT_EntryListener m_valueListener = 0;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
int m_channel;
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace frc {
|
||||
*/
|
||||
class PWMSpeedController : public SafePWM, public SpeedController {
|
||||
public:
|
||||
virtual ~PWMSpeedController() = default;
|
||||
void Set(double value) override;
|
||||
double Get() const override;
|
||||
void SetInverted(bool isInverted) override;
|
||||
|
||||
@@ -18,7 +18,6 @@ namespace frc {
|
||||
class PWMTalonSRX : public PWMSpeedController {
|
||||
public:
|
||||
explicit PWMTalonSRX(int channel);
|
||||
virtual ~PWMTalonSRX() = default;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -7,12 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SensorBase.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -20,7 +15,7 @@ namespace frc {
|
||||
* Class for getting voltage, current, temperature, power and energy from the
|
||||
* CAN PDP.
|
||||
*/
|
||||
class PowerDistributionPanel : public SensorBase, public LiveWindowSendable {
|
||||
class PowerDistributionPanel : public SensorBase {
|
||||
public:
|
||||
PowerDistributionPanel();
|
||||
explicit PowerDistributionPanel(int module);
|
||||
@@ -34,16 +29,9 @@ class PowerDistributionPanel : public SensorBase, public LiveWindowSendable {
|
||||
void ResetTotalEnergy();
|
||||
void ClearStickyFaults();
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
nt::NetworkTableEntry m_chanEntry[16];
|
||||
nt::NetworkTableEntry m_voltageEntry;
|
||||
nt::NetworkTableEntry m_totalCurrentEntry;
|
||||
int m_module;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,15 +8,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <HAL/Types.h>
|
||||
#include <llvm/raw_ostream.h>
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "MotorSafety.h"
|
||||
#include "SensorBase.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -34,13 +32,13 @@ class MotorSafetyHelper;
|
||||
* independently for something that does not care about voltage polarity (like
|
||||
* a solenoid).
|
||||
*/
|
||||
class Relay : public MotorSafety, public SensorBase, public LiveWindowSendable {
|
||||
class Relay : public MotorSafety, public ErrorBase, public SendableBase {
|
||||
public:
|
||||
enum Value { kOff, kOn, kForward, kReverse };
|
||||
enum Direction { kBothDirections, kForwardOnly, kReverseOnly };
|
||||
|
||||
explicit Relay(int channel, Direction direction = kBothDirections);
|
||||
virtual ~Relay();
|
||||
~Relay() override;
|
||||
|
||||
void Set(Value value);
|
||||
Value Get() const;
|
||||
@@ -54,15 +52,7 @@ class Relay : public MotorSafety, public SensorBase, public LiveWindowSendable {
|
||||
void SetSafetyEnabled(bool enabled) override;
|
||||
void GetDescription(llvm::raw_ostream& desc) const override;
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
|
||||
|
||||
protected:
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
NT_EntryListener m_valueListener = 0;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
int m_channel;
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace frc {
|
||||
class SD540 : public PWMSpeedController {
|
||||
public:
|
||||
explicit SD540(int channel);
|
||||
virtual ~SD540() = default;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -9,15 +9,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "SensorBase.h"
|
||||
#include "ErrorBase.h"
|
||||
|
||||
enum HAL_SPIPort : int32_t;
|
||||
|
||||
namespace frc {
|
||||
|
||||
class DigitalOutput;
|
||||
class DigitalInput;
|
||||
|
||||
/**
|
||||
* SPI bus interface class.
|
||||
*
|
||||
@@ -25,12 +22,12 @@ class DigitalInput;
|
||||
* It probably should not be used directly.
|
||||
*
|
||||
*/
|
||||
class SPI : public SensorBase {
|
||||
class SPI : public ErrorBase {
|
||||
public:
|
||||
enum Port { kOnboardCS0 = 0, kOnboardCS1, kOnboardCS2, kOnboardCS3, kMXP };
|
||||
|
||||
explicit SPI(Port port);
|
||||
virtual ~SPI();
|
||||
~SPI() override;
|
||||
|
||||
SPI(const SPI&) = delete;
|
||||
SPI& operator=(const SPI&) = delete;
|
||||
|
||||
@@ -7,8 +7,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Base.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/Sendable.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -18,10 +22,9 @@ namespace frc {
|
||||
* Stores most recent status information as well as containing utility functions
|
||||
* for checking channels and error processing.
|
||||
*/
|
||||
class SensorBase : public ErrorBase {
|
||||
class SensorBase : public ErrorBase, public SendableBase {
|
||||
public:
|
||||
SensorBase() = default;
|
||||
virtual ~SensorBase() = default;
|
||||
|
||||
SensorBase(const SensorBase&) = delete;
|
||||
SensorBase& operator=(const SensorBase&) = delete;
|
||||
|
||||
@@ -7,12 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "SafePWM.h"
|
||||
#include "SpeedController.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -25,7 +21,6 @@ namespace frc {
|
||||
class Servo : public SafePWM {
|
||||
public:
|
||||
explicit Servo(int channel);
|
||||
virtual ~Servo();
|
||||
void Set(double value);
|
||||
void SetOffline();
|
||||
double Get() const;
|
||||
@@ -34,15 +29,7 @@ class Servo : public SafePWM {
|
||||
static double GetMaxAngle() { return kMaxServoAngle; }
|
||||
static double GetMinAngle() { return kMinServoAngle; }
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
|
||||
|
||||
protected:
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
NT_EntryListener m_valueListener = 0;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
double GetServoAngleRange() const { return kMaxServoAngle - kMinServoAngle; }
|
||||
|
||||
@@ -1,29 +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 <string>
|
||||
|
||||
#include "SmartDashboard/Sendable.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* The interface for sendable objects that gives the sendable a default name in
|
||||
* the Smart Dashboard.
|
||||
*/
|
||||
class NamedSendable : public Sendable {
|
||||
public:
|
||||
/**
|
||||
* @return The name of the subtable of SmartDashboard that the Sendable object
|
||||
* will use
|
||||
*/
|
||||
virtual std::string GetName() const = 0;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
@@ -7,27 +7,63 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "networktables/NetworkTable.h"
|
||||
#include <llvm/Twine.h>
|
||||
|
||||
namespace frc {
|
||||
|
||||
class SendableBuilder;
|
||||
|
||||
class Sendable {
|
||||
public:
|
||||
/**
|
||||
* Initializes a table for this sendable object.
|
||||
*
|
||||
* @param subtable The table to put the values in.
|
||||
*/
|
||||
virtual void InitTable(std::shared_ptr<nt::NetworkTable> subtable) = 0;
|
||||
virtual ~Sendable() = default;
|
||||
|
||||
/**
|
||||
* @return The string representation of the named data type that will be used
|
||||
* by the smart dashboard for this sendable
|
||||
* Gets the name of this Sendable object.
|
||||
*
|
||||
* @return Name
|
||||
*/
|
||||
virtual std::string GetSmartDashboardType() const = 0;
|
||||
virtual std::string GetName() const = 0;
|
||||
|
||||
/**
|
||||
* Sets the name of this Sendable object.
|
||||
*
|
||||
* @param name name
|
||||
*/
|
||||
virtual void SetName(const llvm::Twine& name) = 0;
|
||||
|
||||
/**
|
||||
* Sets both the subsystem name and device name of this Sendable object.
|
||||
*
|
||||
* @param subsystem subsystem name
|
||||
* @param name device name
|
||||
*/
|
||||
void SetName(const llvm::Twine& subsystem, const llvm::Twine& name) {
|
||||
SetSubsystem(subsystem);
|
||||
SetName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the subsystem name of this Sendable object.
|
||||
*
|
||||
* @return Subsystem name
|
||||
*/
|
||||
virtual std::string GetSubsystem() const = 0;
|
||||
|
||||
/**
|
||||
* Sets the subsystem name of this Sendable object.
|
||||
*
|
||||
* @param subsystem subsystem name
|
||||
*/
|
||||
virtual void SetSubsystem(const llvm::Twine& subsystem) = 0;
|
||||
|
||||
/**
|
||||
* Initializes this Sendable object.
|
||||
*
|
||||
* @param builder sendable builder
|
||||
*/
|
||||
virtual void InitSendable(SendableBuilder& builder) = 0;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "Sendable.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class SendableBase : public Sendable {
|
||||
public:
|
||||
explicit SendableBase(bool addLiveWindow = true);
|
||||
~SendableBase() override;
|
||||
|
||||
using Sendable::SetName;
|
||||
|
||||
std::string GetName() const final;
|
||||
void SetName(const llvm::Twine& name) final;
|
||||
std::string GetSubsystem() const final;
|
||||
void SetSubsystem(const llvm::Twine& subsystem) final;
|
||||
|
||||
protected:
|
||||
void AddChild(std::shared_ptr<Sendable> child);
|
||||
void AddChild(void* child);
|
||||
|
||||
void SetName(const llvm::Twine& moduleType, int channel);
|
||||
void SetName(const llvm::Twine& moduleType, int moduleNumber, int channel);
|
||||
|
||||
private:
|
||||
mutable wpi::mutex m_mutex;
|
||||
std::string m_name;
|
||||
std::string m_subsystem = "Ungrouped";
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
217
wpilibc/src/main/native/include/SmartDashboard/SendableBuilder.h
Normal file
217
wpilibc/src/main/native/include/SmartDashboard/SendableBuilder.h
Normal file
@@ -0,0 +1,217 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <llvm/ArrayRef.h>
|
||||
#include <llvm/SmallVector.h>
|
||||
#include <llvm/Twine.h>
|
||||
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
#include "networktables/NetworkTableValue.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class SendableBuilder {
|
||||
public:
|
||||
virtual ~SendableBuilder() = default;
|
||||
|
||||
/**
|
||||
* Set the string representation of the named data type that will be used
|
||||
* by the smart dashboard for this sendable.
|
||||
*
|
||||
* @param type data type
|
||||
*/
|
||||
virtual void SetSmartDashboardType(const llvm::Twine& type) = 0;
|
||||
|
||||
/**
|
||||
* Set the function that should be called to set the Sendable into a safe
|
||||
* state. This is called when entering and exiting Live Window mode.
|
||||
*
|
||||
* @param func function
|
||||
*/
|
||||
virtual void SetSafeState(std::function<void()> func) = 0;
|
||||
|
||||
/**
|
||||
* Set the function that should be called to update the network table
|
||||
* for things other than properties. Note this function is not passed
|
||||
* the network table object; instead it should use the entry handles
|
||||
* returned by GetEntry().
|
||||
*
|
||||
* @param func function
|
||||
*/
|
||||
virtual void SetUpdateTable(std::function<void()> func) = 0;
|
||||
|
||||
/**
|
||||
* Add a property without getters or setters. This can be used to get
|
||||
* entry handles for the function called by SetUpdateTable().
|
||||
*
|
||||
* @param key property name
|
||||
* @return Network table entry
|
||||
*/
|
||||
virtual nt::NetworkTableEntry GetEntry(const llvm::Twine& key) = 0;
|
||||
|
||||
/**
|
||||
* Add a boolean property.
|
||||
*
|
||||
* @param key property name
|
||||
* @param getter getter function (returns current value)
|
||||
* @param setter setter function (sets new value)
|
||||
*/
|
||||
virtual void AddBooleanProperty(const llvm::Twine& key,
|
||||
std::function<bool()> getter,
|
||||
std::function<void(bool)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a double property.
|
||||
*
|
||||
* @param key property name
|
||||
* @param getter getter function (returns current value)
|
||||
* @param setter setter function (sets new value)
|
||||
*/
|
||||
virtual void AddDoubleProperty(const llvm::Twine& key,
|
||||
std::function<double()> getter,
|
||||
std::function<void(double)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a string property.
|
||||
*
|
||||
* @param key property name
|
||||
* @param getter getter function (returns current value)
|
||||
* @param setter setter function (sets new value)
|
||||
*/
|
||||
virtual void AddStringProperty(
|
||||
const llvm::Twine& key, std::function<std::string()> getter,
|
||||
std::function<void(llvm::StringRef)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a boolean array property.
|
||||
*
|
||||
* @param key property name
|
||||
* @param getter getter function (returns current value)
|
||||
* @param setter setter function (sets new value)
|
||||
*/
|
||||
virtual void AddBooleanArrayProperty(
|
||||
const llvm::Twine& key, std::function<std::vector<int>()> getter,
|
||||
std::function<void(llvm::ArrayRef<int>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a double array property.
|
||||
*
|
||||
* @param key property name
|
||||
* @param getter getter function (returns current value)
|
||||
* @param setter setter function (sets new value)
|
||||
*/
|
||||
virtual void AddDoubleArrayProperty(
|
||||
const llvm::Twine& key, std::function<std::vector<double>()> getter,
|
||||
std::function<void(llvm::ArrayRef<double>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a string array property.
|
||||
*
|
||||
* @param key property name
|
||||
* @param getter getter function (returns current value)
|
||||
* @param setter setter function (sets new value)
|
||||
*/
|
||||
virtual void AddStringArrayProperty(
|
||||
const llvm::Twine& key, std::function<std::vector<std::string>()> getter,
|
||||
std::function<void(llvm::ArrayRef<std::string>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a raw property.
|
||||
*
|
||||
* @param key property name
|
||||
* @param getter getter function (returns current value)
|
||||
* @param setter setter function (sets new value)
|
||||
*/
|
||||
virtual void AddRawProperty(const llvm::Twine& key,
|
||||
std::function<std::string()> getter,
|
||||
std::function<void(llvm::StringRef)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a NetworkTableValue property.
|
||||
*
|
||||
* @param key property name
|
||||
* @param getter getter function (returns current value)
|
||||
* @param setter setter function (sets new value)
|
||||
*/
|
||||
virtual void AddValueProperty(
|
||||
const llvm::Twine& key,
|
||||
std::function<std::shared_ptr<nt::Value>()> getter,
|
||||
std::function<void(std::shared_ptr<nt::Value>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a string property (SmallString form).
|
||||
*
|
||||
* @param key property name
|
||||
* @param getter getter function (returns current value)
|
||||
* @param setter setter function (sets new value)
|
||||
*/
|
||||
virtual void AddSmallStringProperty(
|
||||
const llvm::Twine& key,
|
||||
std::function<llvm::StringRef(llvm::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(llvm::StringRef)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a boolean array property (SmallVector form).
|
||||
*
|
||||
* @param key property name
|
||||
* @param getter getter function (returns current value)
|
||||
* @param setter setter function (sets new value)
|
||||
*/
|
||||
virtual void AddSmallBooleanArrayProperty(
|
||||
const llvm::Twine& key,
|
||||
std::function<llvm::ArrayRef<int>(llvm::SmallVectorImpl<int>& buf)>
|
||||
getter,
|
||||
std::function<void(llvm::ArrayRef<int>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a double array property (SmallVector form).
|
||||
*
|
||||
* @param key property name
|
||||
* @param getter getter function (returns current value)
|
||||
* @param setter setter function (sets new value)
|
||||
*/
|
||||
virtual void AddSmallDoubleArrayProperty(
|
||||
const llvm::Twine& key,
|
||||
std::function<llvm::ArrayRef<double>(llvm::SmallVectorImpl<double>& buf)>
|
||||
getter,
|
||||
std::function<void(llvm::ArrayRef<double>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a string array property (SmallVector form).
|
||||
*
|
||||
* @param key property name
|
||||
* @param getter getter function (returns current value)
|
||||
* @param setter setter function (sets new value)
|
||||
*/
|
||||
virtual void AddSmallStringArrayProperty(
|
||||
const llvm::Twine& key,
|
||||
std::function<
|
||||
llvm::ArrayRef<std::string>(llvm::SmallVectorImpl<std::string>& buf)>
|
||||
getter,
|
||||
std::function<void(llvm::ArrayRef<std::string>)> setter) = 0;
|
||||
|
||||
/**
|
||||
* Add a raw property (SmallVector form).
|
||||
*
|
||||
* @param key property name
|
||||
* @param getter getter function (returns current value)
|
||||
* @param setter setter function (sets new value)
|
||||
*/
|
||||
virtual void AddSmallRawProperty(
|
||||
const llvm::Twine& key,
|
||||
std::function<llvm::StringRef(llvm::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(llvm::StringRef)> setter) = 0;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,182 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <llvm/ArrayRef.h>
|
||||
#include <llvm/SmallVector.h>
|
||||
#include <llvm/Twine.h>
|
||||
|
||||
#include "SendableBuilder.h"
|
||||
#include "networktables/NetworkTable.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
#include "networktables/NetworkTableValue.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class SendableBuilderImpl : public SendableBuilder {
|
||||
public:
|
||||
SendableBuilderImpl() = default;
|
||||
SendableBuilderImpl(const SendableBuilderImpl&) = delete;
|
||||
SendableBuilderImpl(SendableBuilderImpl&& other) = default;
|
||||
SendableBuilderImpl& operator=(const SendableBuilderImpl&) = delete;
|
||||
SendableBuilderImpl& operator=(SendableBuilderImpl&& other) = default;
|
||||
~SendableBuilderImpl() override = default;
|
||||
|
||||
/**
|
||||
* Set the network table. Must be called prior to any Add* functions being
|
||||
* called.
|
||||
* @param table Network table
|
||||
*/
|
||||
void SetTable(std::shared_ptr<nt::NetworkTable> table);
|
||||
|
||||
/**
|
||||
* Get the network table.
|
||||
* @return The network table
|
||||
*/
|
||||
std::shared_ptr<nt::NetworkTable> GetTable();
|
||||
|
||||
/**
|
||||
* Update the network table values by calling the getters for all properties.
|
||||
*/
|
||||
void UpdateTable();
|
||||
|
||||
/**
|
||||
* Start LiveWindow mode by hooking the setters for all properties.
|
||||
*/
|
||||
void StartLiveWindowMode();
|
||||
|
||||
/**
|
||||
* Stop LiveWindow mode by unhooking the setters for all properties.
|
||||
*/
|
||||
void StopLiveWindowMode();
|
||||
|
||||
void SetSmartDashboardType(const llvm::Twine& type) override;
|
||||
void SetSafeState(std::function<void()> func) override;
|
||||
void SetUpdateTable(std::function<void()> func) override;
|
||||
nt::NetworkTableEntry GetEntry(const llvm::Twine& key) override;
|
||||
|
||||
void AddBooleanProperty(const llvm::Twine& key, std::function<bool()> getter,
|
||||
std::function<void(bool)> setter) override;
|
||||
|
||||
void AddDoubleProperty(const llvm::Twine& key, std::function<double()> getter,
|
||||
std::function<void(double)> setter) override;
|
||||
|
||||
void AddStringProperty(const llvm::Twine& key,
|
||||
std::function<std::string()> getter,
|
||||
std::function<void(llvm::StringRef)> setter) override;
|
||||
|
||||
void AddBooleanArrayProperty(
|
||||
const llvm::Twine& key, std::function<std::vector<int>()> getter,
|
||||
std::function<void(llvm::ArrayRef<int>)> setter) override;
|
||||
|
||||
void AddDoubleArrayProperty(
|
||||
const llvm::Twine& key, std::function<std::vector<double>()> getter,
|
||||
std::function<void(llvm::ArrayRef<double>)> setter) override;
|
||||
|
||||
void AddStringArrayProperty(
|
||||
const llvm::Twine& key, std::function<std::vector<std::string>()> getter,
|
||||
std::function<void(llvm::ArrayRef<std::string>)> setter) override;
|
||||
|
||||
void AddRawProperty(const llvm::Twine& key,
|
||||
std::function<std::string()> getter,
|
||||
std::function<void(llvm::StringRef)> setter) override;
|
||||
|
||||
void AddValueProperty(
|
||||
const llvm::Twine& key,
|
||||
std::function<std::shared_ptr<nt::Value>()> getter,
|
||||
std::function<void(std::shared_ptr<nt::Value>)> setter) override;
|
||||
|
||||
void AddSmallStringProperty(
|
||||
const llvm::Twine& key,
|
||||
std::function<llvm::StringRef(llvm::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(llvm::StringRef)> setter) override;
|
||||
|
||||
void AddSmallBooleanArrayProperty(
|
||||
const llvm::Twine& key,
|
||||
std::function<llvm::ArrayRef<int>(llvm::SmallVectorImpl<int>& buf)>
|
||||
getter,
|
||||
std::function<void(llvm::ArrayRef<int>)> setter) override;
|
||||
|
||||
void AddSmallDoubleArrayProperty(
|
||||
const llvm::Twine& key,
|
||||
std::function<llvm::ArrayRef<double>(llvm::SmallVectorImpl<double>& buf)>
|
||||
getter,
|
||||
std::function<void(llvm::ArrayRef<double>)> setter) override;
|
||||
|
||||
void AddSmallStringArrayProperty(
|
||||
const llvm::Twine& key,
|
||||
std::function<
|
||||
llvm::ArrayRef<std::string>(llvm::SmallVectorImpl<std::string>& buf)>
|
||||
getter,
|
||||
std::function<void(llvm::ArrayRef<std::string>)> setter) override;
|
||||
|
||||
void AddSmallRawProperty(
|
||||
const llvm::Twine& key,
|
||||
std::function<llvm::StringRef(llvm::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(llvm::StringRef)> setter) override;
|
||||
|
||||
private:
|
||||
struct Property {
|
||||
Property(nt::NetworkTable& table, const llvm::Twine& key)
|
||||
: entry(table.GetEntry(key)) {}
|
||||
|
||||
Property(const Property&) = delete;
|
||||
Property& operator=(const Property&) = delete;
|
||||
|
||||
Property(Property&& other) noexcept
|
||||
: entry(other.entry),
|
||||
listener(other.listener),
|
||||
update(std::move(other.update)),
|
||||
createListener(std::move(other.createListener)) {
|
||||
other.entry = nt::NetworkTableEntry();
|
||||
other.listener = 0;
|
||||
}
|
||||
|
||||
Property& operator=(Property&& other) noexcept {
|
||||
entry = other.entry;
|
||||
listener = other.listener;
|
||||
other.entry = nt::NetworkTableEntry();
|
||||
other.listener = 0;
|
||||
update = std::move(other.update);
|
||||
createListener = std::move(other.createListener);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~Property() { StopListener(); }
|
||||
|
||||
void StartListener() {
|
||||
if (entry && listener == 0 && createListener)
|
||||
listener = createListener(entry);
|
||||
}
|
||||
|
||||
void StopListener() {
|
||||
if (entry && listener != 0) {
|
||||
entry.RemoveListener(listener);
|
||||
listener = 0;
|
||||
}
|
||||
}
|
||||
|
||||
nt::NetworkTableEntry entry;
|
||||
NT_EntryListener listener = 0;
|
||||
std::function<void(nt::NetworkTableEntry entry, uint64_t time)> update;
|
||||
std::function<NT_EntryListener(nt::NetworkTableEntry entry)> createListener;
|
||||
};
|
||||
|
||||
std::vector<Property> m_properties;
|
||||
std::function<void()> m_safeState;
|
||||
std::function<void()> m_updateTable;
|
||||
std::shared_ptr<nt::NetworkTable> m_table;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
@@ -8,14 +8,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <llvm/StringMap.h>
|
||||
#include <llvm/StringRef.h>
|
||||
|
||||
#include "SmartDashboard/SendableChooserBase.h"
|
||||
#include "networktables/NetworkTable.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -35,7 +32,6 @@ namespace frc {
|
||||
template <class T>
|
||||
class SendableChooser : public SendableChooserBase {
|
||||
llvm::StringMap<T> m_choices;
|
||||
nt::NetworkTableEntry m_selectedEntry;
|
||||
|
||||
template <class U>
|
||||
static U _unwrap_smart_ptr(const U& value);
|
||||
@@ -47,14 +43,14 @@ class SendableChooser : public SendableChooserBase {
|
||||
static std::weak_ptr<U> _unwrap_smart_ptr(const std::shared_ptr<U>& value);
|
||||
|
||||
public:
|
||||
virtual ~SendableChooser() = default;
|
||||
~SendableChooser() override = default;
|
||||
|
||||
void AddObject(llvm::StringRef name, T object);
|
||||
void AddDefault(llvm::StringRef name, T object);
|
||||
|
||||
auto GetSelected() -> decltype(_unwrap_smart_ptr(m_choices[""]));
|
||||
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <llvm/StringRef.h>
|
||||
|
||||
#include "SendableBuilder.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
@@ -58,8 +62,11 @@ void SendableChooser<T>::AddDefault(llvm::StringRef name, T object) {
|
||||
template <class T>
|
||||
auto SendableChooser<T>::GetSelected()
|
||||
-> decltype(_unwrap_smart_ptr(m_choices[""])) {
|
||||
std::string selected = m_selectedEntry.GetString(m_defaultChoice);
|
||||
if (selected == "") {
|
||||
llvm::StringRef selected = m_defaultChoice;
|
||||
if (m_selectedEntry) {
|
||||
selected = m_selectedEntry.GetString(m_defaultChoice);
|
||||
}
|
||||
if (selected.empty()) {
|
||||
return decltype(_unwrap_smart_ptr(m_choices[""])){};
|
||||
} else {
|
||||
return _unwrap_smart_ptr(m_choices[selected]);
|
||||
@@ -67,21 +74,29 @@ auto SendableChooser<T>::GetSelected()
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void SendableChooser<T>::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
|
||||
std::vector<std::string> keys;
|
||||
if (subtable) {
|
||||
m_selectedEntry = subtable->GetEntry(kSelected);
|
||||
for (const auto& choice : m_choices) {
|
||||
keys.push_back(choice.first());
|
||||
}
|
||||
void SendableChooser<T>::InitSendable(SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("String Chooser");
|
||||
builder.AddStringArrayProperty(kOptions,
|
||||
[=]() {
|
||||
std::vector<std::string> keys;
|
||||
for (const auto& choice : m_choices) {
|
||||
keys.push_back(choice.first());
|
||||
}
|
||||
|
||||
// Unlike std::map, llvm::StringMap elements are not sorted
|
||||
std::sort(keys.begin(), keys.end());
|
||||
// Unlike std::map, llvm::StringMap elements
|
||||
// are not sorted
|
||||
std::sort(keys.begin(), keys.end());
|
||||
|
||||
subtable->GetEntry(kOptions).SetValue(
|
||||
nt::Value::MakeStringArray(std::move(keys)));
|
||||
subtable->GetEntry(kDefault).SetString(m_defaultChoice);
|
||||
}
|
||||
return keys;
|
||||
},
|
||||
nullptr);
|
||||
builder.AddSmallStringProperty(
|
||||
kDefault,
|
||||
[=](const llvm::SmallVectorImpl<char>&) -> llvm::StringRef {
|
||||
return m_defaultChoice;
|
||||
},
|
||||
nullptr);
|
||||
m_selectedEntry = builder.GetEntry(kSelected);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
||||
@@ -7,11 +7,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "SmartDashboard/Sendable.h"
|
||||
#include "networktables/NetworkTable.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -21,11 +20,9 @@ namespace frc {
|
||||
* It contains static, non-templated variables to avoid their duplication in the
|
||||
* template class.
|
||||
*/
|
||||
class SendableChooserBase : public Sendable {
|
||||
class SendableChooserBase : public SendableBase {
|
||||
public:
|
||||
virtual ~SendableChooserBase() = default;
|
||||
|
||||
std::string GetSmartDashboardType() const override;
|
||||
~SendableChooserBase() override = default;
|
||||
|
||||
protected:
|
||||
static const char* kDefault;
|
||||
@@ -33,6 +30,7 @@ class SendableChooserBase : public Sendable {
|
||||
static const char* kSelected;
|
||||
|
||||
std::string m_defaultChoice;
|
||||
nt::NetworkTableEntry m_selectedEntry;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
namespace frc {
|
||||
|
||||
class NamedSendable;
|
||||
class Sendable;
|
||||
|
||||
class SmartDashboard : public SensorBase {
|
||||
@@ -38,7 +37,7 @@ class SmartDashboard : public SensorBase {
|
||||
static void Delete(llvm::StringRef key);
|
||||
|
||||
static void PutData(llvm::StringRef key, Sendable* data);
|
||||
static void PutData(NamedSendable* value);
|
||||
static void PutData(Sendable* value);
|
||||
static Sendable* GetData(llvm::StringRef keyName);
|
||||
|
||||
static bool PutBoolean(llvm::StringRef keyName, bool value);
|
||||
|
||||
@@ -7,14 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <HAL/Types.h>
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SolenoidBase.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -24,28 +19,22 @@ namespace frc {
|
||||
* The Solenoid class is typically used for pneumatics solenoids, but could be
|
||||
* used for any device within the current spec of the PCM.
|
||||
*/
|
||||
class Solenoid : public SolenoidBase, public LiveWindowSendable {
|
||||
class Solenoid : public SolenoidBase {
|
||||
public:
|
||||
explicit Solenoid(int channel);
|
||||
Solenoid(int moduleNumber, int channel);
|
||||
virtual ~Solenoid();
|
||||
~Solenoid() override;
|
||||
virtual void Set(bool on);
|
||||
virtual bool Get() const;
|
||||
bool IsBlackListed() const;
|
||||
void SetPulseDuration(double durationSeconds);
|
||||
void StartPulse();
|
||||
|
||||
void UpdateTable();
|
||||
void StartLiveWindowMode();
|
||||
void StopLiveWindowMode();
|
||||
std::string GetSmartDashboardType() const;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable);
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
HAL_SolenoidHandle m_solenoidHandle = HAL_kInvalidHandle;
|
||||
int m_channel; // The channel on the module to control
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
NT_EntryListener m_valueListener = 0;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SensorBase.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -15,9 +16,8 @@ namespace frc {
|
||||
* SolenoidBase class is the common base class for the Solenoid and
|
||||
* DoubleSolenoid classes.
|
||||
*/
|
||||
class SolenoidBase : public SensorBase {
|
||||
class SolenoidBase : public ErrorBase, public SendableBase {
|
||||
public:
|
||||
virtual ~SolenoidBase() = default;
|
||||
static int GetAll(int module);
|
||||
int GetAll() const;
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace frc {
|
||||
class Spark : public PWMSpeedController {
|
||||
public:
|
||||
explicit Spark(int channel);
|
||||
virtual ~Spark() = default;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -10,15 +10,17 @@
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
#include "SpeedController.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class SpeedControllerGroup : public SpeedController {
|
||||
class SpeedControllerGroup : public SendableBase, public SpeedController {
|
||||
public:
|
||||
template <class... SpeedControllers>
|
||||
explicit SpeedControllerGroup(SpeedController& speedController,
|
||||
SpeedControllers&... speedControllers);
|
||||
~SpeedControllerGroup() override = default;
|
||||
|
||||
void Set(double speed) override;
|
||||
double Get() const override;
|
||||
@@ -28,6 +30,8 @@ class SpeedControllerGroup : public SpeedController {
|
||||
void StopMotor() override;
|
||||
void PIDWrite(double output) override;
|
||||
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
bool m_isInverted = false;
|
||||
std::vector<std::reference_wrapper<SpeedController>> m_speedControllers;
|
||||
|
||||
@@ -12,6 +12,12 @@ namespace frc {
|
||||
template <class... SpeedControllers>
|
||||
SpeedControllerGroup::SpeedControllerGroup(
|
||||
SpeedController& speedController, SpeedControllers&... speedControllers)
|
||||
: m_speedControllers{speedController, speedControllers...} {}
|
||||
: m_speedControllers{speedController, speedControllers...} {
|
||||
for (auto& speedController : m_speedControllers)
|
||||
AddChild(&speedController.get());
|
||||
static int instances = 0;
|
||||
++instances;
|
||||
SetName("SpeedControllerGroup", instances);
|
||||
}
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace frc {
|
||||
class Talon : public PWMSpeedController {
|
||||
public:
|
||||
explicit Talon(int channel);
|
||||
virtual ~Talon() = default;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -9,15 +9,12 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "Counter.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "PIDSource.h"
|
||||
#include "SensorBase.h"
|
||||
#include "networktables/NetworkTableEntry.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -36,9 +33,7 @@ class DigitalOutput;
|
||||
* received. The time that the line is high determines the round trip distance
|
||||
* (time of flight).
|
||||
*/
|
||||
class Ultrasonic : public SensorBase,
|
||||
public PIDSource,
|
||||
public LiveWindowSendable {
|
||||
class Ultrasonic : public SensorBase, public PIDSource {
|
||||
public:
|
||||
enum DistanceUnit { kInches = 0, kMilliMeters = 1 };
|
||||
|
||||
@@ -50,7 +45,7 @@ class Ultrasonic : public SensorBase,
|
||||
std::shared_ptr<DigitalInput> echoChannel,
|
||||
DistanceUnit units = kInches);
|
||||
Ultrasonic(int pingChannel, int echoChannel, DistanceUnit units = kInches);
|
||||
virtual ~Ultrasonic();
|
||||
~Ultrasonic() override;
|
||||
|
||||
void Ping();
|
||||
bool IsRangeValid() const;
|
||||
@@ -65,11 +60,7 @@ class Ultrasonic : public SensorBase,
|
||||
void SetDistanceUnits(DistanceUnit units);
|
||||
DistanceUnit GetDistanceUnits() const;
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
void Initialize();
|
||||
@@ -100,8 +91,6 @@ class Ultrasonic : public SensorBase,
|
||||
bool m_enabled = false;
|
||||
Counter m_counter;
|
||||
DistanceUnit m_units;
|
||||
|
||||
nt::NetworkTableEntry m_valueEntry;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace frc {
|
||||
class Victor : public PWMSpeedController {
|
||||
public:
|
||||
explicit Victor(int channel);
|
||||
virtual ~Victor() = default;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace frc {
|
||||
class VictorSP : public PWMSpeedController {
|
||||
public:
|
||||
explicit VictorSP(int channel);
|
||||
virtual ~VictorSP() = default;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
Reference in New Issue
Block a user