#include <Joystick.h>
Public Types | |
enum | AxisType { kXAxis, kYAxis, kZAxis, kTwistAxis, kThrottleAxis, kNumAxisTypes } |
enum | ButtonType { kTriggerButton, kTopButton, kNumButtonTypes } |
Public Types inherited from GenericHID | |
enum | JoystickHand { kLeftHand = 0, kRightHand = 1 } |
Public Member Functions | |
Joystick (uint32_t port) | |
Joystick (uint32_t port, uint32_t numAxisTypes, uint32_t numButtonTypes) | |
uint32_t | GetAxisChannel (AxisType axis) |
void | SetAxisChannel (AxisType axis, uint32_t channel) |
virtual float | GetX (JoystickHand hand=kRightHand) |
virtual float | GetY (JoystickHand hand=kRightHand) |
virtual float | GetZ () |
virtual float | GetTwist () |
virtual float | GetThrottle () |
virtual float | GetAxis (AxisType axis) |
float | GetRawAxis (uint32_t axis) |
virtual bool | GetTrigger (JoystickHand hand=kRightHand) |
virtual bool | GetTop (JoystickHand hand=kRightHand) |
virtual bool | GetBumper (JoystickHand hand=kRightHand) |
virtual bool | GetButton (ButtonType button) |
bool | GetRawButton (uint32_t button) |
virtual float | GetMagnitude () |
virtual float | GetDirectionRadians () |
virtual float | GetDirectionDegrees () |
Public Member Functions inherited from ErrorBase | |
virtual Error & | GetError () |
Retrieve the current error. Get the current error information associated with this sensor. | |
virtual const Error & | GetError () const |
virtual void | SetErrnoError (const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set error information associated with a C library call that set an error to the "errno" global variable. More... | |
virtual void | SetImaqError (int success, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set the current error information associated from the nivision Imaq API. More... | |
virtual void | SetError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | SetWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | CloneError (ErrorBase *rhs) const |
virtual void | ClearError () const |
Clear the current error information associated with this sensor. | |
virtual bool | StatusIsFatal () const |
Check if the current error code represents a fatal error. More... | |
Static Public Member Functions | |
static Joystick * | GetStickForPort (uint32_t port) |
Static Public Member Functions inherited from ErrorBase | |
static void | SetGlobalError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) |
static void | SetGlobalWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) |
static Error & | GetGlobalError () |
Additional Inherited Members | |
Protected Member Functions inherited from ErrorBase | |
ErrorBase () | |
Initialize the instance status to 0 for now. | |
Protected Attributes inherited from ErrorBase | |
Error | m_error |
Static Protected Attributes inherited from ErrorBase | |
static SEM_ID | _globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE) |
static Error | _globalError |
Handle input from standard Joysticks connected to the Driver Station. This class handles standard input that comes from the Driver Station. Each time a value is requested the most recent value is returned. There is a single class instance for each joystick and the mapping of ports to hardware buttons depends on the code in the driver station.
|
explicit |
Construct an instance of a joystick. The joystick index is the usb port on the drivers station.
port | The port on the driver station that the joystick is plugged into. |
Joystick::Joystick | ( | uint32_t | port, |
uint32_t | numAxisTypes, | ||
uint32_t | numButtonTypes | ||
) |
Version of the constructor to be called by sub-classes.
This constructor allows the subclass to configure the number of constants for axes and buttons.
port | The port on the driver station that the joystick is plugged into. |
numAxisTypes | The number of axis types in the enum. |
numButtonTypes | The number of button types in the enum. |
|
virtual |
For the current joystick, return the axis determined by the argument.
This is for cases where the joystick axis is returned programatically, otherwise one of the previous functions would be preferable (for example GetX()).
axis | The axis to read. |
uint32_t Joystick::GetAxisChannel | ( | AxisType | axis | ) |
Get the channel currently associated with the specified axis.
axis | The axis to look up the channel for. |
|
virtual |
This is not supported for the Joystick. This method is only here to complete the GenericHID interface.
Implements GenericHID.
|
virtual |
Get buttons based on an enumerated type.
The button type will be looked up in the list of buttons and then read.
button | The type of button to read. |
|
virtual |
Get the direction of the vector formed by the joystick and its origin in degrees
uses acos(-1) to represent Pi due to absence of readily accessable Pi constant in C++
|
virtual |
Get the direction of the vector formed by the joystick and its origin in radians
|
virtual |
Get the magnitude of the direction vector formed by the joystick's current position relative to its origin
|
virtual |
Get the value of the axis.
axis | The axis to read [1-6]. |
Implements GenericHID.
|
virtual |
Get the button value for buttons 1 through 12.
The buttons are returned in a single 16 bit value with one bit representing the state of each button. The appropriate button is returned as a boolean value.
button | The button number to be read. |
Implements GenericHID.
|
virtual |
Get the throttle value of the current joystick. This depends on the mapping of the joystick connected to the current port.
Implements GenericHID.
|
virtual |
Read the state of the top button on the joystick.
Look up which button has been assigned to the top and read its state.
hand | This parameter is ignored for the Joystick class and is only here to complete the GenericHID interface. |
Implements GenericHID.
|
virtual |
Read the state of the trigger on the joystick.
Look up which button has been assigned to the trigger and read its state.
hand | This parameter is ignored for the Joystick class and is only here to complete the GenericHID interface. |
Implements GenericHID.
|
virtual |
Get the twist value of the current joystick. This depends on the mapping of the joystick connected to the current port.
Implements GenericHID.
|
virtual |
Get the X value of the joystick. This depends on the mapping of the joystick connected to the current port.
Implements GenericHID.
|
virtual |
Get the Y value of the joystick. This depends on the mapping of the joystick connected to the current port.
Implements GenericHID.
|
virtual |
Get the Z value of the current joystick. This depends on the mapping of the joystick connected to the current port.
Implements GenericHID.
void Joystick::SetAxisChannel | ( | AxisType | axis, |
uint32_t | channel | ||
) |
Set the channel associated with a specified axis.
axis | The axis to set the channel for. |
channel | The channel to set the axis to. |