Class TimedRobot
java.lang.Object
org.wpilib.framework.RobotBase
org.wpilib.framework.IterativeRobotBase
org.wpilib.framework.TimedRobot
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
TimesliceRobot
TimedRobot implements the IterativeRobotBase robot program framework.
The TimedRobot class is intended to be subclassed by a user creating a robot program.
periodic() functions from the base class are called on an interval by a Notifier instance.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor for TimedRobot.protectedTimedRobot(double period) Constructor for TimedRobot.protectedTimedRobot(Frequency frequency) Constructor for TimedRobot.protectedTimedRobot(Time period) Constructor for TimedRobot. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddPeriodic(Runnable callback, double period) Add a callback to run at a specific period.final voidaddPeriodic(Runnable callback, double period, double offset) Add a callback to run at a specific period with a starting time offset.voidclose()voidEnds the main loop in startCompetition().longReturn the system clock time in nanoseconds for the start of the current periodic loop.voidProvide an alternate "main loop" via startCompetition().Methods inherited from class IterativeRobotBase
autonomousExit, autonomousInit, autonomousPeriodic, disabledExit, disabledInit, disabledPeriodic, driverStationConnected, getPeriod, loopFunc, printWatchdogEpochs, robotPeriodic, simulationInit, simulationPeriodic, teleopExit, teleopInit, teleopPeriodic, utilityExit, utilityInit, utilityPeriodicMethods inherited from class RobotBase
getMainThreadId, getOpMode, getOpModeId, getRobotName, getRuntimeType, isAutonomous, isAutonomousEnabled, isDisabled, isEnabled, isReal, isSimulation, isTeleop, isTeleopEnabled, isUtility, isUtilityEnabled, startRobot, suppressExitWarning
-
Field Details
-
DEFAULT_PERIOD
public static final double DEFAULT_PERIODDefault loop period.- See Also:
-
-
Constructor Details
-
TimedRobot
protected TimedRobot()Constructor for TimedRobot. -
TimedRobot
protected TimedRobot(double period) Constructor for TimedRobot.- Parameters:
period- The period of the robot loop function.
-
TimedRobot
Constructor for TimedRobot.- Parameters:
period- The period of the robot loop function.
-
TimedRobot
Constructor for TimedRobot.- Parameters:
frequency- The frequency of the robot loop function.
-
-
Method Details
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classRobotBase
-
startCompetition
public void startCompetition()Provide an alternate "main loop" via startCompetition().- Specified by:
startCompetitionin classIterativeRobotBase
-
endCompetition
public void endCompetition()Ends the main loop in startCompetition().- Specified by:
endCompetitionin classRobotBase
-
getLoopStartTime
public long getLoopStartTime()Return the system clock time in nanoseconds for the start of the current periodic loop. This is in the same time base as Timer.getMonotonicTimestamp(), but is stable through a loop. It is updated at the beginning of every periodic callback (including the normal periodic loop).- Returns:
- Robot running time in nanoseconds, as of the start of the current periodic function.
-
addPeriodic
Add a callback to run at a specific period.This is scheduled on TimedRobot's Notifier, so TimedRobot and the callback run synchronously. Interactions between them are thread-safe.
- Parameters:
callback- The callback to run.period- The period at which to run the callback in seconds.
-
addPeriodic
Add a callback to run at a specific period with a starting time offset.This is scheduled on TimedRobot's Notifier, so TimedRobot and the callback run synchronously. Interactions between them are thread-safe.
- Parameters:
callback- The callback to run.period- The period at which to run the callback in seconds.offset- The offset from the common starting time in seconds. This is useful for scheduling a callback in a different timeslot relative to TimedRobot.
-