WPILibC++ 2024.3.2
|
Analog input class. More...
#include <frc/AnalogInput.h>
Public Member Functions | |
AnalogInput (int channel) | |
Construct an analog input. More... | |
~AnalogInput () override | |
AnalogInput (AnalogInput &&)=default | |
AnalogInput & | operator= (AnalogInput &&)=default |
int | GetValue () const |
Get a sample straight from this channel. More... | |
int | GetAverageValue () const |
Get a sample from the output of the oversample and average engine for this channel. More... | |
double | GetVoltage () const |
Get a scaled sample straight from this channel. More... | |
double | GetAverageVoltage () const |
Get a scaled sample from the output of the oversample and average engine for this channel. More... | |
int | GetChannel () const |
Get the channel number. More... | |
void | SetAverageBits (int bits) |
Set the number of averaging bits. More... | |
int | GetAverageBits () const |
Get the number of averaging bits previously configured. More... | |
void | SetOversampleBits (int bits) |
Set the number of oversample bits. More... | |
int | GetOversampleBits () const |
Get the number of oversample bits previously configured. More... | |
int | GetLSBWeight () const |
Get the factory scaling least significant bit weight constant. More... | |
int | GetOffset () const |
Get the factory scaling offset constant. More... | |
bool | IsAccumulatorChannel () const |
Is the channel attached to an accumulator. More... | |
void | InitAccumulator () |
Initialize the accumulator. More... | |
void | SetAccumulatorInitialValue (int64_t value) |
Set an initial value for the accumulator. More... | |
void | ResetAccumulator () |
Resets the accumulator to the initial value. More... | |
void | SetAccumulatorCenter (int center) |
Set the center value of the accumulator. More... | |
void | SetAccumulatorDeadband (int deadband) |
Set the accumulator's deadband. More... | |
int64_t | GetAccumulatorValue () const |
Read the accumulated value. More... | |
int64_t | GetAccumulatorCount () const |
Read the number of accumulated values. More... | |
void | GetAccumulatorOutput (int64_t &value, int64_t &count) const |
Read the accumulated value and the number of accumulated values atomically. More... | |
void | SetSimDevice (HAL_SimDeviceHandle device) |
Indicates this input is used by a simulated device. More... | |
void | InitSendable (wpi::SendableBuilder &builder) override |
Initializes this Sendable object. More... | |
Public Member Functions inherited from wpi::Sendable | |
virtual | ~Sendable ()=default |
virtual void | InitSendable (SendableBuilder &builder)=0 |
Initializes this Sendable object. More... | |
Public Member Functions inherited from wpi::SendableHelper< AnalogInput > | |
SendableHelper (const SendableHelper &rhs)=default | |
SendableHelper (SendableHelper &&rhs) | |
SendableHelper & | operator= (const SendableHelper &rhs)=default |
SendableHelper & | operator= (SendableHelper &&rhs) |
Static Public Member Functions | |
static void | SetSampleRate (double samplesPerSecond) |
Set the sample rate per channel for all analog channels. More... | |
static double | GetSampleRate () |
Get the current sample rate for all channels. More... | |
Static Public Attributes | |
static constexpr int | kAccumulatorModuleNumber = 1 |
static constexpr int | kAccumulatorNumChannels = 2 |
static constexpr int | kAccumulatorChannels [kAccumulatorNumChannels] = {0, 1} |
Friends | |
class | AnalogTrigger |
class | AnalogGyro |
class | DMA |
class | DMASample |
Additional Inherited Members | |
Protected Member Functions inherited from wpi::SendableHelper< AnalogInput > | |
SendableHelper ()=default | |
~SendableHelper () | |
Analog input class.
Connected to each analog channel is an averaging and oversampling engine. This engine accumulates the specified ( by SetAverageBits() and SetOversampleBits() ) number of samples before returning a new value. This is not a sliding window average. The only difference between the oversampled samples and the averaged samples is that the oversampled samples are simply accumulated effectively increasing the resolution, while the averaged samples are divided by the number of samples to retain the resolution, but get more stable values.
|
explicit |
Construct an analog input.
channel | The channel number on the roboRIO to represent. 0-3 are on-board 4-7 are on the MXP port. |
|
override |
|
default |
int64_t frc::AnalogInput::GetAccumulatorCount | ( | ) | const |
Read the number of accumulated values.
Read the count of the accumulated values since the accumulator was last Reset().
void frc::AnalogInput::GetAccumulatorOutput | ( | int64_t & | value, |
int64_t & | count | ||
) | const |
Read the accumulated value and the number of accumulated values atomically.
This function reads the value and count from the FPGA atomically. This can be used for averaging.
value | Reference to the 64-bit accumulated output. |
count | Reference to the number of accumulation cycles. |
int64_t frc::AnalogInput::GetAccumulatorValue | ( | ) | const |
Read the accumulated value.
Read the value that has been accumulating. The accumulator is attached after the oversample and average engine.
int frc::AnalogInput::GetAverageBits | ( | ) | const |
Get the number of averaging bits previously configured.
This gets the number of averaging bits from the FPGA. The actual number of averaged samples is 2^bits. The averaging is done automatically in the FPGA.
int frc::AnalogInput::GetAverageValue | ( | ) | const |
Get a sample from the output of the oversample and average engine for this channel.
The sample is 12-bit + the bits configured in SetOversampleBits(). The value configured in SetAverageBits() will cause this value to be averaged 2**bits number of samples.
This is not a sliding window. The sample will not change until 2**(OversampleBits + AverageBits) samples have been acquired from the module on this channel.
Use GetAverageVoltage() to get the analog value in calibrated units.
double frc::AnalogInput::GetAverageVoltage | ( | ) | const |
Get a scaled sample from the output of the oversample and average engine for this channel.
The value is scaled to units of Volts using the calibrated scaling data from GetLSBWeight() and GetOffset().
Using oversampling will cause this value to be higher resolution, but it will update more slowly.
Using averaging will cause this value to be more stable, but it will update more slowly.
int frc::AnalogInput::GetChannel | ( | ) | const |
Get the channel number.
int frc::AnalogInput::GetLSBWeight | ( | ) | const |
Get the factory scaling least significant bit weight constant.
Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
int frc::AnalogInput::GetOffset | ( | ) | const |
Get the factory scaling offset constant.
Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
int frc::AnalogInput::GetOversampleBits | ( | ) | const |
Get the number of oversample bits previously configured.
This gets the number of oversample bits from the FPGA. The actual number of oversampled values is 2^bits. The oversampling is done automatically in the FPGA.
|
static |
Get the current sample rate for all channels.
int frc::AnalogInput::GetValue | ( | ) | const |
Get a sample straight from this channel.
The sample is a 12-bit value representing the 0V to 5V range of the A/D converter in the module. The units are in A/D converter codes. Use GetVoltage() to get the analog value in calibrated units.
double frc::AnalogInput::GetVoltage | ( | ) | const |
Get a scaled sample straight from this channel.
The value is scaled to units of Volts using the calibrated scaling data from GetLSBWeight() and GetOffset().
void frc::AnalogInput::InitAccumulator | ( | ) |
Initialize the accumulator.
|
overridevirtual |
bool frc::AnalogInput::IsAccumulatorChannel | ( | ) | const |
Is the channel attached to an accumulator.
|
default |
void frc::AnalogInput::ResetAccumulator | ( | ) |
Resets the accumulator to the initial value.
void frc::AnalogInput::SetAccumulatorCenter | ( | int | center | ) |
Set the center value of the accumulator.
The center value is subtracted from each A/D value before it is added to the accumulator. This is used for the center value of devices like gyros and accelerometers to take the device offset into account when integrating.
This center value is based on the output of the oversampled and averaged source from the accumulator channel. Because of this, any non-zero oversample bits will affect the size of the value for this field.
void frc::AnalogInput::SetAccumulatorDeadband | ( | int | deadband | ) |
Set the accumulator's deadband.
void frc::AnalogInput::SetAccumulatorInitialValue | ( | int64_t | value | ) |
Set an initial value for the accumulator.
This will be added to all values returned to the user.
value | The value that the accumulator should start from when reset. |
void frc::AnalogInput::SetAverageBits | ( | int | bits | ) |
Set the number of averaging bits.
This sets the number of averaging bits. The actual number of averaged samples is 2^bits.
Use averaging to improve the stability of your measurement at the expense of sampling rate. The averaging is done automatically in the FPGA.
bits | Number of bits of averaging. |
void frc::AnalogInput::SetOversampleBits | ( | int | bits | ) |
Set the number of oversample bits.
This sets the number of oversample bits. The actual number of oversampled values is 2^bits. Use oversampling to improve the resolution of your measurements at the expense of sampling rate. The oversampling is done automatically in the FPGA.
bits | Number of bits of oversampling. |
|
static |
Set the sample rate per channel for all analog channels.
The maximum rate is 500kS/s divided by the number of channels in use. This is 62500 samples/s per channel.
samplesPerSecond | The number of samples per second. |
void frc::AnalogInput::SetSimDevice | ( | HAL_SimDeviceHandle | device | ) |
Indicates this input is used by a simulated device.
device | simulated device handle |
|
friend |
|
friend |
|
friend |
|
friend |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |