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…
https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
// Will time out 5 seconds after being scheduled, and be interrupted
button.WhenPressed(command.WithTimeout(5));
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…
m_2Button.WhenPressed(Print3Command().WithTimeout(5));
But when I compile it, it says…
In member function ‘void RobotContainer::ConfigureButtonBindings()’:
error: no matching function for call to ‘Print3Command::WithTimeout(int)’
m_2Button.WhenPressed(Print3Command().WithTimeout(5));
and…
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.
md