Files
allwpilib/wpilibc/src/main/native/include/TimedRobot.h

55 lines
1.4 KiB
C
Raw Normal View History

2017-07-08 10:50:56 -04:00
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
2017-07-08 10:50:56 -04:00
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <HAL/Notifier.h>
2017-07-08 10:50:56 -04:00
#include "ErrorBase.h"
2017-07-08 10:50:56 -04:00
#include "IterativeRobotBase.h"
namespace frc {
/**
* TimedRobot implements the IterativeRobotBase robot program framework.
*
* The TimedRobot class is intended to be subclassed by a user creating a
* robot program.
*
* Periodic() functions from the base class are called on an interval by a
* Notifier instance.
*/
class TimedRobot : public IterativeRobotBase, public ErrorBase {
2017-07-08 10:50:56 -04:00
public:
static constexpr double kDefaultPeriod = 0.02;
void StartCompetition() override;
void SetPeriod(double seconds);
double GetPeriod() const;
2017-07-08 10:50:56 -04:00
protected:
TimedRobot();
~TimedRobot() override;
2017-07-08 10:50:56 -04:00
private:
// Prevents loop from starting if user calls SetPeriod() in RobotInit()
bool m_startLoop = false;
HAL_NotifierHandle m_notifier{0};
// The absolute expiration time
double m_expirationTime = 0;
// The relative time
double m_period = kDefaultPeriod;
void UpdateAlarm();
2017-07-08 10:50:56 -04:00
};
} // namespace frc