mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Moved C++ comments from source files to headers (#1111)
Also sorted functions in C++ sources to match order in related headers.
This commit is contained in:
committed by
Peter Johnson
parent
d9971a705a
commit
8c680a26f8
@@ -19,12 +19,6 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
/**
|
||||
* Construct an analog input.
|
||||
*
|
||||
* @param channel The channel number on the roboRIO to represent. 0-3 are
|
||||
* on-board 4-7 are on the MXP port.
|
||||
*/
|
||||
AnalogInput::AnalogInput(int channel) {
|
||||
if (!SensorUtil::CheckAnalogInputChannel(channel)) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
@@ -49,23 +43,11 @@ AnalogInput::AnalogInput(int channel) {
|
||||
SetName("AnalogInput", channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel destructor.
|
||||
*/
|
||||
AnalogInput::~AnalogInput() {
|
||||
HAL_FreeAnalogInputPort(m_port);
|
||||
m_port = HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return A sample straight from this channel.
|
||||
*/
|
||||
int AnalogInput::GetValue() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
@@ -74,20 +56,6 @@ int AnalogInput::GetValue() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return A sample from the oversample and average engine for this channel.
|
||||
*/
|
||||
int AnalogInput::GetAverageValue() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
@@ -96,14 +64,6 @@ int AnalogInput::GetAverageValue() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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().
|
||||
*
|
||||
* @return A scaled sample straight from this channel.
|
||||
*/
|
||||
double AnalogInput::GetVoltage() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
int32_t status = 0;
|
||||
@@ -112,20 +72,6 @@ double AnalogInput::GetVoltage() const {
|
||||
return voltage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return A scaled sample from the output of the oversample and average engine
|
||||
* for this channel.
|
||||
*/
|
||||
double AnalogInput::GetAverageVoltage() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
int32_t status = 0;
|
||||
@@ -134,57 +80,11 @@ double AnalogInput::GetAverageVoltage() const {
|
||||
return voltage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the factory scaling least significant bit weight constant.
|
||||
*
|
||||
* Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
|
||||
*
|
||||
* @return Least significant bit weight.
|
||||
*/
|
||||
int AnalogInput::GetLSBWeight() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
int lsbWeight = HAL_GetAnalogLSBWeight(m_port, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return lsbWeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the factory scaling offset constant.
|
||||
*
|
||||
* Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
|
||||
*
|
||||
* @return Offset constant.
|
||||
*/
|
||||
int AnalogInput::GetOffset() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
int offset = HAL_GetAnalogOffset(m_port, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channel number.
|
||||
*
|
||||
* @return The channel number.
|
||||
*/
|
||||
int AnalogInput::GetChannel() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param bits Number of bits of averaging.
|
||||
*/
|
||||
void AnalogInput::SetAverageBits(int bits) {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
@@ -192,14 +92,6 @@ void AnalogInput::SetAverageBits(int bits) {
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return Number of bits of averaging previously configured.
|
||||
*/
|
||||
int AnalogInput::GetAverageBits() const {
|
||||
int32_t status = 0;
|
||||
int averageBits = HAL_GetAnalogAverageBits(m_port, &status);
|
||||
@@ -207,16 +99,6 @@ int AnalogInput::GetAverageBits() const {
|
||||
return averageBits;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param bits Number of bits of oversampling.
|
||||
*/
|
||||
void AnalogInput::SetOversampleBits(int bits) {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
@@ -224,15 +106,6 @@ void AnalogInput::SetOversampleBits(int bits) {
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return Number of bits of oversampling previously configured.
|
||||
*/
|
||||
int AnalogInput::GetOversampleBits() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
@@ -241,11 +114,22 @@ int AnalogInput::GetOversampleBits() const {
|
||||
return oversampleBits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the channel attached to an accumulator.
|
||||
*
|
||||
* @return The analog input is attached to an accumulator.
|
||||
*/
|
||||
int AnalogInput::GetLSBWeight() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
int lsbWeight = HAL_GetAnalogLSBWeight(m_port, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return lsbWeight;
|
||||
}
|
||||
|
||||
int AnalogInput::GetOffset() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
int offset = HAL_GetAnalogOffset(m_port, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return offset;
|
||||
}
|
||||
|
||||
bool AnalogInput::IsAccumulatorChannel() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
int32_t status = 0;
|
||||
@@ -254,9 +138,6 @@ bool AnalogInput::IsAccumulatorChannel() const {
|
||||
return isAccum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the accumulator.
|
||||
*/
|
||||
void AnalogInput::InitAccumulator() {
|
||||
if (StatusIsFatal()) return;
|
||||
m_accumulatorOffset = 0;
|
||||
@@ -265,22 +146,11 @@ void AnalogInput::InitAccumulator() {
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an initial value for the accumulator.
|
||||
*
|
||||
* This will be added to all values returned to the user.
|
||||
*
|
||||
* @param initialValue The value that the accumulator should start from when
|
||||
* reset.
|
||||
*/
|
||||
void AnalogInput::SetAccumulatorInitialValue(int64_t initialValue) {
|
||||
if (StatusIsFatal()) return;
|
||||
m_accumulatorOffset = initialValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the accumulator to the initial value.
|
||||
*/
|
||||
void AnalogInput::ResetAccumulator() {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
@@ -297,17 +167,6 @@ void AnalogInput::ResetAccumulator() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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::SetAccumulatorCenter(int center) {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
@@ -315,9 +174,6 @@ void AnalogInput::SetAccumulatorCenter(int center) {
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the accumulator's deadband.
|
||||
*/
|
||||
void AnalogInput::SetAccumulatorDeadband(int deadband) {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
@@ -325,14 +181,6 @@ void AnalogInput::SetAccumulatorDeadband(int deadband) {
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the accumulated value.
|
||||
*
|
||||
* Read the value that has been accumulating.
|
||||
* The accumulator is attached after the oversample and average engine.
|
||||
*
|
||||
* @return The 64-bit value accumulated since the last Reset().
|
||||
*/
|
||||
int64_t AnalogInput::GetAccumulatorValue() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
@@ -341,14 +189,6 @@ int64_t AnalogInput::GetAccumulatorValue() const {
|
||||
return value + m_accumulatorOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the number of accumulated values.
|
||||
*
|
||||
* Read the count of the accumulated values since the accumulator was last
|
||||
* Reset().
|
||||
*
|
||||
* @return The number of times samples from the channel were accumulated.
|
||||
*/
|
||||
int64_t AnalogInput::GetAccumulatorCount() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
@@ -357,15 +197,6 @@ int64_t AnalogInput::GetAccumulatorCount() const {
|
||||
return 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.
|
||||
*
|
||||
* @param value Reference to the 64-bit accumulated output.
|
||||
* @param count Reference to the number of accumulation cycles.
|
||||
*/
|
||||
void AnalogInput::GetAccumulatorOutput(int64_t& value, int64_t& count) const {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
@@ -374,25 +205,12 @@ void AnalogInput::GetAccumulatorOutput(int64_t& value, int64_t& count) const {
|
||||
value += m_accumulatorOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param samplesPerSecond The number of samples per second.
|
||||
*/
|
||||
void AnalogInput::SetSampleRate(double samplesPerSecond) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogSampleRate(samplesPerSecond, &status);
|
||||
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current sample rate for all channels
|
||||
*
|
||||
* @return Sample rate.
|
||||
*/
|
||||
double AnalogInput::GetSampleRate() {
|
||||
int32_t status = 0;
|
||||
double sampleRate = HAL_GetAnalogSampleRate(&status);
|
||||
@@ -400,11 +218,6 @@ double AnalogInput::GetSampleRate() {
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Average value for the PID Source base object.
|
||||
*
|
||||
* @return The average voltage.
|
||||
*/
|
||||
double AnalogInput::PIDGet() {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
return GetAverageVoltage();
|
||||
|
||||
Reference in New Issue
Block a user