2023-Robot
Robot code for 2023 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. | |
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. | |
|
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::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.
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::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.
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::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.
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::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.
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::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.
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::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.
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 |
|
private |
Trigger when all of the selected buttons is true according to the supplied buttonGetterFunc.
buttonCombo | Buttons to check |
buttonGetterFunc | Function to evaluate to determine button state |
|
private |
Trigger when any of the selected buttons is true according to the supplied buttonGetterFunc.
buttonCombo | Buttons to check |
buttonGetterFunc | Function to evaluate to determine button state |
frc2::Trigger XboxController::TriggerDebounced | ( | Button | button | ) |
Generates a trigger that is true when debounced button is true.
button | Button to monitor |
frc2::Trigger XboxController::TriggerDebounced | ( | std::vector< Button > | buttonCombo | ) |
Generates a trigger that is true when all debounced buttons in buttonCombo are true.
buttonCombo | Buttons to monitor |
frc2::Trigger XboxController::TriggerDebouncedAllOf | ( | std::vector< Button > | buttonCombo | ) |
Trigger when all of the selected buttons' debounced values are true.
buttonCombo | Buttons to check |
frc2::Trigger XboxController::TriggerDebouncedAnyOf | ( | std::vector< Button > | buttonCombo | ) |
Trigger when any of the selected buttons' debounced value is true.
buttonCombo | Buttons to check |
frc2::Trigger XboxController::TriggerDebouncedNoneOf | ( | std::vector< Button > | buttonCombo | ) |
Trigger when none of the selected buttons' debounced value is true.
buttonCombo | Buttons to check |
frc2::Trigger XboxController::TriggerDebouncedOneOf | ( | std::vector< Button > | buttonCombo | ) |
Trigger when exactly one of the selected buttons' debounced value is true.
buttonCombo | Buttons to check |
|
private |
Trigger when none of the selected buttons is true according to the supplied buttonGetterFunc.
buttonCombo | Buttons to check |
buttonGetterFunc | Function to evaluate to determine button state |
|
private |
Trigger when exactly one of the selected buttons is true according to the supplied buttonGetterFunc.
buttonCombo | Buttons to check |
buttonGetterFunc | Function to evaluate to determine button state |
frc2::Trigger XboxController::TriggerRaw | ( | Button | button | ) |
Generates a trigger that is true when button is true.
button | Button to monitor |
frc2::Trigger XboxController::TriggerRaw | ( | std::vector< Button > | buttonCombo | ) |
Generates a trigger that is true when all buttons in buttonCombo are true.
buttonCombo | Buttons to monitor |
frc2::Trigger XboxController::TriggerRawAllOf | ( | std::vector< Button > | buttonCombo | ) |
Trigger when all of the selected buttons' raw values are true.
buttonCombo | Buttons to check |
frc2::Trigger XboxController::TriggerRawAnyOf | ( | std::vector< Button > | buttonCombo | ) |
Trigger when any of the selected buttons' raw value is true.
buttonCombo | Buttons to check |
frc2::Trigger XboxController::TriggerRawNoneOf | ( | std::vector< Button > | buttonCombo | ) |
Trigger when none of the selected buttons' raw value is true.
buttonCombo | Buttons to check |
frc2::Trigger XboxController::TriggerRawOneOf | ( | std::vector< Button > | buttonCombo | ) |
Trigger when exactly one of the selected buttons' raw value is true.
buttonCombo | Buttons to check |
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.