2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2014-08-06 11:29:15 -04:00
|
|
|
/* Copyright (c) FIRST 2008. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
2014-05-02 17:54:01 -04:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
#include "SensorBase.h"
|
2014-08-08 17:05:49 -04:00
|
|
|
#include "RobotState.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "Task.h"
|
2014-09-25 20:36:59 -04:00
|
|
|
#include "HAL/HAL.hpp"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2014-08-06 11:29:15 -04:00
|
|
|
struct HALControlWord;
|
2014-06-12 18:07:45 -04:00
|
|
|
class AnalogInput;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provide access to the network communication data to / from the Driver Station.
|
|
|
|
|
*/
|
2014-08-08 17:05:49 -04:00
|
|
|
class DriverStation : public SensorBase, public RobotStateInterface
|
2013-12-15 18:30:16 -05:00
|
|
|
{
|
|
|
|
|
public:
|
2014-05-02 17:54:01 -04:00
|
|
|
enum Alliance
|
|
|
|
|
{
|
|
|
|
|
kRed,
|
|
|
|
|
kBlue,
|
|
|
|
|
kInvalid
|
|
|
|
|
};
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
virtual ~DriverStation();
|
|
|
|
|
static DriverStation *GetInstance();
|
2014-10-20 17:19:28 -04:00
|
|
|
static void ReportError(std::string error);
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2014-10-23 23:57:35 -07:00
|
|
|
static const uint32_t kJoystickPorts = 6;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
float GetStickAxis(uint32_t stick, uint32_t axis);
|
2014-10-17 14:46:25 -04:00
|
|
|
int GetStickPOV(uint32_t stick, uint32_t pov);
|
2014-11-21 11:32:08 -05:00
|
|
|
bool GetStickButton(uint32_t stick, uint8_t button);
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
bool IsEnabled();
|
|
|
|
|
bool IsDisabled();
|
2014-05-02 17:54:01 -04:00
|
|
|
bool IsAutonomous();
|
2013-12-15 18:30:16 -05:00
|
|
|
bool IsOperatorControl();
|
2014-05-02 17:54:01 -04:00
|
|
|
bool IsTest();
|
2014-11-18 10:56:25 -05:00
|
|
|
bool IsDSAttached();
|
2013-12-15 18:30:16 -05:00
|
|
|
bool IsNewControlData();
|
|
|
|
|
bool IsFMSAttached();
|
2014-11-18 10:56:25 -05:00
|
|
|
bool IsSysActive();
|
|
|
|
|
bool IsSysBrownedOut();
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
Alliance GetAlliance();
|
|
|
|
|
uint32_t GetLocation();
|
|
|
|
|
void WaitForData();
|
|
|
|
|
double GetMatchTime();
|
|
|
|
|
float GetBatteryVoltage();
|
|
|
|
|
|
|
|
|
|
/** Only to be used to tell the Driver Station what code you claim to be executing
|
|
|
|
|
* for diagnostic purposes only
|
|
|
|
|
* @param entering If true, starting disabled code; if false, leaving disabled code */
|
2014-05-02 17:54:01 -04:00
|
|
|
void InDisabled(bool entering)
|
|
|
|
|
{
|
|
|
|
|
m_userInDisabled = entering;
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
/** Only to be used to tell the Driver Station what code you claim to be executing
|
|
|
|
|
* for diagnostic purposes only
|
|
|
|
|
* @param entering If true, starting autonomous code; if false, leaving autonomous code */
|
2014-05-02 17:54:01 -04:00
|
|
|
void InAutonomous(bool entering)
|
|
|
|
|
{
|
|
|
|
|
m_userInAutonomous = entering;
|
|
|
|
|
}
|
|
|
|
|
/** Only to be used to tell the Driver Station what code you claim to be executing
|
|
|
|
|
* for diagnostic purposes only
|
|
|
|
|
* @param entering If true, starting teleop code; if false, leaving teleop code */
|
|
|
|
|
void InOperatorControl(bool entering)
|
|
|
|
|
{
|
|
|
|
|
m_userInTeleop = entering;
|
|
|
|
|
}
|
|
|
|
|
/** Only to be used to tell the Driver Station what code you claim to be executing
|
|
|
|
|
* for diagnostic purposes only
|
|
|
|
|
* @param entering If true, starting test code; if false, leaving test code */
|
|
|
|
|
void InTest(bool entering)
|
|
|
|
|
{
|
|
|
|
|
m_userInTest = entering;
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
DriverStation();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static void InitTask(DriverStation *ds);
|
|
|
|
|
static DriverStation *m_instance;
|
2014-12-03 07:42:48 -05:00
|
|
|
void ReportJoystickUnpluggedError(std::string message);
|
2013-12-15 18:30:16 -05:00
|
|
|
void Run();
|
|
|
|
|
|
|
|
|
|
Task m_task;
|
|
|
|
|
SEMAPHORE_ID m_newControlData;
|
2014-11-16 16:57:02 -05:00
|
|
|
MULTIWAIT_ID m_packetDataAvailableMultiWait;
|
|
|
|
|
MUTEX_ID m_packetDataAvailableMutex;
|
2013-12-15 18:30:16 -05:00
|
|
|
MULTIWAIT_ID m_waitForDataSem;
|
2014-11-08 14:27:49 -05:00
|
|
|
MUTEX_ID m_waitForDataMutex;
|
2013-12-15 18:30:16 -05:00
|
|
|
bool m_userInDisabled;
|
|
|
|
|
bool m_userInAutonomous;
|
2014-05-02 17:54:01 -04:00
|
|
|
bool m_userInTeleop;
|
|
|
|
|
bool m_userInTest;
|
2014-12-03 07:42:48 -05:00
|
|
|
double m_nextMessageTime;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|