Class AnalogJNI

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

public class AnalogJNI
extends JNIWrapper
Analog Input / Output / Accumulator / Trigger JNI Functions.
See Also:
"hal/AnalogInput.h", "hal/AnalogOutput.h", "hal/AnalogAccumulator.h", "hal/AnalogTrigger.h"
  • Constructor Details

  • Method Details

    • initializeAnalogInputPort

      public static int initializeAnalogInputPort​(int halPortHandle)
      Initializes the analog input port using the given port object.
      Parameters:
      halPortHandle - Handle to the port to initialize.
      Returns:
      the created analog input handle
      See Also:
      "HAL_InitializeAnalogInputPort"
    • freeAnalogInputPort

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

      public static int initializeAnalogOutputPort​(int halPortHandle)
      Initializes the analog output port using the given port object.
      Parameters:
      halPortHandle - handle to the port
      Returns:
      the created analog output handle
      See Also:
      "HAL_InitializeAnalogOutputPort"
    • freeAnalogOutputPort

      public static void freeAnalogOutputPort​(int portHandle)
      Frees an analog output port.
      Parameters:
      portHandle - the analog output handle
      See Also:
      "HAL_FreeAnalogOutputPort"
    • 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"
    • checkAnalogOutputChannel

      public static boolean checkAnalogOutputChannel​(int channel)
    • 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"
    • setAnalogOutput

      public static void setAnalogOutput​(int portHandle, double voltage)
    • getAnalogOutput

      public static double getAnalogOutput​(int portHandle)
    • 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 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.

      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"
    • isAccumulatorChannel

      public static boolean isAccumulatorChannel​(int analogPortHandle)
      Is the channel attached to an accumulator.
      Parameters:
      analogPortHandle - Handle to the analog port.
      Returns:
      The analog channel is attached to an accumulator.
      See Also:
      "HAL_IsAccumulatorChannel"
    • initAccumulator

      public static void initAccumulator​(int analogPortHandle)
      Initialize the accumulator.
      Parameters:
      analogPortHandle - Handle to the analog port.
      See Also:
      "HAL_InitAccumulator"
    • resetAccumulator

      public static void resetAccumulator​(int analogPortHandle)
      Resets the accumulator to the initial value.
      Parameters:
      analogPortHandle - Handle to the analog port.
      See Also:
      "HAL_ResetAccumulator"
    • setAccumulatorCenter

      public static void setAccumulatorCenter​(int analogPortHandle, int 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 make integration work and to take the device offset into account when integrating.

      This center value is based on the output of the oversampled and averaged source from channel 1. Because of this, any non-zero oversample bits will affect the size of the value for this field.

      Parameters:
      analogPortHandle - Handle to the analog port.
      center - The center value of the accumulator.
      See Also:
      "HAL_SetAccumulatorCenter"
    • setAccumulatorDeadband

      public static void setAccumulatorDeadband​(int analogPortHandle, int deadband)
      Set the accumulator's deadband.
      Parameters:
      analogPortHandle - Handle to the analog port.
      deadband - The deadband of the accumulator.
      See Also:
      "HAL_SetAccumulatorDeadband"
    • getAccumulatorValue

      public static long getAccumulatorValue​(int analogPortHandle)
      Read the accumulated value.

      Read the value that has been accumulating on channel 1. The accumulator is attached after the oversample and average engine.

      Parameters:
      analogPortHandle - Handle to the analog port.
      Returns:
      The 64-bit value accumulated since the last Reset().
      See Also:
      "HAL_GetAccumulatorValue"
    • getAccumulatorCount

      public static int getAccumulatorCount​(int analogPortHandle)
      Read the number of accumulated values.

      Read the count of the accumulated values since the accumulator was last Reset().

      Parameters:
      analogPortHandle - Handle to the analog port.
      Returns:
      The number of times samples from the channel were accumulated.
      See Also:
      "HAL_GetAccumulatorCount"
    • getAccumulatorOutput

      public static void getAccumulatorOutput​(int analogPortHandle, AccumulatorResult result)
      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.

      Parameters:
      analogPortHandle - Handle to the analog port.
      result - Accumulator result.
      See Also:
      "HAL_GetAccumulatorOutput"
    • initializeAnalogTrigger

      public static int initializeAnalogTrigger​(int analogInputHandle)
      Initializes an analog trigger.
      Parameters:
      analogInputHandle - the analog input to use for triggering
      Returns:
      the created analog trigger handle
      See Also:
      "HAL_InitializeAnalogTrigger"
    • initializeAnalogTriggerDutyCycle

      public static int initializeAnalogTriggerDutyCycle​(int dutyCycleHandle)
      Initializes an analog trigger with a Duty Cycle input.
      Parameters:
      dutyCycleHandle - the analog input to use for duty cycle
      Returns:
      tbe created analog trigger handle
      See Also:
      "HAL_InitializeAnalogTriggerDutyCycle"
    • cleanAnalogTrigger

      public static void cleanAnalogTrigger​(int analogTriggerHandle)
      Frees an analog trigger.
      Parameters:
      analogTriggerHandle - the trigger handle
      See Also:
      "HAL_CleanAnalogTrigger"
    • setAnalogTriggerLimitsRaw

      public static void setAnalogTriggerLimitsRaw​(int analogTriggerHandle, int lower, int upper)
      Sets the raw ADC upper and lower limits of the analog trigger.

      HAL_SetAnalogTriggerLimitsVoltage or HAL_SetAnalogTriggerLimitsDutyCycle is likely better in most cases.

      Parameters:
      analogTriggerHandle - the trigger handle
      lower - the lower ADC value
      upper - the upper ADC value
      See Also:
      "HAL_SetAnalogTriggerLimitsRaw"
    • setAnalogTriggerLimitsDutyCycle

      public static void setAnalogTriggerLimitsDutyCycle​(int analogTriggerHandle, double lower, double higher)
      Sets the upper and lower limits of the analog trigger.

      The limits are given as floating point duty cycle values.

      Parameters:
      analogTriggerHandle - the trigger handle
      lower - the lower duty cycle value
      higher - the upper duty cycle value
      See Also:
      "HAL_SetAnalogTriggerLimitsDutyCycle"
    • setAnalogTriggerLimitsVoltage

      public static void setAnalogTriggerLimitsVoltage​(int analogTriggerHandle, double lower, double upper)
      Sets the upper and lower limits of the analog trigger.

      The limits are given as floating point voltage values.

      Parameters:
      analogTriggerHandle - the trigger handle
      lower - the lower voltage value
      upper - the upper voltage value
      See Also:
      "HAL_SetAnalogTriggerLimitsVoltage"
    • setAnalogTriggerAveraged

      public static void setAnalogTriggerAveraged​(int analogTriggerHandle, boolean useAveragedValue)
      Configures the analog trigger to use the averaged vs. raw values.

      If the value is true, then the averaged value is selected for the analog trigger, otherwise the immediate value is used.

      This is not allowed to be used if filtered mode is set. This is not allowed to be used with Duty Cycle based inputs.

      Parameters:
      analogTriggerHandle - the trigger handle
      useAveragedValue - true to use averaged values, false for raw
      See Also:
      "HAL_SetAnalogTriggerAveraged"
    • setAnalogTriggerFiltered

      public static void setAnalogTriggerFiltered​(int analogTriggerHandle, boolean useFilteredValue)
      Configures the analog trigger to use a filtered value.

      The analog trigger will operate with a 3 point average rejection filter. This is designed to help with 360 degree pot applications for the period where the pot crosses through zero.

      This is not allowed to be used if averaged mode is set.

      Parameters:
      analogTriggerHandle - the trigger handle
      useFilteredValue - true to use filtered values, false for average or raw
      See Also:
      "HAL_SetAnalogTriggerFiltered"
    • getAnalogTriggerInWindow

      public static boolean getAnalogTriggerInWindow​(int analogTriggerHandle)
      Returns the InWindow output of the analog trigger.

      True if the analog input is between the upper and lower limits.

      Parameters:
      analogTriggerHandle - the trigger handle
      Returns:
      the InWindow output of the analog trigger
      See Also:
      "HAL_GetAnalogTriggerInWindow"
    • getAnalogTriggerTriggerState

      public static boolean getAnalogTriggerTriggerState​(int analogTriggerHandle)
      Returns the TriggerState output of the analog trigger.

      True if above upper limit. False if below lower limit. If in Hysteresis, maintain previous state.

      Parameters:
      analogTriggerHandle - the trigger handle
      Returns:
      the TriggerState output of the analog trigger
      See Also:
      "HAL_GetAnalogTriggerTriggerState"
    • getAnalogTriggerOutput

      public static boolean getAnalogTriggerOutput​(int analogTriggerHandle, int type)
      Gets the state of the analog trigger output.
      Parameters:
      analogTriggerHandle - the trigger handle
      type - the type of trigger to trigger on
      Returns:
      the state of the analog trigger output
      See Also:
      "HAL_GetAnalogTriggerOutput"
    • getAnalogTriggerFPGAIndex

      public static int getAnalogTriggerFPGAIndex​(int analogTriggerHandle)
      Get the FPGA index for the AnlogTrigger.
      Parameters:
      analogTriggerHandle - the trigger handle
      Returns:
      the FPGA index
      See Also:
      "HAL_GetAnalogTriggerFPGAIndex"