WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2017. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
8 #pragma once
10 #include <memory>
11 #include <string>
13 #include "AnalogTrigger.h"
14 #include "CounterBase.h"
15 #include "HAL/Counter.h"
16 #include "HAL/Types.h"
17 #include "LiveWindow/LiveWindowSendable.h"
18 #include "SensorBase.h"
20 namespace frc {
33 class Counter : public SensorBase,
34  public CounterBase,
35  public LiveWindowSendable {
36  public:
37  enum Mode {
38  kTwoPulse = 0,
39  kSemiperiod = 1,
40  kPulseLength = 2,
41  kExternalDirection = 3
42  };
43  explicit Counter(Mode mode = kTwoPulse);
44  explicit Counter(int channel);
45  explicit Counter(DigitalSource* source);
46  explicit Counter(std::shared_ptr<DigitalSource> source);
47  WPI_DEPRECATED("Use pass-by-reference instead.")
48  explicit Counter(AnalogTrigger* trigger);
49  explicit Counter(const AnalogTrigger& trigger);
50  Counter(EncodingType encodingType, DigitalSource* upSource,
51  DigitalSource* downSource, bool inverted);
52  Counter(EncodingType encodingType, std::shared_ptr<DigitalSource> upSource,
53  std::shared_ptr<DigitalSource> downSource, bool inverted);
54  virtual ~Counter();
56  void SetUpSource(int channel);
57  void SetUpSource(AnalogTrigger* analogTrigger, AnalogTriggerType triggerType);
58  void SetUpSource(std::shared_ptr<AnalogTrigger> analogTrigger,
59  AnalogTriggerType triggerType);
60  void SetUpSource(DigitalSource* source);
61  void SetUpSource(std::shared_ptr<DigitalSource> source);
62  void SetUpSource(DigitalSource& source);
63  void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
64  void ClearUpSource();
66  void SetDownSource(int channel);
67  void SetDownSource(AnalogTrigger* analogTrigger,
68  AnalogTriggerType triggerType);
69  void SetDownSource(std::shared_ptr<AnalogTrigger> analogTrigger,
70  AnalogTriggerType triggerType);
71  void SetDownSource(DigitalSource* source);
72  void SetDownSource(std::shared_ptr<DigitalSource> source);
73  void SetDownSource(DigitalSource& source);
74  void SetDownSourceEdge(bool risingEdge, bool fallingEdge);
75  void ClearDownSource();
77  void SetUpDownCounterMode();
79  void SetSemiPeriodMode(bool highSemiPeriod);
80  void SetPulseLengthMode(double threshold);
82  void SetReverseDirection(bool reverseDirection);
84  // CounterBase interface
85  int Get() const override;
86  void Reset() override;
87  double GetPeriod() const override;
88  void SetMaxPeriod(double maxPeriod) override;
89  void SetUpdateWhenEmpty(bool enabled);
90  bool GetStopped() const override;
91  bool GetDirection() const override;
93  void SetSamplesToAverage(int samplesToAverage);
94  int GetSamplesToAverage() const;
95  int GetFPGAIndex() const { return m_index; }
97  void UpdateTable() override;
98  void StartLiveWindowMode() override;
99  void StopLiveWindowMode() override;
100  std::string GetSmartDashboardType() const override;
101  void InitTable(std::shared_ptr<ITable> subTable) override;
102  std::shared_ptr<ITable> GetTable() const override;
104  protected:
105  // Makes the counter count up.
106  std::shared_ptr<DigitalSource> m_upSource;
107  // Makes the counter count down.
108  std::shared_ptr<DigitalSource> m_downSource;
109  // The FPGA counter object
110  HAL_CounterHandle m_counter = HAL_kInvalidHandle;
112  private:
113  int m_index = 0;
115  std::shared_ptr<ITable> m_table;
116  friend class DigitalGlitchFilter;
117 };
119 } // namespace frc
int Get() const override
Read the current counter value.
Definition: Counter.cpp:496
void ClearDownSource()
Disable the down counting source to the counter.
Definition: Counter.cpp:395
void SetDownSourceEdge(bool risingEdge, bool fallingEdge)
Set the edge sensitivity on a down counting source.
Definition: Counter.cpp:380
Counter(Mode mode=kTwoPulse)
Create an instance of a counter where no sources are selected.
Definition: Counter.cpp:30
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:17
Base class for all sensors.
Definition: SensorBase.h:22
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: Counter.cpp:620
bool GetDirection() const override
The last direction the counter value changed.
Definition: Counter.cpp:597
Class to enable glitch filtering on a set of digital inputs.
Definition: DigitalGlitchFilter.h:26
void Reset() override
Reset the Counter to zero.
Definition: Counter.cpp:510
std::string GetSmartDashboardType() const override
Definition: Counter.cpp:630
Interface for counting the number of ticks on a digital input channel.
Definition: CounterBase.h:22
void SetUpSourceEdge(bool risingEdge, bool fallingEdge)
Set the edge sensitivity on an up counting source.
Definition: Counter.cpp:272
Class for counting the number of ticks on a digital input channel.
Definition: Counter.h:33
void SetExternalDirectionMode()
Set external direction mode on this counter.
Definition: Counter.cpp:421
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: Counter.cpp:628
void SetDownSource(int channel)
Set the down counting source to be a digital input channel.
Definition: Counter.cpp:301
void SetUpdateWhenEmpty(bool enabled)
Select whether you want to continue updating the event timer output when there are no samples capture...
Definition: Counter.cpp:567
DigitalSource Interface.
Definition: DigitalSource.h:25
virtual ~Counter()
Delete the Counter object.
Definition: Counter.cpp:180
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: Counter.cpp:626
void SetPulseLengthMode(double threshold)
Configure the counter to count in up or down based on the length of the input pulse.
Definition: Counter.cpp:449
Definition: AnalogTrigger.h:20
void SetSamplesToAverage(int samplesToAverage)
Set the Samples to Average which specifies the number of samples of the timer to average when calcula...
Definition: Counter.cpp:479
void SetUpDownCounterMode()
Set standard up / down counting mode on this counter.
Definition: Counter.cpp:408
std::shared_ptr< ITable > GetTable() const override
Definition: Counter.cpp:637
double GetPeriod() const override
Get the Period of the most recent count.
Definition: Counter.cpp:525
void SetReverseDirection(bool reverseDirection)
Set the Counter to return reversed sensing on the direction.
Definition: Counter.cpp:613
void InitTable(std::shared_ptr< ITable > subTable) override
Initializes a table for this sendable object.
Definition: Counter.cpp:632
void SetUpSource(int channel)
Set the upsource for the counter as a digital input channel.
Definition: Counter.cpp:195
bool GetStopped() const override
Determine if the clock is stopped.
Definition: Counter.cpp:584
void SetMaxPeriod(double maxPeriod) override
Set the maximum period where the device is still considered "moving".
Definition: Counter.cpp:543
int GetSamplesToAverage() const
Get the Samples to Average which specifies the number of samples of the timer to average when calcula...
Definition: Counter.cpp:465
void SetSemiPeriodMode(bool highSemiPeriod)
Set Semi-period mode on this counter.
Definition: Counter.cpp:433
void ClearUpSource()
Disable the up counting source to the counter.
Definition: Counter.cpp:287