WPILibC++  unspecified
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 "ErrorBase.h"
15 #include "PIDSource.h"
16 #include "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
void SetOversampleBits(int bits)
Set the number of oversample bits.
Definition: AnalogInput.cpp:102
Definition: Utility.cpp:119
static double GetSampleRate()
Get the current sample rate for all channels.
Definition: AnalogInput.cpp:214
int GetOffset() const
Get the factory scaling offset constant.
Definition: AnalogInput.cpp:125
double GetAverageVoltage() const
Get a scaled sample from the output of the oversample and average engine for this channel...
Definition: AnalogInput.cpp:75
int GetLSBWeight() const
Get the factory scaling least significant bit weight constant.
Definition: AnalogInput.cpp:117
void SetAccumulatorCenter(int center)
Set the center value of the accumulator.
Definition: AnalogInput.cpp:170
int GetOversampleBits() const
Get the number of oversample bits previously configured.
Definition: AnalogInput.cpp:109
double GetVoltage() const
Get a scaled sample straight from this channel.
Definition: AnalogInput.cpp:67
void SetAccumulatorInitialValue(int64_t value)
Set an initial value for the accumulator.
Definition: AnalogInput.cpp:149
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:20
int GetAverageValue() const
Get a sample from the output of the oversample and average engine for this channel.
Definition: AnalogInput.cpp:59
AnalogInput(int channel)
Construct an analog input.
Definition: AnalogInput.cpp:22
int GetAverageBits() const
Get the number of averaging bits previously configured.
Definition: AnalogInput.cpp:95
static void SetSampleRate(double samplesPerSecond)
Set the sample rate per channel for all analog channels.
Definition: AnalogInput.cpp:208
int64_t GetAccumulatorValue() const
Read the accumulated value.
Definition: AnalogInput.cpp:184
int64_t GetAccumulatorCount() const
Read the number of accumulated values.
Definition: AnalogInput.cpp:192
int GetChannel() const
Get the channel number.
Definition: AnalogInput.cpp:83
int GetValue() const
Get a sample straight from this channel.
Definition: AnalogInput.cpp:51
Use a rate gyro to return the robots heading relative to a starting position.
Definition: AnalogGyro.h:33
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
Definition: AnalogInput.cpp:226
Base class for most objects.
Definition: ErrorBase.h:74
Definition: SendableBase.h:19
Definition: AnalogTrigger.h:22
void ResetAccumulator()
Resets the accumulator to the initial value.
Definition: AnalogInput.cpp:154
bool IsAccumulatorChannel() const
Is the channel attached to an accumulator.
Definition: AnalogInput.cpp:133
Definition: SendableBuilder.h:23
void SetAccumulatorDeadband(int deadband)
Set the accumulator&#39;s deadband.
Definition: AnalogInput.cpp:177
void InitAccumulator()
Initialize the accumulator.
Definition: AnalogInput.cpp:141
void GetAccumulatorOutput(int64_t &value, int64_t &count) const
Read the accumulated value and the number of accumulated values atomically.
Definition: AnalogInput.cpp:200
void SetAverageBits(int bits)
Set the number of averaging bits.
Definition: AnalogInput.cpp:88
Analog input class.
Definition: AnalogInput.h:32
double PIDGet() override
Get the Average value for the PID Source base object.
Definition: AnalogInput.cpp:221