RaidZeroLib
Coroutine robot framework for VEX V5
Toggle main menu visibility
Loading...
Searching...
No Matches
Settled.hpp
1
#pragma once
2
#include <optional>
3
4
#include "RaidZeroLib/api/Units/Units.hpp"
5
6
namespace
rz
{
7
13
template
<
class
Error>
14
class
Settled
{
15
public
:
16
struct
Config
{
17
Error
tolerance
;
19
Duration
time
{};
20
};
21
22
explicit
Settled
(
Config
config) : config(config) {}
23
25
[[nodiscard]]
bool
update
(Error error,
Time
now
) {
26
if
(au::abs(error) > config.tolerance) {
27
enteredAt.reset();
28
return
false
;
29
}
30
if
(!enteredAt) {
31
enteredAt =
now
;
32
}
33
return
now
- *enteredAt >= config.time;
34
}
35
36
void
reset
() { enteredAt.reset(); }
37
38
private
:
39
Config config;
40
std::optional<Time> enteredAt;
41
};
42
43
}
// namespace rz
rz::Settled::Settled
Settled(Config config)
Definition
Settled.hpp:22
rz::Settled::update
bool update(Error error, Time now)
Whether error (measured at now) has been within the tolerance for the configured time.
Definition
Settled.hpp:25
rz::Settled::reset
void reset()
Definition
Settled.hpp:36
rz::now
Time now()
Time at the start of the current tick of the current runtime.
Definition
Runtime.hpp:209
rz::Duration
au::QuantityD< au::Seconds > Duration
Definition
Units.hpp:16
rz::Time
au::QuantityPointD< au::Seconds > Time
Definition
Units.hpp:17
rz
Definition
DriverControl.hpp:11
rz::Settled::Config
Definition
Settled.hpp:16
rz::Settled::Config::tolerance
Error tolerance
Definition
Settled.hpp:17
rz::Settled::Config::time
Duration time
How long the error must stay within the tolerance. Zero means settled as soon as it is within it.
Definition
Settled.hpp:19
RaidZeroLib
api
Control
Settled.hpp
Generated by
1.18.0