mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-06 03:31:43 +00:00
[hal] Add frequency support to DutyCycle (#8076)
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <hal/DutyCycle.h>
|
||||
#include <hal/Types.h>
|
||||
#include <units/frequency.h>
|
||||
#include <units/time.h>
|
||||
#include <wpi/sendable/Sendable.h>
|
||||
#include <wpi/sendable/SendableHelper.h>
|
||||
@@ -17,11 +18,7 @@ namespace frc {
|
||||
* Class to read a duty cycle PWM input.
|
||||
*
|
||||
* <p>PWM input signals are specified with a frequency and a ratio of high to
|
||||
* low in that frequency. There are 8 of these in the roboRIO, and they can be
|
||||
* attached to any DigitalSource.
|
||||
*
|
||||
* <p>These can be combined as the input of an AnalogTrigger to a Counter in
|
||||
* order to implement rollover checking.
|
||||
* low in that frequency. These can be attached to any SmartIO.
|
||||
*
|
||||
*/
|
||||
class DutyCycle : public wpi::Sendable, public wpi::SendableHelper<DutyCycle> {
|
||||
@@ -44,9 +41,9 @@ class DutyCycle : public wpi::Sendable, public wpi::SendableHelper<DutyCycle> {
|
||||
/**
|
||||
* Get the frequency of the duty cycle signal.
|
||||
*
|
||||
* @return frequency in Hertz
|
||||
* @return frequency
|
||||
*/
|
||||
int GetFrequency() const;
|
||||
units::hertz_t GetFrequency() const;
|
||||
|
||||
/**
|
||||
* Get the output ratio of the duty cycle signal.
|
||||
@@ -64,24 +61,6 @@ class DutyCycle : public wpi::Sendable, public wpi::SendableHelper<DutyCycle> {
|
||||
*/
|
||||
units::second_t GetHighTime() const;
|
||||
|
||||
/**
|
||||
* Get the scale factor of the output.
|
||||
*
|
||||
* <p> An output equal to this value is always high, and then linearly scales
|
||||
* down to 0. Divide a raw result by this in order to get the
|
||||
* percentage between 0 and 1. Used by DMA.
|
||||
*
|
||||
* @return the output scale factor
|
||||
*/
|
||||
unsigned int GetOutputScaleFactor() const;
|
||||
|
||||
/**
|
||||
* Get the FPGA index for the DutyCycle.
|
||||
*
|
||||
* @return the FPGA index
|
||||
*/
|
||||
int GetFPGAIndex() const;
|
||||
|
||||
/**
|
||||
* Get the channel of the source.
|
||||
*
|
||||
|
||||
@@ -103,11 +103,11 @@ class DutyCycleEncoder : public wpi::Sendable,
|
||||
DutyCycleEncoder& operator=(DutyCycleEncoder&&) = default;
|
||||
|
||||
/**
|
||||
* Get the frequency in Hz of the duty cycle signal from the encoder.
|
||||
* Get the frequency of the duty cycle signal from the encoder.
|
||||
*
|
||||
* @return duty cycle frequency in Hz
|
||||
* @return duty cycle frequency
|
||||
*/
|
||||
int GetFrequency() const;
|
||||
units::hertz_t GetFrequency() const;
|
||||
|
||||
/**
|
||||
* Get if the sensor is connected
|
||||
@@ -124,9 +124,9 @@ class DutyCycleEncoder : public wpi::Sendable,
|
||||
* Change the frequency threshold for detecting connection used by
|
||||
* IsConnected.
|
||||
*
|
||||
* @param frequency the minimum frequency in Hz.
|
||||
* @param frequency the minimum frequency.
|
||||
*/
|
||||
void SetConnectedFrequencyThreshold(int frequency);
|
||||
void SetConnectedFrequencyThreshold(units::hertz_t frequency);
|
||||
|
||||
/**
|
||||
* Get the encoder value.
|
||||
@@ -170,13 +170,6 @@ class DutyCycleEncoder : public wpi::Sendable,
|
||||
*/
|
||||
void SetInverted(bool inverted);
|
||||
|
||||
/**
|
||||
* Get the FPGA index for the DutyCycleEncoder.
|
||||
*
|
||||
* @return the FPGA index
|
||||
*/
|
||||
int GetFPGAIndex() const;
|
||||
|
||||
/**
|
||||
* Get the channel of the source.
|
||||
*
|
||||
@@ -191,7 +184,7 @@ class DutyCycleEncoder : public wpi::Sendable,
|
||||
double MapSensorRange(double pos) const;
|
||||
|
||||
std::shared_ptr<DutyCycle> m_dutyCycle;
|
||||
int m_frequencyThreshold = 100;
|
||||
units::hertz_t m_frequencyThreshold = {100_Hz};
|
||||
double m_fullRange;
|
||||
double m_expectedZero;
|
||||
units::second_t m_period{0_s};
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <units/frequency.h>
|
||||
|
||||
#include "frc/simulation/CallbackStore.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -27,23 +29,13 @@ class DutyCycleSim {
|
||||
explicit DutyCycleSim(const DutyCycle& dutyCycle);
|
||||
|
||||
/**
|
||||
* Creates a DutyCycleSim for a digital input channel.
|
||||
* Creates a DutyCycleSim for a SmartIO channel.
|
||||
*
|
||||
* @param channel digital input channel
|
||||
* @param channel SmartIO channel
|
||||
* @return Simulated object
|
||||
* @throws std::out_of_range if no DutyCycle is configured for that channel
|
||||
*/
|
||||
static DutyCycleSim CreateForChannel(int channel);
|
||||
|
||||
/**
|
||||
* Creates a DutyCycleSim for a simulated index.
|
||||
* The index is incremented for each simulated DutyCycle.
|
||||
*
|
||||
* @param index simulator index
|
||||
* @return Simulated object
|
||||
*/
|
||||
static DutyCycleSim CreateForIndex(int index);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when this duty cycle input is initialized.
|
||||
*
|
||||
@@ -85,14 +77,14 @@ class DutyCycleSim {
|
||||
*
|
||||
* @return the duty cycle frequency
|
||||
*/
|
||||
int GetFrequency() const;
|
||||
units::hertz_t GetFrequency() const;
|
||||
|
||||
/**
|
||||
* Change the duty cycle frequency.
|
||||
*
|
||||
* @param frequency the new frequency
|
||||
*/
|
||||
void SetFrequency(int frequency);
|
||||
void SetFrequency(units::hertz_t frequency);
|
||||
|
||||
/**
|
||||
* Register a callback to be run whenever the output changes.
|
||||
|
||||
Reference in New Issue
Block a user