WPILib 2012
WPILibRoboticsLibraryforFRC
Public Member Functions | Static Public Attributes
AnalogChannel Class Reference

#include <AnalogChannel.h>

Inheritance diagram for AnalogChannel:
SensorBase PIDSource ErrorBase

List of all members.

Public Member Functions

 AnalogChannel (UINT8 moduleNumber, UINT32 channel)
 AnalogChannel (UINT32 channel)
virtual ~AnalogChannel ()
AnalogModuleGetModule ()
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}

Detailed Description

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.


Constructor & Destructor Documentation

AnalogChannel::AnalogChannel ( UINT8  moduleNumber,
UINT32  channel 
)

Construct an analog channel on a specified module.

Parameters:
moduleNumberThe analog module (1 or 2).
channelThe channel number to represent.
AnalogChannel::AnalogChannel ( UINT32  channel) [explicit]

Construct an analog channel on the default module.

Parameters:
channelThe channel number to represent.
AnalogChannel::~AnalogChannel ( ) [virtual]

Channel destructor.


Member Function Documentation

UINT32 AnalogChannel::GetAccumulatorCount ( )

Read the number of accumulated values.

Read the count of the accumulated values since the accumulator was last Reset().

Returns:
The number of times samples from the channel were accumulated.
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.

Parameters:
valuePointer to the 64-bit accumulated output.
countPointer 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.

Returns:
The 64-bit value accumulated since the last Reset().
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.

Returns:
Number of bits of averaging previously configured.
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.

Returns:
A sample from the oversample and average engine for this channel.
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.

Returns:
A scaled sample from the output of the oversample and average engine for this channel.
UINT32 AnalogChannel::GetChannel ( )

Get the channel number.

Returns:
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)

Returns:
Least significant bit weight.
AnalogModule * AnalogChannel::GetModule ( )

Get the analog module that this channel is on.

Returns:
A pointer to the AnalogModule that this channel is on.
UINT8 AnalogChannel::GetModuleNumber ( )

Get the module number.

Returns:
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)

Returns:
Offset constant.
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.

Returns:
Number of bits of oversampling previously configured.
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.

Returns:
A sample straight from this channel on the module.
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().

Returns:
A scaled sample straight from this channel on the module.
void AnalogChannel::InitAccumulator ( )

Initialize the accumulator.

bool AnalogChannel::IsAccumulatorChannel ( )

Is the channel attached to an accumulator.

Returns:
The analog channel is attached to an accumulator.
double AnalogChannel::PIDGet ( ) [virtual]

Get the Average voltage for the PID Source base object.

Returns:
The average voltage.

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.

Parameters:
initialValueThe 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.

Parameters:
bitsNumber 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.

Parameters:
bitsNumber of bits of oversampling.

The documentation for this class was generated from the following files:
 All Classes Functions Variables