WPILibC++  2018.4.1-20180816013227-1153-g1462a5b
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
AnalogInput.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2018 FIRST. 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 <hal/Types.h>
13 
14 #include "frc/ErrorBase.h"
15 #include "frc/PIDSource.h"
16 #include "frc/smartdashboard/SendableBase.h"
17 
18 namespace frc {
19 
32 class AnalogInput : public ErrorBase, public SendableBase, public PIDSource {
33  friend class AnalogTrigger;
34  friend class AnalogGyro;
35 
36  public:
37  static constexpr int kAccumulatorModuleNumber = 1;
38  static constexpr int kAccumulatorNumChannels = 2;
39  static constexpr int kAccumulatorChannels[kAccumulatorNumChannels] = {0, 1};
40 
47  explicit AnalogInput(int channel);
48 
49  ~AnalogInput() override;
50 
60  int GetValue() const;
61 
78  int GetAverageValue() const;
79 
88  double GetVoltage() const;
89 
106  double GetAverageVoltage() const;
107 
113  int GetChannel() const;
114 
126  void SetAverageBits(int bits);
127 
137  int GetAverageBits() const;
138 
149  void SetOversampleBits(int bits);
150 
160  int GetOversampleBits() const;
161 
169  int GetLSBWeight() const;
170 
178  int GetOffset() const;
179 
185  bool IsAccumulatorChannel() const;
186 
190  void InitAccumulator();
191 
200  void SetAccumulatorInitialValue(int64_t value);
201 
205  void ResetAccumulator();
206 
218  void SetAccumulatorCenter(int center);
219 
223  void SetAccumulatorDeadband(int deadband);
224 
233  int64_t GetAccumulatorValue() const;
234 
243  int64_t GetAccumulatorCount() const;
244 
254  void GetAccumulatorOutput(int64_t& value, int64_t& count) const;
255 
264  static void SetSampleRate(double samplesPerSecond);
265 
271  static double GetSampleRate();
272 
278  double PIDGet() override;
279 
280  void InitSendable(SendableBuilder& builder) override;
281 
282  private:
283  int m_channel;
284  // TODO: Adjust HAL to avoid use of raw pointers.
285  HAL_AnalogInputHandle m_port;
286  int64_t m_accumulatorOffset;
287 };
288 
289 } // namespace frc
int GetAverageBits() const
Get the number of averaging bits previously configured.
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
void SetAverageBits(int bits)
Set the number of averaging bits.
void InitAccumulator()
Initialize the accumulator.
double PIDGet() override
Get the Average value for the PID Source base object.
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:20
int GetChannel() const
Get the channel number.
int GetOffset() const
Get the factory scaling offset constant.
void SetAccumulatorInitialValue(int64_t value)
Set an initial value for the accumulator.
static void SetSampleRate(double samplesPerSecond)
Set the sample rate per channel for all analog channels.
bool IsAccumulatorChannel() const
Is the channel attached to an accumulator.
double GetVoltage() const
Get a scaled sample straight from this channel.
void GetAccumulatorOutput(int64_t &value, int64_t &count) const
Read the accumulated value and the number of accumulated values atomically.
int GetValue() const
Get a sample straight from this channel.
void SetAccumulatorDeadband(int deadband)
Set the accumulator's deadband.
void SetAccumulatorCenter(int center)
Set the center value of the accumulator.
static double GetSampleRate()
Get the current sample rate for all channels.
Use a rate gyro to return the robots heading relative to a starting position.
Definition: AnalogGyro.h:33
int64_t GetAccumulatorValue() const
Read the accumulated value.
int GetOversampleBits() const
Get the number of oversample bits previously configured.
Base class for most objects.
Definition: ErrorBase.h:74
void ResetAccumulator()
Resets the accumulator to the initial value.
Definition: SendableBase.h:19
Definition: AnalogTrigger.h:22
Definition: SendableBuilder.h:23
AnalogInput(int channel)
Construct an analog input.
double GetAverageVoltage() const
Get a scaled sample from the output of the oversample and average engine for this channel...
int64_t GetAccumulatorCount() const
Read the number of accumulated values.
Analog input class.
Definition: AnalogInput.h:32
int GetAverageValue() const
Get a sample from the output of the oversample and average engine for this channel.
void SetOversampleBits(int bits)
Set the number of oversample bits.
int GetLSBWeight() const
Get the factory scaling least significant bit weight constant.