Robot Command not being triggered by OI

We’re having trouble programming buttons to our commands. Our drive train is working perfectly and have made a few commands and subsystems but when we go and press the button such as (A) which should activate the command “ConveyorBall()” nothing happens.

If anyone could take a look at our GitHub and give us some help that’d be amazing!

https://github.com/jdrevnyak/UhsRoboticKnights2020

It looks like you are missing the following from your robotPeriodic()

CommandScheduler.getInstance().run();

Edit: This is in Robot.java. It should look something like.

@Override
  public void robotPeriodic() {
    CommandScheduler.getInstance().run();
  }

Why the custom XboxController? I assume it’s legacy code. WPILib provides an XboxController class already. Also, your toggle* methods don’t appear to actually do anything other than set a local boolean value.

You shouldn’t create local instances of your Commands. They’re intended to be short-lived objects, and their lifespan should be determined by the JoystickButton method (whileHeld, whenPressed, etc) you’re passing it into.

This also breaks the CommandBased pattern. Just put that code in a command and set that command as the default command for the subsystem.

As for your actual issue, @eddieD is partially correct. Since you’re using the “old” command-based format, that method is individually listed in disabledPeriodic, autonomousPeriodic and teleopPeriodic, though robotPeriodic should work fine as well.

1 Like

I’m very new to programming and was having trouble using the WPILib Xbox Class so I am using Team 4944’s Skeleton program to help me get started. Any ideas to make anything work smoother I’m up to hearing!

I am pretty sure if you just copy that code and put it in your Robot.java it will fix your issue.

However, @Fletch1373 is correct, you should consider switching to using the WPILib XboxController. There is a bunch of documentation on using that. If you have specific questions about using it let me know.

Trying to convert it over to the new wpilib XboxController but can’t find any help online with creating buttons in my OI. All I can find is JoystickButton

From what I’m seeing online it’s telling me to set it up like this.

    public XboxController driver, operator;
    public Button aButton;

    

    public OI() {

        // Controllers

        this.driver = new XboxController(0);
        this.operator = new XboxController(1);

     

        // Commands

        // A -- TEXT HERE (Driver)
        aButton = new Button(1);
        aButton.whileHeld(new ConveyorBall());

You want to put your OI code in configureButtonBindings in RobotContainer

This is true for the new command framework, but the OP is using the old framework.

But trying to switch. See #6.

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