I have a question regarding the command groups in the 2022 edition of VSCode for the FRC.
Is it possible to create a command group that can execute both a sequential series of command and a parallel one right after.
It seems to be possible when creating a Command Group (old), but there doesn’t seem to be a new equivalent.
What I’ve been doing (possibly against best practices), is creating new ParallelCommandGroups inline in my SequentialCommandGroup.
So the code would look like:
class MyGroup extends SequentialCommandGroup {
public MyGroup() {
addCommands(
new CommandA(),
new CommandB(),
new ParallelCommandGroup(
new CommandC(),
new CommandD()
),
new CommandE()
);
}
}
However, if you want one command to stop with the other, the deadlineWith decorator is probably the best approach.
You can also use the new decorators for various other behaviour
We just create ParallelCommandGroups inline in SequentialCommandGroups. It seems to work quite well.
So our commands will look something like this (with better naming of course):
public class MyCommand extends SequentialCommandGroup {
public MyCommand() {
addCommands(
new FirstCommand(),
new SecondCommand(),
new ParallelCommandGroup(
new FirstParallelCommand(),
new SecondParallelCommand()
)
);
}
}
A CommandGroup is still a command, just stack 'em.
IE here is the Quick and Dirty auto I wrote as an example:
private final Command m_autoCommand = new ParallelCommandGroup(
// Main Auton
new SequentialCommandGroup(
new ParallelCommandGroup(
new DrivetrainArcadeDrive(m_drivetrain, ()->0.25, ()->0.0).withTimeout(2.5),
new SetIntakeArmSetpoint(m_intakeArm, ()->IntakeArmConstants.upPositionPotentiometerValue)
),
new SetIntake(m_intake, ()->IntakeConstants.inhaleSpeed).withTimeout(1.5),
new DrivetrainArcadeDrive(m_drivetrain, ()->-0.25, ()->0.0).withTimeout(4.0)
),
// Home the Lift Hooks
new ParallelCommandGroup(
new SetLeftLiftHook(m_leftLiftHook, ()->-0.05),
new SetRightLiftHook(m_rightLiftHook, ()->-0.05)
)
);