blob: b817aa97f2e3c7cb2f2c5342f19dab42f6a6c328 [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#include "frc/TimesliceRobot.h"
6
7#include "frc/Errors.h"
Austin Schuh812d0d12021-11-04 20:16:48 -07008
9using namespace frc;
10
11TimesliceRobot::TimesliceRobot(units::second_t robotPeriodicAllocation,
12 units::second_t controllerPeriod)
13 : m_nextOffset{robotPeriodicAllocation},
14 m_controllerPeriod{controllerPeriod} {}
15
16void TimesliceRobot::Schedule(std::function<void()> func,
17 units::second_t allocation) {
18 if (m_nextOffset + allocation > m_controllerPeriod) {
19 throw FRC_MakeError(err::Error,
20 "Function scheduled at offset {} with allocation {} "
21 "exceeded controller period of {}\n",
22 m_nextOffset, allocation, m_controllerPeriod);
23 }
24
25 AddPeriodic(func, m_controllerPeriod, m_nextOffset);
26 m_nextOffset += allocation;
27}