New Command Based(RobotContainer)

I can’t figure out what to do from here. I checked the documentation and example codes on github to make sure that I am not doing anything wrong. I did not see much of a difference and no clue why its not working. Please help :open_mouth: Thanks :slight_smile:

The first couple of notes are telling you what’s wrong. ExampleAutoCommand has a constructor that takes two arguments (ExampleSubsystem* and std::function<double()>). You’re passing one: just ExampleSubsystem*. You need to pass a lambda or other function, e.g. m_autonomousCommand(&m_subsystem, [=] { return ...; })

1 Like

I have another question regarding the new command based. I am trying to make the same auto command run by pressing on a joystick button with a timeout.

This is my current code:

xboxA.WhenPressed(ExampleAutoCommand(&m_subsystem, [=] {return 0.5;}).WithTimeout(1));

but this returns an error saying :

“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> > > >}’”

is this not the correct way of declaring timeout? this is what is shown in documentation…?

WithTimeout(1.0_s). The documentation may have been copied from Java; in C++ you need the suffix to specify the units.

1 Like

Thank you :slight_smile:

Alright, the error is away now… except…

You’re missing an include. E.g. #include <frc2/command/ParallelRaceGroup.h>

I thought I just needed frc2/command/command.h

Each of the various commands is in a different header file. You need to include what you use.

1 Like

Okay, good to know

Now, I just ran the code. However, it seems that the command can be only run once.
The command is tied to button A and it will run fine the first time around. But when I press it for the second time, it doesn’t run. Do I need to do some kind of timer reset in order for it to work multiple times?