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