Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
conditional_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_CONDITIONAL_TIMER_HPP_
25#define TAPROOT_CONDITIONAL_TIMER_HPP_
26
27#include <cstdint>
28
29#include "timeout.hpp"
30
31namespace tap
32{
33namespace arch
34{
42template <class Timeout>
44{
45public:
49 explicit ConditionalTimer(uint32_t timeout) : timeout(timeout) {}
50
55 inline void restart() { timer.restart(timeout); }
56
62 inline void restart(uint32_t newTimeout)
63 {
64 timeout = newTimeout;
65 timer.restart(newTimeout);
66 }
67
71 inline void stop() { timer.stop(); }
72
82 inline bool execute(bool condition)
83 {
84 if (!condition)
85 {
86 timer.restart(timeout);
87 }
88 return timer.isExpired();
89 }
90
91 inline bool isStopped() { return timer.isStopped(); }
92
93private:
94 Timeout timer;
95 uint32_t timeout;
96};
97
99
100} // namespace arch
101
102} // namespace tap
103
104#endif
Definition conditional_timer.hpp:44
void restart()
Definition conditional_timer.hpp:55
bool execute(bool condition)
Definition conditional_timer.hpp:82
void stop()
Definition conditional_timer.hpp:71
ConditionalTimer(uint32_t timeout)
Definition conditional_timer.hpp:49
bool isStopped()
Definition conditional_timer.hpp:91
void restart(uint32_t newTimeout)
Definition conditional_timer.hpp:62
Definition timeout.hpp:44
void restart(uint32_t timeout)
Definition timeout.hpp:70
bool isExpired() const
Definition timeout.hpp:95
void stop()
Definition timeout.hpp:80
bool isStopped() const
Definition timeout.hpp:89
Definition ballistics.cpp:29