WPILib  2014.0
WPIRoboticsLibraryforFRC
 All Classes Functions Variables Pages
DriverStation.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #ifndef __DRIVER_STATION_H__
8 #define __DRIVER_STATION_H__
9 
10 #include "Dashboard.h"
11 #include "DriverStationEnhancedIO.h"
12 #include "SensorBase.h"
13 #include "Task.h"
14 
15 struct FRCCommonControlData;
16 class AnalogChannel;
17 
21 class DriverStation : public SensorBase
22 {
23 public:
24  enum Alliance {kRed, kBlue, kInvalid};
25 
26  virtual ~DriverStation();
27  static DriverStation *GetInstance();
28 
29  static const uint32_t kBatteryModuleNumber = 1;
30  static const uint32_t kBatteryChannel = 8;
31  static const uint32_t kJoystickPorts = 4;
32  static const uint32_t kJoystickAxes = 6;
33 
34  float GetStickAxis(uint32_t stick, uint32_t axis);
35  short GetStickButtons(uint32_t stick);
36 
37  float GetAnalogIn(uint32_t channel);
38  bool GetDigitalIn(uint32_t channel);
39  void SetDigitalOut(uint32_t channel, bool value);
40  bool GetDigitalOut(uint32_t channel);
41 
42  bool IsEnabled();
43  bool IsDisabled();
44  bool IsAutonomous();
45  bool IsOperatorControl();
46  bool IsTest();
47  bool IsNewControlData();
48  bool IsFMSAttached();
49 
50  uint32_t GetPacketNumber();
51  Alliance GetAlliance();
52  uint32_t GetLocation();
53  void WaitForData();
54  double GetMatchTime();
55  float GetBatteryVoltage();
56  uint16_t GetTeamNumber();
57 
58  // Get the default dashboard packers. These instances stay around even after
59  // a call to SetHigh|LowPriorityDashboardPackerToUse() changes which packer
60  // is in use. You can restore the default high priority packer by calling
61  // SetHighPriorityDashboardPackerToUse(&GetHighPriorityDashboardPacker()).
62  Dashboard& GetHighPriorityDashboardPacker() { return m_dashboardHigh; }
63  Dashboard& GetLowPriorityDashboardPacker() { return m_dashboardLow; }
64 
65  // Get/set the dashboard packers to use. This can sideline or restore the
66  // default packers. Initializing SmartDashboard changes the high priority
67  // packer in use so beware that the default packer will then be idle. These
68  // methods support any kind of DashboardBase, e.g. a Dashboard or a
69  // SmartDashboard.
70  DashboardBase* GetHighPriorityDashboardPackerInUse() { return m_dashboardInUseHigh; }
71  DashboardBase* GetLowPriorityDashboardPackerInUse() { return m_dashboardInUseLow; }
72  void SetHighPriorityDashboardPackerToUse(DashboardBase* db) { m_dashboardInUseHigh = db; }
73  void SetLowPriorityDashboardPackerToUse(DashboardBase* db) { m_dashboardInUseLow = db; }
74 
75  DriverStationEnhancedIO& GetEnhancedIO() { return m_enhancedIO; }
76 
77  void IncrementUpdateNumber() { m_updateNumber++; }
78  SEM_ID GetUserStatusDataSem() { return m_statusDataSemaphore; }
79 
83  void InDisabled(bool entering) {m_userInDisabled=entering;}
87  void InAutonomous(bool entering) {m_userInAutonomous=entering;}
91  void InOperatorControl(bool entering) {m_userInTeleop=entering;}
95  void InTest(bool entering) {m_userInTest=entering;}
96 
97 protected:
98  DriverStation();
99 
100  void GetData();
101  void SetData();
102 
103 private:
104  static void InitTask(DriverStation *ds);
105  static DriverStation *m_instance;
106  static uint8_t m_updateNumber;
108  static constexpr float kUpdatePeriod = 0.02;
109 
110  void Run();
111 
112  struct FRCCommonControlData *m_controlData;
113  uint8_t m_digitalOut;
114  AnalogChannel *m_batteryChannel;
115  SEM_ID m_statusDataSemaphore;
116  Task m_task;
117  Dashboard m_dashboardHigh; // the default dashboard packers
118  Dashboard m_dashboardLow;
119  DashboardBase* m_dashboardInUseHigh; // the current dashboard packers in use
120  DashboardBase* m_dashboardInUseLow;
121  SEM_ID m_newControlData;
122  SEM_ID m_packetDataAvailableSem;
123  DriverStationEnhancedIO m_enhancedIO;
124  SEM_ID m_waitForDataSem;
125  double m_approxMatchTimeOffset;
126  bool m_userInDisabled;
127  bool m_userInAutonomous;
128  bool m_userInTeleop;
129  bool m_userInTest;
130 };
131 
132 #endif
133 
bool GetDigitalOut(uint32_t channel)
Definition: DriverStation.cpp:383
Definition: DashboardBase.h:13
float GetAnalogIn(uint32_t channel)
Definition: DriverStation.cpp:306
uint32_t GetLocation()
Definition: DriverStation.cpp:466
void InDisabled(bool entering)
Definition: DriverStation.h:83
float GetBatteryVoltage()
Definition: DriverStation.cpp:208
uint32_t GetPacketNumber()
Definition: DriverStation.cpp:443
short GetStickButtons(uint32_t stick)
Definition: DriverStation.cpp:275
void SetData()
Definition: DriverStation.cpp:182
float GetStickAxis(uint32_t stick, uint32_t axis)
Definition: DriverStation.cpp:227
bool IsFMSAttached()
Definition: DriverStation.cpp:432
bool IsNewControlData()
Definition: DriverStation.cpp:422
void SetDigitalOut(uint32_t channel, bool value)
Definition: DriverStation.cpp:362
void InAutonomous(bool entering)
Definition: DriverStation.h:87
bool GetDigitalIn(uint32_t channel)
Definition: DriverStation.cpp:338
Definition: SensorBase.h:20
Definition: DriverStationEnhancedIO.h:29
static DriverStation * GetInstance()
Definition: DriverStation.cpp:145
double GetMatchTime()
Definition: DriverStation.cpp:492
void GetData()
Definition: DriverStation.cpp:159
uint16_t GetTeamNumber()
Definition: DriverStation.cpp:503
Definition: Dashboard.h:20
void WaitForData()
Definition: DriverStation.cpp:477
Alliance GetAlliance()
Definition: DriverStation.cpp:453
void InTest(bool entering)
Definition: DriverStation.h:95
void InOperatorControl(bool entering)
Definition: DriverStation.h:91
Definition: Task.h:17
DriverStation()
Definition: DriverStation.cpp:31
Definition: AnalogChannel.h:29
Definition: DriverStation.h:21