WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
AnalogInput.h
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 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <stdint.h>
11 
12 #include <memory>
13 #include <string>
14 
15 #include "HAL/Types.h"
16 #include "LiveWindow/LiveWindowSendable.h"
17 #include "PIDSource.h"
18 #include "SensorBase.h"
19 
20 namespace frc {
21 
34 class AnalogInput : public SensorBase,
35  public PIDSource,
36  public LiveWindowSendable {
37  friend class AnalogTrigger;
38  friend class AnalogGyro;
39 
40  public:
41  static const int kAccumulatorModuleNumber = 1;
42  static const int kAccumulatorNumChannels = 2;
43  static const int kAccumulatorChannels[kAccumulatorNumChannels];
44 
45  explicit AnalogInput(int channel);
46  virtual ~AnalogInput();
47 
48  int GetValue() const;
49  int GetAverageValue() const;
50 
51  double GetVoltage() const;
52  double GetAverageVoltage() const;
53 
54  int GetChannel() const;
55 
56  void SetAverageBits(int bits);
57  int GetAverageBits() const;
58  void SetOversampleBits(int bits);
59  int GetOversampleBits() const;
60 
61  int GetLSBWeight() const;
62  int GetOffset() const;
63 
64  bool IsAccumulatorChannel() const;
65  void InitAccumulator();
66  void SetAccumulatorInitialValue(int64_t value);
67  void ResetAccumulator();
68  void SetAccumulatorCenter(int center);
69  void SetAccumulatorDeadband(int deadband);
70  int64_t GetAccumulatorValue() const;
71  int64_t GetAccumulatorCount() const;
72  void GetAccumulatorOutput(int64_t& value, int64_t& count) const;
73 
74  static void SetSampleRate(double samplesPerSecond);
75  static double GetSampleRate();
76 
77  double PIDGet() override;
78 
79  void UpdateTable() override;
80  void StartLiveWindowMode() override;
81  void StopLiveWindowMode() override;
82  std::string GetSmartDashboardType() const override;
83  void InitTable(std::shared_ptr<ITable> subTable) override;
84  std::shared_ptr<ITable> GetTable() const override;
85 
86  private:
87  int m_channel;
88  // TODO: Adjust HAL to avoid use of raw pointers.
89  HAL_AnalogInputHandle m_port;
90  int64_t m_accumulatorOffset;
91 
92  std::shared_ptr<ITable> m_table;
93 };
94 
95 } // namespace frc
std::string GetSmartDashboardType() const override
Definition: AnalogInput.cpp:430
void SetOversampleBits(int bits)
Set the number of oversample bits.
Definition: AnalogInput.cpp:227
static double GetSampleRate()
Get the current sample rate for all channels.
Definition: AnalogInput.cpp:403
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:17
int GetOffset() const
Get the factory scaling offset constant.
Definition: AnalogInput.cpp:166
double GetAverageVoltage() const
Get a scaled sample from the output of the oversample and average engine for this channel...
Definition: AnalogInput.cpp:136
Base class for all sensors.
Definition: SensorBase.h:20
int GetLSBWeight() const
Get the factory scaling least significant bit weight constant.
Definition: AnalogInput.cpp:151
void SetAccumulatorCenter(int center)
Set the center value of the accumulator.
Definition: AnalogInput.cpp:318
int GetOversampleBits() const
Get the number of oversample bits previously configured.
Definition: AnalogInput.cpp:243
double GetVoltage() const
Get a scaled sample straight from this channel.
Definition: AnalogInput.cpp:114
void SetAccumulatorInitialValue(int64_t value)
Set an initial value for the accumulator.
Definition: AnalogInput.cpp:283
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:19
int GetAverageValue() const
Get a sample from the output of the oversample and average engine for this channel.
Definition: AnalogInput.cpp:98
AnalogInput(int channel)
Construct an analog input.
Definition: AnalogInput.cpp:32
int GetAverageBits() const
Get the number of averaging bits previously configured.
Definition: AnalogInput.cpp:210
static void SetSampleRate(double samplesPerSecond)
Set the sample rate per channel for all analog channels.
Definition: AnalogInput.cpp:392
int64_t GetAccumulatorValue() const
Read the accumulated value.
Definition: AnalogInput.cpp:343
int64_t GetAccumulatorCount() const
Read the number of accumulated values.
Definition: AnalogInput.cpp:359
int GetChannel() const
Get the channel number.
Definition: AnalogInput.cpp:179
int GetValue() const
Get a sample straight from this channel.
Definition: AnalogInput.cpp:76
Use a rate gyro to return the robots heading relative to a starting position.
Definition: AnalogGyro.h:32
virtual ~AnalogInput()
Channel destructor.
Definition: AnalogInput.cpp:62
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: AnalogInput.cpp:420
Definition: AnalogTrigger.h:20
void ResetAccumulator()
Resets the accumulator to the initial value.
Definition: AnalogInput.cpp:291
bool IsAccumulatorChannel() const
Is the channel attached to an accumulator.
Definition: AnalogInput.cpp:256
std::shared_ptr< ITable > GetTable() const override
Definition: AnalogInput.cpp:439
void SetAccumulatorDeadband(int deadband)
Set the accumulator's deadband.
Definition: AnalogInput.cpp:328
void InitAccumulator()
Initialize the accumulator.
Definition: AnalogInput.cpp:267
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: AnalogInput.cpp:428
void InitTable(std::shared_ptr< ITable > subTable) override
Initializes a table for this sendable object.
Definition: AnalogInput.cpp:434
void GetAccumulatorOutput(int64_t &value, int64_t &count) const
Read the accumulated value and the number of accumulated values atomically.
Definition: AnalogInput.cpp:376
void SetAverageBits(int bits)
Set the number of averaging bits.
Definition: AnalogInput.cpp:195
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: AnalogInput.cpp:426
Analog input class.
Definition: AnalogInput.h:34
double PIDGet() override
Get the Average value for the PID Source base object.
Definition: AnalogInput.cpp:415