blob: ccea4f86c27b4e0bbee292925e9ac17be94369ca [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. All Rights Reserved.
3 */
4/* Open Source Software - may be modified and shared by FRC teams. The code */
5/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
6/*----------------------------------------------------------------------------*/
7#pragma once
8
9#include "Timer.h"
10#include "RobotBase.h"
11
12/**
13 * IterativeRobot implements a specific type of Robot Program framework,
14 * extending the RobotBase class.
15 *
16 * The IterativeRobot class is intended to be subclassed by a user creating a
17 * robot program.
18 *
19 * This class is intended to implement the "old style" default code, by
20 * providing
21 * the following functions which are called by the main loop,
22 * StartCompetition(), at the appropriate times:
23 *
24 * RobotInit() -- provide for initialization at robot power-on
25 *
26 * Init() functions -- each of the following functions is called once when the
27 * appropriate mode is entered:
28 * - DisabledInit() -- called only when first disabled
29 * - AutonomousInit() -- called each and every time autonomous is entered from
30 * another mode
31 * - TeleopInit() -- called each and every time teleop is entered from
32 * another mode
33 * - TestInit() -- called each and every time test is entered from
34 * another mode
35 *
36 * Periodic() functions -- each of these functions is called iteratively at the
37 * appropriate periodic rate (aka the "slow loop"). The
38 * default period of
39 * the iterative robot is synced to the driver station
40 * control packets,
41 * giving a periodic frequency of about 50Hz (50 times
42 * per second).
43 * - DisabledPeriodic()
44 * - AutonomousPeriodic()
45 * - TeleopPeriodic()
46 * - TestPeriodic()
47 *
48 */
49
50class IterativeRobot : public RobotBase {
51 public:
52 /*
53 * The default period for the periodic function calls (seconds)
54 * Setting the period to 0.0 will cause the periodic functions to follow
55 * the Driver Station packet rate of about 50Hz.
56 */
57 static constexpr double kDefaultPeriod = 0.0;
58
59 virtual void StartCompetition();
60
61 virtual void RobotInit();
62 virtual void DisabledInit();
63 virtual void AutonomousInit();
64 virtual void TeleopInit();
65 virtual void TestInit();
66
67 virtual void DisabledPeriodic();
68 virtual void AutonomousPeriodic();
69 virtual void TeleopPeriodic();
70 virtual void TestPeriodic();
71
72 protected:
73 virtual ~IterativeRobot() = default;
74 IterativeRobot() = default;
75
76 private:
77 bool m_disabledInitialized = false;
78 bool m_autonomousInitialized = false;
79 bool m_teleopInitialized = false;
80 bool m_testInitialized = false;
81};