Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
periodic_timer.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2020-2021 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef TAPROOT_PERIODIC_TIMER_HPP_
25#define TAPROOT_PERIODIC_TIMER_HPP_
26
28
29namespace tap
30{
31namespace arch
32{
40template <typename T>
42{
43public:
44 PeriodicTimer() : period(0) {}
45
46 explicit PeriodicTimer(uint32_t period) : period(period), timeout(period) {}
47
52 inline void restart() { timeout.restart(period); }
53
59 inline void restart(uint32_t period)
60 {
61 this->period = period;
62 restart();
63 }
64
68 inline void stop() { timeout.stop(); }
69
79 inline bool execute()
80 {
81 if (timeout.execute())
82 {
83 uint32_t now = T::TimeFunc();
84
85 do
86 {
87 timeout.expireTime += period;
88 } while (timeout.expireTime <= now);
89
90 timeout.isRunning = true;
91 timeout.isExecuted = false;
92 return true;
93 }
94 return false;
95 }
96
100 inline bool isStopped() const { return timeout.isStopped(); }
101
102private:
103 uint32_t period;
104 T timeout;
105};
106
109
110} // namespace arch
111} // namespace tap
112
113#endif // TAPROOT_PERIODIC_TIMER_HPP_
Definition periodic_timer.hpp:42
bool isStopped() const
Definition periodic_timer.hpp:100
void restart(uint32_t period)
Definition periodic_timer.hpp:59
PeriodicTimer()
Definition periodic_timer.hpp:44
void restart()
Definition periodic_timer.hpp:52
PeriodicTimer(uint32_t period)
Definition periodic_timer.hpp:46
bool execute()
Definition periodic_timer.hpp:79
void stop()
Definition periodic_timer.hpp:68
Definition ballistics.cpp:29