![]() |
2022-Robot
Robot code for 2022 FRC Season by Argos, FRC team #1756
|
#include <xbox_controller.h>
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... | |
|
strong |
|
strong |
|
strong |
|
delete |
|
explicit |
Construct a new Xbox Controller object connected at port index.
port | Index of new controller |
bool XboxController::GetDebouncedButton | ( | Button | buttonIdx | ) |
Get the status of button after applying debounce.
buttonIdx | Index of requested button |
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.
buttonCombo | Buttons that make up the combination |
bool XboxController::GetDebouncedButtonPressed | ( | Button | buttonIdx | ) |
Detect if a button just transitioned from inactive to active after applying debounce.
buttonIdx | Index of requested button |
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.
buttonCombo | Buttons that make up the combination |
bool XboxController::GetDebouncedButtonReleased | ( | Button | buttonIdx | ) |
Detect if a button just transitioned from active to inactive after applying debounce.
buttonIdx | Index of requested button |
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.
buttonCombo | Buttons that make up the combination |
|
private |
Convert POV angle to usable DPad button values.
bool XboxController::GetRawButton | ( | Button | buttonIdx | ) |
Get the status of button.
buttonIdx | Index of requested button |
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.
buttonCombo | Buttons that make up the combination |
bool XboxController::GetRawButtonPressed | ( | Button | buttonIdx | ) |
Detect if a button just transitioned from inactive to active.
buttonIdx | Index of requested button |
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.
buttonCombo | Buttons that make up the combination |
bool XboxController::GetRawButtonReleased | ( | Button | buttonIdx | ) |
Detect if a button just transitioned from active to inactive.
buttonIdx | Index of requested button |
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.
buttonCombo | Buttons that make up the combination |
double XboxController::GetTriggerAxis | ( | JoystickHand | hand | ) | const |
Get percent from specified controller trigger button.
hand | Left or right trigger |
VibrationModel XboxController::GetVibration | ( | ) | const |
Get the active vibration model.
double XboxController::GetX | ( | JoystickHand | hand | ) | const |
Get X joystick percent from specified joystick.
hand | Left or right joystick |
double XboxController::GetY | ( | JoystickHand | hand | ) | const |
Get Y joystick percent from specified joystick.
hand | Left or right joystick |
void XboxController::SetButtonDebounce | ( | Button | targetButton, |
DebounceSettings | newSettings | ||
) |
Configure debounce for a specified button.
targetButton | Button to configure |
newSettings | New debounce configuration |
void XboxController::SetVibration | ( | VibrationModel | newVibrationModel | ) |
Sets a new vibration pattern and updates vibration output based on that new model.
newVibrationModel | Model to generate vibration output |
void XboxController::SwapSettings | ( | XboxController & | other | ) |
Swap all configurations (debounce, etc) between this and other controller. Useful in conjunction with argos_lib::SwappableControllersSubsystem.
other | Controller to swap settings with |
XboxController::UpdateStatus XboxController::UpdateButton | ( | Button | buttonIdx | ) |
Determines the new status of a button. This is used by the other status retrieval functions.
buttonIdx | Index of button to update |
void XboxController::UpdateVibration | ( | ) |
Update vibration output based on current vibration model.
|
staticconstexprprivate |
Percent trigger pressed to consider as a button press.
|
private |
|
private |
|
private |
Time when new value was first seen.
|
private |
|
private |
Active vibration model.