Class HAL


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

    • initialize

      public static boolean initialize()
      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.

      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

      public static HAL.SimPeriodicBeforeCallback registerSimPeriodicBeforeCallback(Runnable r)
      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

      public static HAL.SimPeriodicAfterCallback registerSimPeriodicAfterCallback(Runnable r)
      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 void 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
    • reportUsage

      public static void 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
    • publishCanVersion

      public static int publishCanVersion(int busId, int deviceId, String name, String version)
      Publishes a version for a device on a CAN bus.
      Parameters:
      busId - bus containing the device
      deviceId - device identifier
      name - version name
      version - version string
      Returns:
      status of the operation
    • publishVersion

      public static int publishVersion(String name, String version)
      Publishes a version without a bus or device identifier.
      Parameters:
      name - version name
      version - version string
      Returns:
      status of the operation
    • publishWpilibVersion

      public static int publishWpilibVersion(String version)
      Publishes the WPILib version.
      Parameters:
      version - WPILib version string
      Returns:
      status of the operation