2023-Robot
Robot code for 2023 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.
 
void SetButtonDebounce (Button targetButton, DebounceSettings newSettings)
 Configure debounce for a specified button.
 
void SwapSettings (XboxController &other)
 Swap all configurations (debounce, etc) between this and other controller. Useful in conjunction with argos_lib::SwappableControllersSubsystem.
 
double GetX (JoystickHand hand) const
 Get X joystick percent from specified joystick.
 
double GetY (JoystickHand hand) const
 Get Y joystick percent from specified joystick.
 
double GetTriggerAxis (JoystickHand hand) const
 Get percent from specified controller trigger button.
 
bool GetDebouncedButton (Button buttonIdx)
 Get the status of button after applying debounce.
 
bool GetDebouncedButtonPressed (Button buttonIdx)
 Detect if a button just transitioned from inactive to active after applying debounce.
 
bool GetDebouncedButtonReleased (Button buttonIdx)
 Detect if a button just transitioned from active to inactive after applying debounce.
 
bool GetDebouncedButton (std::vector< 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.
 
bool GetDebouncedButtonPressed (std::vector< 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.
 
bool GetDebouncedButtonReleased (std::vector< 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.
 
bool GetRawButton (Button buttonIdx)
 Get the status of button.
 
bool GetRawButtonPressed (Button buttonIdx)
 Detect if a button just transitioned from inactive to active.
 
bool GetRawButtonReleased (Button buttonIdx)
 Detect if a button just transitioned from active to inactive.
 
bool GetRawButton (std::vector< Button > buttonCombo)
 Get the status of a combination of buttons ignoring debounce. Raw combo button state is active when all buttons are simultaneously active.
 
bool GetRawButtonPressed (std::vector< 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.
 
bool GetRawButtonReleased (std::vector< 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.
 
VibrationModel GetVibration () const
 Get the active vibration model.
 
void SetVibration (VibrationModel newVibrationModel)
 Sets a new vibration pattern and updates vibration output based on that new model.
 
void UpdateVibration ()
 Update vibration output based on current vibration model.
 
UpdateStatus UpdateButton (Button buttonIdx)
 Determines the new status of a button. This is used by the other status retrieval functions.
 
frc2::Trigger TriggerRaw (Button button)
 Generates a trigger that is true when button is true.
 
frc2::Trigger TriggerRaw (std::vector< Button > buttonCombo)
 Generates a trigger that is true when all buttons in buttonCombo are true.
 
frc2::Trigger TriggerRawAnyOf (std::vector< Button > buttonCombo)
 Trigger when any of the selected buttons' raw value is true.
 
frc2::Trigger TriggerRawAllOf (std::vector< Button > buttonCombo)
 Trigger when all of the selected buttons' raw values are true.
 
frc2::Trigger TriggerRawNoneOf (std::vector< Button > buttonCombo)
 Trigger when none of the selected buttons' raw value is true.
 
frc2::Trigger TriggerRawOneOf (std::vector< Button > buttonCombo)
 Trigger when exactly one of the selected buttons' raw value is true.
 
frc2::Trigger TriggerDebounced (Button button)
 Generates a trigger that is true when debounced button is true.
 
frc2::Trigger TriggerDebounced (std::vector< Button > buttonCombo)
 Generates a trigger that is true when all debounced buttons in buttonCombo are true.
 
frc2::Trigger TriggerDebouncedAnyOf (std::vector< Button > buttonCombo)
 Trigger when any of the selected buttons' debounced value is true.
 
frc2::Trigger TriggerDebouncedAllOf (std::vector< Button > buttonCombo)
 Trigger when all of the selected buttons' debounced values are true.
 
frc2::Trigger TriggerDebouncedNoneOf (std::vector< Button > buttonCombo)
 Trigger when none of the selected buttons' debounced value is true.
 
frc2::Trigger TriggerDebouncedOneOf (std::vector< Button > buttonCombo)
 Trigger when exactly one of the selected buttons' debounced value is true.
 

Private Member Functions

DPadButtons GetPOVButtons ()
 Convert POV angle to usable DPad button values.
 
frc2::Trigger TriggerAnyOf (std::vector< Button > buttonCombo, std::function< bool(Button)> buttonGetterFunc)
 Trigger when any of the selected buttons is true according to the supplied buttonGetterFunc.
 
frc2::Trigger TriggerAllOf (std::vector< Button > buttonCombo, std::function< bool(Button)> buttonGetterFunc)
 Trigger when all of the selected buttons is true according to the supplied buttonGetterFunc.
 
frc2::Trigger TriggerNoneOf (std::vector< Button > buttonCombo, std::function< bool(Button)> buttonGetterFunc)
 Trigger when none of the selected buttons is true according to the supplied buttonGetterFunc.
 
frc2::Trigger TriggerOneOf (std::vector< Button > buttonCombo, std::function< bool(Button)> buttonGetterFunc)
 Trigger when exactly one of the selected buttons is true according to the supplied buttonGetterFunc.
 

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.
 
VibrationModel m_vibrationModel
 Active vibration model.
 

Static Private Attributes

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

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::vector< 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::vector< 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::vector< 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::vector< 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::vector< 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::vector< 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

◆ TriggerAllOf()

frc2::Trigger XboxController::TriggerAllOf ( std::vector< Button buttonCombo,
std::function< bool(Button)>  buttonGetterFunc 
)
private

Trigger when all of the selected buttons is true according to the supplied buttonGetterFunc.

Parameters
buttonComboButtons to check
buttonGetterFuncFunction to evaluate to determine button state
Returns
frc2::Trigger Trigger indicating all buttons are true

◆ TriggerAnyOf()

frc2::Trigger XboxController::TriggerAnyOf ( std::vector< Button buttonCombo,
std::function< bool(Button)>  buttonGetterFunc 
)
private

Trigger when any of the selected buttons is true according to the supplied buttonGetterFunc.

Parameters
buttonComboButtons to check
buttonGetterFuncFunction to evaluate to determine button state
Returns
frc2::Trigger Trigger indicating any button is true

◆ TriggerDebounced() [1/2]

frc2::Trigger XboxController::TriggerDebounced ( Button  button)

Generates a trigger that is true when debounced button is true.

Parameters
buttonButton to monitor
Returns
frc2::Trigger Trigger to monitor debounced button

◆ TriggerDebounced() [2/2]

frc2::Trigger XboxController::TriggerDebounced ( std::vector< Button buttonCombo)

Generates a trigger that is true when all debounced buttons in buttonCombo are true.

Parameters
buttonComboButtons to monitor
Returns
frc2::Trigger Trigger to monitor debounced buttons

◆ TriggerDebouncedAllOf()

frc2::Trigger XboxController::TriggerDebouncedAllOf ( std::vector< Button buttonCombo)

Trigger when all of the selected buttons' debounced values are true.

Parameters
buttonComboButtons to check
Returns
frc2::Trigger Trigger indicating all button debounced values are true

◆ TriggerDebouncedAnyOf()

frc2::Trigger XboxController::TriggerDebouncedAnyOf ( std::vector< Button buttonCombo)

Trigger when any of the selected buttons' debounced value is true.

Parameters
buttonComboButtons to check
Returns
frc2::Trigger Trigger indicating any button debounced value is true

◆ TriggerDebouncedNoneOf()

frc2::Trigger XboxController::TriggerDebouncedNoneOf ( std::vector< Button buttonCombo)

Trigger when none of the selected buttons' debounced value is true.

Parameters
buttonComboButtons to check
Returns
frc2::Trigger Trigger indicating none button debounced value is true

◆ TriggerDebouncedOneOf()

frc2::Trigger XboxController::TriggerDebouncedOneOf ( std::vector< Button buttonCombo)

Trigger when exactly one of the selected buttons' debounced value is true.

Parameters
buttonComboButtons to check
Returns
frc2::Trigger Trigger indicating one button's debounced value is true

◆ TriggerNoneOf()

frc2::Trigger XboxController::TriggerNoneOf ( std::vector< Button buttonCombo,
std::function< bool(Button)>  buttonGetterFunc 
)
private

Trigger when none of the selected buttons is true according to the supplied buttonGetterFunc.

Parameters
buttonComboButtons to check
buttonGetterFuncFunction to evaluate to determine button state
Returns
frc2::Trigger Trigger indicating no button is true

◆ TriggerOneOf()

frc2::Trigger XboxController::TriggerOneOf ( std::vector< Button buttonCombo,
std::function< bool(Button)>  buttonGetterFunc 
)
private

Trigger when exactly one of the selected buttons is true according to the supplied buttonGetterFunc.

Parameters
buttonComboButtons to check
buttonGetterFuncFunction to evaluate to determine button state
Returns
frc2::Trigger Trigger indicating one button is true

◆ TriggerRaw() [1/2]

frc2::Trigger XboxController::TriggerRaw ( Button  button)

Generates a trigger that is true when button is true.

Parameters
buttonButton to monitor
Returns
frc2::Trigger Trigger to monitor button

◆ TriggerRaw() [2/2]

frc2::Trigger XboxController::TriggerRaw ( std::vector< Button buttonCombo)

Generates a trigger that is true when all buttons in buttonCombo are true.

Parameters
buttonComboButtons to monitor
Returns
frc2::Trigger Trigger to monitor buttons

◆ TriggerRawAllOf()

frc2::Trigger XboxController::TriggerRawAllOf ( std::vector< Button buttonCombo)

Trigger when all of the selected buttons' raw values are true.

Parameters
buttonComboButtons to check
Returns
frc2::Trigger Trigger indicating all button raw values are true

◆ TriggerRawAnyOf()

frc2::Trigger XboxController::TriggerRawAnyOf ( std::vector< Button buttonCombo)

Trigger when any of the selected buttons' raw value is true.

Parameters
buttonComboButtons to check
Returns
frc2::Trigger Trigger indicating any button raw value is true

◆ TriggerRawNoneOf()

frc2::Trigger XboxController::TriggerRawNoneOf ( std::vector< Button buttonCombo)

Trigger when none of the selected buttons' raw value is true.

Parameters
buttonComboButtons to check
Returns
frc2::Trigger Trigger indicating none button raw value is true

◆ TriggerRawOneOf()

frc2::Trigger XboxController::TriggerRawOneOf ( std::vector< Button buttonCombo)

Trigger when exactly one of the selected buttons' raw value is true.

Parameters
buttonComboButtons to check
Returns
frc2::Trigger Trigger indicating one button's raw value is true

◆ 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: