WPILibC++  unspecified
TimedRobot.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2017-2018 FIRST. 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 the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <HAL/Notifier.h>
11 
12 #include "ErrorBase.h"
13 #include "IterativeRobotBase.h"
14 
15 namespace frc {
16 
26 class TimedRobot : public IterativeRobotBase, public ErrorBase {
27  public:
28  static constexpr double kDefaultPeriod = 0.02;
29 
33  void StartCompetition() override;
34 
44  void SetPeriod(double seconds);
45 
49  double GetPeriod() const;
50 
51  protected:
52  TimedRobot();
53  ~TimedRobot() override;
54 
55  private:
56  // Prevents loop from starting if user calls SetPeriod() in RobotInit()
57  bool m_startLoop = false;
58 
59  HAL_NotifierHandle m_notifier{0};
60 
61  // The absolute expiration time
62  double m_expirationTime = 0;
63 
64  // The relative time
65  double m_period = kDefaultPeriod;
66 
70  void UpdateAlarm();
71 };
72 
73 } // namespace frc
Definition: Utility.cpp:119
void StartCompetition() override
Provide an alternate "main loop" via StartCompetition().
Definition: TimedRobot.cpp:20
double GetPeriod() const
Get time period between calls to Periodic() functions.
Definition: TimedRobot.cpp:55
Base class for most objects.
Definition: ErrorBase.h:74
TimedRobot implements the IterativeRobotBase robot program framework.
Definition: TimedRobot.h:26
void SetPeriod(double seconds)
Set time period between calls to Periodic() functions.
Definition: TimedRobot.cpp:46
IterativeRobotBase implements a specific type of robot program framework, extending the RobotBase cla...
Definition: IterativeRobotBase.h:43