WPILib 2012
WPILibRoboticsLibraryforFRC
DriverStation.h
00001 /*----------------------------------------------------------------------------*/
00002 /* Copyright (c) FIRST 2008. All Rights Reserved.                                                         */
00003 /* Open Source Software - may be modified and shared by FRC teams. The code   */
00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
00005 /*----------------------------------------------------------------------------*/
00006 
00007 #ifndef __DRIVER_STATION_H__
00008 #define __DRIVER_STATION_H__
00009 
00010 #include "Dashboard.h"
00011 #include "DriverStationEnhancedIO.h"
00012 #include "SensorBase.h"
00013 #include "Task.h"
00014 
00015 struct FRCCommonControlData;
00016 class AnalogChannel;
00017 
00021 class DriverStation : public SensorBase
00022 {
00023 public:
00024         enum Alliance {kRed, kBlue, kInvalid};
00025 
00026         virtual ~DriverStation();
00027         static DriverStation *GetInstance();
00028 
00029         static const UINT32 kBatteryModuleNumber = 1;
00030         static const UINT32 kBatteryChannel = 8;
00031         static const UINT32 kJoystickPorts = 4;
00032         static const UINT32 kJoystickAxes = 6;
00033 
00034         float GetStickAxis(UINT32 stick, UINT32 axis);
00035         short GetStickButtons(UINT32 stick);
00036 
00037         float GetAnalogIn(UINT32 channel);
00038         bool GetDigitalIn(UINT32 channel);
00039         void SetDigitalOut(UINT32 channel, bool value);
00040         bool GetDigitalOut(UINT32 channel);
00041 
00042         bool IsEnabled();
00043         bool IsDisabled();
00044         bool IsAutonomous();
00045         bool IsOperatorControl();
00046         bool IsNewControlData();
00047         bool IsFMSAttached();
00048 
00049         UINT32 GetPacketNumber();
00050         Alliance GetAlliance();
00051         UINT32 GetLocation();
00052         void WaitForData();
00053         double GetMatchTime();
00054         float GetBatteryVoltage();
00055         UINT16 GetTeamNumber();
00056 
00057         // Get the default dashboard packers. These instances stay around even after
00058         // a call to SetHigh|LowPriorityDashboardPackerToUse() changes which packer
00059         // is in use. You can restore the default high priority packer by calling
00060         // SetHighPriorityDashboardPackerToUse(&GetHighPriorityDashboardPacker()).
00061         Dashboard& GetHighPriorityDashboardPacker() { return m_dashboardHigh; }
00062         Dashboard& GetLowPriorityDashboardPacker() { return m_dashboardLow; }
00063 
00064         // Get/set the dashboard packers to use. This can sideline or restore the
00065         // default packers. Initializing SmartDashboard changes the high priority
00066         // packer in use so beware that the default packer will then be idle. These
00067         // methods support any kind of DashboardBase, e.g. a Dashboard or a
00068         // SmartDashboard.
00069         DashboardBase* GetHighPriorityDashboardPackerInUse() { return m_dashboardInUseHigh; }
00070         DashboardBase* GetLowPriorityDashboardPackerInUse() { return m_dashboardInUseLow; }
00071         void SetHighPriorityDashboardPackerToUse(DashboardBase* db) { m_dashboardInUseHigh = db; }
00072         void SetLowPriorityDashboardPackerToUse(DashboardBase* db) { m_dashboardInUseLow = db; }
00073 
00074         DriverStationEnhancedIO& GetEnhancedIO() { return m_enhancedIO; }
00075 
00076         void IncrementUpdateNumber() { m_updateNumber++; }
00077         SEM_ID GetUserStatusDataSem() { return m_statusDataSemaphore; }
00078 
00082         void InDisabled(bool entering) {m_userInDisabled=entering;}
00086         void InAutonomous(bool entering) {m_userInAutonomous=entering;}
00090         void InOperatorControl(bool entering) {m_userInTeleop=entering;}
00091 
00092 protected:
00093         DriverStation();
00094 
00095         void GetData();
00096         void SetData();
00097 
00098 private:
00099         static void InitTask(DriverStation *ds);
00100         static DriverStation *m_instance;
00101         static UINT8 m_updateNumber;
00103         static const float kUpdatePeriod = 0.02;
00104 
00105         void Run();
00106 
00107         struct FRCCommonControlData *m_controlData;
00108         UINT8 m_digitalOut;
00109         AnalogChannel *m_batteryChannel;
00110         SEM_ID m_statusDataSemaphore;
00111         Task m_task;
00112         Dashboard m_dashboardHigh;  // the default dashboard packers
00113         Dashboard m_dashboardLow;
00114         DashboardBase* m_dashboardInUseHigh;  // the current dashboard packers in use
00115         DashboardBase* m_dashboardInUseLow;
00116         bool m_newControlData;
00117         SEM_ID m_packetDataAvailableSem;
00118         DriverStationEnhancedIO m_enhancedIO;
00119         SEM_ID m_waitForDataSem;
00120         double m_approxMatchTimeOffset;
00121         bool m_userInDisabled;
00122         bool m_userInAutonomous;
00123         bool m_userInTeleop;
00124 };
00125 
00126 #endif
00127 
 All Classes Functions Variables