2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-07-13 21:57:54 -07:00
|
|
|
/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-05-02 17:54:01 -04:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2017-10-27 21:45:56 -07:00
|
|
|
#include <array>
|
2016-05-20 17:30:37 -07:00
|
|
|
#include <atomic>
|
2016-09-05 13:55:31 -07:00
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
2016-11-01 20:12:08 -07:00
|
|
|
#include <thread>
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2018-10-29 12:49:17 -07:00
|
|
|
#include <hal/DriverStationTypes.h>
|
2018-04-29 23:33:19 -07:00
|
|
|
#include <wpi/Twine.h>
|
|
|
|
|
#include <wpi/condition_variable.h>
|
|
|
|
|
#include <wpi/deprecated.h>
|
|
|
|
|
#include <wpi/mutex.h>
|
2017-08-27 00:11:52 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/ErrorBase.h"
|
|
|
|
|
#include "frc/RobotState.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
namespace frc {
|
|
|
|
|
|
2018-01-18 23:17:28 -08:00
|
|
|
class MatchDataSender;
|
2017-11-09 19:59:29 -08:00
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Provide access to the network communication data to / from the Driver
|
|
|
|
|
* Station.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2018-07-08 15:41:31 -07:00
|
|
|
class DriverStation : public ErrorBase {
|
2015-06-25 15:07:55 -04:00
|
|
|
public:
|
|
|
|
|
enum Alliance { kRed, kBlue, kInvalid };
|
2017-11-09 19:59:29 -08:00
|
|
|
enum MatchType { kNone, kPractice, kQualification, kElimination };
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
~DriverStation() override;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2018-09-24 00:08:25 -07:00
|
|
|
DriverStation(const DriverStation&) = delete;
|
|
|
|
|
DriverStation& operator=(const DriverStation&) = delete;
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Return a reference to the singleton DriverStation.
|
|
|
|
|
*
|
|
|
|
|
* @return Reference to the DS instance
|
|
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
static DriverStation& GetInstance();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Report an error to the DriverStation messages window.
|
|
|
|
|
*
|
|
|
|
|
* The error is also printed to the program console.
|
|
|
|
|
*/
|
2018-04-29 23:33:19 -07:00
|
|
|
static void ReportError(const wpi::Twine& error);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Report a warning to the DriverStation messages window.
|
|
|
|
|
*
|
|
|
|
|
* The warning is also printed to the program console.
|
|
|
|
|
*/
|
2018-04-29 23:33:19 -07:00
|
|
|
static void ReportWarning(const wpi::Twine& error);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Report an error to the DriverStation messages window.
|
|
|
|
|
*
|
|
|
|
|
* The error is also printed to the program console.
|
|
|
|
|
*/
|
2018-04-29 23:33:19 -07:00
|
|
|
static void ReportError(bool isError, int code, const wpi::Twine& error,
|
2018-05-13 17:09:56 -07:00
|
|
|
const wpi::Twine& location, const wpi::Twine& stack);
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2017-11-19 19:04:28 -08:00
|
|
|
static constexpr int kJoystickPorts = 6;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* The state of one joystick button. Button indexes begin at 1.
|
|
|
|
|
*
|
|
|
|
|
* @param stick The joystick to read.
|
|
|
|
|
* @param button The button index, beginning at 1.
|
|
|
|
|
* @return The state of the joystick button.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetStickButton(int stick, int button);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether one joystick button was pressed since the last check. Button
|
|
|
|
|
* indexes begin at 1.
|
|
|
|
|
*
|
|
|
|
|
* @param stick The joystick to read.
|
|
|
|
|
* @param button The button index, beginning at 1.
|
|
|
|
|
* @return Whether the joystick button was pressed since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetStickButtonPressed(int stick, int button);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether one joystick button was released since the last check. Button
|
|
|
|
|
* indexes begin at 1.
|
|
|
|
|
*
|
|
|
|
|
* @param stick The joystick to read.
|
|
|
|
|
* @param button The button index, beginning at 1.
|
|
|
|
|
* @return Whether the joystick button was released since the last check.
|
|
|
|
|
*/
|
2017-10-27 21:45:56 -07:00
|
|
|
bool GetStickButtonReleased(int stick, int button);
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Get the value of the axis on a joystick.
|
|
|
|
|
*
|
|
|
|
|
* This depends on the mapping of the joystick connected to the specified
|
|
|
|
|
* port.
|
|
|
|
|
*
|
|
|
|
|
* @param stick The joystick to read.
|
|
|
|
|
* @param axis The analog axis value to read from the joystick.
|
|
|
|
|
* @return The value of the axis on the joystick.
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double GetStickAxis(int stick, int axis);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the state of a POV on the joystick.
|
|
|
|
|
*
|
|
|
|
|
* @return the angle of the POV in degrees, or -1 if the POV is not pressed.
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetStickPOV(int stick, int pov);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The state of the buttons on the joystick.
|
|
|
|
|
*
|
|
|
|
|
* @param stick The joystick to read.
|
|
|
|
|
* @return The state of the buttons on the joystick.
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetStickButtons(int stick) const;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Returns the number of axes on a given joystick port.
|
|
|
|
|
*
|
|
|
|
|
* @param stick The joystick port number
|
|
|
|
|
* @return The number of axes on the indicated joystick
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetStickAxisCount(int stick) const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the number of POVs on a given joystick port.
|
|
|
|
|
*
|
|
|
|
|
* @param stick The joystick port number
|
|
|
|
|
* @return The number of POVs on the indicated joystick
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetStickPOVCount(int stick) const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the number of buttons on a given joystick port.
|
|
|
|
|
*
|
|
|
|
|
* @param stick The joystick port number
|
|
|
|
|
* @return The number of buttons on the indicated joystick
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetStickButtonCount(int stick) const;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Returns a boolean indicating if the controller is an xbox controller.
|
|
|
|
|
*
|
|
|
|
|
* @param stick The joystick port number
|
|
|
|
|
* @return A boolean that is true if the controller is an xbox controller.
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
bool GetJoystickIsXbox(int stick) const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the type of joystick at a given port.
|
|
|
|
|
*
|
|
|
|
|
* @param stick The joystick port number
|
|
|
|
|
* @return The HID type of joystick at the given port
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetJoystickType(int stick) const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the name of the joystick at the given port.
|
|
|
|
|
*
|
|
|
|
|
* @param stick The joystick port number
|
|
|
|
|
* @return The name of the joystick at the given port
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
std::string GetJoystickName(int stick) const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the types of Axes on a given joystick port.
|
|
|
|
|
*
|
|
|
|
|
* @param stick The joystick port number and the target axis
|
|
|
|
|
* @return What type of axis the axis is reporting to be
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetJoystickAxisType(int stick, int axis) const;
|
2015-06-19 17:23:54 -07:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Check if the DS has enabled the robot.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the robot is enabled and the DS is connected
|
|
|
|
|
*/
|
2018-07-08 15:41:31 -07:00
|
|
|
bool IsEnabled() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the robot is disabled.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the robot is explicitly disabled or the DS is not connected
|
|
|
|
|
*/
|
2018-07-08 15:41:31 -07:00
|
|
|
bool IsDisabled() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2019-07-16 09:18:23 -05:00
|
|
|
/**
|
|
|
|
|
* Check if the robot is e-stopped.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the robot is e-stopped
|
|
|
|
|
*/
|
|
|
|
|
bool IsEStopped() const;
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Check if the DS is commanding autonomous mode.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the robot is being commanded to be in autonomous mode
|
|
|
|
|
*/
|
2018-07-08 15:41:31 -07:00
|
|
|
bool IsAutonomous() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2020-08-29 16:32:19 -04:00
|
|
|
/**
|
|
|
|
|
* Check if the DS is commanding autonomous mode and if it has enabled the
|
|
|
|
|
* robot.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the robot is being commanded to be in autonomous mode and
|
|
|
|
|
* enabled.
|
|
|
|
|
*/
|
|
|
|
|
bool IsAutonomousEnabled() const;
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Check if the DS is commanding teleop mode.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the robot is being commanded to be in teleop mode
|
|
|
|
|
*/
|
2018-07-08 15:41:31 -07:00
|
|
|
bool IsOperatorControl() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2020-08-29 16:32:19 -04:00
|
|
|
/**
|
|
|
|
|
* Check if the DS is commanding teleop mode and if it has enabled the robot.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the robot is being commanded to be in teleop mode and
|
|
|
|
|
* enabled.
|
|
|
|
|
*/
|
|
|
|
|
bool IsOperatorControlEnabled() const;
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Check if the DS is commanding test mode.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the robot is being commanded to be in test mode
|
|
|
|
|
*/
|
2018-07-08 15:41:31 -07:00
|
|
|
bool IsTest() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the DS is attached.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the DS is connected to the robot
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool IsDSAttached() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Has a new control packet from the driver station arrived since the last
|
|
|
|
|
* time this function was called?
|
|
|
|
|
*
|
|
|
|
|
* Warning: If you call this function from more than one place at the same
|
|
|
|
|
* time, you will not get the intended behavior.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the control data has been updated since the last call.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool IsNewControlData() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is the driver station attached to a Field Management System?
|
|
|
|
|
*
|
|
|
|
|
* @return True if the robot is competing on a field being controlled by a
|
|
|
|
|
* Field Management System
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool IsFMSAttached() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2018-11-02 17:34:48 +11:00
|
|
|
/**
|
|
|
|
|
* Returns the game specific message provided by the FMS.
|
|
|
|
|
*
|
|
|
|
|
* @return A string containing the game specific message.
|
|
|
|
|
*/
|
2017-11-09 19:59:29 -08:00
|
|
|
std::string GetGameSpecificMessage() const;
|
2018-11-02 17:34:48 +11:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the name of the competition event provided by the FMS.
|
|
|
|
|
*
|
|
|
|
|
* @return A string containing the event name
|
|
|
|
|
*/
|
2017-11-09 19:59:29 -08:00
|
|
|
std::string GetEventName() const;
|
2018-11-02 17:34:48 +11:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the type of match being played provided by the FMS.
|
|
|
|
|
*
|
|
|
|
|
* @return The match type enum (kNone, kPractice, kQualification,
|
|
|
|
|
* kElimination)
|
|
|
|
|
*/
|
2017-11-09 19:59:29 -08:00
|
|
|
MatchType GetMatchType() const;
|
2018-11-02 17:34:48 +11:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the match number provided by the FMS.
|
|
|
|
|
*
|
|
|
|
|
* @return The number of the match
|
|
|
|
|
*/
|
2017-11-09 19:59:29 -08:00
|
|
|
int GetMatchNumber() const;
|
2018-11-02 17:34:48 +11:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the number of times the current match has been replayed from the
|
|
|
|
|
* FMS.
|
|
|
|
|
*
|
|
|
|
|
* @return The number of replays
|
|
|
|
|
*/
|
2017-11-09 19:59:29 -08:00
|
|
|
int GetReplayNumber() const;
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Return the alliance that the driver station says it is on.
|
|
|
|
|
*
|
|
|
|
|
* This could return kRed or kBlue.
|
|
|
|
|
*
|
|
|
|
|
* @return The Alliance enum (kRed, kBlue or kInvalid)
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
Alliance GetAlliance() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the driver station location on the field.
|
|
|
|
|
*
|
|
|
|
|
* This could return 1, 2, or 3.
|
|
|
|
|
*
|
|
|
|
|
* @return The location of the driver station (1-3, 0 for invalid)
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetLocation() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Wait until a new packet comes from the driver station.
|
|
|
|
|
*
|
|
|
|
|
* This blocks on a semaphore, so the waiting is efficient.
|
|
|
|
|
*
|
|
|
|
|
* This is a good way to delay processing until there is new driver station
|
|
|
|
|
* data to act on.
|
2020-07-13 21:57:54 -07:00
|
|
|
*
|
|
|
|
|
* Checks if new control data has arrived since the last waitForData call
|
|
|
|
|
* on the current thread. If new data has not arrived, returns immediately.
|
2018-05-31 20:47:15 -07:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void WaitForData();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Wait until a new packet comes from the driver station, or wait for a
|
|
|
|
|
* timeout.
|
|
|
|
|
*
|
2020-07-13 21:57:54 -07:00
|
|
|
* Checks if new control data has arrived since the last waitForData call
|
|
|
|
|
* on the current thread. If new data has not arrived, returns immediately.
|
|
|
|
|
*
|
2018-05-31 20:47:15 -07:00
|
|
|
* If the timeout is less then or equal to 0, wait indefinitely.
|
|
|
|
|
*
|
|
|
|
|
* Timeout is in milliseconds
|
|
|
|
|
*
|
|
|
|
|
* This blocks on a semaphore, so the waiting is efficient.
|
|
|
|
|
*
|
|
|
|
|
* This is a good way to delay processing until there is new driver station
|
|
|
|
|
* data to act on.
|
|
|
|
|
*
|
|
|
|
|
* @param timeout Timeout time in seconds
|
|
|
|
|
*
|
|
|
|
|
* @return true if new data, otherwise false
|
|
|
|
|
*/
|
2016-10-09 11:46:01 -07:00
|
|
|
bool WaitForData(double timeout);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the approximate match time.
|
|
|
|
|
*
|
|
|
|
|
* The FMS does not send an official match time to the robots, but does send
|
|
|
|
|
* an approximate match time. The value will count down the time remaining in
|
|
|
|
|
* the current period (auto or teleop).
|
|
|
|
|
*
|
|
|
|
|
* Warning: This is not an official time (so it cannot be used to dispute ref
|
|
|
|
|
* calls or guarantee that a function will trigger before the match ends).
|
|
|
|
|
*
|
|
|
|
|
* The Practice Match function of the DS approximates the behaviour seen on
|
|
|
|
|
* the field.
|
|
|
|
|
*
|
|
|
|
|
* @return Time remaining in current match period (auto or teleop)
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
double GetMatchTime() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read the battery voltage.
|
|
|
|
|
*
|
|
|
|
|
* @return The battery voltage in Volts.
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double GetBatteryVoltage() const;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2017-11-16 00:33:51 -08:00
|
|
|
/**
|
|
|
|
|
* Only to be used to tell the Driver Station what code you claim to be
|
|
|
|
|
* executing for diagnostic purposes only.
|
|
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* @param entering If true, starting disabled code; if false, leaving disabled
|
2017-11-16 00:33:51 -08:00
|
|
|
* code.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void InDisabled(bool entering) { m_userInDisabled = entering; }
|
2017-11-16 00:33:51 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Only to be used to tell the Driver Station what code you claim to be
|
|
|
|
|
* executing for diagnostic purposes only.
|
|
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* @param entering If true, starting autonomous code; if false, leaving
|
2017-11-16 00:33:51 -08:00
|
|
|
* autonomous code.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void InAutonomous(bool entering) { m_userInAutonomous = entering; }
|
2017-11-16 00:33:51 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Only to be used to tell the Driver Station what code you claim to be
|
|
|
|
|
* executing for diagnostic purposes only.
|
|
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* @param entering If true, starting teleop code; if false, leaving teleop
|
2017-11-16 00:33:51 -08:00
|
|
|
* code.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void InOperatorControl(bool entering) { m_userInTeleop = entering; }
|
2017-11-16 00:33:51 -08: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 test code; if false, leaving test code.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void InTest(bool entering) { m_userInTest = entering; }
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2019-11-05 21:33:09 -08:00
|
|
|
/**
|
|
|
|
|
* Forces WaitForData() to return immediately.
|
|
|
|
|
*/
|
|
|
|
|
void WakeupWaitForData();
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
protected:
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Copy data from the DS task for the user.
|
|
|
|
|
*
|
|
|
|
|
* If no new data exists, it will just be returned, otherwise
|
|
|
|
|
* the data will be copied from the DS polling loop.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void GetData();
|
|
|
|
|
|
|
|
|
|
private:
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* DriverStation constructor.
|
|
|
|
|
*
|
|
|
|
|
* This is only called once the first time GetInstance() is called
|
|
|
|
|
*/
|
2016-07-14 20:50:38 -07:00
|
|
|
DriverStation();
|
2017-11-16 00:33:51 -08:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Reports errors related to unplugged joysticks.
|
|
|
|
|
*
|
|
|
|
|
* Throttles the errors so that they don't overwhelm the DS.
|
|
|
|
|
*/
|
2018-04-29 23:33:19 -07:00
|
|
|
void ReportJoystickUnpluggedError(const wpi::Twine& message);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reports errors related to unplugged joysticks.
|
|
|
|
|
*
|
|
|
|
|
* Throttles the errors so that they don't overwhelm the DS.
|
|
|
|
|
*/
|
2018-04-29 23:33:19 -07:00
|
|
|
void ReportJoystickUnpluggedWarning(const wpi::Twine& message);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
void Run();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2018-01-18 23:17:28 -08:00
|
|
|
void SendMatchData();
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2018-01-18 23:17:28 -08:00
|
|
|
std::unique_ptr<MatchDataSender> m_matchDataSender;
|
|
|
|
|
|
2017-10-27 21:45:56 -07:00
|
|
|
// Joystick button rising/falling edge flags
|
2018-07-18 22:22:41 -07:00
|
|
|
wpi::mutex m_buttonEdgeMutex;
|
|
|
|
|
std::array<HAL_JoystickButtons, kJoystickPorts> m_previousButtonStates;
|
2017-10-27 21:45:56 -07:00
|
|
|
std::array<uint32_t, kJoystickPorts> m_joystickButtonsPressed;
|
|
|
|
|
std::array<uint32_t, kJoystickPorts> m_joystickButtonsReleased;
|
|
|
|
|
|
2016-10-24 20:32:43 -07:00
|
|
|
// Internal Driver Station thread
|
2016-11-01 20:12:08 -07:00
|
|
|
std::thread m_dsThread;
|
2014-08-14 00:07:02 -07:00
|
|
|
std::atomic<bool> m_isRunning{false};
|
2016-10-24 20:32:43 -07:00
|
|
|
|
2020-07-13 21:57:54 -07:00
|
|
|
mutable wpi::mutex m_waitForDataMutex;
|
2018-01-18 21:54:33 -08:00
|
|
|
wpi::condition_variable m_waitForDataCond;
|
|
|
|
|
int m_waitForDataCounter;
|
|
|
|
|
|
2016-10-24 20:32:43 -07:00
|
|
|
// Robot state status variables
|
2015-06-24 01:06:29 -07:00
|
|
|
bool m_userInDisabled = false;
|
|
|
|
|
bool m_userInAutonomous = false;
|
|
|
|
|
bool m_userInTeleop = false;
|
|
|
|
|
bool m_userInTest = false;
|
2016-10-24 20:32:43 -07:00
|
|
|
|
2015-06-24 01:06:29 -07:00
|
|
|
double m_nextMessageTime = 0;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|
2016-11-01 22:33:12 -07:00
|
|
|
|
|
|
|
|
} // namespace frc
|