public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSendable
Each analog channel is read from hardware as a 12-bit number representing 0V to 5V.
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.
Modifier and Type | Field and Description |
---|---|
protected PIDSourceType |
m_pidSource |
kAnalogInputChannels, kAnalogOutputChannels, kDigitalChannels, kPCMModules, kPDPChannels, kPDPModules, kPwmChannels, kRelayChannels, kSolenoidChannels, kSystemClockTicksPerMicrosecond
Constructor and Description |
---|
AnalogInput(int channel)
Construct an analog channel.
|
Modifier and Type | Method and Description |
---|---|
void |
free()
Channel destructor.
|
long |
getAccumulatorCount()
Read the number of accumulated values.
|
void |
getAccumulatorOutput(AccumulatorResult result)
Read the accumulated value and the number of accumulated values atomically.
|
long |
getAccumulatorValue()
Read the accumulated value.
|
int |
getAverageBits()
Get the number of averaging bits.
|
int |
getAverageValue()
Get a sample from the output of the oversample and average engine for this channel.
|
double |
getAverageVoltage()
Get a scaled sample from the output of the oversample and average engine for this channel.
|
int |
getChannel()
Get the channel number.
|
static double |
getGlobalSampleRate()
Get the current sample rate.
|
long |
getLSBWeight()
Get the factory scaling least significant bit weight constant.
|
int |
getOffset()
Get the factory scaling offset constant.
|
int |
getOversampleBits()
Get the number of oversample bits.
|
PIDSourceType |
getPIDSourceType()
Get which parameter of the device you are using as a process control variable.
|
java.lang.String |
getSmartDashboardType()
Live Window code, only does anything if live window is activated.
|
ITable |
getTable()
The table that is associated with this
Sendable . |
int |
getValue()
Get a sample straight from this channel.
|
double |
getVoltage()
Get a scaled sample straight from this channel.
|
void |
initAccumulator()
Initialize the accumulator.
|
void |
initTable(ITable subtable)
Initializes a table for this
Sendable object. |
boolean |
isAccumulatorChannel()
Is the channel attached to an accumulator.
|
double |
pidGet()
Get the average voltage for use with PIDController.
|
void |
resetAccumulator()
Resets the accumulator to the initial value.
|
void |
setAccumulatorCenter(int center)
Set the center value of the accumulator.
|
void |
setAccumulatorDeadband(int deadband)
Set the accumulator's deadband.
|
void |
setAccumulatorInitialValue(long initialValue)
Set an initial value for the accumulator.
|
void |
setAverageBits(int bits)
Set the number of averaging bits.
|
static void |
setGlobalSampleRate(double samplesPerSecond)
Set the sample rate per channel.
|
void |
setOversampleBits(int bits)
Set the number of oversample bits.
|
void |
setPIDSourceType(PIDSourceType pidSource)
Set which parameter of the device you are using as a process control variable.
|
void |
startLiveWindowMode()
Analog Channels don't have to do anything special when entering the LiveWindow.
|
void |
stopLiveWindowMode()
Analog Channels don't have to do anything special when exiting the LiveWindow.
|
void |
updateTable()
Update the table for this sendable object with the latest values.
|
checkAnalogInputChannel, checkAnalogOutputChannel, checkDigitalChannel, checkPDPChannel, checkPDPModule, checkPWMChannel, checkRelayChannel, checkSolenoidChannel, checkSolenoidModule, getDefaultSolenoidModule, setDefaultSolenoidModule
protected PIDSourceType m_pidSource
public AnalogInput(int channel)
channel
- The channel number to represent. 0-3 are on-board 4-7 are on the MXP port.public void free()
free
in class SensorBase
public int getValue()
public int getAverageValue()
public double getVoltage()
public double getAverageVoltage()
public long getLSBWeight()
Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
public int getOffset()
Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
public int getChannel()
public void setAverageBits(int bits)
bits
- The number of averaging bits.public int getAverageBits()
public void setOversampleBits(int bits)
bits
- The number of oversample bits.public int getOversampleBits()
public void initAccumulator()
public void setAccumulatorInitialValue(long initialValue)
This will be added to all values returned to the user.
initialValue
- The value that the accumulator should start from when reset.public void resetAccumulator()
public void setAccumulatorCenter(int center)
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 the accumulator channel. Because of this, any non-zero oversample bits will affect the size of the value for this field.
public void setAccumulatorDeadband(int deadband)
deadband
- The deadband size in ADC codes (12-bit value)public long getAccumulatorValue()
Read the value that has been accumulating. The accumulator is attached after the oversample and average engine.
public long getAccumulatorCount()
Read the count of the accumulated values since the accumulator was last Reset().
public void getAccumulatorOutput(AccumulatorResult result)
This function reads the value and count from the FPGA atomically. This can be used for averaging.
result
- AccumulatorResult object to store the results in.public boolean isAccumulatorChannel()
public static void setGlobalSampleRate(double samplesPerSecond)
This is a global setting for all channels. The maximum rate is 500kS/s divided by the number of channels in use. This is 62500 samples/s per channel if all 8 channels are used.
samplesPerSecond
- The number of samples per second.public static double getGlobalSampleRate()
This assumes one entry in the scan list. This is a global setting for all channels.
public void setPIDSourceType(PIDSourceType pidSource)
PIDSource
setPIDSourceType
in interface PIDSource
pidSource
- An enum to select the parameter.public PIDSourceType getPIDSourceType()
PIDSource
getPIDSourceType
in interface PIDSource
public double pidGet()
public java.lang.String getSmartDashboardType()
getSmartDashboardType
in interface Sendable
Sendable
.public void initTable(ITable subtable)
Sendable
Sendable
object.public void updateTable()
LiveWindowSendable
updateTable
in interface LiveWindowSendable
public ITable getTable()
Sendable
Sendable
.public void startLiveWindowMode()
startLiveWindowMode
in interface LiveWindowSendable
public void stopLiveWindowMode()
stopLiveWindowMode
in interface LiveWindowSendable