[hal, wpilib] Remove DigitalSource and AnalogTrigger (#7753)

This commit is contained in:
Thad House
2025-01-30 18:58:21 -08:00
committed by GitHub
parent 7533b323d1
commit 6e704370b3
63 changed files with 7 additions and 2994 deletions

View File

@@ -27,8 +27,6 @@ namespace frc {
*/
class AnalogInput : public wpi::Sendable,
public wpi::SendableHelper<AnalogInput> {
friend class AnalogTrigger;
public:
/**
* Construct an analog input.

View File

@@ -1,194 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <memory>
#include <hal/AnalogTrigger.h>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/AnalogTriggerOutput.h"
namespace frc {
class AnalogInput;
class DutyCycle;
class AnalogTrigger : public wpi::Sendable,
public wpi::SendableHelper<AnalogTrigger> {
friend class AnalogTriggerOutput;
public:
/**
* Constructor for an analog trigger given a channel number.
*
* @param channel The channel number on the roboRIO to represent. 0-3 are
* on-board 4-7 are on the MXP port.
*/
explicit AnalogTrigger(int channel);
/**
* Construct an analog trigger using an existing analog input.
*
* This should be used in the case of sharing an analog channel between the
* trigger and an analog input object.
*
* @param input A reference to the existing AnalogInput object
*/
explicit AnalogTrigger(AnalogInput& input);
/**
* Construct an analog trigger using an existing analog input.
*
* This should be used in the case of sharing an analog channel between the
* trigger and an analog input object.
*
* @param input A pointer to the existing AnalogInput object
*/
explicit AnalogTrigger(AnalogInput* input);
/**
* Construct an analog trigger using an existing analog input.
*
* This should be used in the case of sharing an analog channel between the
* trigger and an analog input object.
*
* @param input A shared_ptr to the existing AnalogInput object
*/
explicit AnalogTrigger(std::shared_ptr<AnalogInput> input);
/**
* Construct an analog trigger using an existing duty cycle input.
*
* @param dutyCycle A reference to the existing DutyCycle object
*/
explicit AnalogTrigger(DutyCycle& dutyCycle);
/**
* Construct an analog trigger using an existing duty cycle input.
*
* @param dutyCycle A pointer to the existing DutyCycle object
*/
explicit AnalogTrigger(DutyCycle* dutyCycle);
/**
* Construct an analog trigger using an existing duty cycle input.
*
* @param dutyCycle A shared_ptr to the existing DutyCycle object
*/
explicit AnalogTrigger(std::shared_ptr<DutyCycle> dutyCycle);
AnalogTrigger(AnalogTrigger&&) = default;
AnalogTrigger& operator=(AnalogTrigger&&) = default;
~AnalogTrigger() override = default;
/**
* Set the upper and lower limits of the analog trigger.
*
* The limits are given as floating point voltage values.
*
* @param lower The lower limit of the trigger in Volts.
* @param upper The upper limit of the trigger in Volts.
*/
void SetLimitsVoltage(double lower, double upper);
/**
* Set the upper and lower duty cycle limits of the analog trigger.
*
* The limits are given as floating point values between 0 and 1.
*
* @param lower The lower limit of the trigger in percentage.
* @param upper The upper limit of the trigger in percentage.
*/
void SetLimitsDutyCycle(double lower, double upper);
/**
* Set the upper and lower limits of the analog trigger.
*
* The limits are given in ADC codes. If oversampling is used, the units must
* be scaled appropriately.
*
* @param lower The lower limit of the trigger in ADC codes (12-bit values).
* @param upper The upper limit of the trigger in ADC codes (12-bit values).
*/
void SetLimitsRaw(int lower, int upper);
/**
* Configure the analog trigger to use the averaged vs. raw values.
*
* If the value is true, then the averaged value is selected for the analog
* trigger, otherwise the immediate value is used.
*
* @param useAveragedValue If true, use the Averaged value, otherwise use the
* instantaneous reading
*/
void SetAveraged(bool useAveragedValue);
/**
* Configure the analog trigger to use a filtered value.
*
* The analog trigger will operate with a 3 point average rejection filter.
* This is designed to help with 360 degree pot applications for the period
* where the pot crosses through zero.
*
* @param useFilteredValue If true, use the 3 point rejection filter,
* otherwise use the unfiltered value
*/
void SetFiltered(bool useFilteredValue);
/**
* Return the index of the analog trigger.
*
* This is the FPGA index of this analog trigger instance.
*
* @return The index of the analog trigger.
*/
int GetIndex() const;
/**
* Return the InWindow output of the analog trigger.
*
* True if the analog input is between the upper and lower limits.
*
* @return True if the analog input is between the upper and lower limits.
*/
bool GetInWindow();
/**
* Return the TriggerState output of the analog trigger.
*
* True if above upper limit.
* False if below lower limit.
* If in Hysteresis, maintain previous state.
*
* @return True if above upper limit. False if below lower limit. If in
* Hysteresis, maintain previous state.
*/
bool GetTriggerState();
/**
* Creates an AnalogTriggerOutput object.
*
* @param type An enum of the type of output object to create.
* @return A pointer to a new AnalogTriggerOutput object.
*/
std::shared_ptr<AnalogTriggerOutput> CreateOutput(
AnalogTriggerType type) const;
void InitSendable(wpi::SendableBuilder& builder) override;
private:
int GetSourceChannel() const;
std::shared_ptr<AnalogInput> m_analogInput;
std::shared_ptr<DutyCycle> m_dutyCycle;
hal::Handle<HAL_AnalogTriggerHandle, HAL_CleanAnalogTrigger> m_trigger;
bool m_ownsAnalog = false;
};
} // namespace frc

View File

@@ -1,106 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/DigitalSource.h"
namespace frc {
class AnalogTrigger;
/**
* Class to represent a specific output from an analog trigger.
*
* This class is used to get the current output value and also as a
* DigitalSource to provide routing of an output to digital subsystems on the
* FPGA such as Counter, Encoder, and Interrupt.
*
* The TriggerState output indicates the primary output value of the trigger.
* If the analog signal is less than the lower limit, the output is false. If
* the analog value is greater than the upper limit, then the output is true.
* If the analog value is in between, then the trigger output state maintains
* its most recent value.
*
* The InWindow output indicates whether or not the analog signal is inside the
* range defined by the limits.
*
* The RisingPulse and FallingPulse outputs detect an instantaneous transition
* from above the upper limit to below the lower limit, and vice versa. These
* pulses represent a rollover condition of a sensor and can be routed to an up
* / down counter or to interrupts. Because the outputs generate a pulse, they
* cannot be read directly. To help ensure that a rollover condition is not
* missed, there is an average rejection filter available that operates on the
* upper 8 bits of a 12 bit number and selects the nearest outlier of 3 samples.
* This will reject a sample that is (due to averaging or sampling) errantly
* between the two limits. This filter will fail if more than one sample in a
* row is errantly in between the two limits. You may see this problem if
* attempting to use this feature with a mechanical rollover sensor, such as a
* 360 degree no-stop potentiometer without signal conditioning, because the
* 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,
public wpi::Sendable,
public wpi::SendableHelper<AnalogTriggerOutput> {
friend class AnalogTrigger;
public:
/**
* Get the state of the analog trigger output.
*
* @return The state of the analog trigger output.
*/
bool Get() const;
// DigitalSource interface
/**
* @return The HAL Handle to the specified source.
*/
HAL_Handle GetPortHandleForRouting() const override;
/**
* @return The type of analog trigger output to be used.
*/
AnalogTriggerType GetAnalogTriggerTypeForRouting() const override;
/**
* Is source an AnalogTrigger
*/
bool IsAnalogTrigger() const override;
/**
* @return The channel of the source.
*/
int GetChannel() const override;
void InitSendable(wpi::SendableBuilder& builder) override;
protected:
/**
* Create an object that represents one of the four outputs from an analog
* trigger.
*
* Because this class derives from DigitalSource, it can be passed into
* routing functions for Counter, Encoder, etc.
*
* @param trigger A pointer to the trigger for which this is an output.
* @param outputType An enum that specifies the output on the trigger to
* represent.
*/
AnalogTriggerOutput(const AnalogTrigger& trigger,
AnalogTriggerType outputType);
private:
// Uses pointer rather than smart pointer because a user can not construct
// an AnalogTriggerOutput themselves and because the AnalogTriggerOutput
// should always be in scope at the same time as an AnalogTrigger.
const AnalogTrigger* m_trigger;
AnalogTriggerType m_outputType;
};
} // namespace frc

View File

@@ -1,21 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
namespace frc {
/** Defines the state in which the AnalogTrigger triggers. */
enum class AnalogTriggerType {
/// In window.
kInWindow = 0,
/// State.
kState = 1,
/// Rising Pulse.
kRisingPulse = 2,
/// Falling pulse.
kFallingPulse = 3
};
} // namespace frc

View File

@@ -8,8 +8,6 @@
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/DigitalSource.h"
namespace frc {
/**
@@ -21,8 +19,7 @@ namespace frc {
* as required. This class is only for devices like switches etc. that aren't
* implemented anywhere else.
*/
class DigitalInput : public DigitalSource,
public wpi::Sendable,
class DigitalInput : public wpi::Sendable,
public wpi::SendableHelper<DigitalInput> {
public:
/**
@@ -46,26 +43,10 @@ class DigitalInput : public DigitalSource,
*/
bool Get() const;
// Digital Source Interface
/**
* @return The HAL Handle to the specified source.
*/
HAL_Handle GetPortHandleForRouting() const override;
/**
* @return The type of analog trigger output to be used. 0 for Digitals
*/
AnalogTriggerType GetAnalogTriggerTypeForRouting() const override;
/**
* Is source an AnalogTrigger
*/
bool IsAnalogTrigger() const override;
/**
* @return The GPIO channel number that this object represents.
*/
int GetChannel() const override;
int GetChannel() const;
/**
* Indicates this input is used by a simulated device.

View File

@@ -10,8 +10,6 @@
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/DigitalSource.h"
namespace frc {
/**
@@ -21,8 +19,7 @@ namespace frc {
* elsewhere will allocate channels automatically so for those devices it
* shouldn't be done here.
*/
class DigitalOutput : public DigitalSource,
public wpi::Sendable,
class DigitalOutput : public wpi::Sendable,
public wpi::SendableHelper<DigitalOutput> {
public:
/**
@@ -56,26 +53,10 @@ class DigitalOutput : public DigitalSource,
*/
bool Get() const;
// Digital Source Interface
/**
* @return The HAL Handle to the specified source.
*/
HAL_Handle GetPortHandleForRouting() const override;
/**
* @return The type of analog trigger output to be used. 0 for Digitals
*/
AnalogTriggerType GetAnalogTriggerTypeForRouting() const override;
/**
* Is source an AnalogTrigger
*/
bool IsAnalogTrigger() const override;
/**
* @return The GPIO channel number that this object represents.
*/
int GetChannel() const override;
int GetChannel() const;
/**
* Output a single pulse on the digital output line.

View File

@@ -1,34 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <hal/Types.h>
#include "frc/AnalogTriggerType.h"
namespace frc {
/**
* DigitalSource Interface.
*
* The DigitalSource represents all the possible inputs for a counter or a
* quadrature encoder. The source may be either a digital input or an analog
* input. If the caller just provides a channel, then a digital input will be
* constructed and freed when finished for the source. The source can either be
* a digital input or analog trigger but not both.
*/
class DigitalSource {
public:
DigitalSource() = default;
DigitalSource(DigitalSource&&) = default;
DigitalSource& operator=(DigitalSource&&) = default;
virtual HAL_Handle GetPortHandleForRouting() const = 0;
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
virtual bool IsAnalogTrigger() const = 0;
virtual int GetChannel() const = 0;
};
} // namespace frc

View File

@@ -13,9 +13,6 @@
#include <wpi/sendable/SendableHelper.h>
namespace frc {
class DigitalSource;
class AnalogTrigger;
/**
* Class to read a duty cycle PWM input.
*
@@ -28,8 +25,6 @@ class AnalogTrigger;
*
*/
class DutyCycle : public wpi::Sendable, public wpi::SendableHelper<DutyCycle> {
friend class AnalogTrigger;
public:
/**
* Constructs a DutyCycle input from a smartio channel.

View File

@@ -15,7 +15,6 @@
namespace frc {
class DutyCycle;
class DigitalSource;
/**
* Class for supporting duty cycle/PWM encoders, such as the US Digital MA3 with

View File

@@ -14,9 +14,6 @@
#include "frc/CounterBase.h"
namespace frc {
class DigitalSource;
/**
* Class to read quad encoders.
*

View File

@@ -17,8 +17,6 @@
#include "EdgeConfiguration.h"
namespace frc {
class DigitalSource;
/**
* Tachometer for getting rotational speed from a device.
*

View File

@@ -14,8 +14,6 @@
#include "EdgeConfiguration.h"
namespace frc {
class DigitalSource;
/** Up Down Counter.
*
* This class can count edges on a single digital input or count up based on an

View File

@@ -1,137 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <memory>
#include "frc/simulation/CallbackStore.h"
namespace frc {
class AnalogTrigger;
namespace sim {
/**
* Class to control a simulated analog trigger.
*/
class AnalogTriggerSim {
public:
/**
* Constructs from an AnalogTrigger object.
*
* @param analogTrigger AnalogTrigger to simulate
*/
explicit AnalogTriggerSim(const AnalogTrigger& analogTrigger);
/**
* Creates an AnalogTriggerSim for an analog input channel.
*
* @param channel analog input channel
* @return Simulated object
* @throws std::out_of_range if no AnalogTrigger is configured for that
* channel
*/
static AnalogTriggerSim CreateForChannel(int channel);
/**
* Creates an AnalogTriggerSim for a simulated index.
* The index is incremented for each simulated AnalogTrigger.
*
* @param index simulator index
* @return Simulated object
*/
static AnalogTriggerSim CreateForIndex(int index);
/**
* Register a callback on whether the analog trigger is initialized.
*
* @param callback the callback that will be called whenever the analog
* trigger is initialized
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check if this analog trigger has been initialized.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Change whether this analog trigger has been initialized.
*
* @param initialized the new value
*/
void SetInitialized(bool initialized);
/**
* Register a callback on the lower bound.
*
* @param callback the callback that will be called whenever the lower bound
* is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterTriggerLowerBoundCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the lower bound.
*
* @return the lower bound
*/
double GetTriggerLowerBound() const;
/**
* Change the lower bound.
*
* @param triggerLowerBound the new lower bound
*/
void SetTriggerLowerBound(double triggerLowerBound);
/**
* Register a callback on the upper bound.
*
* @param callback the callback that will be called whenever the upper bound
* is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterTriggerUpperBoundCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the upper bound.
*
* @return the upper bound
*/
double GetTriggerUpperBound() const;
/**
* Change the upper bound.
*
* @param triggerUpperBound the new upper bound
*/
void SetTriggerUpperBound(double triggerUpperBound);
/**
* Reset all simulation data for this object.
*/
void ResetData();
private:
explicit AnalogTriggerSim(int index) : m_index{index} {}
int m_index;
};
} // namespace sim
} // namespace frc