#include <AnalogModule.h>
Public Member Functions | |
void | SetSampleRate (float samplesPerSecond) |
float | GetSampleRate () |
void | SetAverageBits (uint32_t channel, uint32_t bits) |
uint32_t | GetAverageBits (uint32_t channel) |
void | SetOversampleBits (uint32_t channel, uint32_t bits) |
uint32_t | GetOversampleBits (uint32_t channel) |
int16_t | GetValue (uint32_t channel) |
int32_t | GetAverageValue (uint32_t channel) |
float | GetAverageVoltage (uint32_t channel) |
float | GetVoltage (uint32_t channel) |
uint32_t | GetLSBWeight (uint32_t channel) |
int32_t | GetOffset (uint32_t channel) |
int32_t | VoltsToValue (int32_t channel, float voltage) |
Public Member Functions inherited from Module | |
nLoadOut::tModuleType | GetType () |
uint8_t | GetNumber () |
Public Member Functions inherited from SensorBase | |
SensorBase () | |
virtual | ~SensorBase () |
Public Member Functions inherited from ErrorBase | |
virtual Error & | GetError () |
Retrieve the current error. Get the current error information associated with this sensor. | |
virtual const Error & | GetError () 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 Member Functions | |
static AnalogModule * | GetInstance (uint8_t moduleNumber) |
Static Public Member Functions inherited from Module | |
static Module * | GetModule (nLoadOut::tModuleType type, uint8_t number) |
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 Error & | GetGlobalError () |
Static Public Attributes | |
static const long | kTimebase = 40000000 |
40 MHz clock | |
static const long | kDefaultOversampleBits = 0 |
static const long | kDefaultAverageBits = 7 |
static constexpr float | kDefaultSampleRate = 50000.0 |
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 |
Protected Member Functions | |
AnalogModule (uint8_t moduleNumber) | |
virtual | ~AnalogModule () |
Protected Member Functions inherited from Module | |
Module (nLoadOut::tModuleType type, uint8_t number) | |
virtual | ~Module () |
Protected Member Functions inherited from SensorBase | |
void | AddToSingletonList () |
Protected Member Functions inherited from ErrorBase | |
ErrorBase () | |
Initialize the instance status to 0 for now. | |
Friends | |
class | Module |
Additional Inherited Members | |
Protected Attributes inherited from Module | |
nLoadOut::tModuleType | m_moduleType |
The type of module represented. | |
uint8_t | m_moduleNumber |
The module index within the module type. | |
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 |
Analog Module class. Each module can independently sample its channels at a configurable rate. There is a 64-bit hardware accumulator associated with channel 1 on each module. The accumulator is attached to the output of the oversample and average engine so that the center value can be specified in higher resolution resulting in less error.
|
explicitprotected |
Create a new instance of an analog module.
Create an instance of the analog module object. Initialize all the parameters to reasonable values on start. Setting a global value on an analog module can be done only once unless subsequent values are set the previously set value. Analog modules are a singleton, so the constructor is never called outside of this class.
moduleNumber | The analog module to create (1 or 2). |
|
protectedvirtual |
Destructor for AnalogModule.
uint32_t AnalogModule::GetAverageBits | ( | uint32_t | channel | ) |
Get the number of averaging bits.
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.
channel | Channel to address. |
int32_t AnalogModule::GetAverageValue | ( | uint32_t | channel | ) |
Get a sample from the output of the oversample and average engine for the 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.
channel | Channel number to read. |
float AnalogModule::GetAverageVoltage | ( | uint32_t | channel | ) |
Get a scaled sample from the output of the oversample and average engine for the 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.
channel | The channel to read. |
|
static |
Get an instance of an Analog Module.
Singleton analog module creation where a module is allocated on the first use and the same module is returned on subsequent uses.
moduleNumber | The analog module to get (1 or 2). |
uint32_t AnalogModule::GetLSBWeight | ( | uint32_t | channel | ) |
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)
channel | The channel to get calibration data for. |
int32_t AnalogModule::GetOffset | ( | uint32_t | channel | ) |
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)
channel | The channel to get calibration data for. |
uint32_t AnalogModule::GetOversampleBits | ( | uint32_t | channel | ) |
Get the number of oversample bits.
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.
channel | Channel to address. |
float AnalogModule::GetSampleRate | ( | ) |
Get the current sample rate on the module.
This assumes one entry in the scan list. This is a global setting for the module and effects all channels.
int16_t AnalogModule::GetValue | ( | uint32_t | channel | ) |
Get a sample straight from the channel on this 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 AnalogModule::GetVoltage | ( | uint32_t | channel | ) |
Get a scaled sample straight from the channel on this module.
The value is scaled to units of Volts using the calibrated scaling data from GetLSBWeight() and GetOffset().
channel | The channel to read. |
void AnalogModule::SetAverageBits | ( | uint32_t | channel, |
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.
channel | Analog channel to configure. |
bits | Number of bits to average. |
void AnalogModule::SetOversampleBits | ( | uint32_t | channel, |
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.
channel | Analog channel to configure. |
bits | Number of bits to oversample. |
void AnalogModule::SetSampleRate | ( | float | samplesPerSecond | ) |
Set the sample rate on the module.
This is a global setting for the module and effects all channels.
samplesPerSecond | The number of samples per channel per second. |
int32_t AnalogModule::VoltsToValue | ( | int32_t | channel, |
float | voltage | ||
) |
Convert a voltage to a raw value for a specified channel.
This process depends on the calibration of each channel, so the channel must be specified.
channel | The channel to convert for. |
voltage | The voltage to convert. |