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