"

2013 FRC Java API

"

edu.wpi.first.wpilibj
Class AnalogModule

java.lang.Object
  extended by edu.wpi.first.wpilibj.SensorBase
      extended by edu.wpi.first.wpilibj.Module
          extended by edu.wpi.first.wpilibj.AnalogModule

public class AnalogModule
extends Module

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.


Field Summary
static int kDefaultAverageBits
          The default number of averaging bits to use
static int kDefaultOversampleBits
          The default number of Oversample bits to use
static double kDefaultSampleRate
          The default sample rate
static int kTimebase
          The time base used by the module
 
Fields inherited from class edu.wpi.first.wpilibj.Module
m_moduleNumber, m_modules, m_moduleType
 
Fields inherited from class edu.wpi.first.wpilibj.SensorBase
kAnalogChannels, kAnalogModules, kDigitalChannels, kPwmChannels, kRelayChannels, kSolenoidChannels, kSolenoidModules, kSystemClockTicksPerMicrosecond
 
Constructor Summary
protected AnalogModule(int moduleNumber)
          Create a new instance of an analog module.
 
Method Summary
 int getAverageBits(int channel)
          Get the number of averaging bits.
 int getAverageValue(int channel)
          Get the raw averaged and oversampled value.
 double getAverageVoltage(int channel)
          Get the averaged voltage.
static AnalogModule getInstance(int moduleNumber)
          Get an instance of an Analog Module.
 long getLSBWeight(int channel)
          Get the LSB Weight portion of the calibration for a channel.
 int getOffset(int channel)
          Get the Offset portion of the calibration for a channel.
 int getOversampleBits(int channel)
          Get the number of oversample bits.
 double getSampleRate()
          Get the current sample rate on the module.
 int getValue(int channel)
          Get the raw analog value.
 double getVoltage(int channel)
          Get the voltage.
 void setAverageBits(int channel, int bits)
          Set the number of averaging bits.
 void setOversampleBits(int channel, int bits)
          Set the number of oversample bits.
 void setSampleRate(double samplesPerSecond)
          Set the sample rate on the module.
 int voltsToValue(int channel, double voltage)
          Convert a voltage to a raw value for a specified channel.
 
Methods inherited from class edu.wpi.first.wpilibj.Module
getModule, getModuleNumber, getModuleType
 
Methods inherited from class edu.wpi.first.wpilibj.SensorBase
checkAnalogChannel, checkAnalogModule, checkDigitalChannel, checkDigitalModule, checkPWMChannel, checkPWMModule, checkRelayChannel, checkRelayModule, checkSolenoidChannel, checkSolenoidModule, free, getDefaultAnalogModule, getDefaultDigitalModule, getDefaultSolenoidModule, setDefaultAnalogModule, setDefaultDigitalModule, setDefaultSolenoidModule
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kTimebase

public static final int kTimebase
The time base used by the module

See Also:
Constant Field Values

kDefaultOversampleBits

public static final int kDefaultOversampleBits
The default number of Oversample bits to use

See Also:
Constant Field Values

kDefaultAverageBits

public static final int kDefaultAverageBits
The default number of averaging bits to use

See Also:
Constant Field Values

kDefaultSampleRate

public static final double kDefaultSampleRate
The default sample rate

See Also:
Constant Field Values
Constructor Detail

AnalogModule

protected AnalogModule(int moduleNumber)
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.

Parameters:
moduleNumber - The index of the analog module to create (1 or 2).
Method Detail

getInstance

public static AnalogModule getInstance(int moduleNumber)
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.

Parameters:
moduleNumber - The index of the analog module to get (1 or 2).
Returns:
The AnalogModule.

setSampleRate

public void setSampleRate(double samplesPerSecond)
Set the sample rate on the module. This is a global setting for the module and effects all channels.

Parameters:
samplesPerSecond - The number of samples per channel per second.

getSampleRate

public double 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.

Returns:
Sample rate.

setAverageBits

public void setAverageBits(int channel,
                           int bits)
Set the number of averaging bits. This sets the number of averaging bits. The actual number of averaged samples is 2**bits. The averaging is done automatically in the FPGA.

Parameters:
channel - Analog channel to configure.
bits - Number of bits to average.

getAverageBits

public int getAverageBits(int 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.

Parameters:
channel - Channel to address.
Returns:
Bits to average.

setOversampleBits

public void setOversampleBits(int channel,
                              int 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:
channel - Analog channel to configure.
bits - Number of bits to oversample.

getOversampleBits

public int getOversampleBits(int 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.

Parameters:
channel - Channel to address.
Returns:
Bits to oversample.

getValue

public int getValue(int channel)
Get the raw analog value. Get the analog value as it is returned from the D/A converter.

Parameters:
channel - Channel number to read.
Returns:
Raw value.

getAverageValue

public int getAverageValue(int channel)
Get the raw averaged and oversampled value.

Parameters:
channel - Channel number to read.
Returns:
The averaged and oversampled raw value.

voltsToValue

public int voltsToValue(int channel,
                        double 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.

Parameters:
channel - The channel to convert for.
voltage - The voltage to convert.
Returns:
The raw value for the channel.

getVoltage

public double getVoltage(int channel)
Get the voltage. Return the voltage from the A/D converter.

Parameters:
channel - The channel to read.
Returns:
The scaled voltage from the channel.

getAverageVoltage

public double getAverageVoltage(int channel)
Get the averaged voltage. Return the averaged voltage from the A/D converter.

Parameters:
channel - The channel to read.
Returns:
The scaled averaged and oversampled voltage from the channel.

getLSBWeight

public long getLSBWeight(int channel)
Get the LSB Weight portion of the calibration for a channel.

Parameters:
channel - The channel to get calibration data for.
Returns:
LSB Weight calibration point.

getOffset

public int getOffset(int channel)
Get the Offset portion of the calibration for a channel.

Parameters:
channel - The channel to get calibration data for.
Returns:
Offset calibration point.

"

2013 FRC Java API

"

"
For updated information see the Java FRC site
"