WPILibC++  2019.1.1-beta-2-30-g0d0492b
 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 
51  AnalogInput(AnalogInput&& rhs);
52  AnalogInput& operator=(AnalogInput&& rhs);
53 
63  int GetValue() const;
64 
81  int GetAverageValue() const;
82 
91  double GetVoltage() const;
92 
109  double GetAverageVoltage() const;
110 
116  int GetChannel() const;
117 
129  void SetAverageBits(int bits);
130 
140  int GetAverageBits() const;
141 
152  void SetOversampleBits(int bits);
153 
163  int GetOversampleBits() const;
164 
172  int GetLSBWeight() const;
173 
181  int GetOffset() const;
182 
188  bool IsAccumulatorChannel() const;
189 
193  void InitAccumulator();
194 
203  void SetAccumulatorInitialValue(int64_t value);
204 
208  void ResetAccumulator();
209 
221  void SetAccumulatorCenter(int center);
222 
226  void SetAccumulatorDeadband(int deadband);
227 
236  int64_t GetAccumulatorValue() const;
237 
246  int64_t GetAccumulatorCount() const;
247 
257  void GetAccumulatorOutput(int64_t& value, int64_t& count) const;
258 
267  static void SetSampleRate(double samplesPerSecond);
268 
274  static double GetSampleRate();
275 
281  double PIDGet() override;
282 
283  void InitSendable(SendableBuilder& builder) override;
284 
285  private:
286  int m_channel;
287  HAL_AnalogInputHandle m_port = HAL_kInvalidHandle;
288  int64_t m_accumulatorOffset;
289 };
290 
291 } // 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.