Subclassed command crashing when scheduled

Hello!
I have two command classes:
A FireNote class:

public class FireNote extends ParallelRaceGroup {
    public FireNote(double height, double shooterRPM, Intake intake, Shooter shooter, ShooterLift shooterLift) {
        super(
            shooterLift.getGoToPositionCommand(height),
            shooter.getGoToRPMCommand(shooterRPM),
            sequence(
                waitUntil(() -> shooterLift.atSetpoint()),
                waitUntil(() -> shooter.atSetpoint()),
                intake.intakeIntoShooter()
            )
        );
    }
}

And a FireIntoAmp class:

public class FireIntoAmp extends FireNote {
    final private static double kHeightToFireAt = 0.95;
    final private static double kShooterRPMToFireAt = 500;

    public FireIntoAmp(Intake intake, Shooter shooter, ShooterLift shooterLift, SwerveDrivetrain drivetrain, Limelight limelight) {
        super(
            kHeightToFireAt,
            kShooterRPMToFireAt,
            intake,
            shooter,
            shooterLift
        );
        beforeStarting(new AimWithLimelight(drivetrain, limelight));
    }
}

When scheduled, FireIntoAmp crashes.
I’m scheduling it via a shuffleboard tab:
commandsForTesting.add(“Fire into amp”, new FireIntoAmp(intake, shooter, shooterLift, drivetrain, limelight));

When I schedule just FireNote, the code doesn’t crash.

I’ve figured out that the problematic line is:
beforeStarting(new AimWithLimelight(drivetrain, limelight));

When I remove the line that causes the command to aim before starting, it doesn’t crash.

I also tried running this:
commandsForTesting.add(“Fire into amp”, new FireIntoAmp(intake, shooter, shooterLift, drivetrain, limelight).beforeStarting(new AimWithLimelight(drivetrain, limelight)));

And that didn’t crash.

Here is the error message:

Error at frc.robot.commands.autos.FireIntoAmp.<init>(FireIntoAmp.java:22): Unhandled exception: java.lang.Exception: Originally composed at:
        at edu.wpi.first.wpilibj2.command.CommandScheduler.registerComposedCommands(CommandScheduler.java:599)
        at edu.wpi.first.wpilibj2.command.SequentialCommandGroup.addCommands(SequentialCommandGroup.java:47)
        at edu.wpi.first.wpilibj2.command.SequentialCommandGroup.<init>(SequentialCommandGroup.java:33)
        at edu.wpi.first.wpilibj2.command.Command.beforeStarting(Command.java:218)
        at frc.robot.commands.autos.FireIntoAmp.<init>(FireIntoAmp.java:22)
        at frc.robot.RobotContainer.configureCommandsForTesting(RobotContainer.java:125)
        at frc.robot.RobotContainer.<init>(RobotContainer.java:61)
        at frc.robot.Robot.<init>(Robot.java:12)
        at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:317)
        at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(RobotBase.java:438)
        at java.base/java.lang.Thread.run(Thread.java:840)

Warning at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:380): The robot program quit unexpectedly. This is usually due to a code error.
  The above stacktrace can help determine where the error occurred.
  See https://wpilib.org/stacktrace for more information.
Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:387): The startCompetition() method (or methods called by it) should have handled the exception above.
Warning at edu.wpi.first.wpilibj.IterativeRobotBase.printLoopOverrunMessage(IterativeRobotBase.java:412): Loop time of 0.02s overrun

Thanks in advance :smile:

Also one more thing, I don’t think it matters, but I’ve been using simulation to test this code

1 Like

I don’t think your subclass is necessary at all.

Try this:

commandsForTesting.add(“Fire into amp”, new AimWithLimelight(drivetrain, 
    limelight)
    .andThen( new FireIntoAmp(intake, shooter, shooterLift, drivetrain, limelight)
    .withName("AimAndFireIntoAmp")
);

That will produce an equivalent output, which is, your command will be a squentialcommandgroup, that will aim with the limelight first and then run through your FireIntoAmp sequence that you know works well.

Thank you! this works.

Why did it crashed? We have the same issue and would like to understand. Thanks!

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