About button-controlled speed controllers

I am trying to have the shooting wheel spin at full speed when I hit a button. It is controlled via a Jaguar, and in the method, I just use (name).set(1.0);.

When I actually hit the button, though, the wheel just twitches on for a second and then stops before repeating it. On the smart dashboard, the command for the firing subsystem still reads the ShooterOn command.

Does anyone know how to fix this?

In FiringJag subsystem:

Jaguar firingjag;
public FiringJag(){
     firingjag = new Jaguar (3); // It is in PWM port 3
     setSafetyEnabled(false);
}
public void initDefaultCommand(){
     setDefaultCommand(new ShooterStop());
}
public void StartShooter(){
     firingjag.set(1.0);
}
public void StopShooter(){
     firingjag.set(0);
}

Here’s ShooterStart and ShooterStop commands:

execute(){
     firingjag.StartShooter();
}
execute(){
     firingjag.StopShooter();
}

And finally, in OI:

public OI(){
     new JoystickButton(stick1, 4).whenPressed(new ShooterOn());
     new JoystickButton(stick1, 5).whenPressed(new ShooterOff());
}

Thanks in advance to anyone who can tell me what’s wrong.

Edit: I’ve also tried the .whileHeld(new ShooterOn()), but the result is still the same; there’s only pulsing

I’m guessing that the issue is that both your start/stop commands terminate immediately. So, the following sequence occurs:

  1. You press the button to start the shooter.
  2. The command runs and turns on the shooter and then is finished.
  3. The default command associated with your subsystem then runs (the one you defined in initDefaultCommand()).

This results in the motor being turned off almost instantaneously.

To see the difference, try commenting out your default command:


public void initDefaultCommand(){
     // setDefaultCommand(new ShooterStop());
}

Alternatively, you could set your stop/start commands to be interruptible and update the isFinished() method to return false. In this case, they will both run until interrupted.

Hope that helps.