2017-07-08 10:50:56 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-03-31 20:43:04 -07:00
|
|
|
/* Copyright (c) 2017-2020 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
|
|
|
|
|
|
2018-10-29 12:49:17 -07:00
|
|
|
#include <hal/Types.h>
|
2019-08-17 00:56:48 -04:00
|
|
|
#include <units/units.h>
|
|
|
|
|
#include <wpi/deprecated.h>
|
2017-07-08 10:50:56 -04:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/ErrorBase.h"
|
|
|
|
|
#include "frc/IterativeRobotBase.h"
|
2017-07-08 10:50:56 -04:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2018-04-30 00:00:09 -07:00
|
|
|
class TimedRobot : public IterativeRobotBase, public ErrorBase {
|
2017-07-08 10:50:56 -04:00
|
|
|
public:
|
2019-08-17 00:56:48 -04:00
|
|
|
static constexpr units::second_t kDefaultPeriod = 20_ms;
|
2017-07-08 10:50:56 -04:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Provide an alternate "main loop" via StartCompetition().
|
|
|
|
|
*/
|
2017-07-08 10:50:56 -04:00
|
|
|
void StartCompetition() override;
|
|
|
|
|
|
2019-11-05 21:33:09 -08:00
|
|
|
/**
|
|
|
|
|
* Ends the main loop in StartCompetition().
|
|
|
|
|
*/
|
|
|
|
|
void EndCompetition() override;
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
2018-06-24 02:29:21 -05:00
|
|
|
* Get the time period between calls to Periodic() functions.
|
2018-05-31 20:47:15 -07:00
|
|
|
*/
|
2019-08-17 00:56:48 -04:00
|
|
|
units::second_t GetPeriod() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
2018-06-24 02:29:21 -05:00
|
|
|
* Constructor for TimedRobot.
|
|
|
|
|
*
|
2020-03-31 20:43:04 -07:00
|
|
|
* @deprecated use unit safe constructor instead.
|
|
|
|
|
* TimedRobot(units::second_t period = kDefaultPeriod)
|
|
|
|
|
*
|
2018-06-24 02:29:21 -05:00
|
|
|
* @param period Period in seconds.
|
2018-05-31 20:47:15 -07:00
|
|
|
*/
|
2019-08-17 00:56:48 -04:00
|
|
|
WPI_DEPRECATED("Use constructor with unit-safety instead.")
|
|
|
|
|
explicit TimedRobot(double period);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor for TimedRobot.
|
|
|
|
|
*
|
|
|
|
|
* @param period Period.
|
|
|
|
|
*/
|
|
|
|
|
explicit TimedRobot(units::second_t period = kDefaultPeriod);
|
2017-07-08 10:50:56 -04:00
|
|
|
|
2018-04-30 00:00:09 -07:00
|
|
|
~TimedRobot() override;
|
2017-07-08 10:50:56 -04:00
|
|
|
|
2019-08-25 18:42:00 -07:00
|
|
|
TimedRobot(TimedRobot&&) = default;
|
|
|
|
|
TimedRobot& operator=(TimedRobot&&) = default;
|
2018-09-24 00:08:25 -07:00
|
|
|
|
2017-07-08 10:50:56 -04:00
|
|
|
private:
|
2019-08-25 18:42:00 -07:00
|
|
|
hal::Handle<HAL_NotifierHandle> m_notifier;
|
2018-04-30 00:00:09 -07:00
|
|
|
|
|
|
|
|
// The absolute expiration time
|
2019-09-03 15:58:31 -07:00
|
|
|
units::second_t m_expirationTime{0};
|
2018-04-30 00:00:09 -07:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Update the HAL alarm time.
|
|
|
|
|
*/
|
2018-04-30 00:00:09 -07:00
|
|
|
void UpdateAlarm();
|
2017-07-08 10:50:56 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace frc
|