WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2017. 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 /*----------------------------------------------------------------------------*/
8 #pragma once
10 #include <memory>
11 #include <string>
13 #include "HAL/Types.h"
14 #include "LiveWindow/LiveWindowSendable.h"
15 #include "PIDSource.h"
16 #include "SensorBase.h"
18 namespace frc {
32 class AnalogInput : public SensorBase,
33  public PIDSource,
34  public LiveWindowSendable {
35  friend class AnalogTrigger;
36  friend class AnalogGyro;
38  public:
39  static const int kAccumulatorModuleNumber = 1;
40  static const int kAccumulatorNumChannels = 2;
41  static const int kAccumulatorChannels[kAccumulatorNumChannels];
43  explicit AnalogInput(int channel);
44  virtual ~AnalogInput();
46  int GetValue() const;
47  int GetAverageValue() const;
49  double GetVoltage() const;
50  double GetAverageVoltage() const;
52  int GetChannel() const;
54  void SetAverageBits(int bits);
55  int GetAverageBits() const;
56  void SetOversampleBits(int bits);
57  int GetOversampleBits() const;
59  int GetLSBWeight() const;
60  int GetOffset() const;
62  bool IsAccumulatorChannel() const;
63  void InitAccumulator();
64  void SetAccumulatorInitialValue(int64_t value);
65  void ResetAccumulator();
66  void SetAccumulatorCenter(int center);
67  void SetAccumulatorDeadband(int deadband);
68  int64_t GetAccumulatorValue() const;
69  int64_t GetAccumulatorCount() const;
70  void GetAccumulatorOutput(int64_t& value, int64_t& count) const;
72  static void SetSampleRate(double samplesPerSecond);
73  static double GetSampleRate();
75  double PIDGet() override;
77  void UpdateTable() override;
78  void StartLiveWindowMode() override;
79  void StopLiveWindowMode() override;
80  std::string GetSmartDashboardType() const override;
81  void InitTable(std::shared_ptr<ITable> subTable) override;
82  std::shared_ptr<ITable> GetTable() const override;
84  private:
85  int m_channel;
86  // TODO: Adjust HAL to avoid use of raw pointers.
87  HAL_AnalogInputHandle m_port;
88  int64_t m_accumulatorOffset;
90  std::shared_ptr<ITable> m_table;
91 };
93 } // namespace frc
std::string GetSmartDashboardType() const override
Definition: AnalogInput.cpp:429
void SetOversampleBits(int bits)
Set the number of oversample bits.
Definition: AnalogInput.cpp:226
static double GetSampleRate()
Get the current sample rate for all channels.
Definition: AnalogInput.cpp:402
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:165
double GetAverageVoltage() const
Get a scaled sample from the output of the oversample and average engine for this channel...
Definition: AnalogInput.cpp:135
Base class for all sensors.
Definition: SensorBase.h:22
int GetLSBWeight() const
Get the factory scaling least significant bit weight constant.
Definition: AnalogInput.cpp:150
void SetAccumulatorCenter(int center)
Set the center value of the accumulator.
Definition: AnalogInput.cpp:317
int GetOversampleBits() const
Get the number of oversample bits previously configured.
Definition: AnalogInput.cpp:242
double GetVoltage() const
Get a scaled sample straight from this channel.
Definition: AnalogInput.cpp:113
void SetAccumulatorInitialValue(int64_t value)
Set an initial value for the accumulator.
Definition: AnalogInput.cpp:282
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:97
AnalogInput(int channel)
Construct an analog input.
Definition: AnalogInput.cpp:32
int GetAverageBits() const
Get the number of averaging bits previously configured.
Definition: AnalogInput.cpp:209
static void SetSampleRate(double samplesPerSecond)
Set the sample rate per channel for all analog channels.
Definition: AnalogInput.cpp:391
int64_t GetAccumulatorValue() const
Read the accumulated value.
Definition: AnalogInput.cpp:342
int64_t GetAccumulatorCount() const
Read the number of accumulated values.
Definition: AnalogInput.cpp:358
int GetChannel() const
Get the channel number.
Definition: AnalogInput.cpp:178
int GetValue() const
Get a sample straight from this channel.
Definition: AnalogInput.cpp:75
Use a rate gyro to return the robots heading relative to a starting position.
Definition: AnalogGyro.h:32
virtual ~AnalogInput()
Channel destructor.
Definition: AnalogInput.cpp:61
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: AnalogInput.cpp:419
Definition: AnalogTrigger.h:20
void ResetAccumulator()
Resets the accumulator to the initial value.
Definition: AnalogInput.cpp:290
bool IsAccumulatorChannel() const
Is the channel attached to an accumulator.
Definition: AnalogInput.cpp:255
std::shared_ptr< ITable > GetTable() const override
Definition: AnalogInput.cpp:438
void SetAccumulatorDeadband(int deadband)
Set the accumulator's deadband.
Definition: AnalogInput.cpp:327
void InitAccumulator()
Initialize the accumulator.
Definition: AnalogInput.cpp:266
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: AnalogInput.cpp:427
void InitTable(std::shared_ptr< ITable > subTable) override
Initializes a table for this sendable object.
Definition: AnalogInput.cpp:433
void GetAccumulatorOutput(int64_t &value, int64_t &count) const
Read the accumulated value and the number of accumulated values atomically.
Definition: AnalogInput.cpp:375
void SetAverageBits(int bits)
Set the number of averaging bits.
Definition: AnalogInput.cpp:194
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:32
double PIDGet() override
Get the Average value for the PID Source base object.
Definition: AnalogInput.cpp:414