WPILibC++  2020.3.2
AnalogInput.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2019 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/Sendable.h"
17 #include "frc/smartdashboard/SendableHelper.h"
18 
19 namespace frc {
20 
21 class SendableBuilder;
22 class DMA;
23 class DMASample;
24 
37 class AnalogInput : public ErrorBase,
38  public PIDSource,
39  public Sendable,
40  public SendableHelper<AnalogInput> {
41  friend class AnalogTrigger;
42  friend class AnalogGyro;
43  friend class DMA;
44  friend class DMASample;
45 
46  public:
47  static constexpr int kAccumulatorModuleNumber = 1;
48  static constexpr int kAccumulatorNumChannels = 2;
49  static constexpr int kAccumulatorChannels[kAccumulatorNumChannels] = {0, 1};
50 
57  explicit AnalogInput(int channel);
58 
59  ~AnalogInput() override;
60 
61  AnalogInput(AnalogInput&&) = default;
62  AnalogInput& operator=(AnalogInput&&) = default;
63 
73  int GetValue() const;
74 
91  int GetAverageValue() const;
92 
101  double GetVoltage() const;
102 
119  double GetAverageVoltage() const;
120 
126  int GetChannel() const;
127 
139  void SetAverageBits(int bits);
140 
150  int GetAverageBits() const;
151 
162  void SetOversampleBits(int bits);
163 
173  int GetOversampleBits() const;
174 
182  int GetLSBWeight() const;
183 
191  int GetOffset() const;
192 
198  bool IsAccumulatorChannel() const;
199 
203  void InitAccumulator();
204 
213  void SetAccumulatorInitialValue(int64_t value);
214 
218  void ResetAccumulator();
219 
231  void SetAccumulatorCenter(int center);
232 
236  void SetAccumulatorDeadband(int deadband);
237 
246  int64_t GetAccumulatorValue() const;
247 
256  int64_t GetAccumulatorCount() const;
257 
267  void GetAccumulatorOutput(int64_t& value, int64_t& count) const;
268 
277  static void SetSampleRate(double samplesPerSecond);
278 
284  static double GetSampleRate();
285 
291  double PIDGet() override;
292 
298  void SetSimDevice(HAL_SimDeviceHandle device);
299 
300  void InitSendable(SendableBuilder& builder) override;
301 
302  private:
303  int m_channel;
304  hal::Handle<HAL_AnalogInputHandle> m_port;
305  int64_t m_accumulatorOffset;
306 };
307 
308 } // namespace frc
frc::PIDSource
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:20
frc::AnalogInput::GetAverageValue
int GetAverageValue() const
Get a sample from the output of the oversample and average engine for this channel.
frc::DMA
Definition: DMA.h:22
frc::AnalogGyro
Use a rate gyro to return the robots heading relative to a starting position.
Definition: AnalogGyro.h:35
frc::AnalogInput::GetOffset
int GetOffset() const
Get the factory scaling offset constant.
frc::AnalogInput::GetLSBWeight
int GetLSBWeight() const
Get the factory scaling least significant bit weight constant.
frc::DMASample
Definition: DMASample.h:23
frc::AnalogInput::InitAccumulator
void InitAccumulator()
Initialize the accumulator.
frc::AnalogInput::GetAccumulatorOutput
void GetAccumulatorOutput(int64_t &value, int64_t &count) const
Read the accumulated value and the number of accumulated values atomically.
frc::AnalogTrigger
Definition: AnalogTrigger.h:25
frc::AnalogInput::PIDGet
double PIDGet() override
Get the Average value for the PID Source base object.
frc::AnalogInput::GetOversampleBits
int GetOversampleBits() const
Get the number of oversample bits previously configured.
frc::AnalogInput::GetAverageVoltage
double GetAverageVoltage() const
Get a scaled sample from the output of the oversample and average engine for this channel.
frc::AnalogInput::SetOversampleBits
void SetOversampleBits(int bits)
Set the number of oversample bits.
frc::ErrorBase
Base class for most objects.
Definition: ErrorBase.h:104
frc::AnalogInput::GetChannel
int GetChannel() const
Get the channel number.
frc::AnalogInput::GetValue
int GetValue() const
Get a sample straight from this channel.
frc::AnalogInput::GetAccumulatorValue
int64_t GetAccumulatorValue() const
Read the accumulated value.
frc::AnalogInput::GetAccumulatorCount
int64_t GetAccumulatorCount() const
Read the number of accumulated values.
frc::AnalogInput::SetAccumulatorCenter
void SetAccumulatorCenter(int center)
Set the center value of the accumulator.
frc::AnalogInput::SetAverageBits
void SetAverageBits(int bits)
Set the number of averaging bits.
frc::Sendable
Interface for Sendable objects.
Definition: Sendable.h:17
frc::AnalogInput::SetSampleRate
static void SetSampleRate(double samplesPerSecond)
Set the sample rate per channel for all analog channels.
frc::AnalogInput::IsAccumulatorChannel
bool IsAccumulatorChannel() const
Is the channel attached to an accumulator.
frc::AnalogInput
Analog input class.
Definition: AnalogInput.h:37
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
frc::AnalogInput::ResetAccumulator
void ResetAccumulator()
Resets the accumulator to the initial value.
frc::AnalogInput::SetAccumulatorInitialValue
void SetAccumulatorInitialValue(int64_t value)
Set an initial value for the accumulator.
frc::AnalogInput::GetVoltage
double GetVoltage() const
Get a scaled sample straight from this channel.
frc::AnalogInput::GetAverageBits
int GetAverageBits() const
Get the number of averaging bits previously configured.
frc::AnalogInput::AnalogInput
AnalogInput(int channel)
Construct an analog input.
frc::SendableHelper
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:28
frc::AnalogInput::SetAccumulatorDeadband
void SetAccumulatorDeadband(int deadband)
Set the accumulator's deadband.
frc::SendableBuilder
Definition: SendableBuilder.h:23
frc::AnalogInput::InitSendable
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
frc::AnalogInput::SetSimDevice
void SetSimDevice(HAL_SimDeviceHandle device)
Indicates this input is used by a simulated device.
frc::AnalogInput::GetSampleRate
static double GetSampleRate()
Get the current sample rate for all channels.