Running command while robot is disabled

Does anyone know how to bind a button to a command that will run even when the robot is disabled?

2 Likes

You cannot do that, and if you can, that would be illegal

There are two parts to this. You can run a command while disabled. The command needs to override

    @Override
    public boolean runsWhenDisabled()
    {
        return true;
    }

and then for example a command that updates some LED pattern will run just fine while disabled.
You can for example schedule it in disabledInit().

But if the command tries to control motors, they won’t move while disabled. Access to buttons etc. from the drive station will also be limited.

10 Likes

Access to buttons isn’t limited in disabled, only in autonomous.

4 Likes

Honestly, I hadn’t tried that, but good to know!
So as long as the command runsWhenDisabled, you can schedule it in response to button pushes. Those commands will be able to update LED patterns, but motors tend to not run when disabled, and I think the pneumatics will also be off.

2 Likes

Ah ok, that makes sense. Assuming there’s no way to do this inline?

You mean override runsWhenDisabled? I don’t think that InstantCommand etc. offer that.
But easy enough to create your own command:

class MyCommand extends CommandBase
{
   // Maybe a MyCommand  constructor to pass in what you need,
   //  like a subsystem or addressable LEDs or ...

    @Override
    public boolean runsWhenDisabled()
    {
        return true;
    }

    @Override
    pubic void execute()
    {
        // Do what you need to do ..
    }
}

Thanks! I wish I could do this without making an entire class for a command as trivial as I need though (literally calling a single function with no arguments).

You can use an anonymous class:

public void disabledInit()
{
    CommandBase my_command = new CommandBase()
    {
        public boolean runsWhenDisabled()
        {
            return true;
        }

        public void execute()
        {
            // Do what you need to do ..
        }
    };
    my_command.schedule();
}
3 Likes

A little shorter, using InstantCommand or RunCommand depending on your needs:

        new InstantCommand( () -> do_something() )
        {
            @Override
            public boolean runsWhenDisabled()
            {
                return true;
            }
        }.schedule();
3 Likes

We’ll look into making this less ugly for 2023; we’d like to encourage inlining as much as possible…

6 Likes

Does this work in C++ ?
When I put
bool RunsWhenDisabled() override;
in the header of a command
I get a warning saying that:-
member function declared with ‘override’ does not override a base class member
Regards
Warren

It does, but the API shape may be slightly different. Check the API documentation for the Command class.

1 Like

Thanks.
We were missing the const keyword.
It should have read
bool RunsWhenDisabled() const override;

1 Like

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