Command Based Robot - Team1100/CodeExamples GitHub Wiki
What is command-based programming?
"I quote the entirety of screensteps, and the wplilib javadocs" -Thomas C. Hayden, 2017
The command-based robot is how we do things here at team 0x44C. You may be asking yourself now, "Hey, what does that term mean? Why does he keep saying 'Command-Based Robot'? I really wish he stopped using the phrase 'Command-Based Robot' before telling me what it means! I don't know why, but I am suddenly compelled to say 'Command-Based Robot' again! 'Command-Based Robot'!"
Anyway, as a display of what programming is like, this is already defined, so I will give a pointer rather than a value. Use this here link.
Just kidding, of course I'm going to explain it; that's why they pay me the big bux. I am actually not paid, I'm just writing this purely for your benefit. The link is helpful too. All of screensteps is, as well as StackOverflow, but that's for a whole different page (Debugging).
The basic concept is that we consider the robot as a bunch of subsystems that work together, and are actuated by special objects called commands. More literally, a subsystem is a class that extends Subsystem (Or PIDSubsystem, but you probably have CANTalons or something even better that will do PID for you. Who knows what the future will hold?) Some subsystem examples could be the drive train, the shooter, the elevator, the pneumatics, etc. If you're anything like me, you like using threading in your code. Don't do that, use a subsystem instead. If you're not like me, and don't have any interest in optimizing speed by threading as much as possible, then you already have some desirable qualities for working as an FRC programmer.
Once we have subsystems, it's time for the namesake of this model, commands. A command is any class that extends Command. Once your IDE fills in all the methods for you because young programmers these days never had to write with a text editor and compile manually (or with your own script. Emacs rules VI drools!), there will be two methods of note: execute() and isFinished(). The constructor is also important, but I'm certain you can figure out what you need to do with that if you're here looking for more high level guidance. execute() is what will be called repeatedly as the command runs; put your logic here. isFinished is also called repeatedly, and will return a boolean if the command is done.
Keep in mind, this is all very high level. See the page on conventions for further code advice, and how to make things not suck.