WPILib 2012
WPILibRoboticsLibraryforFRC
|
#include <AnalogChannel.h>
Public Member Functions | |
AnalogChannel (UINT8 moduleNumber, UINT32 channel) | |
AnalogChannel (UINT32 channel) | |
virtual | ~AnalogChannel () |
AnalogModule * | GetModule () |
INT16 | GetValue () |
INT32 | GetAverageValue () |
float | GetVoltage () |
float | GetAverageVoltage () |
UINT8 | GetModuleNumber () |
UINT32 | GetChannel () |
void | SetAverageBits (UINT32 bits) |
UINT32 | GetAverageBits () |
void | SetOversampleBits (UINT32 bits) |
UINT32 | GetOversampleBits () |
UINT32 | GetLSBWeight () |
INT32 | GetOffset () |
bool | IsAccumulatorChannel () |
void | InitAccumulator () |
void | SetAccumulatorInitialValue (INT64 value) |
void | ResetAccumulator () |
void | SetAccumulatorCenter (INT32 center) |
void | SetAccumulatorDeadband (INT32 deadband) |
INT64 | GetAccumulatorValue () |
UINT32 | GetAccumulatorCount () |
void | GetAccumulatorOutput (INT64 *value, UINT32 *count) |
double | PIDGet () |
Static Public Attributes | |
static const UINT8 | kAccumulatorModuleNumber = 1 |
static const UINT32 | kAccumulatorNumChannels = 2 |
static const UINT32 | kAccumulatorChannels [kAccumulatorNumChannels] = {1, 2} |
Analog channel class.
Each analog channel is read from hardware as a 12-bit number representing -10V to 10V.
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.
AnalogChannel::AnalogChannel | ( | UINT8 | moduleNumber, |
UINT32 | channel | ||
) |
Construct an analog channel on a specified module.
moduleNumber | The analog module (1 or 2). |
channel | The channel number to represent. |
AnalogChannel::AnalogChannel | ( | UINT32 | channel | ) | [explicit] |
Construct an analog channel on the default module.
channel | The channel number to represent. |
AnalogChannel::~AnalogChannel | ( | ) | [virtual] |
Channel destructor.
UINT32 AnalogChannel::GetAccumulatorCount | ( | ) |
Read the number of accumulated values.
Read the count of the accumulated values since the accumulator was last Reset().
void AnalogChannel::GetAccumulatorOutput | ( | INT64 * | value, |
UINT32 * | count | ||
) |
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 | Pointer to the 64-bit accumulated output. |
count | Pointer to the number of accumulation cycles. |
INT64 AnalogChannel::GetAccumulatorValue | ( | ) |
Read the accumulated value.
Read the value that has been accumulating on channel 1. The accumulator is attached after the oversample and average engine.
UINT32 AnalogChannel::GetAverageBits | ( | ) |
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.
INT32 AnalogChannel::GetAverageValue | ( | ) |
Get a sample from the output of the oversample and average engine for this channel. The sample is 12-bit + the value 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**(OversamplBits + AverageBits) samples have been acquired from the module on this channel. Use GetAverageVoltage() to get the analog value in calibrated units.
float AnalogChannel::GetAverageVoltage | ( | ) |
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.
UINT32 AnalogChannel::GetChannel | ( | ) |
Get the channel number.
UINT32 AnalogChannel::GetLSBWeight | ( | ) |
Get the factory scaling least significant bit weight constant. The least significant bit weight constant for the channel that was calibrated in manufacturing and stored in an eeprom in the module.
Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
AnalogModule * AnalogChannel::GetModule | ( | ) |
Get the analog module that this channel is on.
UINT8 AnalogChannel::GetModuleNumber | ( | ) |
Get the module number.
INT32 AnalogChannel::GetOffset | ( | ) |
Get the factory scaling offset constant. The offset constant for the channel that was calibrated in manufacturing and stored in an eeprom in the module.
Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
UINT32 AnalogChannel::GetOversampleBits | ( | ) |
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.
INT16 AnalogChannel::GetValue | ( | ) |
Get a sample straight from this channel on the module. The sample is a 12-bit value representing the -10V to 10V 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.
float AnalogChannel::GetVoltage | ( | ) |
Get a scaled sample straight from this channel on the module. The value is scaled to units of Volts using the calibrated scaling data from GetLSBWeight() and GetOffset().
void AnalogChannel::InitAccumulator | ( | ) |
Initialize the accumulator.
bool AnalogChannel::IsAccumulatorChannel | ( | ) |
Is the channel attached to an accumulator.
double AnalogChannel::PIDGet | ( | ) | [virtual] |
Get the Average voltage for the PID Source base object.
Implements PIDSource.
void AnalogChannel::ResetAccumulator | ( | ) |
Resets the accumulator to the initial value.
void AnalogChannel::SetAccumulatorCenter | ( | INT32 | 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 make integration work and to take the device offset into account when integrating.
This center value is based on the output of the oversampled and averaged source from channel 1. Because of this, any non-zero oversample bits will affect the size of the value for this field.
void AnalogChannel::SetAccumulatorDeadband | ( | INT32 | deadband | ) |
Set the accumulator's deadband.
void AnalogChannel::SetAccumulatorInitialValue | ( | INT64 | initialValue | ) |
Set an inital value for the accumulator.
This will be added to all values returned to the user.
initialValue | The value that the accumulator should start from when reset. |
void AnalogChannel::SetAverageBits | ( | UINT32 | 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 AnalogChannel::SetOversampleBits | ( | UINT32 | 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. |