With OI.java gone this year, I’m having difficulty assigning commands to buttons. In RobotContainer, I created a Joystick object and button objects. But when I press the button, the command only runs once (right when the robot enables).
How do I make it so the buttons run throughout the enable period?
Side question: I can only run one command at a time by using CommandScheduler.getInstance().setDefault(subsystem, command);
How do I run multiple commands at once (based on joystick control)?
public class RobotContainer {
// The robot's subsystems and commands are defined here...
private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem();
private final ExampleCommand m_autoCommand = new ExampleCommand(m_exampleSubsystem);
public static DriveTrain drive;
public static JoystickDrive joyDrive;
//public static ToggleShift toggleShift = new ToggleShift(drive);
public static Joystick joy = new Joystick(0);
public static JoystickButton buttonA = new JoystickButton(joy, 1);
/**
* The container for the robot. Contains subsystems, OI devices, and commands.
*/
public RobotContainer() {
// Configure the button bindings
configureButtonBindings();
drive = new DriveTrain();
joyDrive = new JoystickDrive(drive);
}
/**
* Use this method to define your button->command mappings. Buttons can be created by
* instantiating a {@link GenericHID} or one of its subclasses ({@link
* edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a
* {@link edu.wpi.first.wpilibj2.command.button.JoystickButton}.
*/
private void configureButtonBindings() {
buttonA.whenPressed(new ToggleShift(drive));
}
/**
* Use this to pass the autonomous command to the main {@link Robot} class.
*
* @return the command to run in autonomous
*/
public Command getAutonomousCommand() {
// An ExampleCommand will run in autonomous
return m_autoCommand;
}
}