Does this autonomous logic works?

the commands that i use in my robot does not finish, so i have use this combination of sequential and parallel command groups with a waitcommand in the middle.
i dont have access to my robot now, so i cannot test on my robot

 return  new SequentialCommandGroup(
                new InstantCommand(() -> swerveSubsystem.resetOdometry(trajectory1.getInitialPose())),
                new ParallelCommandGroup(
                        new MoveArmCmd(ArmSubsystem,-19.8),
                        new SequentialCommandGroup(
                                        new WaitCommand(1.5),
                                        new ParallelCommandGroup(
                                                esquentarShooter,
                                                new SequentialCommandGroup(
                                                        new WaitCommand(2),
                                                        new ParallelCommandGroup(
                                                                lancar,
                                                                new WaitCommand(2),
                                                                new ParallelCommandGroup( 
                                                                        parar,
                                                                        new MoveArmCmd(ArmSubsystem,0))))))));/*
                

I’m on my phone and a little confused by your logic, but I believe you could simplify it to something like this:

return  new SequentialCommandGroup(
    new InstantCommand(() -> swerveSubsystem.resetOdometry(trajectory1.getInitialPose())),
    new ParallelCommandGroup(
        new MoveArmCmd(ArmSubsystem,-19.8),
        new WaitCommand(1.5)
    ),
    new ParallelCommandGroup(
        esquentarShooter,
        new WaitCommand(2)
    ),
    new ParallelCommandGroup(
        lancar,
        new WaitCommand(2),
    ),
    new ParallelCommandGroup( 
        parar,
        new MoveArmCmd(ArmSubsystem,0)
    )
);

In short, you do a sequence of commands that take a minimum of WaitCommand(seconds) to complete. If the action takes longer, fine.
But if it finishes faster, then the waitcommand will prevent the next step from running before starting the next one.

If I read it wrong and you’re simply trying to add a time-based end condition, then this could be simplified even further using timeouts. Something like myCommand.withTimeout(2) I believe (again, going from memory here)

If you need something to end your commands that aren’t ending so you keep moving through the sequence, use the .withTimeout decorator for each one of those.

That will turn the command into a parallel racegroup, so you will move through the sequence as fast as possible, but making sure best effort is made to get the command to finish.

1 Like

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