mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Made SensorBase a utility class and renamed it to SensorUtil (#813)
This commit is contained in:
committed by
Peter Johnson
parent
ba93f79d8b
commit
ecfe95383c
@@ -7,8 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "I2C.h"
|
||||
#include "SensorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
#include "interfaces/Accelerometer.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -20,7 +21,9 @@ namespace frc {
|
||||
* an I2C bus. This class assumes the default (not alternate) sensor address of
|
||||
* 0x1D (7-bit address).
|
||||
*/
|
||||
class ADXL345_I2C : public SensorBase, public Accelerometer {
|
||||
class ADXL345_I2C : public ErrorBase,
|
||||
public SendableBase,
|
||||
public Accelerometer {
|
||||
public:
|
||||
enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
|
||||
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "SPI.h"
|
||||
#include "SensorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
#include "interfaces/Accelerometer.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -19,7 +20,9 @@ namespace frc {
|
||||
* 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 SensorBase, public Accelerometer {
|
||||
class ADXL345_SPI : public ErrorBase,
|
||||
public SendableBase,
|
||||
public Accelerometer {
|
||||
public:
|
||||
enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
|
||||
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "SPI.h"
|
||||
#include "SensorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
#include "interfaces/Accelerometer.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -18,7 +19,7 @@ namespace frc {
|
||||
*
|
||||
* This class allows access to an Analog Devices ADXL362 3-axis accelerometer.
|
||||
*/
|
||||
class ADXL362 : public SensorBase, public Accelerometer {
|
||||
class ADXL362 : public ErrorBase, public SendableBase, public Accelerometer {
|
||||
public:
|
||||
enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
|
||||
struct AllAxes {
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
#include <memory>
|
||||
|
||||
#include "AnalogInput.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "PIDSource.h"
|
||||
#include "SensorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -22,7 +23,9 @@ 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 {
|
||||
class AnalogAccelerometer : public ErrorBase,
|
||||
public SendableBase,
|
||||
public PIDSource {
|
||||
public:
|
||||
explicit AnalogAccelerometer(int channel);
|
||||
explicit AnalogAccelerometer(AnalogInput* channel);
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
|
||||
#include <HAL/Types.h>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "PIDSource.h"
|
||||
#include "SensorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -28,7 +29,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 {
|
||||
class AnalogInput : public ErrorBase, public SendableBase, public PIDSource {
|
||||
friend class AnalogTrigger;
|
||||
friend class AnalogGyro;
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
#include <memory>
|
||||
|
||||
#include "AnalogInput.h"
|
||||
#include "SensorBase.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
#include "interfaces/Potentiometer.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -21,7 +22,9 @@ namespace frc {
|
||||
* units you choose, by way of the scaling and offset constants passed to the
|
||||
* constructor.
|
||||
*/
|
||||
class AnalogPotentiometer : public SensorBase, public Potentiometer {
|
||||
class AnalogPotentiometer : public ErrorBase,
|
||||
public SendableBase,
|
||||
public Potentiometer {
|
||||
public:
|
||||
/**
|
||||
* AnalogPotentiometer constructor.
|
||||
|
||||
@@ -12,13 +12,14 @@
|
||||
#include <HAL/Types.h>
|
||||
|
||||
#include "AnalogTriggerOutput.h"
|
||||
#include "SensorBase.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class AnalogInput;
|
||||
|
||||
class AnalogTrigger : public SensorBase {
|
||||
class AnalogTrigger : public ErrorBase, public SendableBase {
|
||||
friend class AnalogTriggerOutput;
|
||||
|
||||
public:
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SensorBase.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
#include "interfaces/Accelerometer.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -17,7 +18,9 @@ namespace frc {
|
||||
*
|
||||
* This class allows access to the roboRIO's internal accelerometer.
|
||||
*/
|
||||
class BuiltInAccelerometer : public SensorBase, public Accelerometer {
|
||||
class BuiltInAccelerometer : public ErrorBase,
|
||||
public SendableBase,
|
||||
public Accelerometer {
|
||||
public:
|
||||
explicit BuiltInAccelerometer(Range range = kRange_8G);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <HAL/Types.h>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "SensorBase.h"
|
||||
#include "SensorUtil.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -33,7 +33,7 @@ namespace frc {
|
||||
class Compressor : public ErrorBase, public SendableBase {
|
||||
public:
|
||||
// Default PCM ID is 0
|
||||
explicit Compressor(int pcmID = SensorBase::GetDefaultSolenoidModule());
|
||||
explicit Compressor(int pcmID = SensorUtil::GetDefaultSolenoidModule());
|
||||
~Compressor() override = default;
|
||||
|
||||
void Start();
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
|
||||
#include "AnalogTrigger.h"
|
||||
#include "CounterBase.h"
|
||||
#include "SensorBase.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -30,7 +31,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 {
|
||||
class Counter : public ErrorBase, public SendableBase, public CounterBase {
|
||||
public:
|
||||
enum Mode {
|
||||
kTwoPulse = 0,
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "DigitalSource.h"
|
||||
#include "SensorBase.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -28,7 +29,7 @@ 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 SensorBase {
|
||||
class DigitalGlitchFilter : public ErrorBase, public SendableBase {
|
||||
public:
|
||||
DigitalGlitchFilter();
|
||||
~DigitalGlitchFilter() override;
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
|
||||
#include "Counter.h"
|
||||
#include "CounterBase.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "PIDSource.h"
|
||||
#include "SensorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -36,7 +37,10 @@ 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 {
|
||||
class Encoder : public ErrorBase,
|
||||
public SendableBase,
|
||||
public CounterBase,
|
||||
public PIDSource {
|
||||
public:
|
||||
enum IndexingType {
|
||||
kResetWhileHigh,
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "PIDSource.h"
|
||||
#include "SensorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
#include "interfaces/Gyro.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -17,7 +18,10 @@ namespace frc {
|
||||
* GyroBase is the common base class for Gyro implementations such as
|
||||
* AnalogGyro.
|
||||
*/
|
||||
class GyroBase : public Gyro, public SensorBase, public PIDSource {
|
||||
class GyroBase : public Gyro,
|
||||
public ErrorBase,
|
||||
public SendableBase,
|
||||
public PIDSource {
|
||||
public:
|
||||
// PIDSource interface
|
||||
double PIDGet() override;
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
#include <HAL/Interrupts.h>
|
||||
|
||||
#include "AnalogTriggerType.h"
|
||||
#include "SensorBase.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class InterruptableSensorBase : public SensorBase {
|
||||
class InterruptableSensorBase : public ErrorBase, public SendableBase {
|
||||
public:
|
||||
enum WaitResult {
|
||||
kTimeout = 0x0,
|
||||
|
||||
@@ -49,11 +49,11 @@ class LiveWindow {
|
||||
void AddActuator(const wpi::Twine& subsystem, const wpi::Twine& name,
|
||||
std::shared_ptr<Sendable> component);
|
||||
|
||||
WPI_DEPRECATED("use SensorBase::SetName() instead")
|
||||
WPI_DEPRECATED("use SensorUtil::SetName() instead")
|
||||
void AddSensor(const wpi::Twine& type, int channel, Sendable* component);
|
||||
WPI_DEPRECATED("use SensorBase::SetName() instead")
|
||||
WPI_DEPRECATED("use SensorUtil::SetName() instead")
|
||||
void AddActuator(const wpi::Twine& type, int channel, Sendable* component);
|
||||
WPI_DEPRECATED("use SensorBase::SetName() instead")
|
||||
WPI_DEPRECATED("use SensorUtil::SetName() instead")
|
||||
void AddActuator(const wpi::Twine& type, int module, int channel,
|
||||
Sendable* component);
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SensorBase.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -15,7 +16,7 @@ namespace frc {
|
||||
* Class for getting voltage, current, temperature, power and energy from the
|
||||
* CAN PDP.
|
||||
*/
|
||||
class PowerDistributionPanel : public SensorBase {
|
||||
class PowerDistributionPanel : public ErrorBase, public SendableBase {
|
||||
public:
|
||||
PowerDistributionPanel();
|
||||
explicit PowerDistributionPanel(int module);
|
||||
|
||||
@@ -7,28 +7,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Base.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/Sendable.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* Base class for all sensors.
|
||||
*
|
||||
* Stores most recent status information as well as containing utility functions
|
||||
* for checking channels and error processing.
|
||||
*/
|
||||
class SensorBase : public ErrorBase, public SendableBase {
|
||||
class SensorUtil final {
|
||||
public:
|
||||
SensorBase() = default;
|
||||
|
||||
SensorBase(const SensorBase&) = delete;
|
||||
SensorBase& operator=(const SensorBase&) = delete;
|
||||
|
||||
static int GetDefaultSolenoidModule() { return 0; }
|
||||
|
||||
static bool CheckSolenoidModule(int moduleNumber);
|
||||
@@ -48,6 +34,9 @@ class SensorBase : public ErrorBase, public SendableBase {
|
||||
static const int kPwmChannels;
|
||||
static const int kRelayChannels;
|
||||
static const int kPDPChannels;
|
||||
|
||||
private:
|
||||
SensorUtil() = default;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
@@ -13,13 +13,14 @@
|
||||
|
||||
#include <networktables/NetworkTableValue.h>
|
||||
|
||||
#include "SensorBase.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class Sendable;
|
||||
|
||||
class SmartDashboard : public SensorBase {
|
||||
class SmartDashboard : public ErrorBase, public SendableBase {
|
||||
public:
|
||||
static void init();
|
||||
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include "Counter.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "PIDSource.h"
|
||||
#include "SensorBase.h"
|
||||
#include "SmartDashboard/SendableBase.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -33,7 +34,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 {
|
||||
class Ultrasonic : public ErrorBase, public SendableBase, public PIDSource {
|
||||
public:
|
||||
enum DistanceUnit { kInches = 0, kMilliMeters = 1 };
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
#include "SD540.h"
|
||||
#include "SPI.h"
|
||||
#include "SampleRobot.h"
|
||||
#include "SensorBase.h"
|
||||
#include "SensorUtil.h"
|
||||
#include "SerialPort.h"
|
||||
#include "Servo.h"
|
||||
#include "SmartDashboard/SendableChooser.h"
|
||||
|
||||
Reference in New Issue
Block a user