WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Counter.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2016. 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 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include "HAL/HAL.hpp"
11 #include "AnalogTriggerOutput.h"
12 #include "CounterBase.h"
13 #include "SensorBase.h"
14 #include "LiveWindow/LiveWindowSendable.h"
15 
16 #include <memory>
17 
19 
31 class Counter : public SensorBase,
32  public CounterBase,
33  public LiveWindowSendable {
34  public:
35  explicit Counter(Mode mode = kTwoPulse);
36  explicit Counter(int32_t channel);
37  explicit Counter(DigitalSource *source);
38  explicit Counter(std::shared_ptr<DigitalSource> source);
39  DEPRECATED("Use pass-by-reference instead.")
40  explicit Counter(AnalogTrigger *trigger);
41  explicit Counter(const AnalogTrigger &trigger);
42  Counter(EncodingType encodingType, DigitalSource *upSource,
43  DigitalSource *downSource, bool inverted);
44  Counter(EncodingType encodingType, std::shared_ptr<DigitalSource> upSource,
45  std::shared_ptr<DigitalSource> downSource, bool inverted);
46  virtual ~Counter();
47 
48  void SetUpSource(int32_t channel);
49  void SetUpSource(AnalogTrigger *analogTrigger, AnalogTriggerType triggerType);
50  void SetUpSource(std::shared_ptr<AnalogTrigger> analogTrigger,
51  AnalogTriggerType triggerType);
52  void SetUpSource(DigitalSource *source);
53  void SetUpSource(std::shared_ptr<DigitalSource> source);
54  void SetUpSource(DigitalSource &source);
55  void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
56  void ClearUpSource();
57 
58  void SetDownSource(int32_t channel);
59  void SetDownSource(AnalogTrigger *analogTrigger,
60  AnalogTriggerType triggerType);
61  void SetDownSource(std::shared_ptr<AnalogTrigger> analogTrigger,
62  AnalogTriggerType triggerType);
63  void SetDownSource(DigitalSource *source);
64  void SetDownSource(std::shared_ptr<DigitalSource> source);
65  void SetDownSource(DigitalSource &source);
66  void SetDownSourceEdge(bool risingEdge, bool fallingEdge);
67  void ClearDownSource();
68 
69  void SetUpDownCounterMode();
71  void SetSemiPeriodMode(bool highSemiPeriod);
72  void SetPulseLengthMode(float threshold);
73 
74  void SetReverseDirection(bool reverseDirection);
75 
76  // CounterBase interface
77  int32_t Get() const override;
78  void Reset() override;
79  double GetPeriod() const override;
80  void SetMaxPeriod(double maxPeriod) override;
81  void SetUpdateWhenEmpty(bool enabled);
82  bool GetStopped() const override;
83  bool GetDirection() const override;
84 
85  void SetSamplesToAverage(int samplesToAverage);
86  int GetSamplesToAverage() const;
87  uint32_t GetFPGAIndex() const { return m_index; }
88 
89  void UpdateTable() override;
90  void StartLiveWindowMode() override;
91  void StopLiveWindowMode() override;
92  virtual std::string GetSmartDashboardType() const override;
93  void InitTable(std::shared_ptr<ITable> subTable) override;
94  std::shared_ptr<ITable> GetTable() const override;
95 
96  protected:
97  // Makes the counter count up.
98  std::shared_ptr<DigitalSource> m_upSource;
99  // Makes the counter count down.
100  std::shared_ptr<DigitalSource> m_downSource;
101  // The FPGA counter object
102  void *m_counter = nullptr;
103  private:
104  uint32_t m_index = 0;
105 
106  std::shared_ptr<ITable> m_table;
107  friend class DigitalGlitchFilter;
108 };
Definition: AnalogTrigger.h:16
bool GetStopped() const override
Determine if the clock is stopped.
Definition: Counter.cpp:539
void SetPulseLengthMode(float threshold)
Configure the counter to count in up or down based on the length of the input pulse.
Definition: Counter.cpp:402
void Reset() override
Reset the Counter to zero.
Definition: Counter.cpp:461
Class to enable glitch filtering on a set of digital inputs.
Definition: DigitalGlitchFilter.h:24
void * m_counter
The FPGA counter object.
Definition: Counter.h:102
void SetSemiPeriodMode(bool highSemiPeriod)
Set Semi-period mode on this counter.
Definition: Counter.cpp:388
DigitalSource Interface.
Definition: DigitalSource.h:22
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:18
void ClearUpSource()
Disable the up counting source to the counter.
Definition: Counter.cpp:260
void SetUpSource(int32_t channel)
Set the upsource for the counter as a digital input channel.
Definition: Counter.cpp:178
double GetPeriod() const override
Get the Period of the most recent count.
Definition: Counter.cpp:475
void SetMaxPeriod(double maxPeriod) override
Set the maximum period where the device is still considered "moving".
Definition: Counter.cpp:492
int GetSamplesToAverage() const
Get the Samples to Average which specifies the number of samples of the timer to average when calcula...
Definition: Counter.cpp:416
void InitTable(std::shared_ptr< ITable > subTable) override
Initializes a table for this sendable object.
Definition: Counter.cpp:585
void SetDownSourceEdge(bool risingEdge, bool fallingEdge)
Set the edge sensitivity on a down counting source.
Definition: Counter.cpp:338
virtual ~Counter()
Delete the Counter object.
Definition: Counter.cpp:164
virtual std::string GetSmartDashboardType() const override
Definition: Counter.cpp:583
void ClearDownSource()
Disable the down counting source to the counter.
Definition: Counter.cpp:353
Interface for counting the number of ticks on a digital input channel.
Definition: CounterBase.h:20
Base class for all sensors.
Definition: SensorBase.h:20
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: Counter.cpp:581
void SetUpdateWhenEmpty(bool enabled)
Select whether you want to continue updating the event timer output when there are no samples capture...
Definition: Counter.cpp:521
bool GetDirection() const override
The last direction the counter value changed.
Definition: Counter.cpp:551
void SetUpSourceEdge(bool risingEdge, bool fallingEdge)
Set the edge sensitivity on an up counting source.
Definition: Counter.cpp:245
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: Counter.cpp:579
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:430
void SetReverseDirection(bool reverseDirection)
Set the Counter to return reversed sensing on the direction.
Definition: Counter.cpp:566
Class for counting the number of ticks on a digital input channel.
Definition: Counter.h:31
void SetDownSource(int32_t channel)
Set the down counting source to be a digital input channel.
Definition: Counter.cpp:273
std::shared_ptr< ITable > GetTable() const override
Definition: Counter.cpp:590
Counter(Mode mode=kTwoPulse)
Create an instance of a counter where no sources are selected.
Definition: Counter.cpp:26
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: Counter.cpp:573
void SetUpDownCounterMode()
Set standard up / down counting mode on this counter.
Definition: Counter.cpp:365
void SetExternalDirectionMode()
Set external direction mode on this counter.
Definition: Counter.cpp:377
int32_t Get() const override
Read the current counter value.
Definition: Counter.cpp:447