WPILibC++
unspecified
|
Analog input class. More...
#include <AnalogInput.h>
Public Member Functions | |
AnalogInput (uint32_t channel) | |
Construct an analog input. More... | |
virtual | ~AnalogInput () |
Channel destructor. | |
int16_t | GetValue () const |
Get a sample straight from this channel. More... | |
int32_t | GetAverageValue () const |
Get a sample from the output of the oversample and average engine for this channel. More... | |
float | GetVoltage () const |
Get a scaled sample straight from this channel. More... | |
float | GetAverageVoltage () const |
Get a scaled sample from the output of the oversample and average engine for this channel. More... | |
uint32_t | GetChannel () const |
Get the channel number. More... | |
void | SetAverageBits (uint32_t bits) |
Set the number of averaging bits. More... | |
uint32_t | GetAverageBits () const |
Get the number of averaging bits previously configured. More... | |
void | SetOversampleBits (uint32_t bits) |
Set the number of oversample bits. More... | |
uint32_t | GetOversampleBits () const |
Get the number of oversample bits previously configured. More... | |
uint32_t | GetLSBWeight () const |
Get the factory scaling least significant bit weight constant. More... | |
int32_t | 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. | |
void | SetAccumulatorInitialValue (int64_t value) |
Set an initial value for the accumulator. More... | |
void | ResetAccumulator () |
Resets the accumulator to the initial value. | |
void | SetAccumulatorCenter (int32_t center) |
Set the center value of the accumulator. More... | |
void | SetAccumulatorDeadband (int32_t deadband) |
Set the accumulator's deadband. More... | |
int64_t | GetAccumulatorValue () const |
Read the accumulated value. More... | |
uint32_t | GetAccumulatorCount () const |
Read the number of accumulated values. More... | |
void | GetAccumulatorOutput (int64_t &value, uint32_t &count) const |
Read the accumulated value and the number of accumulated values atomically. More... | |
double | PIDGet () override |
Get the Average value for the PID Source base object. More... | |
void | UpdateTable () override |
Update the table for this sendable object with the latest values. | |
void | StartLiveWindowMode () override |
Start having this sendable object automatically respond to value changes reflect the value on the table. | |
void | StopLiveWindowMode () override |
Stop having this sendable object automatically respond to value changes. | |
std::string | GetSmartDashboardType () const override |
void | InitTable (std::shared_ptr< ITable > subTable) override |
Initializes a table for this sendable object. More... | |
std::shared_ptr< ITable > | GetTable () const override |
![]() | |
SensorBase () | |
Creates an instance of the sensor base and gets an FPGA handle. | |
SensorBase (const SensorBase &)=delete | |
SensorBase & | operator= (const SensorBase &)=delete |
![]() | |
ErrorBase (const ErrorBase &)=delete | |
ErrorBase & | operator= (const ErrorBase &)=delete |
virtual Error & | GetError () |
Retrieve the current error. More... | |
virtual const Error & | GetError () const |
virtual void | SetErrnoError (llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef 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, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const |
Set the current error information associated from the nivision Imaq API. More... | |
virtual void | SetError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | SetWPIError (llvm::StringRef errorMessage, Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | CloneError (const 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... | |
![]() | |
virtual void | SetPIDSourceType (PIDSourceType pidSource) |
Set which parameter you are using as a process control variable. More... | |
PIDSourceType | GetPIDSourceType () const |
Static Public Member Functions | |
static void | SetSampleRate (float samplesPerSecond) |
Set the sample rate per channel for all analog channels. More... | |
static float | GetSampleRate () |
Get the current sample rate for all channels. More... | |
![]() | |
static void | DeleteSingletons () |
Delete all the singleton classes on the list. More... | |
static uint32_t | GetDefaultSolenoidModule () |
static bool | CheckSolenoidModule (uint8_t moduleNumber) |
Check that the solenoid module number is valid. More... | |
static bool | CheckDigitalChannel (uint32_t channel) |
Check that the digital channel number is valid. More... | |
static bool | CheckRelayChannel (uint32_t channel) |
Check that the digital channel number is valid. More... | |
static bool | CheckPWMChannel (uint32_t channel) |
Check that the digital channel number is valid. More... | |
static bool | CheckAnalogInput (uint32_t channel) |
Check that the analog input number is value. More... | |
static bool | CheckAnalogOutput (uint32_t channel) |
Check that the analog output number is valid. More... | |
static bool | CheckSolenoidChannel (uint32_t channel) |
Verify that the solenoid channel number is within limits. More... | |
static bool | CheckPDPChannel (uint32_t channel) |
Verify that the power distribution channel number is within limits. More... | |
![]() | |
static void | SetGlobalError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) |
static void | SetGlobalWPIError (llvm::StringRef errorMessage, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) |
static Error & | GetGlobalError () |
Retrieve the current global error. | |
Static Public Attributes | |
static const uint8_t | kAccumulatorModuleNumber = 1 |
static const uint32_t | kAccumulatorNumChannels = 2 |
static const uint32_t | kAccumulatorChannels [kAccumulatorNumChannels] = {0, 1} |
![]() | |
static const uint32_t | kDigitalChannels = 26 |
static const uint32_t | kAnalogInputs = 8 |
static const uint32_t | kAnalogOutputs = 2 |
static const uint32_t | kSolenoidChannels = 8 |
static const uint32_t | kSolenoidModules = 2 |
static const uint32_t | kPwmChannels = 20 |
static const uint32_t | kRelayChannels = 8 |
static const uint32_t | kPDPChannels = 16 |
static const uint32_t | kChassisSlots = 8 |
Additional Inherited Members | |
![]() | |
void | AddToSingletonList () |
Add sensor to the singleton list. More... | |
![]() | |
Error | m_error |
![]() | |
PIDSourceType | m_pidSource = PIDSourceType::kDisplacement |
![]() | |
static void * | m_digital_ports [kDigitalChannels] |
static void * | m_relay_ports [kRelayChannels] |
static void * | m_pwm_ports [kPwmChannels] |
![]() | |
static priority_mutex | _globalErrorMutex |
static Error | _globalError |
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. |
uint32_t AnalogInput::GetAccumulatorCount | ( | ) | const |
Read the number of accumulated values.
Read the count of the accumulated values since the accumulator was last Reset().
void AnalogInput::GetAccumulatorOutput | ( | int64_t & | value, |
uint32_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 AnalogInput::GetAccumulatorValue | ( | ) | const |
Read the accumulated value.
Read the value that has been accumulating. The accumulator is attached after the oversample and average engine.
uint32_t 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.
int32_t 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.
float 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.
uint32_t AnalogInput::GetChannel | ( | ) | const |
Get the channel number.
uint32_t AnalogInput::GetLSBWeight | ( | ) | const |
Get the factory scaling least significant bit weight constant.
Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
int32_t AnalogInput::GetOffset | ( | ) | const |
Get the factory scaling offset constant.
Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
uint32_t 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.
|
overridevirtual |
Implements Sendable.
|
overridevirtual |
Implements Sendable.
int16_t 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.
float 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().
|
overridevirtual |
Initializes a table for this sendable object.
subtable | The table to put the values in. |
Implements Sendable.
bool AnalogInput::IsAccumulatorChannel | ( | ) | const |
Is the channel attached to an accumulator.
|
overridevirtual |
Get the Average value for the PID Source base object.
Implements PIDSource.
void AnalogInput::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 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 AnalogInput::SetAccumulatorDeadband | ( | int32_t | deadband | ) |
Set the accumulator's deadband.
void AnalogInput::SetAccumulatorInitialValue | ( | int64_t | initialValue | ) |
Set an initial 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 AnalogInput::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.
bits | Number of bits of averaging. |
void AnalogInput::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.
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. |