WPILibC++  unspecified
AnalogInput.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2017 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 <memory>
13 #include <string>
14 
15 #include <HAL/Types.h>
16 
17 #include "LiveWindow/LiveWindowSendable.h"
18 #include "PIDSource.h"
19 #include "SensorBase.h"
20 #include "networktables/NetworkTableEntry.h"
21 
22 namespace frc {
23 
36 class AnalogInput : public SensorBase,
37  public PIDSource,
38  public LiveWindowSendable {
39  friend class AnalogTrigger;
40  friend class AnalogGyro;
41 
42  public:
43  static const int kAccumulatorModuleNumber = 1;
44  static const int kAccumulatorNumChannels = 2;
45  static const int kAccumulatorChannels[kAccumulatorNumChannels];
46 
47  explicit AnalogInput(int channel);
48  virtual ~AnalogInput();
49 
50  int GetValue() const;
51  int GetAverageValue() const;
52 
53  double GetVoltage() const;
54  double GetAverageVoltage() const;
55 
56  int GetChannel() const;
57 
58  void SetAverageBits(int bits);
59  int GetAverageBits() const;
60  void SetOversampleBits(int bits);
61  int GetOversampleBits() const;
62 
63  int GetLSBWeight() const;
64  int GetOffset() const;
65 
66  bool IsAccumulatorChannel() const;
67  void InitAccumulator();
68  void SetAccumulatorInitialValue(int64_t value);
69  void ResetAccumulator();
70  void SetAccumulatorCenter(int center);
71  void SetAccumulatorDeadband(int deadband);
72  int64_t GetAccumulatorValue() const;
73  int64_t GetAccumulatorCount() const;
74  void GetAccumulatorOutput(int64_t& value, int64_t& count) const;
75 
76  static void SetSampleRate(double samplesPerSecond);
77  static double GetSampleRate();
78 
79  double PIDGet() override;
80 
81  void UpdateTable() override;
82  void StartLiveWindowMode() override;
83  void StopLiveWindowMode() override;
84  std::string GetSmartDashboardType() const override;
85  void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
86 
87  private:
88  int m_channel;
89  // TODO: Adjust HAL to avoid use of raw pointers.
90  HAL_AnalogInputHandle m_port;
91  int64_t m_accumulatorOffset;
92 
93  nt::NetworkTableEntry m_valueEntry;
94 };
95 
96 } // namespace frc
std::string GetSmartDashboardType() const override
Definition: AnalogInput.cpp:429
void SetOversampleBits(int bits)
Set the number of oversample bits.
Definition: AnalogInput.cpp:228
Definition: Timer.cpp:18
static double GetSampleRate()
Get the current sample rate for all channels.
Definition: AnalogInput.cpp:404
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:167
double GetAverageVoltage() const
Get a scaled sample from the output of the oversample and average engine for this channel...
Definition: AnalogInput.cpp:137
Base class for all sensors.
Definition: SensorBase.h:20
int GetLSBWeight() const
Get the factory scaling least significant bit weight constant.
Definition: AnalogInput.cpp:152
void SetAccumulatorCenter(int center)
Set the center value of the accumulator.
Definition: AnalogInput.cpp:319
int GetOversampleBits() const
Get the number of oversample bits previously configured.
Definition: AnalogInput.cpp:244
double GetVoltage() const
Get a scaled sample straight from this channel.
Definition: AnalogInput.cpp:115
void SetAccumulatorInitialValue(int64_t value)
Set an initial value for the accumulator.
Definition: AnalogInput.cpp:284
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:99
AnalogInput(int channel)
Construct an analog input.
Definition: AnalogInput.cpp:33
int GetAverageBits() const
Get the number of averaging bits previously configured.
Definition: AnalogInput.cpp:211
static void SetSampleRate(double samplesPerSecond)
Set the sample rate per channel for all analog channels.
Definition: AnalogInput.cpp:393
int64_t GetAccumulatorValue() const
Read the accumulated value.
Definition: AnalogInput.cpp:344
int64_t GetAccumulatorCount() const
Read the number of accumulated values.
Definition: AnalogInput.cpp:360
int GetChannel() const
Get the channel number.
Definition: AnalogInput.cpp:180
int GetValue() const
Get a sample straight from this channel.
Definition: AnalogInput.cpp:77
Use a rate gyro to return the robots heading relative to a starting position.
Definition: AnalogGyro.h:33
virtual ~AnalogInput()
Channel destructor.
Definition: AnalogInput.cpp:63
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: AnalogInput.cpp:421
Definition: AnalogTrigger.h:21
void ResetAccumulator()
Resets the accumulator to the initial value.
Definition: AnalogInput.cpp:292
bool IsAccumulatorChannel() const
Is the channel attached to an accumulator.
Definition: AnalogInput.cpp:257
void InitTable(std::shared_ptr< nt::NetworkTable > subTable) override
Initializes a table for this sendable object.
Definition: AnalogInput.cpp:433
NetworkTables Entry.
Definition: NetworkTableEntry.h:30
void SetAccumulatorDeadband(int deadband)
Set the accumulator&#39;s deadband.
Definition: AnalogInput.cpp:329
void InitAccumulator()
Initialize the accumulator.
Definition: AnalogInput.cpp:268
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: AnalogInput.cpp:427
void GetAccumulatorOutput(int64_t &value, int64_t &count) const
Read the accumulated value and the number of accumulated values atomically.
Definition: AnalogInput.cpp:377
void SetAverageBits(int bits)
Set the number of averaging bits.
Definition: AnalogInput.cpp:196
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: AnalogInput.cpp:425
Analog input class.
Definition: AnalogInput.h:36
double PIDGet() override
Get the Average value for the PID Source base object.
Definition: AnalogInput.cpp:416