Robot.java
Robot.java
is where everything originates.
Here's the WPILib doc page that explains it in more detail.
Key methods you should know about
robotInit()
is called when the robot code startsrobotPeriodic()
runs periodically regardless of Operational Mode (see note below)
Operational Mode refers to whether the robot is in Teleoperated (Teleop), Autonomous, Disabled, or Test mode.
teleopInit()
is called when Teleop is EnabledteleopPeriodic()
is called periodically when Teleop is EnabledautonomousInit()
is called when Autonomous is EnabledautonomousPeriodic()
is called periodically when Autonomous is EnabledtestInit()
is called when Test is EnabledtestPeriodic()
is called periodically when Test is Enabled
And finally,
disabledInit()
is called when the robot is DisableddisabledPeriodic()
is called periodically when the robot is Disabled
A quick excerpt is included below:
import edu.wpi.first.wpilibj.TimedRobot;
public class Robot extends TimedRobot {
@Override
public void robotInit() {}
@Override
public void robotPeriodic() {}
@Override
public void autonomousInit() {}
@Override
public void autonomousPeriodic() {}
@Override
public void teleopInit() {}
@Override
public void teleopPeriodic() {}
@Override
public void disabledInit() {}
@Override
public void disabledPeriodic() {}
@Override
public void testInit() {}
@Override
public void testPeriodic() {}
@Override
public void simulationInit() {}
@Override
public void simulationPeriodic() {}
}
Bonus: Main.java
If you take a look at Main.java (copied below), do you notice anything?
package org.aceshigh176.frc2023;
import edu.wpi.first.wpilibj.RobotBase;
/**
* Do NOT add any static variables to this class, or any initialization at all.
* Unless you know what you are doing, do not modify this file except to
* change the parameter class to the startRobot call.
*/
public final class Main {
private Main() {
}
/**
* Main initialization function. Do not perform any initialization here.
*
* <p>If you change your main robot class, change the parameter type.
*/
public static void main(String... args) {
RobotBase.startRobot(Robot::new);
}
}
That's right, this is what calls the code in Robot.java