WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
AnalogInput.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2016. 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 "HAL/HAL.hpp"
11 #include "SensorBase.h"
12 #include "PIDSource.h"
13 #include "LiveWindow/LiveWindowSendable.h"
14 
15 #include <memory>
16 
32 class AnalogInput : public SensorBase,
33  public PIDSource,
34  public LiveWindowSendable {
35  public:
36  static const uint8_t kAccumulatorModuleNumber = 1;
37  static const uint32_t kAccumulatorNumChannels = 2;
38  static const uint32_t kAccumulatorChannels[kAccumulatorNumChannels];
39 
40  explicit AnalogInput(uint32_t channel);
41  virtual ~AnalogInput();
42 
43  int16_t GetValue() const;
44  int32_t GetAverageValue() const;
45 
46  float GetVoltage() const;
47  float GetAverageVoltage() const;
48 
49  uint32_t GetChannel() const;
50 
51  void SetAverageBits(uint32_t bits);
52  uint32_t GetAverageBits() const;
53  void SetOversampleBits(uint32_t bits);
54  uint32_t GetOversampleBits() const;
55 
56  uint32_t GetLSBWeight() const;
57  int32_t GetOffset() const;
58 
59  bool IsAccumulatorChannel() const;
60  void InitAccumulator();
61  void SetAccumulatorInitialValue(int64_t value);
62  void ResetAccumulator();
63  void SetAccumulatorCenter(int32_t center);
64  void SetAccumulatorDeadband(int32_t deadband);
65  int64_t GetAccumulatorValue() const;
66  uint32_t GetAccumulatorCount() const;
67  void GetAccumulatorOutput(int64_t &value, uint32_t &count) const;
68 
69  static void SetSampleRate(float samplesPerSecond);
70  static float GetSampleRate();
71 
72  double PIDGet() override;
73 
74  void UpdateTable() override;
75  void StartLiveWindowMode() override;
76  void StopLiveWindowMode() override;
77  std::string GetSmartDashboardType() const override;
78  void InitTable(std::shared_ptr<ITable> subTable) override;
79  std::shared_ptr<ITable> GetTable() const override;
80 
81  private:
82  uint32_t m_channel;
83  //TODO: Adjust HAL to avoid use of raw pointers.
84  void *m_port;
85  int64_t m_accumulatorOffset;
86 
87  std::shared_ptr<ITable> m_table;
88 };
std::string GetSmartDashboardType() const override
Definition: AnalogInput.cpp:418
uint32_t GetLSBWeight() const
Get the factory scaling least significant bit weight constant.
Definition: AnalogInput.cpp:142
int64_t GetAccumulatorValue() const
Read the accumulated value.
Definition: AnalogInput.cpp:333
void SetAccumulatorCenter(int32_t center)
Set the center value of the accumulator.
Definition: AnalogInput.cpp:307
float GetAverageVoltage() const
Get a scaled sample from the output of the oversample and average engine for this channel...
Definition: AnalogInput.cpp:127
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:18
AnalogInput(uint32_t channel)
Construct an analog input.
Definition: AnalogInput.cpp:29
int16_t GetValue() const
Get a sample straight from this channel.
Definition: AnalogInput.cpp:73
int32_t GetOffset() const
Get the factory scaling offset constant.
Definition: AnalogInput.cpp:157
bool IsAccumulatorChannel() const
Is the channel attached to an accumulator.
Definition: AnalogInput.cpp:244
uint32_t GetChannel() const
Get the channel number.
Definition: AnalogInput.cpp:169
void SetAccumulatorDeadband(int32_t deadband)
Set the accumulator's deadband.
Definition: AnalogInput.cpp:318
Base class for all sensors.
Definition: SensorBase.h:20
void ResetAccumulator()
Resets the accumulator to the initial value.
Definition: AnalogInput.cpp:278
void SetAccumulatorInitialValue(int64_t value)
Set an initial value for the accumulator.
Definition: AnalogInput.cpp:270
void GetAccumulatorOutput(int64_t &value, uint32_t &count) const
Read the accumulated value and the number of accumulated values atomically.
Definition: AnalogInput.cpp:366
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: AnalogInput.cpp:408
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: AnalogInput.cpp:416
double PIDGet() override
Get the Average value for the PID Source base object.
Definition: AnalogInput.cpp:403
static void SetSampleRate(float samplesPerSecond)
Set the sample rate per channel for all analog channels.
Definition: AnalogInput.cpp:380
uint32_t GetOversampleBits() const
Get the number of oversample bits previously configured.
Definition: AnalogInput.cpp:231
static float GetSampleRate()
Get the current sample rate for all channels.
Definition: AnalogInput.cpp:391
std::shared_ptr< ITable > GetTable() const override
Definition: AnalogInput.cpp:427
virtual ~AnalogInput()
Channel destructor.
Definition: AnalogInput.cpp:60
void SetAverageBits(uint32_t bits)
Set the number of averaging bits.
Definition: AnalogInput.cpp:184
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:18
float GetVoltage() const
Get a scaled sample straight from this channel.
Definition: AnalogInput.cpp:107
Analog input class.
Definition: AnalogInput.h:32
void InitAccumulator()
Initialize the accumulator.
Definition: AnalogInput.cpp:255
uint32_t GetAverageBits() const
Get the number of averaging bits previously configured.
Definition: AnalogInput.cpp:199
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: AnalogInput.cpp:414
void SetOversampleBits(uint32_t bits)
Set the number of oversample bits.
Definition: AnalogInput.cpp:216
void InitTable(std::shared_ptr< ITable > subTable) override
Initializes a table for this sendable object.
Definition: AnalogInput.cpp:422
int32_t GetAverageValue() const
Get a sample from the output of the oversample and average engine for this channel.
Definition: AnalogInput.cpp:93
uint32_t GetAccumulatorCount() const
Read the number of accumulated values.
Definition: AnalogInput.cpp:349