Simplify Sendable interface (#1864)

This removes the name and subsystem from individual objects, and instead
puts this data into a new singleton class, SendableRegistry.  Much of
LiveWindow has been refactored into SendableRegistry.

In C++, a new CRTP helper class, SendableHelper, has been added to provide
move and destruction functionality.

Shims for GetName, SetName, GetSubsystem, and SetSubsystem have been added
to Command and Subsystem (both old and new), and also to SendableHelper to
prevent code breakage.

This deprecates SendableBase in preparation for future removal.
This commit is contained in:
Peter Johnson
2019-09-14 15:22:54 -05:00
committed by GitHub
parent 1d8c4d016f
commit 471f375a38
216 changed files with 2448 additions and 1433 deletions

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2008-2019 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. */
@@ -10,10 +10,13 @@
#include "frc/ErrorBase.h"
#include "frc/I2C.h"
#include "frc/interfaces/Accelerometer.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* ADXL345 Accelerometer on I2C.
*
@@ -22,8 +25,9 @@ namespace frc {
* 0x1D (7-bit address).
*/
class ADXL345_I2C : public ErrorBase,
public SendableBase,
public Accelerometer {
public Accelerometer,
public Sendable,
public SendableHelper<ADXL345_I2C> {
public:
enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2008-2019 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. */
@@ -10,7 +10,8 @@
#include "frc/ErrorBase.h"
#include "frc/SPI.h"
#include "frc/interfaces/Accelerometer.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -21,8 +22,9 @@ namespace frc {
* via SPI. This class assumes the sensor is wired in 4-wire SPI mode.
*/
class ADXL345_SPI : public ErrorBase,
public SendableBase,
public Accelerometer {
public Accelerometer,
public Sendable,
public SendableHelper<ADXL345_SPI> {
public:
enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2008-2019 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. */
@@ -10,16 +10,22 @@
#include "frc/ErrorBase.h"
#include "frc/SPI.h"
#include "frc/interfaces/Accelerometer.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* ADXL362 SPI Accelerometer.
*
* This class allows access to an Analog Devices ADXL362 3-axis accelerometer.
*/
class ADXL362 : public ErrorBase, public SendableBase, public Accelerometer {
class ADXL362 : public ErrorBase,
public Accelerometer,
public Sendable,
public SendableHelper<ADXL362> {
public:
enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
struct AllAxes {
@@ -44,7 +50,7 @@ class ADXL362 : public ErrorBase, public SendableBase, public Accelerometer {
*/
explicit ADXL362(SPI::Port port, Range range = kRange_2G);
virtual ~ADXL362() = default;
~ADXL362() override = default;
ADXL362(ADXL362&&) = default;
ADXL362& operator=(ADXL362&&) = default;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2015-2019 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. */
@@ -40,7 +40,7 @@ class ADXRS450_Gyro : public GyroBase {
*/
explicit ADXRS450_Gyro(SPI::Port port);
virtual ~ADXRS450_Gyro() = default;
~ADXRS450_Gyro() override = default;
ADXRS450_Gyro(ADXRS450_Gyro&&) = default;
ADXRS450_Gyro& operator=(ADXRS450_Gyro&&) = default;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2008-2019 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. */
@@ -12,10 +12,13 @@
#include "frc/AnalogInput.h"
#include "frc/ErrorBase.h"
#include "frc/PIDSource.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* Handle operation of an analog accelerometer.
*
@@ -24,8 +27,9 @@ namespace frc {
* calibrated by finding the center value over a period of time.
*/
class AnalogAccelerometer : public ErrorBase,
public SendableBase,
public PIDSource {
public PIDSource,
public Sendable,
public SendableHelper<AnalogAccelerometer> {
public:
/**
* Create a new instance of an accelerometer.

View File

@@ -12,6 +12,8 @@
#include <hal/Types.h>
#include "frc/GyroBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -100,7 +102,7 @@ class AnalogGyro : public GyroBase {
*/
AnalogGyro(std::shared_ptr<AnalogInput> channel, int center, double offset);
virtual ~AnalogGyro();
~AnalogGyro() override;
AnalogGyro(AnalogGyro&& rhs);
AnalogGyro& operator=(AnalogGyro&& rhs);

View File

@@ -13,10 +13,13 @@
#include "frc/ErrorBase.h"
#include "frc/PIDSource.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* Analog input class.
*
@@ -29,7 +32,10 @@ namespace frc {
* are divided by the number of samples to retain the resolution, but get more
* stable values.
*/
class AnalogInput : public ErrorBase, public SendableBase, public PIDSource {
class AnalogInput : public ErrorBase,
public PIDSource,
public Sendable,
public SendableHelper<AnalogInput> {
friend class AnalogTrigger;
friend class AnalogGyro;

View File

@@ -10,14 +10,19 @@
#include <hal/Types.h>
#include "frc/ErrorBase.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* MXP analog output class.
*/
class AnalogOutput : public ErrorBase, public SendableBase {
class AnalogOutput : public ErrorBase,
public Sendable,
public SendableHelper<AnalogOutput> {
public:
/**
* Construct an analog output on the given channel.

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-2019 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. */
@@ -12,10 +12,13 @@
#include "frc/AnalogInput.h"
#include "frc/ErrorBase.h"
#include "frc/interfaces/Potentiometer.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* Class for reading analog potentiometers. Analog potentiometers read in an
* analog voltage that corresponds to a position. The position is in whichever
@@ -23,8 +26,9 @@ namespace frc {
* constructor.
*/
class AnalogPotentiometer : public ErrorBase,
public SendableBase,
public Potentiometer {
public Potentiometer,
public Sendable,
public SendableHelper<AnalogPotentiometer> {
public:
/**
* Construct an Analog Potentiometer object from a channel number.

View File

@@ -13,13 +13,17 @@
#include "frc/AnalogTriggerOutput.h"
#include "frc/ErrorBase.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class AnalogInput;
class SendableBuilder;
class AnalogTrigger : public ErrorBase, public SendableBase {
class AnalogTrigger : public ErrorBase,
public Sendable,
public SendableHelper<AnalogTrigger> {
friend class AnalogTriggerOutput;
public:

View File

@@ -8,6 +8,8 @@
#pragma once
#include "frc/DigitalSource.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -44,7 +46,9 @@ class AnalogTrigger;
* rollover transition is not sharp / clean enough. Using the averaging engine
* may help with this, but rotational speeds of the sensor will then be limited.
*/
class AnalogTriggerOutput : public DigitalSource {
class AnalogTriggerOutput : public DigitalSource,
public Sendable,
public SendableHelper<AnalogTriggerOutput> {
friend class AnalogTrigger;
public:

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2014-2019 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. */
@@ -9,18 +9,22 @@
#include "frc/ErrorBase.h"
#include "frc/interfaces/Accelerometer.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* Built-in accelerometer.
*
* This class allows access to the roboRIO's internal accelerometer.
*/
class BuiltInAccelerometer : public ErrorBase,
public SendableBase,
public Accelerometer {
public Accelerometer,
public Sendable,
public SendableHelper<BuiltInAccelerometer> {
public:
/**
* Constructor.

View File

@@ -11,10 +11,13 @@
#include "frc/ErrorBase.h"
#include "frc/SensorUtil.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* Class for operating a compressor connected to a %PCM (Pneumatic Control
* Module).
@@ -30,7 +33,9 @@ namespace frc {
* loop control. You can only turn off closed loop control, thereby stopping
* the compressor from operating.
*/
class Compressor : public ErrorBase, public SendableBase {
class Compressor : public ErrorBase,
public Sendable,
public SendableHelper<Compressor> {
public:
/**
* Constructor. The default PCM ID is 0.

View File

@@ -14,11 +14,13 @@
#include "frc/AnalogTrigger.h"
#include "frc/CounterBase.h"
#include "frc/ErrorBase.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class DigitalGlitchFilter;
class SendableBuilder;
/**
* Class for counting the number of ticks on a digital input channel.
@@ -30,7 +32,10 @@ class DigitalGlitchFilter;
* All counters will immediately start counting - Reset() them if you need them
* to be zeroed before use.
*/
class Counter : public ErrorBase, public SendableBase, public CounterBase {
class Counter : public ErrorBase,
public CounterBase,
public Sendable,
public SendableHelper<Counter> {
public:
enum Mode {
kTwoPulse = 0,

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2015-2019 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. */
@@ -15,7 +15,8 @@
#include "frc/DigitalSource.h"
#include "frc/ErrorBase.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -29,7 +30,9 @@ class Counter;
* filter. The filter lets the user configure the time that an input must remain
* high or low before it is classified as high or low.
*/
class DigitalGlitchFilter : public ErrorBase, public SendableBase {
class DigitalGlitchFilter : public ErrorBase,
public Sendable,
public SendableHelper<DigitalGlitchFilter> {
public:
DigitalGlitchFilter();
~DigitalGlitchFilter() override;

View File

@@ -8,10 +8,13 @@
#pragma once
#include "frc/DigitalSource.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class DigitalGlitchFilter;
class SendableBuilder;
/**
* Class to read a digital input.
@@ -22,7 +25,9 @@ class DigitalGlitchFilter;
* as required. This class is only for devices like switches etc. that aren't
* implemented anywhere else.
*/
class DigitalInput : public DigitalSource {
class DigitalInput : public DigitalSource,
public Sendable,
public SendableHelper<DigitalInput> {
public:
/**
* Create an instance of a Digital Input class.

View File

@@ -10,10 +10,13 @@
#include <hal/Types.h>
#include "frc/ErrorBase.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* Class to write to digital outputs.
*
@@ -21,7 +24,9 @@ namespace frc {
* elsewhere will allocate channels automatically so for those devices it
* shouldn't be done here.
*/
class DigitalOutput : public ErrorBase, public SendableBase {
class DigitalOutput : public ErrorBase,
public Sendable,
public SendableHelper<DigitalOutput> {
public:
/**
* Create an instance of a digital output.

View File

@@ -10,9 +10,13 @@
#include <hal/Types.h>
#include "frc/SolenoidBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* DoubleSolenoid class for running 2 channels of high voltage Digital Output
* (PCM).
@@ -20,7 +24,9 @@ namespace frc {
* The DoubleSolenoid class is typically used for pneumatics solenoids that
* have two positions controlled by two separate channels.
*/
class DoubleSolenoid : public SolenoidBase {
class DoubleSolenoid : public SolenoidBase,
public Sendable,
public SendableHelper<DoubleSolenoid> {
public:
enum Value { kOff, kForward, kReverse };

View File

@@ -15,12 +15,14 @@
#include "frc/CounterBase.h"
#include "frc/ErrorBase.h"
#include "frc/PIDSource.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class DigitalSource;
class DigitalGlitchFilter;
class SendableBuilder;
/**
* Class to read quad encoders.
@@ -38,9 +40,10 @@ class DigitalGlitchFilter;
* to be zeroed before use.
*/
class Encoder : public ErrorBase,
public SendableBase,
public CounterBase,
public PIDSource {
public PIDSource,
public Sendable,
public SendableHelper<Encoder> {
public:
enum IndexingType {
kResetWhileHigh,

View File

@@ -79,6 +79,8 @@ class ErrorBase {
ErrorBase();
virtual ~ErrorBase() = default;
ErrorBase(const ErrorBase&) = default;
ErrorBase& operator=(const ErrorBase&) = default;
ErrorBase(ErrorBase&&) = default;
ErrorBase& operator=(ErrorBase&&) = default;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2008-2019 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. */
@@ -10,7 +10,8 @@
#include "frc/ErrorBase.h"
#include "frc/PIDSource.h"
#include "frc/interfaces/Gyro.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -20,8 +21,9 @@ namespace frc {
*/
class GyroBase : public Gyro,
public ErrorBase,
public SendableBase,
public PIDSource {
public PIDSource,
public Sendable,
public SendableHelper<GyroBase> {
public:
GyroBase() = default;
GyroBase(GyroBase&&) = default;

View File

@@ -14,11 +14,10 @@
#include "frc/AnalogTriggerType.h"
#include "frc/ErrorBase.h"
#include "frc/smartdashboard/SendableBase.h"
namespace frc {
class InterruptableSensorBase : public ErrorBase, public SendableBase {
class InterruptableSensorBase : public ErrorBase {
public:
enum WaitResult {
kTimeout = 0x0,

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2017-2019 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. */
@@ -14,16 +14,20 @@
#include "frc/MotorSafety.h"
#include "frc/PWM.h"
#include "frc/SpeedController.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* Nidec Brushless Motor.
*/
class NidecBrushless : public SendableBase,
public SpeedController,
public MotorSafety {
class NidecBrushless : public SpeedController,
public MotorSafety,
public Sendable,
public SendableHelper<NidecBrushless> {
public:
/**
* Constructor.

View File

@@ -19,10 +19,13 @@
#include "frc/PIDOutput.h"
#include "frc/PIDSource.h"
#include "frc/Timer.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* Class implements a PID Control Loop.
*
@@ -33,7 +36,10 @@ namespace frc {
* in the integral and derivative calculations. Therefore, the sample rate
* affects the controller's behavior for a given set of PID constants.
*/
class PIDBase : public SendableBase, public PIDInterface, public PIDOutput {
class PIDBase : public PIDInterface,
public PIDOutput,
public Sendable,
public SendableHelper<PIDBase> {
public:
/**
* Allocate a PID object with the given constants for P, I, D.
@@ -58,7 +64,7 @@ class PIDBase : public SendableBase, public PIDInterface, public PIDOutput {
PIDBase(double p, double i, double d, double f, PIDSource& source,
PIDOutput& output);
~PIDBase() override = default;
virtual ~PIDBase() = default;
PIDBase(PIDBase&&) = default;
PIDBase& operator=(PIDBase&&) = default;

View File

@@ -13,10 +13,13 @@
#include <wpi/raw_ostream.h>
#include "frc/MotorSafety.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* Class implements the PWM generation in the FPGA.
*
@@ -34,7 +37,7 @@ namespace frc {
* - 1 = minimum pulse width (currently .5ms)
* - 0 = disabled (i.e. PWM output is held low)
*/
class PWM : public MotorSafety, public SendableBase {
class PWM : public MotorSafety, public Sendable, public SendableHelper<PWM> {
public:
/**
* Represents the amount to multiply the minimum servo-pulse pwm period by.

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2008-2019 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. */

View File

@@ -10,15 +10,20 @@
#include <hal/Types.h>
#include "frc/ErrorBase.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* Class for getting voltage, current, temperature, power and energy from the
* CAN PDP.
*/
class PowerDistributionPanel : public ErrorBase, public SendableBase {
class PowerDistributionPanel : public ErrorBase,
public Sendable,
public SendableHelper<PowerDistributionPanel> {
public:
PowerDistributionPanel();
explicit PowerDistributionPanel(int module);

View File

@@ -14,10 +14,13 @@
#include "frc/ErrorBase.h"
#include "frc/MotorSafety.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* Class for Spike style relay outputs.
*
@@ -30,7 +33,9 @@ namespace frc {
* independently for something that does not care about voltage polarity (like
* a solenoid).
*/
class Relay : public MotorSafety, public SendableBase {
class Relay : public MotorSafety,
public Sendable,
public SendableHelper<Relay> {
public:
enum Value { kOff, kOn, kForward, kReverse };
enum Direction { kBothDirections, kForwardOnly, kReverseOnly };

View File

@@ -10,16 +10,22 @@
#include <hal/Types.h>
#include "frc/SolenoidBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBuilder;
/**
* Solenoid class for running high voltage Digital Output (PCM).
*
* 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 {
class Solenoid : public SolenoidBase,
public Sendable,
public SendableHelper<Solenoid> {
public:
/**
* Constructor using the default PCM ID (0).

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2008-2019 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. */
@@ -8,7 +8,6 @@
#pragma once
#include "frc/ErrorBase.h"
#include "frc/smartdashboard/SendableBase.h"
namespace frc {
@@ -16,7 +15,7 @@ namespace frc {
* SolenoidBase class is the common base class for the Solenoid and
* DoubleSolenoid classes.
*/
class SolenoidBase : public ErrorBase, public SendableBase {
class SolenoidBase : public ErrorBase {
public:
/**
* Read all 8 solenoids as a single byte

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-2019 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. */
@@ -11,11 +11,14 @@
#include <vector>
#include "frc/SpeedController.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SpeedControllerGroup : public SendableBase, public SpeedController {
class SpeedControllerGroup : public Sendable,
public SpeedController,
public SendableHelper<SpeedControllerGroup> {
public:
template <class... SpeedControllers>
explicit SpeedControllerGroup(SpeedController& speedController,

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-2019 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. */
@@ -7,6 +7,8 @@
#pragma once
#include "frc/smartdashboard/SendableRegistry.h"
namespace frc {
template <class... SpeedControllers>
@@ -14,10 +16,10 @@ SpeedControllerGroup::SpeedControllerGroup(
SpeedController& speedController, SpeedControllers&... speedControllers)
: m_speedControllers{speedController, speedControllers...} {
for (auto& speedController : m_speedControllers)
AddChild(&speedController.get());
SendableRegistry::GetInstance().AddChild(this, &speedController.get());
static int instances = 0;
++instances;
SetName("SpeedControllerGroup", instances);
SendableRegistry::GetInstance().Add(this, "SpeedControllerGroup", instances);
}
} // namespace frc

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2008-2019 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. */
@@ -15,7 +15,8 @@
#include "frc/Counter.h"
#include "frc/ErrorBase.h"
#include "frc/PIDSource.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -34,7 +35,10 @@ class DigitalOutput;
* received. The time that the line is high determines the round trip distance
* (time of flight).
*/
class Ultrasonic : public ErrorBase, public SendableBase, public PIDSource {
class Ultrasonic : public ErrorBase,
public Sendable,
public PIDSource,
public SendableHelper<Ultrasonic> {
public:
enum DistanceUnit { kInches = 0, kMilliMeters = 1 };

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2011-2019 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. */
@@ -9,7 +9,8 @@
#include <atomic>
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -28,7 +29,7 @@ class Command;
* only have to write the {@link Trigger#Get()} method to get the full
* functionality of the Trigger class.
*/
class Trigger : public SendableBase {
class Trigger : public Sendable, public SendableHelper<Trigger> {
public:
Trigger() = default;
~Trigger() override = default;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2011-2019 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. */
@@ -15,7 +15,8 @@
#include "frc/ErrorBase.h"
#include "frc/commands/Subsystem.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -45,7 +46,9 @@ class CommandGroup;
* @see CommandGroup
* @see Subsystem
*/
class Command : public ErrorBase, public SendableBase {
class Command : public ErrorBase,
public Sendable,
public SendableHelper<Command> {
friend class CommandGroup;
friend class Scheduler;
@@ -385,6 +388,34 @@ class Command : public ErrorBase, public SendableBase {
friend class ConditionalCommand;
/**
* Gets the name of this Command.
*
* @return Name
*/
std::string GetName() const;
/**
* Sets the name of this Command.
*
* @param name name
*/
void SetName(const wpi::Twine& name);
/**
* Gets the subsystem name of this Command.
*
* @return Subsystem name
*/
std::string GetSubsystem() const;
/**
* Sets the subsystem name of this Command.
*
* @param subsystem subsystem name
*/
void SetSubsystem(const wpi::Twine& subsystem);
private:
/**
* Prevents further changes from being made.

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2011-2019 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. */
@@ -10,7 +10,8 @@
#include <memory>
#include "frc/ErrorBase.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -18,7 +19,9 @@ class ButtonScheduler;
class Command;
class Subsystem;
class Scheduler : public ErrorBase, public SendableBase {
class Scheduler : public ErrorBase,
public Sendable,
public SendableHelper<Scheduler> {
public:
/**
* Returns the Scheduler, creating it if one does not exist.

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2011-2019 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. */
@@ -8,19 +8,22 @@
#pragma once
#include <memory>
#include <string>
#include <wpi/StringRef.h>
#include <wpi/Twine.h>
#include "frc/ErrorBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class Command;
class Subsystem : public ErrorBase, public SendableBase {
class Subsystem : public ErrorBase,
public Sendable,
public SendableHelper<Subsystem> {
friend class Scheduler;
public:
@@ -97,6 +100,34 @@ class Subsystem : public ErrorBase, public SendableBase {
*/
virtual void InitDefaultCommand();
/**
* Gets the name of this Subsystem.
*
* @return Name
*/
std::string GetName() const;
/**
* Sets the name of this Subsystem.
*
* @param name name
*/
void SetName(const wpi::Twine& name);
/**
* Gets the subsystem name of this Subsystem.
*
* @return Subsystem name
*/
std::string GetSubsystem() const;
/**
* Sets the subsystem name of this Subsystem.
*
* @param subsystem subsystem name
*/
void SetSubsystem(const wpi::Twine& subsystem);
/**
* Associate a Sendable with this Subsystem.
* Also update the child's name.

View File

@@ -12,14 +12,16 @@
#include <units/units.h>
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc2 {
/**
* Implements a PID control loop.
*/
class PIDController : public frc::SendableBase {
class PIDController : public frc::Sendable,
public frc::SendableHelper<PIDController> {
public:
/**
* Allocates a PIDController with the given constants for Kp, Ki, and Kd.

View File

@@ -13,7 +13,8 @@
#include <units/units.h>
#include "frc/controller/PIDController.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
#include "frc/trajectory/TrapezoidProfile.h"
namespace frc {
@@ -22,7 +23,8 @@ namespace frc {
* Implements a PID control loop whose setpoint is constrained by a trapezoid
* profile.
*/
class ProfiledPIDController : public SendableBase {
class ProfiledPIDController : public Sendable,
public SendableHelper<ProfiledPIDController> {
public:
/**
* Allocates a ProfiledPIDController with the given constants for Kp, Ki, and

View File

@@ -10,6 +10,8 @@
#include <wpi/raw_ostream.h>
#include "frc/drive/RobotDriveBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -96,7 +98,9 @@ class SpeedController;
* RobotDrive#Drive(double, double) with the addition of a quick turn
* mode. However, it is not designed to give exactly the same response.
*/
class DifferentialDrive : public RobotDriveBase {
class DifferentialDrive : public RobotDriveBase,
public Sendable,
public SendableHelper<DifferentialDrive> {
public:
static constexpr double kDefaultQuickStopThreshold = 0.2;
static constexpr double kDefaultQuickStopAlpha = 0.1;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2017-2019 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. */
@@ -13,6 +13,8 @@
#include "frc/drive/RobotDriveBase.h"
#include "frc/drive/Vector2d.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -44,7 +46,9 @@ class SpeedController;
* and the positive Z axis points down. Rotations follow the right-hand rule, so
* clockwise rotation around the Z axis is positive.
*/
class KilloughDrive : public RobotDriveBase {
class KilloughDrive : public RobotDriveBase,
public Sendable,
public SendableHelper<KilloughDrive> {
public:
static constexpr double kDefaultLeftMotorAngle = 60.0;
static constexpr double kDefaultRightMotorAngle = 120.0;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2008-2019 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. */
@@ -12,6 +12,8 @@
#include <wpi/raw_ostream.h>
#include "frc/drive/RobotDriveBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -62,7 +64,9 @@ class SpeedController;
* RobotDrive#MecanumDrive_Polar(double, double, double) if a
* deadband of 0 is used.
*/
class MecanumDrive : public RobotDriveBase {
class MecanumDrive : public RobotDriveBase,
public Sendable,
public SendableHelper<MecanumDrive> {
public:
/**
* Construct a MecanumDrive.

View File

@@ -13,7 +13,6 @@
#include <wpi/raw_ostream.h>
#include "frc/MotorSafety.h"
#include "frc/smartdashboard/SendableBase.h"
namespace frc {
@@ -22,7 +21,7 @@ class SpeedController;
/**
* Common base class for drive platforms.
*/
class RobotDriveBase : public MotorSafety, public SendableBase {
class RobotDriveBase : public MotorSafety {
public:
/**
* The location of a motor on the robot for the purpose of driving.

View File

@@ -9,13 +9,10 @@
#include <memory>
#include <wpi/Twine.h>
#include <wpi/deprecated.h>
#include "frc/smartdashboard/Sendable.h"
namespace frc {
class Sendable;
/**
* The LiveWindow class is the public interface for putting sensors and
* actuators on the LiveWindow.
@@ -33,44 +30,6 @@ class LiveWindow {
*/
static LiveWindow* GetInstance();
/**
* Add a component to the LiveWindow.
*
* @param sendable component to add
*/
void Add(std::shared_ptr<Sendable> component);
/**
* Add a component to the LiveWindow.
*
* @param sendable component to add
*/
void Add(Sendable* component);
/**
* Add a child component to a component.
*
* @param parent parent component
* @param child child component
*/
void AddChild(Sendable* parent, std::shared_ptr<Sendable> component);
/**
* Add a child component to a component.
*
* @param parent parent component
* @param child child component
*/
void AddChild(Sendable* parent, void* component);
/**
* Remove the component from the LiveWindow.
*
* @param sendable component to remove
* @return true if the component was removed; false if it was not present
*/
bool Remove(Sendable* component);
/**
* Enable telemetry for a single component.
*

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2018-2019 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. */
@@ -11,7 +11,8 @@
#include <cscore_c.h>
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace cs {
class VideoSource;
@@ -22,7 +23,8 @@ namespace frc {
/**
* A wrapper to make video sources sendable and usable from Shuffleboard.
*/
class SendableCameraWrapper : public SendableBase {
class SendableCameraWrapper : public Sendable,
public SendableHelper<SendableCameraWrapper> {
private:
struct private_init {};

View File

@@ -14,7 +14,6 @@
#include "frc/shuffleboard/ShuffleboardComponent.h"
#include "frc/shuffleboard/ShuffleboardContainer.h"
#include "frc/smartdashboard/Sendable.h"
#ifdef _WIN32
#pragma warning(push)

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2018-2019 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. */
@@ -13,7 +13,6 @@
#include <wpi/StringRef.h>
#include "frc/shuffleboard/ShuffleboardContainer.h"
#include "frc/smartdashboard/Sendable.h"
namespace frc {

View File

@@ -7,63 +7,17 @@
#pragma once
#include <string>
#include <wpi/Twine.h>
namespace frc {
class SendableBuilder;
/**
* Interface for Sendable objects.
*/
class Sendable {
public:
Sendable() = default;
virtual ~Sendable() = default;
Sendable(const Sendable&) = default;
Sendable& operator=(const Sendable&) = default;
Sendable(Sendable&&) = default;
Sendable& operator=(Sendable&&) = default;
/**
* Gets the name of this Sendable object.
*
* @return Name
*/
virtual std::string GetName() const = 0;
/**
* Sets the name of this Sendable object.
*
* @param name name
*/
virtual void SetName(const wpi::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 wpi::Twine& subsystem, const wpi::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 wpi::Twine& subsystem) = 0;
/**
* Initializes this Sendable object.
*

View File

@@ -7,74 +7,22 @@
#pragma once
#include <memory>
#include <string>
#include <wpi/deprecated.h>
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class SendableBase : public Sendable {
class SendableBase : public Sendable, public SendableHelper<SendableBase> {
public:
/**
* Creates an instance of the sensor base.
*
* @param addLiveWindow if true, add this Sendable to LiveWindow
*/
WPI_DEPRECATED("use Sendable and SendableHelper")
explicit SendableBase(bool addLiveWindow = true);
~SendableBase() override;
SendableBase(const SendableBase&) = default;
SendableBase& operator=(const SendableBase&) = default;
SendableBase(SendableBase&&);
SendableBase& operator=(SendableBase&&);
using Sendable::SetName;
std::string GetName() const final;
void SetName(const wpi::Twine& name) final;
std::string GetSubsystem() const final;
void SetSubsystem(const wpi::Twine& subsystem) final;
protected:
/**
* Add a child component.
*
* @param child child component
*/
void AddChild(std::shared_ptr<Sendable> child);
/**
* Add a child component.
*
* @param child child component
*/
void AddChild(void* child);
/**
* Sets the name of the sensor with a channel number.
*
* @param moduleType A string that defines the module name in the label for
* the value
* @param channel The channel number the device is plugged into
*/
void SetName(const wpi::Twine& moduleType, int channel);
/**
* Sets the name of the sensor with a module and channel number.
*
* @param moduleType A string that defines the module name in the label for
* the value
* @param moduleNumber The number of the particular module type
* @param channel The channel number the device is plugged into (usually
* PWM)
*/
void SetName(const wpi::Twine& moduleType, int moduleNumber, int channel);
private:
std::string m_name;
std::string m_subsystem = "Ungrouped";
};
} // namespace frc

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2017-2019 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. */
@@ -14,7 +14,8 @@
#include <wpi/SmallVector.h>
#include <wpi/mutex.h>
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -24,7 +25,8 @@ namespace frc {
* It contains static, non-templated variables to avoid their duplication in the
* template class.
*/
class SendableChooserBase : public SendableBase {
class SendableChooserBase : public Sendable,
public SendableHelper<SendableChooserBase> {
public:
SendableChooserBase();
~SendableChooserBase() override = default;

View File

@@ -0,0 +1,161 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 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 <wpi/Twine.h>
#include <wpi/deprecated.h>
#include "frc/smartdashboard/SendableRegistry.h"
namespace frc {
/**
* A helper class for use with objects that add themselves to SendableRegistry.
* It takes care of properly calling Move() and Remove() on move and
* destruction. No action is taken if the object is copied.
* Use public inheritance with CRTP when using this class.
* @tparam CRTP derived class
*/
template <typename Derived>
class SendableHelper {
public:
SendableHelper(const SendableHelper& rhs) = default;
SendableHelper& operator=(const SendableHelper& rhs) = default;
SendableHelper(SendableHelper&& rhs) {
// it is safe to call Move() multiple times with the same rhs
SendableRegistry::GetInstance().Move(static_cast<Derived*>(this),
static_cast<Derived*>(&rhs));
}
SendableHelper& operator=(SendableHelper&& rhs) {
// it is safe to call Move() multiple times with the same rhs
SendableRegistry::GetInstance().Move(static_cast<Derived*>(this),
static_cast<Derived*>(&rhs));
return *this;
}
/**
* Gets the name of this Sendable object.
*
* @return Name
*/
WPI_DEPRECATED("use SendableRegistry::GetName()")
std::string GetName() const {
return SendableRegistry::GetInstance().GetName(
static_cast<const Derived*>(this));
}
/**
* Sets the name of this Sendable object.
*
* @param name name
*/
WPI_DEPRECATED("use SendableRegistry::SetName()")
void SetName(const wpi::Twine& name) {
SendableRegistry::GetInstance().SetName(static_cast<Derived*>(this), name);
}
/**
* Sets both the subsystem name and device name of this Sendable object.
*
* @param subsystem subsystem name
* @param name device name
*/
WPI_DEPRECATED("use SendableRegistry::SetName()")
void SetName(const wpi::Twine& subsystem, const wpi::Twine& name) {
SendableRegistry::GetInstance().SetName(static_cast<Derived*>(this),
subsystem, name);
}
/**
* Gets the subsystem name of this Sendable object.
*
* @return Subsystem name
*/
WPI_DEPRECATED("use SendableRegistry::GetSubsystem()")
std::string GetSubsystem() const {
return SendableRegistry::GetInstance().GetSubsystem(
static_cast<const Derived*>(this));
}
/**
* Sets the subsystem name of this Sendable object.
*
* @param subsystem subsystem name
*/
WPI_DEPRECATED("use SendableRegistry::SetSubsystem()")
void SetSubsystem(const wpi::Twine& subsystem) {
SendableRegistry::GetInstance().SetSubsystem(static_cast<Derived*>(this),
subsystem);
}
protected:
/**
* Add a child component.
*
* @param child child component
*/
WPI_DEPRECATED("use SendableRegistry::AddChild()")
void AddChild(std::shared_ptr<Sendable> child) {
SendableRegistry::GetInstance().AddChild(static_cast<Derived*>(this),
child.get());
}
/**
* Add a child component.
*
* @param child child component
*/
WPI_DEPRECATED("use SendableRegistry::AddChild()")
void AddChild(void* child) {
SendableRegistry::GetInstance().AddChild(static_cast<Derived*>(this),
child);
}
/**
* Sets the name of the sensor with a channel number.
*
* @param moduleType A string that defines the module name in the label for
* the value
* @param channel The channel number the device is plugged into
*/
WPI_DEPRECATED("use SendableRegistry::SetName()")
void SetName(const wpi::Twine& moduleType, int channel) {
SendableRegistry::GetInstance().SetName(static_cast<Derived*>(this),
moduleType, channel);
}
/**
* Sets the name of the sensor with a module and channel number.
*
* @param moduleType A string that defines the module name in the label for
* the value
* @param moduleNumber The number of the particular module type
* @param channel The channel number the device is plugged into (usually
* PWM)
*/
WPI_DEPRECATED("use SendableRegistry::SetName()")
void SetName(const wpi::Twine& moduleType, int moduleNumber, int channel) {
SendableRegistry::GetInstance().SetName(static_cast<Derived*>(this),
moduleType, moduleNumber, channel);
}
protected:
SendableHelper() = default;
~SendableHelper() {
// it is safe to call Remove() multiple times with the same object
SendableRegistry::GetInstance().Remove(static_cast<Derived*>(this));
}
};
} // namespace frc

View File

@@ -0,0 +1,277 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 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 <wpi/STLExtras.h>
#include <wpi/Twine.h>
namespace frc {
class Sendable;
/**
* The SendableRegistry class is the public interface for registering sensors
* and actuators for use on dashboards and LiveWindow.
*/
class SendableRegistry {
public:
SendableRegistry(const SendableRegistry&) = delete;
SendableRegistry& operator=(const SendableRegistry&) = delete;
/**
* Gets an instance of the SendableRegistry class.
*
* This is a singleton to guarantee that there is only a single instance
* regardless of how many times GetInstance is called.
*/
static SendableRegistry& GetInstance();
/**
* Adds an object to the registry.
*
* @param sendable object to add
* @param name component name
*/
void Add(Sendable* sendable, const wpi::Twine& name);
/**
* Adds an object to the registry.
*
* @param sendable object to add
* @param moduleType A string that defines the module name in the label for
* the value
* @param channel The channel number the device is plugged into
*/
void Add(Sendable* sendable, const wpi::Twine& moduleType, int channel);
/**
* Adds an object to the registry.
*
* @param sendable object to add
* @param moduleType A string that defines the module name in the label for
* the value
* @param moduleNumber The number of the particular module type
* @param channel The channel number the device is plugged into
*/
void Add(Sendable* sendable, const wpi::Twine& moduleType, int moduleNumber,
int channel);
/**
* Adds an object to the registry.
*
* @param sendable object to add
* @param subsystem subsystem name
* @param name component name
*/
void Add(Sendable* sendable, const wpi::Twine& subsystem,
const wpi::Twine& name);
/**
* Adds an object to the registry and LiveWindow.
*
* @param sendable object to add
* @param name component name
*/
void AddLW(Sendable* sendable, const wpi::Twine& name);
/**
* Adds an object to the registry and LiveWindow.
*
* @param sendable object to add
* @param moduleType A string that defines the module name in the label for
* the value
* @param channel The channel number the device is plugged into
*/
void AddLW(Sendable* sendable, const wpi::Twine& moduleType, int channel);
/**
* Adds an object to the registry and LiveWindow.
*
* @param sendable object to add
* @param moduleType A string that defines the module name in the label for
* the value
* @param moduleNumber The number of the particular module type
* @param channel The channel number the device is plugged into
*/
void AddLW(Sendable* sendable, const wpi::Twine& moduleType, int moduleNumber,
int channel);
/**
* Adds an object to the registry and LiveWindow.
*
* @param sendable object to add
* @param subsystem subsystem name
* @param name component name
*/
void AddLW(Sendable* sendable, const wpi::Twine& subsystem,
const wpi::Twine& name);
/**
* Adds a child object to an object. Adds the child object to the registry
* if it's not already present.
*
* @param parent parent object
* @param child child object
*/
void AddChild(Sendable* parent, void* child);
/**
* Removes an object from the registry.
*
* @param sendable object to remove
* @return true if the object was removed; false if it was not present
*/
bool Remove(Sendable* sendable);
/**
* Moves an object in the registry (for use in move constructors/assignments).
*
* @param to new object
* @param from old object
*/
void Move(Sendable* to, Sendable* from);
/**
* Determines if an object is in the registry.
*
* @param sendable object to check
* @return True if in registry, false if not.
*/
bool Contains(const Sendable* sendable) const;
/**
* Gets the name of an object.
*
* @param sendable object
* @return Name (empty if object is not in registry)
*/
std::string GetName(const Sendable* sendable) const;
/**
* Sets the name of an object.
*
* @param sendable object
* @param name name
*/
void SetName(Sendable* sendable, const wpi::Twine& name);
/**
* Sets the name of an object with a channel number.
*
* @param sendable object
* @param moduleType A string that defines the module name in the label for
* the value
* @param channel The channel number the device is plugged into
*/
void SetName(Sendable* sendable, const wpi::Twine& moduleType, int channel);
/**
* Sets the name of an object with a module and channel number.
*
* @param sendable object
* @param moduleType A string that defines the module name in the label for
* the value
* @param moduleNumber The number of the particular module type
* @param channel The channel number the device is plugged into
*/
void SetName(Sendable* sendable, const wpi::Twine& moduleType,
int moduleNumber, int channel);
/**
* Sets both the subsystem name and device name of an object.
*
* @param sendable object
* @param subsystem subsystem name
* @param name device name
*/
void SetName(Sendable* sendable, const wpi::Twine& subsystem,
const wpi::Twine& name);
/**
* Gets the subsystem name of an object.
*
* @param sendable object
* @return Subsystem name (empty if object is not in registry)
*/
std::string GetSubsystem(const Sendable* sendable) const;
/**
* Sets the subsystem name of an object.
*
* @param sendable object
* @param subsystem subsystem name
*/
void SetSubsystem(Sendable* sendable, const wpi::Twine& subsystem);
/**
* Gets a unique handle for setting/getting data with SetData() and GetData().
*
* @return Handle
*/
int GetDataHandle();
/**
* Associates arbitrary data with an object in the registry.
*
* @param sendable object
* @param handle data handle returned by GetDataHandle()
* @param data data to set
* @return Previous data (may be null)
*/
std::shared_ptr<void> SetData(Sendable* sendable, int handle,
std::shared_ptr<void> data);
/**
* Gets arbitrary data associated with an object in the registry.
*
* @param sendable object
* @param handle data handle returned by GetDataHandle()
* @return data (may be null if none associated)
*/
std::shared_ptr<void> GetData(Sendable* sendable, int handle);
/**
* Enables LiveWindow for an object.
*
* @param sendable object
*/
void EnableLiveWindow(Sendable* sendable);
/**
* Disables LiveWindow for an object.
*
* @param sendable object
*/
void DisableLiveWindow(Sendable* sendable);
/**
* Iterates over LiveWindow-enabled objects in the registry.
* It is *not* safe to call other SendableRegistry functions from the
* callback (this will likely deadlock).
*
* @param dataHandle data handle to get data pointer passed to callback
* @param callback function to call for each object
*/
void ForeachLiveWindow(
int dataHandle,
wpi::function_ref<void(Sendable* sendable, wpi::StringRef name,
wpi::StringRef subsystem, Sendable* parent,
std::shared_ptr<void>& data)>
callback) const;
private:
SendableRegistry();
struct Impl;
std::unique_ptr<Impl> m_impl;
};
} // namespace frc

View File

@@ -15,13 +15,14 @@
#include "frc/ErrorBase.h"
#include "frc/smartdashboard/ListenerExecutor.h"
#include "frc/smartdashboard/SendableBase.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
class Sendable;
class SmartDashboard : public ErrorBase, public SendableBase {
class SmartDashboard : public ErrorBase,
public Sendable,
public SendableHelper<SmartDashboard> {
public:
static void init();
@@ -101,6 +102,9 @@ class SmartDashboard : public ErrorBase, public SendableBase {
* The value can be retrieved by calling the get method with a key that is
* equal to the original key.
*
* In order for the value to appear in the dashboard, it must be registered
* with SendableRegistry. WPILib components do this automatically.
*
* @param keyName the key
* @param value the value
*/
@@ -113,6 +117,9 @@ class SmartDashboard : public ErrorBase, public SendableBase {
* The value can be retrieved by calling the get method with a key that is
* equal to the original key.
*
* In order for the value to appear in the dashboard, it must be registered
* with SendableRegistry. WPILib components do this automatically.
*
* @param value the value
*/
static void PutData(Sendable* value);

View File

@@ -52,9 +52,13 @@ class ProxyScheduleCommand;
class Command : public frc::ErrorBase {
public:
Command() = default;
Command(Command&& other) = default;
virtual ~Command();
Command(const Command&);
Command& operator=(const Command&);
Command(Command&&) = default;
Command& operator=(Command&&) = default;
/**
* The initial subroutine of a command. Called once when the command is
* initially scheduled.

View File

@@ -8,11 +8,12 @@
#pragma once
#include <frc/smartdashboard/Sendable.h>
#include <frc/smartdashboard/SendableHelper.h>
#include <string>
#include <wpi/SmallSet.h>
#include <wpi/SmallVector.h>
#include <wpi/Twine.h>
#include "Command.h"
@@ -20,12 +21,10 @@ namespace frc2 {
/**
* A Sendable base class for Commands.
*/
class CommandBase : public frc::Sendable, public Command {
class CommandBase : public Command,
public frc::Sendable,
public frc::SendableHelper<CommandBase> {
public:
CommandBase(CommandBase&& other) = default;
CommandBase(const CommandBase& other);
/**
* Adds the specified requirements to the command.
*
@@ -37,20 +36,38 @@ class CommandBase : public frc::Sendable, public Command {
wpi::SmallSet<Subsystem*, 4> GetRequirements() const override;
void SetName(const wpi::Twine& name) override;
/**
* Sets the name of this Command.
*
* @param name name
*/
void SetName(const wpi::Twine& name);
/**
* Gets the name of this Command.
*
* @return Name
*/
std::string GetName() const override;
std::string GetSubsystem() const override;
/**
* Gets the subsystem name of this Command.
*
* @return Subsystem name
*/
std::string GetSubsystem() const;
void SetSubsystem(const wpi::Twine& subsystem) override;
/**
* Sets the subsystem name of this Command.
*
* @param subsystem subsystem name
*/
void SetSubsystem(const wpi::Twine& subsystem);
void InitSendable(frc::SendableBuilder& builder) override;
protected:
CommandBase();
std::string m_name;
std::string m_subsystem;
wpi::SmallSet<Subsystem*, 4> m_requirements;
};
} // namespace frc2

View File

@@ -10,7 +10,8 @@
#include <frc/ErrorBase.h>
#include <frc/RobotState.h>
#include <frc/WPIErrors.h>
#include <frc/smartdashboard/SendableBase.h>
#include <frc/smartdashboard/Sendable.h>
#include <frc/smartdashboard/SendableHelper.h>
#include <memory>
#include <unordered_map>
@@ -34,7 +35,9 @@ class Subsystem;
* with the scheduler using RegisterSubsystem() in order for their Periodic()
* methods to be called and for their default commands to be scheduled.
*/
class CommandScheduler final : public frc::SendableBase, frc::ErrorBase {
class CommandScheduler final : public frc::Sendable,
public frc::ErrorBase,
public frc::SendableHelper<CommandScheduler> {
public:
/**
* Returns the Scheduler instance.

View File

@@ -8,6 +8,7 @@
#pragma once
#include <frc/smartdashboard/Sendable.h>
#include <frc/smartdashboard/SendableHelper.h>
#include <string>
@@ -18,17 +19,50 @@ namespace frc2 {
* A base for subsystems that handles registration in the constructor, and
* provides a more intuitive method for setting the default command.
*/
class SubsystemBase : public Subsystem, public frc::Sendable {
class SubsystemBase : public Subsystem,
public frc::Sendable,
public frc::SendableHelper<SubsystemBase> {
public:
void InitSendable(frc::SendableBuilder& builder) override;
std::string GetName() const override;
void SetName(const wpi::Twine& name) override;
std::string GetSubsystem() const override;
void SetSubsystem(const wpi::Twine& name) override;
/**
* Gets the name of this Subsystem.
*
* @return Name
*/
std::string GetName() const;
/**
* Sets the name of this Subsystem.
*
* @param name name
*/
void SetName(const wpi::Twine& name);
/**
* Gets the subsystem name of this Subsystem.
*
* @return Subsystem name
*/
std::string GetSubsystem() const;
/**
* Sets the subsystem name of this Subsystem.
*
* @param subsystem subsystem name
*/
void SetSubsystem(const wpi::Twine& name);
/**
* Associate a Sendable with this Subsystem.
* Also update the child's name.
*
* @param name name to give child
* @param child sendable
*/
void AddChild(std::string name, frc::Sendable* child);
protected:
SubsystemBase();
std::string m_name;
};
} // namespace frc2