Class IterativeRobotBase
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
TimedRobot
The IterativeRobotBase class does not implement startCompetition(), so it should not be used by teams directly.
This class provides the following functions which are called by the main loop, startCompetition(), at the appropriate times:
robotInit() -- provide for initialization at robot power-on
driverStationConnected() -- provide for initialization the first time the DS is connected
init() functions -- each of the following functions is called once when the appropriate mode is entered:
- disabledInit() -- called each and every time disabled is entered from another mode
- autonomousInit() -- called each and every time autonomous is entered from another mode
- teleopInit() -- called each and every time teleop is entered from another mode
- testInit() -- called each and every time test is entered from another mode
periodic() functions -- each of these functions is called on an interval:
- robotPeriodic()
- disabledPeriodic()
- autonomousPeriodic()
- teleopPeriodic()
- testPeriodic()
exit() functions -- each of the following functions is called once when the appropriate mode is exited:
- disabledExit() -- called each and every time disabled is exited
- autonomousExit() -- called each and every time autonomous is exited
- teleopExit() -- called each and every time teleop is exited
- testExit() -- called each and every time test is exited
-
Constructor Summary
ModifierConstructorDescriptionprotected
IterativeRobotBase
(double period) Constructor for IterativeRobotBase. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Exit code for autonomous mode should go here.void
Initialization code for autonomous mode should go here.void
Periodic code for autonomous mode should go here.void
Exit code for disabled mode should go here.void
Initialization code for disabled mode should go here.void
Periodic code for disabled mode should go here.void
Code that needs to know the DS state should go here.void
enableLiveWindowInTest
(boolean testLW) Sets whether LiveWindow operation is enabled during test mode.double
Gets time period between calls to Periodic() functions.boolean
Whether LiveWindow operation is enabled during test mode.protected void
loopFunc()
Loop function.void
Prints list of epochs added so far and their times.void
Robot-wide initialization code should go here.void
Periodic code for all robot modes should go here.void
setNetworkTablesFlushEnabled
(boolean enabled) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated without replacement.void
Robot-wide simulation initialization code should go here.void
Periodic simulation code should go here.abstract void
Provide an alternate "main loop" via startCompetition().void
Exit code for teleop mode should go here.void
Initialization code for teleop mode should go here.void
Periodic code for teleop mode should go here.void
testExit()
Exit code for test mode should go here.void
testInit()
Initialization code for test mode should go here.void
Periodic code for test mode should go here.Methods inherited from class edu.wpi.first.wpilibj.RobotBase
close, endCompetition, getMainThreadId, getRuntimeType, isAutonomous, isAutonomousEnabled, isDisabled, isEnabled, isReal, isSimulation, isTeleop, isTeleopEnabled, isTest, isTestEnabled, startRobot, suppressExitWarning
-
Constructor Details
-
IterativeRobotBase
Constructor for IterativeRobotBase.- Parameters:
period
- Period in seconds.
-
-
Method Details
-
startCompetition
Provide an alternate "main loop" via startCompetition().- Specified by:
startCompetition
in classRobotBase
-
robotInit
Robot-wide initialization code should go here.Users should override this method for default Robot-wide initialization which will be called when the robot is first powered on. It will be called exactly one time.
Note: This method is functionally identical to the class constructor so that should be used instead.
-
driverStationConnected
Code that needs to know the DS state should go here.Users should override this method for initialization that needs to occur after the DS is connected, such as needing the alliance information.
-
simulationInit
Robot-wide simulation initialization code should go here.Users should override this method for default Robot-wide simulation related initialization which will be called when the robot is first started. It will be called exactly one time after RobotInit is called only when the robot is in simulation.
-
disabledInit
Initialization code for disabled mode should go here.Users should override this method for initialization code which will be called each time the robot enters disabled mode.
-
autonomousInit
Initialization code for autonomous mode should go here.Users should override this method for initialization code which will be called each time the robot enters autonomous mode.
-
teleopInit
Initialization code for teleop mode should go here.Users should override this method for initialization code which will be called each time the robot enters teleop mode.
-
testInit
Initialization code for test mode should go here.Users should override this method for initialization code which will be called each time the robot enters test mode.
-
robotPeriodic
Periodic code for all robot modes should go here. -
simulationPeriodic
Periodic simulation code should go here.This function is called in a simulated robot after user code executes.
-
disabledPeriodic
Periodic code for disabled mode should go here. -
autonomousPeriodic
Periodic code for autonomous mode should go here. -
teleopPeriodic
Periodic code for teleop mode should go here. -
testPeriodic
Periodic code for test mode should go here. -
disabledExit
Exit code for disabled mode should go here.Users should override this method for code which will be called each time the robot exits disabled mode.
-
autonomousExit
Exit code for autonomous mode should go here.Users should override this method for code which will be called each time the robot exits autonomous mode.
-
teleopExit
Exit code for teleop mode should go here.Users should override this method for code which will be called each time the robot exits teleop mode.
-
testExit
Exit code for test mode should go here.Users should override this method for code which will be called each time the robot exits test mode.
-
setNetworkTablesFlushEnabled
@Deprecated(forRemoval=true, since="2025") public void setNetworkTablesFlushEnabled(boolean enabled) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated without replacement.Enables or disables flushing NetworkTables every loop iteration. By default, this is enabled.- Parameters:
enabled
- True to enable, false to disable
-
enableLiveWindowInTest
Sets whether LiveWindow operation is enabled during test mode. Calling- Parameters:
testLW
- True to enable, false to disable. Defaults to false.- Throws:
ConcurrentModificationException
- if this is called during test mode.
-
isLiveWindowEnabledInTest
Whether LiveWindow operation is enabled during test mode.- Returns:
- whether LiveWindow should be enabled in test mode.
-
getPeriod
Gets time period between calls to Periodic() functions.- Returns:
- The time period between calls to Periodic() functions.
-
loopFunc
Loop function. -
printWatchdogEpochs
Prints list of epochs added so far and their times.
-