WPILibC++ 2024.3.2
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 /**
21 * Type of debouncing to perform.
22 */
24 /// Rising edge.
26 /// Falling edge.
28 /// Both rising and falling edges.
29 kBoth
30 };
31
32 /**
33 * Creates a new Debouncer.
34 *
35 * @param debounceTime The number of seconds the value must change from
36 * baseline for the filtered value to change.
37 * @param type Which type of state change the debouncing will be
38 * performed on.
39 */
40 explicit Debouncer(units::second_t debounceTime,
41 DebounceType type = DebounceType::kRising);
42
43 /**
44 * Applies the debouncer to the input stream.
45 *
46 * @param input The current value of the input stream.
47 * @return The debounced value of the input stream.
48 */
49 bool Calculate(bool input);
50
51 private:
52 units::second_t m_debounceTime;
53 bool m_baseline;
54 DebounceType m_debounceType;
55
56 units::second_t m_prevTime;
57
58 void ResetTimer();
59
60 bool HasElapsed() const;
61};
62} // 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
Type of debouncing to perform.
Definition: Debouncer.h:23
@ kFalling
Falling edge.
Definition: Debouncer.h:27
@ kRising
Rising edge.
Definition: Debouncer.h:25
bool Calculate(bool input)
Applies the debouncer to the input stream.
type
Definition: core.h:556
Definition: AprilTagPoseEstimator.h:15
@ kBoth
Both rising and falling edges configuration.