WPILibC++  2019.1.1-beta-1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
DriverStation.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2013-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <stdint.h>
11 
12 #include "hal/Types.h"
13 
20 #define HAL_IO_CONFIG_DATA_SIZE 32
21 #define HAL_SYS_STATUS_DATA_SIZE 44
22 #define HAL_USER_STATUS_DATA_SIZE \
23  (984 - HAL_IO_CONFIG_DATA_SIZE - HAL_SYS_STATUS_DATA_SIZE)
24 
25 #define HALFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Input 17
26 #define HALFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Output 18
27 #define HALFRC_NetworkCommunication_DynamicType_Kinect_Header 19
28 #define HALFRC_NetworkCommunication_DynamicType_Kinect_Extra1 20
29 #define HALFRC_NetworkCommunication_DynamicType_Kinect_Vertices1 21
30 #define HALFRC_NetworkCommunication_DynamicType_Kinect_Extra2 22
31 #define HALFRC_NetworkCommunication_DynamicType_Kinect_Vertices2 23
32 #define HALFRC_NetworkCommunication_DynamicType_Kinect_Joystick 24
33 #define HALFRC_NetworkCommunication_DynamicType_Kinect_Custom 25
34 
36  uint32_t enabled : 1;
37  uint32_t autonomous : 1;
38  uint32_t test : 1;
39  uint32_t eStop : 1;
40  uint32_t fmsAttached : 1;
41  uint32_t dsAttached : 1;
42  uint32_t control_reserved : 26;
43 };
44 typedef struct HAL_ControlWord HAL_ControlWord;
45 
46 // clang-format off
47 HAL_ENUM(HAL_AllianceStationID) {
48  HAL_AllianceStationID_kRed1,
49  HAL_AllianceStationID_kRed2,
50  HAL_AllianceStationID_kRed3,
51  HAL_AllianceStationID_kBlue1,
52  HAL_AllianceStationID_kBlue2,
53  HAL_AllianceStationID_kBlue3,
54 };
55 
56 HAL_ENUM(HAL_MatchType) {
57  HAL_kMatchType_none,
58  HAL_kMatchType_practice,
59  HAL_kMatchType_qualification,
60  HAL_kMatchType_elimination,
61 };
62 // clang-format on
63 
64 /* The maximum number of axes that will be stored in a single HALJoystickAxes
65  * struct. This is used for allocating buffers, not bounds checking, since
66  * there are usually less axes in practice.
67  */
68 #define HAL_kMaxJoystickAxes 12
69 #define HAL_kMaxJoystickPOVs 12
70 #define HAL_kMaxJoysticks 6
71 
73  int16_t count;
74  float axes[HAL_kMaxJoystickAxes];
75 };
76 typedef struct HAL_JoystickAxes HAL_JoystickAxes;
77 
79  int16_t count;
80  int16_t povs[HAL_kMaxJoystickPOVs];
81 };
82 typedef struct HAL_JoystickPOVs HAL_JoystickPOVs;
83 
85  uint32_t buttons;
86  uint8_t count;
87 };
89 
91  uint8_t isXbox;
92  uint8_t type;
93  char name[256];
94  uint8_t axisCount;
95  uint8_t axisTypes[HAL_kMaxJoystickAxes];
96  uint8_t buttonCount;
97  uint8_t povCount;
98 };
100 
102  char eventName[64];
103  HAL_MatchType matchType;
104  uint16_t matchNumber;
105  uint8_t replayNumber;
106  uint8_t gameSpecificMessage[64];
107  uint16_t gameSpecificMessageSize;
108 };
109 typedef struct HAL_MatchInfo HAL_MatchInfo;
110 
111 #ifdef __cplusplus
112 extern "C" {
113 #endif
114 
127 int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
128  const char* details, const char* location,
129  const char* callStack, HAL_Bool printMsg);
130 
139 int32_t HAL_GetControlWord(HAL_ControlWord* controlWord);
140 
147 HAL_AllianceStationID HAL_GetAllianceStation(int32_t* status);
148 
156 int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes);
157 
165 int32_t HAL_GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs);
166 
174 int32_t HAL_GetJoystickButtons(int32_t joystickNum,
175  HAL_JoystickButtons* buttons);
176 
189 int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
190  HAL_JoystickDescriptor* desc);
191 
198 HAL_Bool HAL_GetJoystickIsXbox(int32_t joystickNum);
199 
209 int32_t HAL_GetJoystickType(int32_t joystickNum);
210 
221 char* HAL_GetJoystickName(int32_t joystickNum);
222 
228 void HAL_FreeJoystickName(char* name);
229 
240 int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis);
241 
251 int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
252  int32_t leftRumble, int32_t rightRumble);
253 
270 double HAL_GetMatchTime(int32_t* status);
271 
278 int32_t HAL_GetMatchInfo(HAL_MatchInfo* info);
279 
280 #ifndef HAL_USE_LABVIEW
281 
286 void HAL_ReleaseDSMutex(void);
287 
294 HAL_Bool HAL_IsNewControlData(void);
295 
299 void HAL_WaitForDSData(void);
300 
309 HAL_Bool HAL_WaitForDSDataTimeout(double timeout);
310 
316 void HAL_InitializeDriverStation(void);
317 
324 
333 
342 
351 
359 void HAL_ObserveUserProgramTest(void);
360 
361 #endif // HAL_USE_LABVIEW
362 
363 #ifdef __cplusplus
364 } // extern "C"
365 #endif
366 
HAL_Bool HAL_IsNewControlData(void)
Has a new control packet from the driver station arrived since the last time this function was called...
Definition: DriverStation.h:90
Definition: DriverStation.h:101
HAL_Bool HAL_GetJoystickIsXbox(int32_t joystickNum)
Gets is a specific joystick is considered to be an XBox controller.
int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis)
Gets the type of a specific joystick axis.
int32_t HAL_GetJoystickButtons(int32_t joystickNum, HAL_JoystickButtons *buttons)
Gets the buttons of a specific joystick.
int32_t HAL_GetJoystickType(int32_t joystickNum)
Gets the type of joystick connected.
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs, int32_t leftRumble, int32_t rightRumble)
Set joystick outputs.
void HAL_ReleaseDSMutex(void)
Releases the DS Mutex to allow proper shutdown of any threads that are waiting on it...
HAL_AllianceStationID HAL_GetAllianceStation(int32_t *status)
Gets the current alliance station ID.
void HAL_WaitForDSData(void)
Waits for the newest DS packet to arrive.
Definition: DriverStation.h:78
int32_t HAL_GetMatchInfo(HAL_MatchInfo *info)
Gets info about a specific match.
void HAL_ObserveUserProgramStarting(void)
Sets the program starting flag in the DS.
char * HAL_GetJoystickName(int32_t joystickNum)
Gets the name of a joystick.
void HAL_ObserveUserProgramAutonomous(void)
Sets the autonomous enabled flag in the DS.
HAL_Bool HAL_WaitForDSDataTimeout(double timeout)
Waits for the newest DS packet to arrive.
int32_t HAL_GetJoystickDescriptor(int32_t joystickNum, HAL_JoystickDescriptor *desc)
Retrieves the Joystick Descriptor for particular slot.
void HAL_ObserveUserProgramTest(void)
Sets the test mode flag in the DS.
int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode, const char *details, const char *location, const char *callStack, HAL_Bool printMsg)
Sends an error to the driver station.
void HAL_ObserveUserProgramDisabled(void)
Sets the disabled flag in the DS.
int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes *axes)
Gets the axes of a specific joystick.
Definition: DriverStation.h:84
void HAL_ObserveUserProgramTeleop(void)
Sets the teleoperated enabled flag in the DS.
void HAL_InitializeDriverStation(void)
Initializes the driver station communication.
void HAL_FreeJoystickName(char *name)
Frees a joystick name received with HAL_GetJoystickName.
int32_t HAL_GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs *povs)
Gets the POVs of a specific joystick.
double HAL_GetMatchTime(int32_t *status)
Returns the approximate match time.
Definition: DriverStation.h:35
Definition: DriverStation.h:72
int32_t HAL_GetControlWord(HAL_ControlWord *controlWord)
Gets the current control word of the driver station.