WPILib  2014.0
WPIRoboticsLibraryforFRC
All Classes Functions Variables Pages
Public Member Functions | Static Public Attributes | List of all members
AnalogChannel Class Reference

#include <AnalogChannel.h>

Inheritance diagram for AnalogChannel:
SensorBase PIDSource ErrorBase

Public Member Functions

 AnalogChannel (uint8_t moduleNumber, uint32_t channel)
 
 AnalogChannel (uint32_t channel)
 
virtual ~AnalogChannel ()
 
AnalogModuleGetModule ()
 
int16_t GetValue ()
 
int32_t GetAverageValue ()
 
float GetVoltage ()
 
float GetAverageVoltage ()
 
uint8_t GetModuleNumber ()
 
uint32_t GetChannel ()
 
void SetAverageBits (uint32_t bits)
 
uint32_t GetAverageBits ()
 
void SetOversampleBits (uint32_t bits)
 
uint32_t GetOversampleBits ()
 
uint32_t GetLSBWeight ()
 
int32_t GetOffset ()
 
bool IsAccumulatorChannel ()
 
void InitAccumulator ()
 
void SetAccumulatorInitialValue (INT64 value)
 
void ResetAccumulator ()
 
void SetAccumulatorCenter (int32_t center)
 
void SetAccumulatorDeadband (int32_t deadband)
 
INT64 GetAccumulatorValue ()
 
uint32_t GetAccumulatorCount ()
 
void GetAccumulatorOutput (INT64 *value, uint32_t *count)
 
void SetVoltageForPID (bool shouldUseVoltageForPID)
 
double PIDGet ()
 
void UpdateTable ()
 
void StartLiveWindowMode ()
 
void StopLiveWindowMode ()
 
std::string GetSmartDashboardType ()
 
void InitTable (ITable *subTable)
 
ITable * GetTable ()
 
- Public Member Functions inherited from SensorBase
 SensorBase ()
 
virtual ~SensorBase ()
 
- Public Member Functions inherited from ErrorBase
virtual ErrorGetError ()
 Retrieve the current error. Get the current error information associated with this sensor.
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set error information associated with a C library call that set an error to the "errno" global variable. More...
 
virtual void SetImaqError (int success, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (ErrorBase *rhs) const
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 

Static Public Attributes

static const uint8_t kAccumulatorModuleNumber = 1
 
static const uint32_t kAccumulatorNumChannels = 2
 
static const uint32_t kAccumulatorChannels [kAccumulatorNumChannels] = {1, 2}
 
- Static Public Attributes inherited from SensorBase
static const uint32_t kSystemClockTicksPerMicrosecond = 40
 
static const uint32_t kDigitalChannels = 14
 
static const uint32_t kAnalogChannels = 8
 
static const uint32_t kAnalogModules = 2
 
static const uint32_t kDigitalModules = 2
 
static const uint32_t kSolenoidChannels = 8
 
static const uint32_t kSolenoidModules = 2
 
static const uint32_t kPwmChannels = 10
 
static const uint32_t kRelayChannels = 8
 
static const uint32_t kChassisSlots = 8
 

Additional Inherited Members

- Public Types inherited from PIDSource
enum  PIDSourceParameter { kDistance, kRate, kAngle }
 
- Static Public Member Functions inherited from SensorBase
static void DeleteSingletons ()
 
static uint32_t GetDefaultAnalogModule ()
 
static uint32_t GetDefaultDigitalModule ()
 
static uint32_t GetDefaultSolenoidModule ()
 
static bool CheckAnalogModule (uint8_t moduleNumber)
 
static bool CheckDigitalModule (uint8_t moduleNumber)
 
static bool CheckPWMModule (uint8_t moduleNumber)
 
static bool CheckRelayModule (uint8_t moduleNumber)
 
static bool CheckSolenoidModule (uint8_t moduleNumber)
 
static bool CheckDigitalChannel (uint32_t channel)
 
static bool CheckRelayChannel (uint32_t channel)
 
static bool CheckPWMChannel (uint32_t channel)
 
static bool CheckAnalogChannel (uint32_t channel)
 
static bool CheckSolenoidChannel (uint32_t channel)
 
- Static Public Member Functions inherited from ErrorBase
static void SetGlobalError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber)
 
static void SetGlobalWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber)
 
static ErrorGetGlobalError ()
 
- Protected Member Functions inherited from SensorBase
void AddToSingletonList ()
 
- Protected Member Functions inherited from ErrorBase
 ErrorBase ()
 Initialize the instance status to 0 for now.
 
- Protected Attributes inherited from ErrorBase
Error m_error
 
- Static Protected Attributes inherited from ErrorBase
static SEM_ID _globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE)
 
static Error _globalError
 

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_t  moduleNumber,
uint32_t  channel 
)

Construct an analog channel on a specified module.

Parameters
moduleNumberThe analog module (1 or 2).
channelThe channel number to represent.
AnalogChannel::AnalogChannel ( uint32_t  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_t 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_t *  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_t 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_t 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_t AnalogChannel::GetChannel ( )

Get the channel number.

Returns
The channel number.
uint32_t 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_t AnalogChannel::GetModuleNumber ( )

Get the module number.

Returns
The module number.
int32_t 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_t 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_t 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 value 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_t  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_t  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_t  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_t  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.
void AnalogChannel::SetVoltageForPID ( bool  shouldUseVoltageForPID)

Set whether to use voltage or value for PIDGet. This method determines whether PIDGet should use average voltage or value for PIDControllers for a particular channel. This is to preserve compatibility with existng programs and is likely to change in favor of voltage for 2015 and beyond.

Parameters
shouldUseVoltageForPIDtrue if voltage should be used for PIDGet.

The documentation for this class was generated from the following files: