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