2022-Robot
Robot code for 2022 FRC Season by Argos, FRC team #1756
Loading...
Searching...
No Matches
argos_lib::XboxController Class Reference

#include <xbox_controller.h>

Inheritance diagram for argos_lib::XboxController:

Classes

struct  DPadButtons
 Parsed directional pad button states. More...
 
struct  UpdateStatus
 State of an individual button. More...
 

Public Types

enum class  JoystickHand { kLeftHand , kRightHand }
 Replaces legacy joystick hand API for WPILib. More...
 
enum class  Button {
  kA = 1 , kB = 2 , kX = 3 , kY = 4 ,
  kBumperLeft = 5 , kBumperRight = 6 , kBack = 7 , kStart = 8 ,
  kStickLeft = 9 , kStickRight = 10 , kLeftTrigger = 11 , kRightTrigger = 12 ,
  kUp = 13 , kRight = 14 , kDown = 15 , kLeft = 16 ,
  COUNT
}
 
enum class  Axis {
  kLeftX = 0 , kLeftY = 1 , kLeftTrigger = 2 , kRightTrigger = 3 ,
  kRightX = 4 , kRightY = 5 , COUNT
}
 

Public Member Functions

 XboxController ()=delete
 
 XboxController (int port)
 Construct a new Xbox Controller object connected at port index. More...
 
void SetButtonDebounce (Button targetButton, DebounceSettings newSettings)
 Configure debounce for a specified button. More...
 
void SwapSettings (XboxController &other)
 Swap all configurations (debounce, etc) between this and other controller. Useful in conjunction with argos_lib::SwappableControllersSubsystem. More...
 
double GetX (JoystickHand hand) const
 Get X joystick percent from specified joystick. More...
 
double GetY (JoystickHand hand) const
 Get Y joystick percent from specified joystick. More...
 
double GetTriggerAxis (JoystickHand hand) const
 Get percent from specified controller trigger button. More...
 
bool GetDebouncedButton (Button buttonIdx)
 Get the status of button after applying debounce. More...
 
bool GetDebouncedButtonPressed (Button buttonIdx)
 Detect if a button just transitioned from inactive to active after applying debounce. More...
 
bool GetDebouncedButtonReleased (Button buttonIdx)
 Detect if a button just transitioned from active to inactive after applying debounce. More...
 
bool GetDebouncedButton (std::initializer_list< Button > buttonCombo)
 Get the status of a combination of buttons after applying debounce. Raw combo button state is active when all buttons are simultaneously active based on their independent debounce settings. More...
 
bool GetDebouncedButtonPressed (std::initializer_list< Button > buttonCombo)
 Detect if a combination of buttons just transitioned from inactive to active after applying debounce. Raw combo button state is active when all buttons are simultaneously active based on their independent debounce settings. More...
 
bool GetDebouncedButtonReleased (std::initializer_list< Button > buttonCombo)
 Detect if a combination of buttons just transitioned from active to inactive after applying debounce. Raw combo button state is active when all buttons are simultaneously active based on their independent debounce settings. More...
 
bool GetRawButton (Button buttonIdx)
 Get the status of button. More...
 
bool GetRawButtonPressed (Button buttonIdx)
 Detect if a button just transitioned from inactive to active. More...
 
bool GetRawButtonReleased (Button buttonIdx)
 Detect if a button just transitioned from active to inactive. More...
 
bool GetRawButton (std::initializer_list< Button > buttonCombo)
 Get the status of a combination of buttons ignoring debounce. Raw combo button state is active when all buttons are simultaneously active. More...
 
bool GetRawButtonPressed (std::initializer_list< Button > buttonCombo)
 Detect if a combination of buttons just transitioned from inactive to active. Raw combo button state is active when all buttons are simultaneously active. More...
 
bool GetRawButtonReleased (std::initializer_list< Button > buttonCombo)
 Detect if a combination of buttons just transitioned from active to inactive. Raw combo button state is active when all buttons are simultaneously active. More...
 
VibrationModel GetVibration () const
 Get the active vibration model. More...
 
void SetVibration (VibrationModel newVibrationModel)
 Sets a new vibration pattern and updates vibration output based on that new model. More...
 
void UpdateVibration ()
 Update vibration output based on current vibration model. More...
 
UpdateStatus UpdateButton (Button buttonIdx)
 Determines the new status of a button. This is used by the other status retrieval functions. More...
 

Private Member Functions

DPadButtons GetPOVButtons ()
 Convert POV angle to usable DPad button values. More...
 

Private Attributes

std::array< DebounceSettings, static_cast< int >(Button::COUNT)> m_buttonDebounceSettings
 
std::array< bool, static_cast< int >(Button::COUNT)> m_buttonDebounceStatus
 
std::array< bool, static_cast< int >(Button::COUNT)> m_rawButtonStatus
 
std::array< std::chrono::time_point< std::chrono::steady_clock >, static_cast< int >(Button::COUNT)> m_buttonDebounceTransitionTime
 Time when new value was first seen. More...
 
VibrationModel m_vibrationModel
 Active vibration model. More...
 

Static Private Attributes

static constexpr double analogTriggerThresh = 0.5
 Percent trigger pressed to consider as a button press. More...
 

Member Enumeration Documentation

◆ Axis

Enumerator
kLeftX 
kLeftY 
kLeftTrigger 
kRightTrigger 
kRightX 
kRightY 
COUNT 

◆ Button

Enumerator
kA 
kB 
kX 
kY 
kBumperLeft 
kBumperRight 
kBack 
kStart 
kStickLeft 
kStickRight 
kLeftTrigger 

virtual button

kRightTrigger 

virtual button

kUp 

virtual button

kRight 

virtual button

kDown 

virtual button

kLeft 

virtual button

COUNT 

◆ JoystickHand

Replaces legacy joystick hand API for WPILib.

Enumerator
kLeftHand 
kRightHand 

Constructor & Destructor Documentation

◆ XboxController() [1/2]

argos_lib::XboxController::XboxController ( )
delete

◆ XboxController() [2/2]

XboxController::XboxController ( int  port)
explicit

Construct a new Xbox Controller object connected at port index.

Parameters
portIndex of new controller

Member Function Documentation

◆ GetDebouncedButton() [1/2]

bool XboxController::GetDebouncedButton ( Button  buttonIdx)

Get the status of button after applying debounce.

Parameters
buttonIdxIndex of requested button
Returns
debounced status

◆ GetDebouncedButton() [2/2]

bool XboxController::GetDebouncedButton ( std::initializer_list< Button buttonCombo)

Get the status of a combination of buttons after applying debounce. Raw combo button state is active when all buttons are simultaneously active based on their independent debounce settings.

Parameters
buttonComboButtons that make up the combination
Returns
debounced status

◆ GetDebouncedButtonPressed() [1/2]

bool XboxController::GetDebouncedButtonPressed ( Button  buttonIdx)

Detect if a button just transitioned from inactive to active after applying debounce.

Parameters
buttonIdxIndex of requested button
Returns
true if inactive to active transition occurred

◆ GetDebouncedButtonPressed() [2/2]

bool XboxController::GetDebouncedButtonPressed ( std::initializer_list< Button buttonCombo)

Detect if a combination of buttons just transitioned from inactive to active after applying debounce. Raw combo button state is active when all buttons are simultaneously active based on their independent debounce settings.

Parameters
buttonComboButtons that make up the combination
Returns
true if combination transition to active occurred

◆ GetDebouncedButtonReleased() [1/2]

bool XboxController::GetDebouncedButtonReleased ( Button  buttonIdx)

Detect if a button just transitioned from active to inactive after applying debounce.

Parameters
buttonIdxIndex of requested button
Returns
true if active to inactive transition occurred

◆ GetDebouncedButtonReleased() [2/2]

bool XboxController::GetDebouncedButtonReleased ( std::initializer_list< Button buttonCombo)

Detect if a combination of buttons just transitioned from active to inactive after applying debounce. Raw combo button state is active when all buttons are simultaneously active based on their independent debounce settings.

Parameters
buttonComboButtons that make up the combination
Returns
true if combination transition to inactive occurred

◆ GetPOVButtons()

XboxController::DPadButtons XboxController::GetPOVButtons ( )
private

Convert POV angle to usable DPad button values.

Returns
DPadButtons Active status for each cardinal direction

◆ GetRawButton() [1/2]

bool XboxController::GetRawButton ( Button  buttonIdx)

Get the status of button.

Parameters
buttonIdxIndex of requested button
Returns
Status ignoring any debounce

◆ GetRawButton() [2/2]

bool XboxController::GetRawButton ( std::initializer_list< Button buttonCombo)

Get the status of a combination of buttons ignoring debounce. Raw combo button state is active when all buttons are simultaneously active.

Parameters
buttonComboButtons that make up the combination
Returns
Status ignoring any debounce

◆ GetRawButtonPressed() [1/2]

bool XboxController::GetRawButtonPressed ( Button  buttonIdx)

Detect if a button just transitioned from inactive to active.

Parameters
buttonIdxIndex of requested button
Returns
true if inactive to active transition occurred

◆ GetRawButtonPressed() [2/2]

bool XboxController::GetRawButtonPressed ( std::initializer_list< Button buttonCombo)

Detect if a combination of buttons just transitioned from inactive to active. Raw combo button state is active when all buttons are simultaneously active.

Parameters
buttonComboButtons that make up the combination
Returns
true if combination transition to active occurred

◆ GetRawButtonReleased() [1/2]

bool XboxController::GetRawButtonReleased ( Button  buttonIdx)

Detect if a button just transitioned from active to inactive.

Parameters
buttonIdxIndex of requested button
Returns
true if active to inactive transition occurred

◆ GetRawButtonReleased() [2/2]

bool XboxController::GetRawButtonReleased ( std::initializer_list< Button buttonCombo)

Detect if a combination of buttons just transitioned from active to inactive. Raw combo button state is active when all buttons are simultaneously active.

Parameters
buttonComboButtons that make up the combination
Returns
true if combination transition to inactive occurred

◆ GetTriggerAxis()

double XboxController::GetTriggerAxis ( JoystickHand  hand) const

Get percent from specified controller trigger button.

Parameters
handLeft or right trigger
Returns
double Percent [0,1]

◆ GetVibration()

VibrationModel XboxController::GetVibration ( ) const

Get the active vibration model.

Returns
Active vibration model

◆ GetX()

double XboxController::GetX ( JoystickHand  hand) const

Get X joystick percent from specified joystick.

Parameters
handLeft or right joystick
Returns
double Percent [-1,1]

◆ GetY()

double XboxController::GetY ( JoystickHand  hand) const

Get Y joystick percent from specified joystick.

Parameters
handLeft or right joystick
Returns
double Percent [-1,1]

◆ SetButtonDebounce()

void XboxController::SetButtonDebounce ( Button  targetButton,
DebounceSettings  newSettings 
)

Configure debounce for a specified button.

Parameters
targetButtonButton to configure
newSettingsNew debounce configuration

◆ SetVibration()

void XboxController::SetVibration ( VibrationModel  newVibrationModel)

Sets a new vibration pattern and updates vibration output based on that new model.

Parameters
newVibrationModelModel to generate vibration output

◆ SwapSettings()

void XboxController::SwapSettings ( XboxController other)

Swap all configurations (debounce, etc) between this and other controller. Useful in conjunction with argos_lib::SwappableControllersSubsystem.

Parameters
otherController to swap settings with

◆ UpdateButton()

XboxController::UpdateStatus XboxController::UpdateButton ( Button  buttonIdx)

Determines the new status of a button. This is used by the other status retrieval functions.

Parameters
buttonIdxIndex of button to update
Returns
UpdateStatus Full button state

◆ UpdateVibration()

void XboxController::UpdateVibration ( )

Update vibration output based on current vibration model.

Member Data Documentation

◆ analogTriggerThresh

constexpr double argos_lib::XboxController::analogTriggerThresh = 0.5
staticconstexprprivate

Percent trigger pressed to consider as a button press.

◆ m_buttonDebounceSettings

std::array<DebounceSettings, static_cast<int>(Button::COUNT)> argos_lib::XboxController::m_buttonDebounceSettings
private

◆ m_buttonDebounceStatus

std::array<bool, static_cast<int>(Button::COUNT)> argos_lib::XboxController::m_buttonDebounceStatus
private

◆ m_buttonDebounceTransitionTime

std::array<std::chrono::time_point<std::chrono::steady_clock>, static_cast<int>(Button::COUNT)> argos_lib::XboxController::m_buttonDebounceTransitionTime
private

Time when new value was first seen.

◆ m_rawButtonStatus

std::array<bool, static_cast<int>(Button::COUNT)> argos_lib::XboxController::m_rawButtonStatus
private

◆ m_vibrationModel

VibrationModel argos_lib::XboxController::m_vibrationModel
private

Active vibration model.


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