Low-level hardware interface for roboRIO and FRC control system
The Hardware Abstraction Layer (HAL) provides low-level access to the roboRIO hardware and FRC control system. It serves as the foundation for WPILib’s higher-level APIs.
The HAL is a C-based API that provides direct hardware access while abstracting platform-specific details. Most users should use WPILib’s higher-level APIs instead of calling HAL directly.
The HAL is primarily used internally by WPILib. Direct HAL usage is only recommended for advanced users implementing custom hardware interfaces or debugging low-level issues.
#include <hal/HAL.h>// Initialize HAL - must be called before any other HAL functionsint32_t status = 0;HAL_Bool success = HAL_Initialize(500, 0);if (!success) { // Handle initialization failure}// Get system statusint32_t fpgaVersion = HAL_GetFPGAVersion(&status);int64_t fpgaTime = HAL_GetFPGATime(&status);// Observe user program startingHAL_ObserveUserProgramStarting();// Shutdown HAL when doneHAL_Shutdown();
#include <hal/DriverStation.h>int32_t status = 0;// Get control wordHAL_ControlWord controlWord;HAL_GetControlWord(&controlWord);if (controlWord.enabled && controlWord.autonomous) { // Robot is enabled in autonomous mode}// Get alliance stationHAL_AllianceStationID station;HAL_GetAllianceStation(&station, &status);// Get joystick dataHAL_JoystickAxes axes;HAL_GetJoystickAxes(0, &axes); // Joystick 0HAL_JoystickButtons buttons;HAL_GetJoystickButtons(0, &buttons);HAL_JoystickPOVs povs;HAL_GetJoystickPOVs(0, &povs);// Get match infoHAL_MatchInfo matchInfo;HAL_GetMatchInfo(&matchInfo);
The HAL uses opaque handle types for resource management:
typedef int32_t HAL_DigitalHandle;typedef int32_t HAL_AnalogInputHandle;typedef int32_t HAL_PWMHandle;typedef int32_t HAL_EncoderHandle;typedef int32_t HAL_CounterHandle;// ... and many more