Question regarding command based robot


So, when you are driving with a command based robot and one command controls the drivetrain and the other command controls a claw. For the drive train I have duel joysticks with a whileHeld method. For the claw opening ad closing I have a button on an xbox controller. This is also on a move whileHeld method. My hope would be that you can drive around with the joysticks and while you are driving around, open and close the claw (while they are both in separate commands controlled by separate buttons and by separate subsystems)? if not how can I make it so this works?

Also in case it is important, I am programming in Java…


I would be happy to help with this and any other questions. (I lead command-based java programing for my team). You can definitely do what you want to. You just run all the commands at once if they are on different subsystems.

My understanding is you want to run the commands on different subsystems and the only problem is button allocation. I would recommend not needing to hold a button while driving preferably by making your drive command a default command. You can also have your drive command start in teleop init and never finish.

The general principal with commands in the Command-Based Framework, is that you can have a single command running on any given Subsystem of the robot, and generally one Subsystem being utilized by any given Command (with multiple being used by CommandGroups). This is why you use a requires() statement in the Constructor method of the command, so the Scheduler knows what Subsystem(s) the Command needs and can make sure no other commands are currently trying to use it, or Cancel those that are.

As @reerkat said, you probably want to have the command for driving with the joysticks as a default command for your Drivetrain Subsystem. Since the Scheduler will cancel any command utilizing a subsystem if another such command is started, the Default Command will be Cancelled, and be allowed to resume automatically once no command is using that subsystem again.

I noticed you asking several questions about the relative basics of the Command-based Framework in the last couple of days, I’d highly recommend looking over what Documentation exists.
ScreenStepsLive goes over all the Control System Setup and Configuration as well as introductions to Java/C++, and an overview of the CommandBased Robot Framework.
FRC Programming Done Right is a Community Developed Resource that goes into best practices for many aspects of FRC Robot Programming, including some on the Command Based Template and methodology.
WPILIBJ Java Docs are the “Technical” Documentation of each Class in the WPILIB libraries. Need to know what methods a class has? Its a good place to look it up quickly.

All the above resources (and more, including some GREAT YouTube Videos from various teams) can also be found on my Resource Compendium Document that I maintain for my team:

1 Like

But can a command that requires the drive train run at the same time as a command requiring the arm or claw?

Yes. The statement above would hardly make any sense if you could only have one command running at all. The Command-Based Robot Framework uses a Scheduler to call each currently running command’s execute() method in a round-robin fashion (Command A, Command B, Command C, Command A, Command B, …) every ~20ms. The scheduler is also what handles cancelling any command where a new command was told to start that requires the same subsystem as a currently running command.

1 Like

thanks very much for the clarification… I missed that line the first time, sorry lol

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