Running a command more than once

I am using the new command-based format and it seems that I can’t run a command more than once with a joystick button. Here is the link to my code:

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? Or is there a command reset that I have to run?

Initial impression…

Your command is triggered “whenPressed()”, but doesn’t have an “isFinished()”, which by default returns false. So it’ll never end.

1 Like

but doesn’t the “WithTimeout” make it “finished”? This is in robotContianer

“xboxA.WhenPressed(ExampleAutoCommand(&m_subsystem, [=] {return 0.5;}).WithTimeout(1.0_s));”

Ah, fair… I missed that originally.

Open Shuffleboard and checkout the scheduler widget so actually see it being scheduled.

You can also add your subsystem to see what is scheduled for it as well (after you’ve instantiated/and/or initialized it:
SmartDashboard.putData(m_examplesubsystem);

Then in Shuffleboard on the SmartDashboard tab you can see what your subsystem is doing at any time to better visualize your robot.

So as seen in video, the ids change when I press the button. They even interrupt when I try to run the other command on the second button. However, once the command is finished, I can never run them again.

also I have printf in the command that are not showing up on the console print.

I’m assuming it’s the same for the C++ implementation, however, when a command is interrupted by another (in the new framework) the end() method is called with a boolean flag as to whether or not the command ended cleanly or not.

The fact that when you toggle the buttons in the video it flips back and forth leads me to believe that you are indeed scheduling the command multiple times Successfully. It seems like the bug is when your ParallelRaceGroup command is ending (which is what happens when you let the 1 second timer elapse), THEN you aren’t able to run any more instances of the commands.

It’s not totally obvious to me because I can’t see what is happening in the Subsystem on the Dashboard. In the Java implementation you can actually see the names of the commands being run, not just their numeric IDs.

So your command should be ending by 1 of 2 triggers:

  1. Timeout of 1 s
  2. Other button requiring the subsystem

From what I saw in your video, 2 seems to be working just fine, and 1 does not.

How about you try eliminating the controller trigger as a possible source and just run that command from SmartDashboard directly. If in RobotContainer you just

frc::SmartDashboard::putData(ExampleAutoCommand(&m_subsystem, [=] {return 0.5;}).WithTimeout(1.0_s));

You can then schedule the command with a click of the mouse, and see if you can run it multiple times.

This looks like it’s caused by an issue with ParallelRaceGroup.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.