Class TimedRobot

All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
TimesliceRobot

public class TimedRobot extends IterativeRobotBase
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 Details

  • Constructor Details

    • TimedRobot

      protected TimedRobot()
      Constructor for TimedRobot.
    • TimedRobot

      protected TimedRobot(double period)
      Constructor for TimedRobot.
      Parameters:
      period - Period in seconds.
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class RobotBase
    • startCompetition

      public void startCompetition()
      Provide an alternate "main loop" via startCompetition().
      Specified by:
      startCompetition in class IterativeRobotBase
    • endCompetition

      public void endCompetition()
      Ends the main loop in startCompetition().
      Specified by:
      endCompetition in class RobotBase
    • getLoopStartTime

      public long getLoopStartTime()
      Return the system clock time in micrseconds for the start of the current periodic loop. This is in the same time base as Timer.getFPGATimestamp(), 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 microseconds, as of the start of the current periodic function.
    • addPeriodic

      public final void addPeriodic(Runnable callback, double periodSeconds)
      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.
      periodSeconds - The period at which to run the callback in seconds.
    • addPeriodic

      public final void addPeriodic(Runnable callback, double periodSeconds, double offsetSeconds)
      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.
      periodSeconds - The period at which to run the callback in seconds.
      offsetSeconds - The offset from the common starting time in seconds. This is useful for scheduling a callback in a different timeslot relative to TimedRobot.
    • addPeriodic

      public final void addPeriodic(Runnable callback, Time period)
      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.
    • addPeriodic

      public final void addPeriodic(Runnable callback, Time period, Time offset)
      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.
      offset - The offset from the common starting time. This is useful for scheduling a callback in a different timeslot relative to TimedRobot.