Class AnalogJNI

java.lang.Object
edu.wpi.first.hal.JNIWrapper
edu.wpi.first.hal.AnalogJNI

public class AnalogJNI extends JNIWrapper
Analog Input / Output / Trigger JNI Functions.
See Also:
  • "hal/AnalogInput.h"
  • Method Details

    • initializeAnalogInputPort

      public static int initializeAnalogInputPort(int channel)
      Initializes the analog input port using the given port object.
      Parameters:
      channel - The smartio channel.
      Returns:
      the created analog input handle
      See Also:
      • "HAL_InitializeAnalogInputPort"
    • freeAnalogInputPort

      public static void freeAnalogInputPort(int analogPortHandle)
      Frees an analog input port.
      Parameters:
      analogPortHandle - Handle to the analog port.
      See Also:
      • "HAL_FreeAnalogInputPort"
    • checkAnalogModule

      public static boolean checkAnalogModule(byte module)
      Checks that the analog module number is valid.
      Parameters:
      module - The analog module number.
      Returns:
      Analog module is valid and present
      See Also:
      • "HAL_CheckAnalogModule"
    • checkAnalogInputChannel

      public static boolean checkAnalogInputChannel(int channel)
      Checks that the analog output channel number is valid. Verifies that the analog channel number is one of the legal channel numbers. Channel numbers are 0-based.
      Parameters:
      channel - The analog output channel number.
      Returns:
      Analog channel is valid
      See Also:
      • "HAL_CheckAnalogInputChannel"
    • setAnalogInputSimDevice

      public static void setAnalogInputSimDevice(int handle, int device)
      Indicates the analog input is used by a simulated device.
      Parameters:
      handle - the analog input handle
      device - simulated device handle
      See Also:
      • "HAL_SetAnalogInputSimDevice"
    • setAnalogSampleRate

      public static void setAnalogSampleRate(double samplesPerSecond)
      Sets the sample rate.

      This is a global setting for the Athena and effects all channels.

      Parameters:
      samplesPerSecond - The number of samples per channel per second.
      See Also:
      • "HAL_SetAnalogSampleRate"
    • getAnalogSampleRate

      public static double getAnalogSampleRate()
      Gets the current sample rate.

      This assumes one entry in the scan list. This is a global setting for the Athena and effects all channels.

      Returns:
      Sample rate.
      See Also:
      • "HAL_GetAnalogSampleRate"
    • setAnalogAverageBits

      public static void setAnalogAverageBits(int analogPortHandle, int bits)
      Sets 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.

      Parameters:
      analogPortHandle - Handle to the analog port to configure.
      bits - Number of bits to average.
      See Also:
      • "HAL_SetAnalogAverageBits"
    • getAnalogAverageBits

      public static int getAnalogAverageBits(int analogPortHandle)
      Gets 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:
      analogPortHandle - Handle to the analog port to use.
      Returns:
      Bits to average.
      See Also:
      • "HAL_GetAnalogAverageBits"
    • setAnalogOversampleBits

      public static void setAnalogOversampleBits(int analogPortHandle, int bits)
      Sets 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:
      analogPortHandle - Handle to the analog port to use.
      bits - Number of bits to oversample.
      See Also:
      • "HAL_SetAnalogOversampleBits"
    • getAnalogOversampleBits

      public static int getAnalogOversampleBits(int analogPortHandle)
      Gets 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:
      analogPortHandle - Handle to the analog port to use.
      Returns:
      Bits to oversample.
      See Also:
      • "HAL_GetAnalogOversampleBits"
    • getAnalogValue

      public static short getAnalogValue(int analogPortHandle)
      Gets a sample straight from the channel on this module.

      The sample is a 12-bit value representing the 0V to 3.3V 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.

      Parameters:
      analogPortHandle - Handle to the analog port to use.
      Returns:
      A sample straight from the channel on this module.
      See Also:
      • "HAL_GetAnalogValue"
    • getAnalogAverageValue

      public static int getAnalogAverageValue(int analogPortHandle)
      Gets 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**(OversampleBits + AverageBits) samples have been acquired from the module on this channel. Use GetAverageVoltage() to get the analog value in calibrated units.

      Parameters:
      analogPortHandle - Handle to the analog port to use.
      Returns:
      A sample from the oversample and average engine for the channel.
      See Also:
      • "HAL_GetAnalogAverageValue"
    • getAnalogVoltsToValue

      public static int getAnalogVoltsToValue(int analogPortHandle, double voltage)
      Converts 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.

      todo This assumes raw values. Oversampling not supported as is.

      Parameters:
      analogPortHandle - Handle to the analog port to use.
      voltage - The voltage to convert.
      Returns:
      The raw value for the channel.
      See Also:
      • "HAL_GetAnalogVoltsToValue"
    • getAnalogValueToVolts

      public static double getAnalogValueToVolts(int analogPortHandle, int value)
      Get the analog voltage from a raw value.
      Parameters:
      analogPortHandle - Handle to the analog port the values were read from.
      value - The raw analog value
      Returns:
      The voltage relating to the value
      See Also:
      • "HAL_GetAnalogValueToVolts"
    • getAnalogVoltage

      public static double getAnalogVoltage(int analogPortHandle)
      Gets 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().

      Parameters:
      analogPortHandle - Handle to the analog port to use.
      Returns:
      A scaled sample straight from the channel on this module.
      See Also:
      • "HAL_GetAnalogVoltage"
    • getAnalogAverageVoltage

      public static double getAnalogAverageVoltage(int analogPortHandle)
      Gets 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.

      Parameters:
      analogPortHandle - Handle to the analog port to use.
      Returns:
      A scaled sample from the output of the oversample and average engine for the channel.
      See Also:
      • "HAL_GetAnalogAverageVoltage"
    • getAnalogLSBWeight

      public static int getAnalogLSBWeight(int analogPortHandle)
      Gets 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)

      Parameters:
      analogPortHandle - Handle to the analog port to use.
      Returns:
      Least significant bit weight.
      See Also:
      • "HAL_GetAnalogLSBWeight"
    • getAnalogOffset

      public static int getAnalogOffset(int analogPortHandle)
      Gets 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)

      Parameters:
      analogPortHandle - Handle to the analog port to use.
      Returns:
      Offset constant.
      See Also:
      • "HAL_GetAnalogOffset"