2020 Decorator functions - does your code compile?

New this year in 2020 is the concept of decorator functions, that add features to basic commands.
The example given is if you have a command that you want to simply run for X seconds you can write the command as you normally would and then on the button defintion do this…


// Will time out 5 seconds after being scheduled, and be interrupted


So, I have done this in our code… I created a command that would print the number 3 “forever” because the isFinished check is set to false, and my button invocation looks like…


But when I compile it, it says…

In member function ‘void RobotContainer::ConfigureButtonBindings()’:
error: no matching function for call to ‘Print3Command::WithTimeout(int)’


no known conversion for argument 1 from ‘int’ to ‘units::time::second_t {aka units::unit_t<units::unit<std::ratio<1>, units::base_unit<std::ratio<0, 1>, std::ratio<0, 1>, std::ratio<1> > > >}’

So then I tried to cast the 5 as as unit::time::second_t

and while the argument conversion error goes away… I still get the first error…

In member function ‘void RobotContainer::ConfigureButtonBindings()’:
src\main\cpp\RobotContainer.cpp:84:70: error: invalid use of incomplete type ‘class frc2::ParallelRaceGroup’
m_2Button.WhenPressed(Print3Command().WithTimeout((units::second_t) 5));

related to this, I am also trying to take advantage of this feature in invoking the command for auto.

The automode chooser line is:

m_autoChooser.AddOption(“Print 3 for forever!” , &m_print3auto);

which works, but if I try to add the .WithTimeout(5) to the autochooser line I simply can not get the syntax to work.

So, On the first problem, have I run into a WPI bug? and how would I add this decorator function to a command in auto or a command group in auto?

Many thanks everyone.


I may have found it in another thread, which I did not see earlier.

looks like I need an include, …

That said, if anyone knows how to add a decorator function to an auto chooser, I still can’t figure that out…


You probably have to declare the .withTimeout as a separate command which you then feed into the chooser.
Not a c programmer but try it.