Default Commands aren't running their execute() methods

I’m having a problem setting up default commands. Using debugging by setting values on shuffleboard, I can tell that the default commands gets initialized but isn’t scheduled, meaning that the execute() method isn’t called.

I’m very confused as to why this is? It doesn’t make any sense to me

Relevant code:

TeleopDriveCommand execute()

 @Override
 public void execute() {
 //squares input in second term. first term re-multiplies the negative if there was one bc squaring removes the negative
    m_fwd = (m_controllerSubsystem.controllerY() > 0 ? 1 : -1) * (-Math.pow(m_controllerSubsystem.controllerY(), 2));
    m_rot = -(m_controllerSubsystem.controllerX() > 0 ? 1 : -1) * (Math.pow(m_controllerSubsystem.controllerX(), 2)); 
    m_driveSubsystem.arcadeDrive(m_fwd, m_rot);
}

Where default commands are set

public RobotContainer() {
//Configure default commands
    CommandScheduler.getInstance().setDefaultCommand(m_robotDrive, new TelopDriveCommand(m_robotDrive, m_controllerSubsystem));
    CommandScheduler.getInstance().setDefaultCommand(m_armSubsystem, new ArmMoveCommand(m_armSubsystem, m_controllerSubsystem));
}

How DriveSubsytem.arcadeDrive() is handled

public void arcadeDrive(double fwd, double rot) {
    m_fwd = fwd;
    m_rot = rot;
  }

  @Override
  public void periodic(){
    m_drive.arcadeDrive(m_fwd, m_rot);
  }

GitHub repo:

Can you link to your repository? It’s impossible to help from these snippets alone.

It looks like you’re doing things very strangely, though. You should not have a subsystem for your controllers; the point of the Subsystem class is primarily to provide hardware mutexes for Commands through the requirement API. There’s no reason to guard access to your HID devices with a mutex.

I don’t have a GitHub repository, but I can get a .zip file in about 30 minutes

Took a while, but I got a GitHub set up. Uploading the repo took forever

Your default commands are cancelling each other because they’re both trying to hold the ControllerSubsystem mutex. See my advice above about why it’s not appropriate to use Subsystem there.

How would I access the controller globally though? I’m new to command based if it isn’t obvious already

You can keep your HID wrapper class mostly as-is if you really want, just don’t make it extend Subsystem.

I’d suggest looking at the RapidReactCommandBot example project for some inspiration as to how you could structure this differently, though. It’s not great practice to touch HID inputs directly from command implementations.

1 Like

I will check this out!

Would you recommend this for the gyro as well?

The only things that should be Subsystem classes are hardware resources that need to be guarded against simultaneous access.

Thank you so much for the help. I’ve updated my code, still in a weird way but in a way that I can understand

1 Like

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