Unit 5: Basic FRC Coding
Every FRC robot project has a `Robot.java` file. It's the main entry point for your code and serves as the manager for the robot's entire lifecycle, telling different parts of your code when to run during a match.
Think of a match as a play with different acts (autonomous, teleop, disabled). `Robot.java` is the director who calls out the cues for each act. It contains special methods that WPILib calls automatically at the right times.
In the past, programmers would fill the `teleopPeriodic` and `autonomousPeriodic` methods with lots of complex logic. However, with the modern Command-Based Framework that we use, `Robot.java` has become much simpler.
Its only two jobs now are:
The `Robot.java` file is now just a clean, simple starting point. All the complex logic for subsystems, commands, and button bindings is neatly organized in other files.
public class Robot extends TimedRobot {
private Command m_autonomousCommand;
private RobotContainer m_robotContainer;
// 1. Create the RobotContainer
@Override
public void robotInit() {
// This is the most important line in robotInit().
// It creates the central hub for our entire robot's code.
m_robotContainer = new RobotContainer();
}
// 2. Run the CommandScheduler
@Override
public void robotPeriodic() {
// This is the most important line in robotPeriodic().
// It's the engine that makes the entire Command-Based system work.
CommandScheduler.getInstance().run();
}
@Override
public void autonomousInit() {
m_autonomousCommand = m_robotContainer.getAutonomousCommand();
if (m_autonomousCommand != null) {
m_autonomousCommand.schedule();
}
}
// ... other lifecycle methods are often empty in a command-based project ...
}
Question: In a modern command-based robot project, what is the most important line of code inside the `robotPeriodic()` method?