Ah yes. Command-Based programming and its respective hierarchy was one of the things that confused me the most when I first started learning FRC Java.
Put simply, everything in Command-Based starts with Robot.java. In the Robot.java class, you declare Subsystem objects - see lines 56:65 of 1058’s Robot.java. In addition you can call other methods at different robot states, defined by the methods that are automatically created in Robot.java.
Subsystems are where you declare objects for speed controllers, solenoids, and other physical items on your robot, as well as set up methods that can be called from Commands (we’ll get to that in a minute). See 1058’s Climberclass for an example of a simple subsystem. In this class, we declare the two CANTalon speed controller objects that drive our climber in lines 17 & 18, as well as enable brake mode on the initialization of the subsystem in lines 22 & 23. Then, we set up a setClimberOutput() method in lines 28:37, which is called from the ManualClimberDrive command. If you have a good understanding of basic Subsystems, you can explore our GearManipulatorclass for a more complex example.
On to Commands! Commands are the the part of your Java software that activates methods in Subsystems at specific times. To start, commands must declare the subsystems in which they are affiliated to keep things organized and so that multiple commands do not run on a single subsystem simultaneously (unless desired). In line 19 of our ManualClimberDrive command, we declare that it requires the climber subsystem, more specifically, the climber object we created in the Robot class (defined by Robot.climber). Next, when the climber command is initialized, in the initialize() method, we set a boolean to false once (line 25), then edit a value in the Robot class to set our LED state (line 27). In the execute() method, we repeatedly set the output of the climber to the desired speed value in line 38 - this is a method that is found in our Climber class - until the command is ended, when the climber output is set to 0 in line 48. If the command is interrupted, for example when another command requiring the Climber subsystem is called, the same is done - setting the climber output to 0 (line 55) and changing the LED state (line 57).
Commands can be grouped to run at the same time or sequentially with CommandGroups - this is useful in Autonomous. See our AutoShooter class for an example of a simple CommandGroup.
Commands (and CommandGroups) can be called from the OI on Joystick button pushes or during Autonomous - see line 204 of Robot where we fetch and set the Autonomous command, and line 222 when we start it.
tl-dr; Robot.java creates Subsystems which contain methods called by Commands, commands are scheduled by the OI in teleop or by the Robot.java class in Autonomous.