[commands] Add functions to HID classes to allow use of axes as BooleanEvents/Triggers (#4762)

This commit is contained in:
Ryan Blue
2022-12-26 14:29:14 -05:00
committed by GitHub
parent 87a34af367
commit 176fddeb4c
12 changed files with 413 additions and 0 deletions

View File

@@ -179,5 +179,41 @@ class CommandGenericHID : public frc::GenericHID {
*/
Trigger POVCenter(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance that is true when the axis value is less than
* {@code threshold}, attached to {@link
* CommandScheduler::GetDefaultButtonLoop() the default command scheduler
* button loop}.
* @param axis The axis to read, starting at 0.
* @param threshold The value below which this trigger should return true.
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance that is true when the axis value is less than
* the provided threshold.
*/
Trigger AxisLessThan(
int axis, double threshold,
frc::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance that is true when the axis value is greater
* than {@code threshold}, attached to {@link
* CommandScheduler::GetDefaultButtonLoop() the default command scheduler
* button loop}.
* @param axis The axis to read, starting at 0.
* @param threshold The value below which this trigger should return true.
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance that is true when the axis value is greater than
* the provided threshold.
*/
Trigger AxisGreaterThan(
int axis, double threshold,
frc::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
};
} // namespace frc2

View File

@@ -141,5 +141,40 @@ class CommandXboxController : public frc::XboxController {
*/
Trigger Start(frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance around the axis value of the left trigger.
* The returned Trigger will be true when the axis value is greater than
* {@code threshold}.
*
* @param threshold the minimum axis value for the returned Trigger to be
* true. This value should be in the range [0, 1] where 0 is the unpressed
* state of the axis. Defaults to 0.5.
* @param loop the event loop instance to attach the Trigger to. Defaults to
* the CommandScheduler's default loop.
* @return a Trigger instance that is true when the left trigger's axis
* exceeds the provided threshold, attached to the given loop
*/
Trigger LeftTrigger(double threshold = 0.5,
frc::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance around the axis value of the right trigger.
* The returned Trigger will be true when the axis value is greater than
* {@code threshold}.
*
* @param threshold the minimum axis value for the returned Trigger to be
* true. This value should be in the range [0, 1] where 0 is the unpressed
* state of the axis. Defaults to 0.5.
* @param loop the event loop instance to attach the Trigger to. Defaults to
* the CommandScheduler's default loop.
* @return a Trigger instance that is true when the right trigger's axis
* exceeds the provided threshold, attached to the given loop
*/
Trigger RightTrigger(
double threshold = 0.5,
frc::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
};
} // namespace frc2