LibDS
Qt-based library for controlling FRC robots
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
DriverStation Class Reference

Exposes the functionality of the LibDS to the application. More...

#include <DriverStation.h>

Inheritance diagram for DriverStation:
DS_Base DS

Public Types

enum  ProtocolType { kFRC2016 = 0, kFRC2015 = 1, kFRC2014 = 2 }
 
enum  TeamStation {
  kRed1 = 0, kRed2 = 1, kRed3 = 2, kBlue1 = 3,
  kBlue2 = 4, kBlue3 = 5
}
 
- Public Types inherited from DS
enum  ControlMode { kControlTest, kControlAutonomous, kControlTeleoperated }
 Represents the available control modes of the robot. More...
 
enum  Alliance { kAllianceRed, kAllianceBlue }
 Represents the team alliance. More...
 
enum  Position { kPosition1, kPosition2, kPosition3 }
 Represents the different team positions for each alliance. More...
 
enum  CommStatus { kCommsWorking, kCommsFailing }
 Represents the communication status between the client and a target. More...
 
enum  CodeStatus { kCodeRunning, kCodeFailing }
 Represents the status of the robot code. More...
 
enum  EnableStatus { kEnabled, kDisabled }
 Represents the enabled state of the robot. More...
 
enum  OperationStatus { kNormal, kEmergencyStop }
 Represents the operation status of the robot. More...
 
enum  VoltageStatus { kVoltageNormal, kVoltageBrownout }
 Represents the status of the robot power supply. When the battery level is low or there are too many power spikes, the robot may report a voltage brownout. More...
 
enum  SocketType { kSocketTypeUDP, kSocketTypeTCP }
 Represents the socket types that can be used by the DS modules. More...
 

Public Slots

void init ()
 
void browseLogs ()
 
void rebootRobot ()
 
void enableRobot ()
 
void openLogsPath ()
 
void disableRobot ()
 
void resetJoysticks ()
 
void setTeam (int team)
 
void restartRobotCode ()
 
void switchToTestMode ()
 
void switchToAutonomous ()
 
void switchToTeleoperated ()
 
void triggerEmergencyStop ()
 
void reconfigureJoysticks ()
 
void removeJoystick (int id)
 
void setEnabled (bool enabled)
 
void setTeamStation (int station)
 
void openLog (const QString &file)
 
void setProtocolType (int protocol)
 
void setAlliance (Alliance alliance)
 
void setPosition (Position position)
 
void setProtocol (Protocol *protocol)
 
void setControlMode (ControlMode mode)
 
void updatePOV (int id, int pov, int angle)
 
void setEnabled (EnableStatus statusChanged)
 
void updateAxis (int id, int axis, qreal value)
 
void updateButton (int id, int button, bool state)
 
void setCustomFMSAddress (const QString &address)
 
void setCustomRadioAddress (const QString &address)
 
void setCustomRobotAddress (const QString &address)
 
void setOperationStatus (OperationStatus statusChanged)
 

Signals

void resetted ()
 
void initialized ()
 
void logFileChanged ()
 
void protocolChanged ()
 
void joystickCountChanged (int count)
 
void newMessage (const QString &message)
 
- Signals inherited from DS_Base
void elapsedTimeChanged (int msecs)
 
void elapsedTimeChanged (const QString &string)
 
void statusChanged (const QString &status)
 
void simulatedChanged (const bool isSimulation)
 
void enabledChanged (const EnableStatus status)
 
void allianceChanged (const Alliance alliance)
 
void positionChanged (const Position position)
 
void codeStatusChanged (const CodeStatus statusChanged)
 
void controlModeChanged (const ControlMode mode)
 
void robotAddressChanged (const QString &address)
 
void radioAddressChanged (const QString &address)
 
void fmsCommStatusChanged (const CommStatus statusChanged)
 
void robotCommStatusChanged (const CommStatus statusChanged)
 
void radioCommStatusChanged (const CommStatus statusChanged)
 
void voltageStatusChanged (const VoltageStatus statusChanged)
 
void operationStatusChanged (const OperationStatus statusChanged)
 
void pdpVersionChanged (const QString &version)
 
void pcmVersionChanged (const QString &version)
 
void libVersionChanged (const QString &version)
 
void voltageChanged (const qreal voltage)
 
void voltageChanged (const QString &voltageString)
 
void teamChanged (const int team)
 
void cpuUsageChanged (const int usage)
 
void ramUsageChanged (const int usage)
 
void diskUsageChanged (const int usage)
 

Public Member Functions

Q_INVOKABLE bool canBeEnabled ()
 
Q_INVOKABLE bool running () const
 
Q_INVOKABLE bool isInTest () const
 
Q_INVOKABLE bool isEnabled () const
 
Q_INVOKABLE bool isSimulated () const
 
Q_INVOKABLE bool isInAutonomous () const
 
Q_INVOKABLE bool isInTeleoperated () const
 
Q_INVOKABLE bool isConnectedToFMS () const
 
Q_INVOKABLE bool isVoltageBrownout () const
 
Q_INVOKABLE bool isEmergencyStopped () const
 
Q_INVOKABLE bool isConnectedToRobot () const
 
Q_INVOKABLE bool isConnectedToRadio () const
 
Q_INVOKABLE bool isRobotCodeRunning () const
 
Q_INVOKABLE QString logsPath () const
 
Q_INVOKABLE QVariant logVariant () const
 
Q_INVOKABLE QStringList availableLogs () const
 
Q_INVOKABLE QJsonDocument logDocument () const
 
Q_INVOKABLE qreal maxBatteryVoltage () const
 
Q_INVOKABLE qreal currentBatteryVoltage () const
 
Q_INVOKABLE qreal nominalBatteryAmperage () const
 
Q_INVOKABLE int team () const
 
Q_INVOKABLE int cpuUsage () const
 
Q_INVOKABLE int ramUsage () const
 
Q_INVOKABLE int diskUsage () const
 
Q_INVOKABLE int packetLoss () const
 
Q_INVOKABLE int maxPOVCount () const
 
Q_INVOKABLE int maxAxisCount () const
 
Q_INVOKABLE int maxButtonCount () const
 
Q_INVOKABLE int maxJoystickCount () const
 
Q_INVOKABLE int getNumAxes (int joystick)
 
Q_INVOKABLE int getNumPOVs (int joystick)
 
Q_INVOKABLE int getNumButtons (int joystick)
 
Q_INVOKABLE int getRealNumAxes (int joystick)
 
Q_INVOKABLE int getRealNumPOVs (int joystick)
 
Q_INVOKABLE int getRealNumButtons (int joystick)
 
Q_INVOKABLE int joystickCount ()
 
Q_INVOKABLE DS_Joysticks * joysticks ()
 
Q_INVOKABLE Alliance alliance () const
 
Q_INVOKABLE Position position () const
 
Q_INVOKABLE ControlMode controlMode () const
 
Q_INVOKABLE CommStatus fmsCommStatus () const
 
Q_INVOKABLE EnableStatus enableStatus () const
 
Q_INVOKABLE CommStatus radioCommStatus () const
 
Q_INVOKABLE CommStatus robotCommStatus () const
 
Q_INVOKABLE CodeStatus robotCodeStatus () const
 
Q_INVOKABLE VoltageStatus voltageStatus () const
 
Q_INVOKABLE QString fmsAddress () const
 
Q_INVOKABLE QString radioAddress () const
 
Q_INVOKABLE QString robotAddress () const
 
Q_INVOKABLE QString generalStatus () const
 
Q_INVOKABLE QString customFMSAddress () const
 
Q_INVOKABLE QString customRadioAddress () const
 
Q_INVOKABLE QString customRobotAddress () const
 
Q_INVOKABLE QString defaultFMSAddress () const
 
Q_INVOKABLE QString defaultRadioAddress () const
 
Q_INVOKABLE QString defaultRobotAddress () const
 
Q_INVOKABLE OperationStatus operationStatus () const
 
Q_INVOKABLE QStringList protocols () const
 
Q_INVOKABLE QStringList teamStations () const
 
Q_INVOKABLE bool registerJoystick (int axes, int buttons, int povs)
 

Static Public Member Functions

static DriverStationgetInstance ()
 
static void logger (QtMsgType type, const QMessageLogContext &context, const QString &data)
 
- Static Public Member Functions inherited from DS
static QString getStaticIP (int net, int team, int host)
 Returns a calculated IP address based on the team address. More...
 
static QString timezone ()
 Returns the current timezone as a string.
 
static QByteArray readSocket (QUdpSocket *socket)
 Reads the datagrams received by the given UDP socket.
 
static QByteArray readSocket (QTcpSocket *socket)
 Reads the data received by the given TCP socket.
 

Private Slots

void stop ()
 
void start ()
 
void resetFMS ()
 
void resetRadio ()
 
void resetRobot ()
 
void finishInit ()
 
void sendFMSPacket ()
 
void updateAddresses ()
 
void sendRadioPacket ()
 
void sendRobotPacket ()
 
void updatePacketLoss ()
 
void updateAddresses (int unused)
 
void updateLogs (const QString &file)
 
void readFMSPacket (const QByteArray &data)
 
void readRadioPacket (const QByteArray &data)
 
void readRobotPacket (const QByteArray &data)
 

Private Member Functions

DS_Configconfig () const
 
Protocolprotocol () const
 

Private Attributes

bool m_init
 
bool m_running
 
int m_packetLoss
 
int m_fmsInterval
 
int m_radioInterval
 
int m_robotInterval
 
QString m_logDocumentPath
 
DS_Joysticks m_joysticks
 
QString m_customFMSAddress
 
QJsonDocument m_logDocument
 
QString m_customRadioAddress
 
QString m_customRobotAddress
 
Socketsm_sockets
 
Protocolm_protocol
 
NetConsolem_console
 
Watchdogm_fmsWatchdog
 
Watchdogm_radioWatchdog
 
Watchdogm_robotWatchdog
 

Detailed Description

Exposes the functionality of the LibDS to the application.

The DriverStation class exposes the LibDS library to the application, and implements functions that allow the safe operation of robots, protocol switching/lodaing and joystick management.

The DriverStation class provides several reduntant functions in order to be more user-friendly and giving application developers more flexibility regarding the use of LibDS types.

Member Function Documentation

DS::Alliance DriverStation::alliance ( ) const

Returns the current alliance (red or blue) of the robot.

References DS_Config::alliance(), and config().

Referenced by FRC_2014::getAlliance(), and FRC_2014::interpretFMSPacket().

QStringList DriverStation::availableLogs ( ) const

Returns a list with all the robot logs saved to the logs path

References Logger::availableLogs(), config(), and DS_Config::logger().

void DriverStation::browseLogs ( )
slot

Shows an open file dialog and lets the user select a DS log file to load...

References config(), Logger::extension(), DS_Config::logger(), logsPath(), and openLog().

bool DriverStation::canBeEnabled ( )

Returns true if we have communications with the robot controller and the robot code is running.

Note
This function will return false if the robot is emergency stopped.

References isConnectedToRobot(), isEmergencyStopped(), and isRobotCodeRunning().

DS_Config * DriverStation::config ( ) const
private

Returns a pointer to the DS_Config class, which is shared by the DriverStation and the protocol.

The point of having a config class is to allow the protocol to change the status of the DriverStation and the LibDS system without increasing the complexity of the Protocol and DriverStation classes, whilst ensuring that values are the same throughout the LibDS and that signals are only fired when necessary.

References DS_Config::getInstance().

Referenced by alliance(), availableLogs(), browseLogs(), controlMode(), cpuUsage(), currentBatteryVoltage(), diskUsage(), enableStatus(), fmsCommStatus(), init(), isSimulated(), logsPath(), openLog(), operationStatus(), position(), radioCommStatus(), ramUsage(), resetFMS(), resetRadio(), resetRobot(), robotCodeStatus(), robotCommStatus(), setAlliance(), setControlMode(), setEnabled(), setOperationStatus(), setPosition(), setTeam(), team(), updatePacketLoss(), and voltageStatus().

DS::ControlMode DriverStation::controlMode ( ) const

Returns the current control mode (test, auto or teleop) of the robot.

References config(), and DS_Config::controlMode().

Referenced by generalStatus(), FRC_2014::getOperationCode(), isInAutonomous(), isInTeleoperated(), and isInTest().

int DriverStation::cpuUsage ( ) const

Returns the current CPU usage of the robot. Value range is from 0 to 100.

References config(), and DS_Config::cpuUsage().

qreal DriverStation::currentBatteryVoltage ( ) const

Returns the current battery voltage of the robot

References config(), and DS_Config::voltage().

QString DriverStation::customFMSAddress ( ) const

Returns the user-set FMS address

Referenced by fmsAddress().

QString DriverStation::customRadioAddress ( ) const

Returns the user-set radio address

Referenced by radioAddress().

QString DriverStation::customRobotAddress ( ) const

Returns the user-set robot address

Referenced by robotAddress().

QString DriverStation::defaultFMSAddress ( ) const

Returns the protocol-set robot address.

Note
If the protocol is invalid, this function will return an empty string

References Protocol::fmsAddress(), and protocol().

Referenced by fmsAddress().

QString DriverStation::defaultRadioAddress ( ) const

Returns the protocol-set radio address.

Note
If the protocol is invalid, this function will return an empty string

References protocol(), and Protocol::radioAddress().

Referenced by radioAddress().

QString DriverStation::defaultRobotAddress ( ) const

Returns the protocol-set robot address.

Note
If the protocol is invalid, this function will return an empty string

References protocol(), and Protocol::robotAddress().

Referenced by robotAddress().

void DriverStation::disableRobot ( )
slot

Disables the robot directly

References DS::kDisabled, and setEnabled().

int DriverStation::diskUsage ( ) const

Returns the current disk usage of the robot. Value range is from 0 to 100.

References config(), and DS_Config::diskUsage().

void DriverStation::enableRobot ( )
slot

Enables the robot directly

References DS::kEnabled, and setEnabled().

DS::EnableStatus DriverStation::enableStatus ( ) const

Returns the current enable status of the robot.

References config(), and DS_Config::enableStatus().

Referenced by generalStatus(), and isEnabled().

void DriverStation::finishInit ( )
privateslot

Notifies the UI that the DS has been initialized

References generalStatus(), and DS_Base::statusChanged().

Referenced by init().

QString DriverStation::fmsAddress ( ) const

Returns the applied FMS address (be it DS-set or user-set)

References customFMSAddress(), and defaultFMSAddress().

Referenced by Sockets::onFMSLookupFinished(), Sockets::performLookups(), setCustomFMSAddress(), and updateAddresses().

DS::CommStatus DriverStation::fmsCommStatus ( ) const

Returns the current client/FMS communication status.

References config(), and DS_Config::fmsCommStatus().

Referenced by isConnectedToFMS().

QString DriverStation::generalStatus ( ) const

Returns the current status of the Driver Station. This string is used in the large label below the status lights of the DS.

References controlMode(), enableStatus(), isConnectedToRobot(), isEmergencyStopped(), isRobotCodeRunning(), isVoltageBrownout(), DS::kControlAutonomous, DS::kControlTeleoperated, DS::kControlTest, DS::kDisabled, and DS::kEnabled.

Referenced by finishInit(), and resetRobot().

DriverStation * DriverStation::getInstance ( )
static

Returns the one and only instance of the DriverStation class. The DriverStation class must be singleton to ensure the safe operation of the robot and also to ensure availability to the input and output sockets used by each protocol.

Referenced by Protocol::joysticks(), Sockets::performLookups(), DS_Config::updateControlMode(), DS_Config::updateEnabled(), DS_Config::updateFMSCommStatus(), DS_Config::updateOperationStatus(), DS_Config::updateRobotCodeStatus(), DS_Config::updateRobotCommStatus(), DS_Config::updateVoltage(), and DS_Config::updateVoltageStatus().

int DriverStation::getNumAxes ( int  joystick)

Returns the number of axes registered with the given joystick.

Note
This will only return the value supported by the protocol, to get the actual value, use the getRealNumAxes() function

References joysticks().

int DriverStation::getNumButtons ( int  joystick)

Returns the number of buttons registered with the given joystick.

Note
This will only return the value supported by the protocol, to get the actual value, use the getRealNumButtons() function

References joysticks().

int DriverStation::getNumPOVs ( int  joystick)

Returns the number of POVs registered with the given joystick.

Note
This will only return the value supported by the protocol, to get the actual value, use the getRealNumPOVs() function

References joysticks().

int DriverStation::getRealNumAxes ( int  joystick)

Returns the number of axes registered with the given joystick, this value can be greater than what the protocol supports. If you are interested in getting only the number of axes used by the DS, use the getNumAxes() function.

References joysticks().

int DriverStation::getRealNumButtons ( int  joystick)

Returns the number of buttons registered with the given joystick, this value can be greater than what the protocol supports. If you are interested in getting only the number of buttons used by the DS, use the getNumButtons() function.

References joysticks().

int DriverStation::getRealNumPOVs ( int  joystick)

Returns the number of POVs registered with the given joystick, this value can be greater than what the protocol supports. If you are interested in getting only the number of POVs used by the DS, use the getNumPOVs() function.

References joysticks().

void DriverStation::init ( )
slot

This function must be called in order to start DS operations. It is recommended to call this function AFTER your UI has been initialized, so that the UI can react to the signals sent by the DriverStation.

Note
You can safely call this function several times, however, it will only have effect the first time you call it.

References config(), finishInit(), DS_Config::logger(), Logger::registerInitialEvents(), resetFMS(), resetRadio(), resetRobot(), sendFMSPacket(), sendRadioPacket(), sendRobotPacket(), and updatePacketLoss().

bool DriverStation::isConnectedToFMS ( ) const

Returns true if the Driver Station has established communications with the FMS.

References fmsCommStatus(), and DS::kCommsWorking.

Referenced by Sockets::performLookups(), removeJoystick(), resetJoysticks(), and sendFMSPacket().

bool DriverStation::isConnectedToRadio ( ) const

Returns true if the Driver Station has established communications with the radio.

References DS::kCommsWorking, and radioCommStatus().

Referenced by Sockets::performLookups().

bool DriverStation::isConnectedToRobot ( ) const

Returns true if the Driver Station has established communications with the robot.

References DS::kCommsWorking, and robotCommStatus().

Referenced by canBeEnabled(), generalStatus(), Sockets::performLookups(), and updatePacketLoss().

bool DriverStation::isEmergencyStopped ( ) const

Returns true if the robot is emergency stopped

References DS::kEmergencyStop, and operationStatus().

Referenced by canBeEnabled(), generalStatus(), and FRC_2014::getOperationCode().

bool DriverStation::isEnabled ( ) const

Returns true if the robot is currently enabled

References enableStatus(), and DS::kEnabled.

bool DriverStation::isInAutonomous ( ) const

Returns true if the robot is currently in autonomous mode

References controlMode(), and DS::kControlAutonomous.

bool DriverStation::isInTeleoperated ( ) const

Returns true if the robot is currently in teleop mode

References controlMode(), and DS::kControlTeleoperated.

bool DriverStation::isInTest ( ) const

Returns true if the robot is currently in test mode

References controlMode(), and DS::kControlTest.

bool DriverStation::isRobotCodeRunning ( ) const

Returns true if the robot code is running

References DS::kCodeRunning, and robotCodeStatus().

Referenced by canBeEnabled(), and generalStatus().

bool DriverStation::isSimulated ( ) const

Returns true if the robot is a simulated robot

References config(), and DS_Config::isSimulated().

bool DriverStation::isVoltageBrownout ( ) const

Returns true if the robot is experiencing a brownout (ouch!)

References DS::kVoltageBrownout, and voltageStatus().

Referenced by generalStatus().

int DriverStation::joystickCount ( )

Returns the current number of joysticks registered with the DS.

References joysticks().

Referenced by registerJoystick(), removeJoystick(), and resetJoysticks().

DS_Joysticks * DriverStation::joysticks ( )
QJsonDocument DriverStation::logDocument ( ) const

Returns the current JSON log document

Referenced by logVariant().

void DriverStation::logger ( QtMsgType  type,
const QMessageLogContext &  context,
const QString &  data 
)
static

Calls the custom Qt message handler of the LibDS

References DS_Config::getInstance(), DS_Config::logger(), and Logger::messageHandler().

QString DriverStation::logsPath ( ) const

Returns the path in which application log files are stored

References config(), DS_Config::logger(), and Logger::logsPath().

Referenced by browseLogs(), and openLogsPath().

QVariant DriverStation::logVariant ( ) const

Returns the current JSON document as a variant list

References logDocument().

int DriverStation::maxAxisCount ( ) const

Returns the maximum number of axes that a joystick can have

Note
If the protocol is invalid, this function will return 0

References Protocol::maxAxisCount(), and protocol().

Referenced by reconfigureJoysticks(), and registerJoystick().

qreal DriverStation::maxBatteryVoltage ( ) const

Returns the nominal battery voltage of the robot. This value, along with the currentBatteryVoltage() function, can be used to draw graphs or do other cool stuff.

Note
If there is no protocol loaded, this function will return 0

References Protocol::nominalBatteryVOltage(), and protocol().

Referenced by DS_Config::updateVoltage().

int DriverStation::maxButtonCount ( ) const

Returns the maximum number of buttons that a joystick can have

Note
If the protocol is invalid, this function will return 0

References Protocol::maxButtonCount(), and protocol().

Referenced by reconfigureJoysticks(), and registerJoystick().

int DriverStation::maxJoystickCount ( ) const

Returns the maximum number of joysticks that the protocol can handle

Note
If the protocol is invalid, this function will return 0

References Protocol::maxJoystickCount(), and protocol().

Referenced by reconfigureJoysticks(), and registerJoystick().

int DriverStation::maxPOVCount ( ) const

Returns the maximum number of POVs that a joystick can have

Note
If the protocol is invalid, this function will return 0

References Protocol::maxPOVCount(), and protocol().

Referenced by reconfigureJoysticks(), and registerJoystick().

qreal DriverStation::nominalBatteryAmperage ( ) const

Returns the nominal battery amperage of the robot. This value, along with the currentBatteryVoltage() function, can be used to calculate the power (in watts) used by the robot.

You could do some cool stuff with this function, such as making a dashboard similar to Tesla's car dashboard.

References Protocol::nominalBatteryAmperage(), and protocol().

void DriverStation::openLog ( const QString &  file)
slot

Opens the given log file file and parses it as a JSON document

References config(), DS_Config::logger(), and Logger::openLog().

Referenced by browseLogs(), and updateLogs().

void DriverStation::openLogsPath ( )
slot

Opens the application logs in an explorer window

References logsPath().

DS::OperationStatus DriverStation::operationStatus ( ) const

Returns the current operation status of the robot (normal or e-stop).

References config(), and DS_Config::operationStatus().

Referenced by isEmergencyStopped().

int DriverStation::packetLoss ( ) const

Returns the current packet loss percentage (from 0 to 100).

Note
This value is updated every 250 milliseconds.
DS::Position DriverStation::position ( ) const

Returns the current position (1, 2 or 3) of the robot.

References config(), and DS_Config::position().

Referenced by FRC_2014::getPosition(), and FRC_2014::interpretFMSPacket().

Protocol * DriverStation::protocol ( ) const
private
QStringList DriverStation::protocols ( ) const

Returns a list with the included protocols of the library. This function is meant to be used to generate your UI elements and seamessly use them with the setProtocolType() function.

QString DriverStation::radioAddress ( ) const

Returns the applied radio address (be it DS-set or user-set)

References customRadioAddress(), and defaultRadioAddress().

Referenced by Sockets::onRadioLookupFinished(), Sockets::performLookups(), setCustomRadioAddress(), and updateAddresses().

DS::CommStatus DriverStation::radioCommStatus ( ) const

Returns the current radio/FMS communication status.

References config(), and DS_Config::radioCommStatus().

Referenced by isConnectedToRadio().

int DriverStation::ramUsage ( ) const

Returns the current RAM usage of the robot. Value range is from 0 to 100.

References config(), and DS_Config::ramUsage().

void DriverStation::readFMSPacket ( const QByteArray &  data)
privateslot

Instructs the current protocol to interpret the given data, which was sent by the FMS.

References protocol(), Watchdog::reset(), and running().

void DriverStation::readRadioPacket ( const QByteArray &  data)
privateslot

Instructs the current protocol to interpret the given data, which was sent by the robot radio.

References protocol(), Watchdog::reset(), and running().

void DriverStation::readRobotPacket ( const QByteArray &  data)
privateslot

Instructs the current protocol to interpret the given data, which was sent by the robot controller.

References protocol(), Watchdog::reset(), and running().

void DriverStation::rebootRobot ( )
slot

Reboots the robot controller (if a protocol is loaded)

References protocol(), and Protocol::rebootRobot().

void DriverStation::reconfigureJoysticks ( )
slot

Re-registers all joysticks based on the criteria specified by the new protocol.

Note
If the number of buttons of a joystick exceeds the number of buttons supported by the protocol, the DriverStation will register only the ammount of buttons supported by the protocol. The same process takes place for axes and POVs.

References maxAxisCount(), maxButtonCount(), maxJoystickCount(), maxPOVCount(), Protocol::name(), protocol(), DS::Joystick::realNumAxes, DS::Joystick::realNumButtons, DS::Joystick::realNumPOVs, registerJoystick(), and resetJoysticks().

Referenced by setProtocol().

bool DriverStation::registerJoystick ( int  axes,
int  buttons,
int  povs 
)

Registers a new joystick with the given number of axes, buttons & POVs hats.

Note
If joystick registration fails, this function will return false.

References DS::Joystick::axes, DS::Joystick::buttons, joystickCount(), joysticks(), maxAxisCount(), maxButtonCount(), maxJoystickCount(), maxPOVCount(), DS::Joystick::numAxes, DS::Joystick::numButtons, DS::Joystick::numPOVs, DS::Joystick::povs, DS::Joystick::realNumAxes, DS::Joystick::realNumButtons, and DS::Joystick::realNumPOVs.

Referenced by reconfigureJoysticks().

void DriverStation::removeJoystick ( int  id)
slot

Removes the joystick at the given id

References isConnectedToFMS(), joystickCount(), joysticks(), and setEnabled().

void DriverStation::resetFMS ( )
privateslot

Called when the FMS watchdog expires

References config(), DS::kCommsFailing, Protocol::onFMSWatchdogExpired(), protocol(), and DS_Config::updateFMSCommStatus().

Referenced by init(), and setProtocol().

void DriverStation::resetJoysticks ( )
slot

Removes all the registered joysticks

References isConnectedToFMS(), joystickCount(), joysticks(), and setEnabled().

Referenced by reconfigureJoysticks().

void DriverStation::resetRadio ( )
privateslot

Called when the radio watchdog expires

References config(), DS::kCommsFailing, Protocol::onRadioWatchdogExpired(), protocol(), and DS_Config::updateRadioCommStatus().

Referenced by init(), and setProtocol().

void DriverStation::resetRobot ( )
privateslot
void DriverStation::restartRobotCode ( )
slot

Restarts the robot code (if a protocol is loaded)

References protocol(), and Protocol::restartRobotCode().

QString DriverStation::robotAddress ( ) const

Returns the applied robot address (be it DS-set or user-set)

References customRobotAddress(), and defaultRobotAddress().

Referenced by Sockets::onRobotLookupFinished(), Sockets::performLookups(), setCustomRobotAddress(), and updateAddresses().

DS::CodeStatus DriverStation::robotCodeStatus ( ) const

Returns the current status of the robot code

References config(), and DS_Config::robotCodeStatus().

Referenced by isRobotCodeRunning().

DS::CommStatus DriverStation::robotCommStatus ( ) const

Returns the current robot/FMS communication status.

References config(), and DS_Config::robotCommStatus().

Referenced by isConnectedToRobot().

bool DriverStation::running ( ) const

Returns true if the DS is currently allowed to send and receive data. This function is called whenever we send a packet or when we receive a packet.

Note
If this function returns false, then the DS will ignore all incoming packets and inhibit packet sending

Referenced by readFMSPacket(), readRadioPacket(), readRobotPacket(), sendFMSPacket(), sendRadioPacket(), and sendRobotPacket().

void DriverStation::sendFMSPacket ( )
privateslot

Generates and sends a new FMS packet only if we are already connected to the FMS

References isConnectedToFMS(), protocol(), running(), and Sockets::sendToFMS().

Referenced by init().

void DriverStation::sendRadioPacket ( )
privateslot

Generates and sends a new radio packet

References protocol(), running(), and Sockets::sendToRadio().

Referenced by init().

void DriverStation::sendRobotPacket ( )
privateslot

Generates and sends a new robot packet

References protocol(), running(), and Sockets::sendToRobot().

Referenced by init().

void DriverStation::setAlliance ( Alliance  alliance)
slot

Updates the team alliance.

Note
This value can be overwritten by the FMS system

References config(), and DS_Config::updateAlliance().

Referenced by setTeamStation().

void DriverStation::setControlMode ( ControlMode  mode)
slot

Changes the control mode of the robot.

Note
This value can be overwritten by the FMS system

References config(), and DS_Config::updateControlMode().

Referenced by switchToAutonomous(), switchToTeleoperated(), and switchToTestMode().

void DriverStation::setCustomFMSAddress ( const QString &  address)
slot

Forces the system to look for the FMS at the given address instead of using the default FMS address specified by the current protocol.

References fmsAddress(), and Sockets::setFMSAddress().

void DriverStation::setCustomRadioAddress ( const QString &  address)
slot

Forces the system to look for the robot radio at the given address instead of using the default radio address specified by the current protocol.

References radioAddress(), and Sockets::setRadioAddress().

void DriverStation::setCustomRobotAddress ( const QString &  address)
slot

Forces the system to use the given address. This can be useful when you already know the IP address of the robot, or you are simulating your robot program with a specific virtual IP address.

Using this function is discouraged, the LibDS is fast enough to remove the need of defining the IP address of the robot by yourself.

References robotAddress(), and Sockets::setRobotAddress().

void DriverStation::setEnabled ( bool  enabled)
slot

Changes the enabled status of the robot.

Note
This value can be overwritten by the FMS system or the robot application itself.

References DS::kDisabled, and DS::kEnabled.

Referenced by disableRobot(), enableRobot(), removeJoystick(), resetJoysticks(), switchToAutonomous(), switchToTeleoperated(), switchToTestMode(), and triggerEmergencyStop().

void DriverStation::setEnabled ( EnableStatus  status)
slot

Changes the enabled status of the robot.

Note
This value can be overwritten by the FMS system or the robot application itself.

References config(), and DS_Config::updateEnabled().

void DriverStation::setOperationStatus ( OperationStatus  status)
slot

Changes the operation status of the robot. Possible values are:

  • kDisconnected
  • kNormal
  • kEmergencyStop

If you are writting your own Driver Station client, we strongly encourage you to implement the hability to e-stop the robot in your custom client.

References config(), and DS_Config::updateOperationStatus().

Referenced by triggerEmergencyStop().

void DriverStation::setPosition ( Position  position)
slot

Updates the team position

Note
This value can be overwritten by the FMS system

References config(), and DS_Config::updatePosition().

Referenced by setTeamStation().

void DriverStation::setProtocol ( Protocol protocol)
slot
void DriverStation::setProtocolType ( int  protocol)
slot

Given the protocol, this function will initialize, load and configure the defined protocol.

This function is meant to be used in co-junction of the list outputted by the protocols() function.

References setProtocol().

void DriverStation::setTeam ( int  team)
slot

Changes the team number to the given team.

Note
Calling this function will trigger a re-evaluation of the FMS, radio and robot IPs (only if communications have not been established yet)

References config(), and DS_Config::updateTeam().

void DriverStation::setTeamStation ( int  station)
slot

If you are lazy enough to not wanting to use two function calls to change the alliance & position of the robot, we've got you covered!

Actually, this function is available so that the UI elements (such as a combobox with team stations) can interact directly with the DriverStation

References DS::kAllianceBlue, DS::kAllianceRed, DS::kPosition1, DS::kPosition2, DS::kPosition3, setAlliance(), and setPosition().

void DriverStation::start ( )
privateslot

Allows the DS to send and receive packets

Referenced by setProtocol().

void DriverStation::stop ( )
privateslot

Inhibits the DS to send and receive packets

Referenced by setProtocol().

void DriverStation::switchToAutonomous ( )
slot

Disables the robot and changes the control mode to kControlAutonomous

References DS::kControlAutonomous, DS::kDisabled, setControlMode(), and setEnabled().

void DriverStation::switchToTeleoperated ( )
slot

Disables the robot and changes the control mode to kControlTeleoperated

References DS::kControlTeleoperated, DS::kDisabled, setControlMode(), and setEnabled().

void DriverStation::switchToTestMode ( )
slot

Disables the robot and changes the control mode to kControlTest

References DS::kControlTest, DS::kDisabled, setControlMode(), and setEnabled().

int DriverStation::team ( ) const

Returns the current team number, which can be used by the client application.

References config(), and DS_Config::team().

Referenced by FRC_2014::radioAddress(), and FRC_2014::robotAddress().

QStringList DriverStation::teamStations ( ) const

Returns a list with the possible alliances and positions. This function is meant to be used to generate your UI elements and seamessly use them with the setAllianceAndPosition() function.

void DriverStation::triggerEmergencyStop ( )
slot

Disables the robot and triggers an emergency stop on the robot

References DS::kDisabled, DS::kEmergencyStop, setEnabled(), and setOperationStatus().

void DriverStation::updateAddresses ( )
privateslot

Ensures that the IP addresses are updated when the application changes the team number.

References fmsAddress(), radioAddress(), robotAddress(), Sockets::setFMSAddress(), Sockets::setRadioAddress(), and Sockets::setRobotAddress().

Referenced by setProtocol(), and updateAddresses().

void DriverStation::updateAddresses ( int  unused)
privateslot

This overloaded function is called when the team number is changed (hence the int in the argument).

As its name suggests, the input value is unused, this function was implemented to avoid possible errors in the Qt signal/slot system, while maintaining the functionality of the original updateAddresses() function

References updateAddresses().

void DriverStation::updateAxis ( int  id,
int  axis,
qreal  value 
)
slot

Updates the value of the given axis of the joystick with the specified id

Note
If the given joystick is invalid, this function will silently ignore your request

References joysticks().

void DriverStation::updateButton ( int  id,
int  button,
bool  state 
)
slot

Updates the pressed state of the given button of the joystick with the specified id

Note
If the given joystick is invalid, this function will silently ignore your request

References joysticks().

void DriverStation::updateLogs ( const QString &  file)
privateslot

Used to ensure that the log feed of the UI is constantly updated

References openLog().

void DriverStation::updatePacketLoss ( )
privateslot
void DriverStation::updatePOV ( int  id,
int  pov,
int  angle 
)
slot

Updates the angle of the given pov of the joystick with the specified id

Note
If the given joystick is invalid, this function will silently ignore your request

References joysticks().

DS::VoltageStatus DriverStation::voltageStatus ( ) const

Returns the current voltage status (normal or brownout) of the robot.

References config(), and DS_Config::voltageStatus().

Referenced by isVoltageBrownout().


The documentation for this class was generated from the following files: