Skip to content

Allow .Until(Trigger()) in C++ #8031

@Liam-Stow

Description

@Liam-Stow

Is your feature request related to a problem? Please describe.
Somewhat related to a problem, yes. In Java, it is possible to run a Command until a Trigger occurs using myCommand().until(myTrigger()). This works because Trigger inherits from BooleanSupplier. The problem being that this does not work in C++. frc2::Trigger does not inherit from anything, and Until() takes a std::function<bool()> as input.

Describe the solution you'd like
Would be great if either:

  • the C++ frc2::Trigger inherited from std::function<bool()>, or
  • Until() had the option of taking an frc2::Trigger as input.

This would allow MyCommand().Until(MyTrigger()).

Describe alternatives you've considered
The currently possible alternative is to do MyCommand().Until([]{ return MyTrigger().Get(); });. While this does work, it gets messy when you have to do it a lot.
Another potential solution is to add some sort of "Convert to function" option in Trigger, like so: MyCommand().Until(MyTrigger().AsFunction());, but I feel it might as well work the same way as it does in Java.

Additional context
This may also apply to other decorators like .OnlyWhile() or .Unless(). But supporting Until() would be a great start.

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: command-basedWPILib Command Based Librarytype: featureBrand new functionality, features, pages, workflows, endpoints, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions