WPILibC++ 2023.4.3-108-ge5452e3
Debouncer.h
Go to the documentation of this file.
1// 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#pragma once
6
7#include <wpi/SymbolExports.h>
8#include <wpi/timestamp.h>
9
10#include "units/time.h"
11
12namespace frc {
13/**
14 * A simple debounce filter for boolean streams. Requires that the boolean
15 * change value from baseline for a specified period of time before the filtered
16 * value changes.
17 */
19 public:
20 enum DebounceType { kRising, kFalling, kBoth };
21
22 /**
23 * Creates a new Debouncer.
24 *
25 * @param debounceTime The number of seconds the value must change from
26 * baseline for the filtered value to change.
27 * @param type Which type of state change the debouncing will be
28 * performed on.
29 */
30 explicit Debouncer(units::second_t debounceTime,
31 DebounceType type = DebounceType::kRising);
32
33 /**
34 * Applies the debouncer to the input stream.
35 *
36 * @param input The current value of the input stream.
37 * @return The debounced value of the input stream.
38 */
39 bool Calculate(bool input);
40
41 private:
42 units::second_t m_debounceTime;
43 bool m_baseline;
44 DebounceType m_debounceType;
45
46 units::second_t m_prevTime;
47
48 void ResetTimer();
49
50 bool HasElapsed() const;
51};
52} // namespace frc
#define WPILIB_DLLEXPORT
Definition: SymbolExports.h:36
A simple debounce filter for boolean streams.
Definition: Debouncer.h:18
Debouncer(units::second_t debounceTime, DebounceType type=DebounceType::kRising)
Creates a new Debouncer.
DebounceType
Definition: Debouncer.h:20
bool Calculate(bool input)
Applies the debouncer to the input stream.
type
Definition: core.h:575
Definition: AprilTagPoseEstimator.h:15