Best way to run command that isn't part of subsystem?

I have a command to control driver controller rumble. It gets input from a few different subsystems and has some logic to start and stop rumbling based on this input, so fairly straight forward. This command is somewhat unique though, since it doesn’t primarily belong to any subsystem but also needs to be running constantly. What is the best way to run this command? I can think of a few different ways but they all seem janky, and I can’t find a good answer after reading all the WPILib command documentation.

(If you use command-based)
You may use a static enum to define the controller state and change the states in the command’s (or subsystem’s) execute/periodic methods. Then, the rumble command can be written into a piece of code that runs periodically according to the conditional state of the enum.

Schedule the command on teleop init (just like you’d do with your autonomous command in auton init). Ensure the command does not “require” any of the robot subsystems. Have it never return true in is finished.

1 Like

As far as handling the requirements or lack-thereof in this case, just don’t require any subsystems and it will be fine.

As for getting it scheduled, scheduling it in Robot.java’s teleopInit method would work as microbuns said, or if you want to keep it in RobotContainer, you could make a trigger to schedule it at the start of teleop, something like this:

Trigger teleopTrigger = new Trigger(() -> RobotState.isEnabled() && RobotState.isTeleop());
teleopTrigger.onTrue(new RumbleCommand());

1 Like

I’ll probably go with this solution, thank you