Motor Toggle Problem

We cannot get a falcon500 motor to run on a toggle, instead we have it on a hold for now. The whileTrue() command in the TalonFx class works for the hold, however the onTrue() command, which is supposed to be a toggle command, does not stop the command when the button is pressed again.

This is the code that fails:

package frc.robot;
import frc.robot.Constants.OperatorConstants;
import frc.robot.commands.Autos;
import frc.robot.commands.Shoot;
import frc.robot.subsystems.Shooter;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.Trigger;


public class RobotContainer {

  private final Shooter shooter = new Shooter();

  private final Shoot shoot = new Shoot(shooter);

 
  private final CommandXboxController xboxController =
      new CommandXboxController(OperatorConstants.kDriverControllerPort);

  public RobotContainer() {
    configureBindings();
  }

  private void configureBindings() {
  
    //xboxController.a().whileTrue(shoot); - this is the whileTrue() method that works when holding the button
   
      xboxController.a().onTrue(shoot); - this is the method that fails to toggle the motor
    
  }

  /**
   * Use this to pass the autonomous command to the main {@link Robot} class.
   *
   * @return the command to run in autonomous
   */
  public Command getAutonomousCommand() {
    // An example command will be run in autonomous
    return null;
  }
}

Have you tried .toggleOnTrue() instead?

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