Class HAL


public final class HAL extends JNIWrapper
JNI Wrapper for Hardware Abstraction Layer (HAL).
See Also:
  • "hal/HALBase.h"
  • "hal/Main.h"
  • "hal/UsageReporting.h"
  • Method Details

    • initialize

      public static boolean initialize(int timeout, int mode)
      Call this to start up HAL. This is required for robot programs.

      This must be called before any other HAL functions. Failure to do so will result in undefined behavior, and likely segmentation faults. This means that any statically initialized variables in a program MUST call this function in their constructors if they want to use other HAL calls.

      The common parameters are 500 for timeout and 0 for mode.

      This function is safe to call from any thread, and as many times as you wish. It internally guards from any reentrancy.

      The applicable modes are: 0: Try to kill an existing HAL from another program, if not successful, error. 1: Force kill a HAL from another program. 2: Just warn if another hal exists and cannot be killed. Will likely result in undefined behavior.

      Parameters:
      timeout - the initialization timeout (ms)
      mode - the initialization mode (see remarks)
      Returns:
      true if initialization was successful, otherwise false.
      See Also:
      • "HAL_Initialize"
    • shutdown

      public static void shutdown()
      Call this to shut down HAL.

      This must be called at termination of the robot program to avoid potential segmentation faults with simulation extensions at exit.

      See Also:
      • "HAL_Shutdown"
    • hasMain

      public static boolean hasMain()
      Returns true if HAL_SetMain() has been called.
      Returns:
      True if HAL_SetMain() has been called, false otherwise.
      See Also:
      • "HAL_HasMain"
    • runMain

      public static void runMain()
      Runs the main function provided to HAL_SetMain().

      If HAL_SetMain() has not been called, simply sleeps until exitMain() is called.

      See Also:
      • "HAL_RunMain"
    • exitMain

      public static void exitMain()
      Causes HAL_RunMain() to exit.

      If HAL_SetMain() has been called, this calls the exit function provided to that function.

      See Also:
      • "HAL_ExitMain"
    • terminate

      public static void terminate()
      Terminates the executable (at the native level). Does nothing in simulation.
    • registerSimPeriodicBeforeCallback

      Registers a callback to be run by IterativeRobotBase prior to the user's simulationPeriodic code.
      Parameters:
      r - runnable
      Returns:
      Callback object (must be retained for callback to stay active).
    • simPeriodicBefore

      public static void simPeriodicBefore()
      Runs SimPeriodicBefore callbacks. IterativeRobotBase calls this prior to the user's simulationPeriodic code.
    • registerSimPeriodicAfterCallback

      Registers a callback to be run by IterativeRobotBase after the user's simulationPeriodic code.
      Parameters:
      r - runnable
      Returns:
      Callback object (must be retained for callback to stay active).
    • simPeriodicAfter

      public static void simPeriodicAfter()
      Runs SimPeriodicAfter callbacks. IterativeRobotBase calls this after the user's simulationPeriodic code.
    • getBrownedOut

      public static boolean getBrownedOut()
      Gets if the system is in a browned out state.
      Returns:
      true if the system is in a low voltage brown out, false otherwise
      See Also:
      • "HAL_GetBrownedOut"
    • getSystemActive

      public static boolean getSystemActive()
      Gets if the system outputs are currently active.
      Returns:
      true if the system outputs are active, false if disabled
      See Also:
      • "HAL_GetSystemActive"
    • getRSLState

      public static boolean getRSLState()
      Gets the current state of the Robot Signal Light (RSL).
      Returns:
      The current state of the RSL- true if on, false if off
      See Also:
      • "HAL_GetRSLState"
    • getCommsDisableCount

      public static int getCommsDisableCount()
      Gets the number of times the system has been disabled due to communication errors with the Driver Station.
      Returns:
      number of disables due to communication errors.
    • getSystemTimeValid

      public static boolean getSystemTimeValid()
      Gets if the system time is valid.
      Returns:
      True if the system time is valid, false otherwise
      See Also:
      • "HAL_GetSystemTimeValid"
    • reportUsage

      public static int reportUsage(String resource, String data)
      Reports usage of a resource of interest. Repeated calls for the same resource name replace the previous report.
      Parameters:
      resource - the used resource name
      data - arbitrary associated data string
      Returns:
      a handle
    • reportUsage

      public static int reportUsage(String resource, int instanceNumber, String data)
      Reports usage of a resource of interest. Repeated calls for the same resource name replace the previous report.
      Parameters:
      resource - the used resource name
      instanceNumber - an index that identifies the resource instance
      data - arbitrary associated data string
      Returns:
      a handle