Hi all, is there a way to run a command constantly without defining it as a default command?
We want to do it because we need a button that when it gets pressed (whenPressed()) the command (in this case conditional command) needs to constantly switch between two command if the currently chosen command is finished.
To be more specific:
Choose between “Align by vision” (until vision target is not found) or “align by other mean if no target found” (until vision target is found).
Maybe define it as a sequential command group, where the first command (“align by other means”) simply ends immediately if the target is already in view, then letting the vision command take over for fine-tuning.
The problem is that if we loose the target while using vision (maybe a robot is blocking our view?) we want to switch back to the other command to align. So our seq command needs to run forever.
We did the same thing last year, we thought that the best way to do it was to do it all in one command then just have an if statement. That way you can update values without having another class.
I’ll argue that if you’re spending more time trying to fit working logic into the command base than testing that logic, then the structure is holding you back (in that use case). Use it to the degree which helps you make the best robot code the quickest.
That’s highly dependent on how you interpret the problem.
I saw it as a single command, “Target goal with vision”. The main goal of the command was to vision track the target. However, in case you can’t see the target, it defaults to another mode.
However, your problem could also be interpreted as two commands. “Target with vision” and “Target Manually”.
It’s highly dependent on what specifically you the command to be doing.
I would disagree here. Each command should have a singular goal. In this case it is align to the goal. That does not mean that each time through execute() it does the same thing every time to accomplish the goal.
Edit: Note that I do not mean by this statement to endorse throwing anything and everything that has to do with a goal into one command. I am just advocating for a measure of practicality. I believe the case at hand falls within the boundaries of practically of one command. The more complex cases often call for a command group or in extreme cases, totally separate commands.
Do you only want these commands to run when the button is held? If so, create the command group and bind it with whileHeld, not whenHeld. I asked the same question a couple day ago here: Loop commandgroup while button held
new JoystickButton(driverController, XboxController.Button.kX.value).whileHeld(
new ConditionalCommand(new AlignByVision(), new AlignByOtherMeans(), this::canAlignByVision);
But the driver doesn’t want to hold the button, which, btw, shouldn’t make as change the whole logic to work.
What wpilib needs to do is to make the.perpetually decorator to reinit the command if the isFinished of this command returns true (which, In may case, will force the command group to start all over again forever as I intended and ended up doing to slove my problem).