Add Debouncer (#3590)

Supersedes #2358 with updates and cleanups.

Closes #2482 and closes #2487 because we shouldn't support both
time-based and count-based debouncing approaches.

Co-authored-by: oblarg <emichaelbarnett@gmail.com>
This commit is contained in:
Tyler Veness
2021-09-19 19:58:16 -07:00
committed by GitHub
parent 179fde3a7b
commit 1ca383b23b
10 changed files with 344 additions and 1 deletions

View File

@@ -2,7 +2,9 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include <frc/simulation/SimHooks.h>
#include "../CommandTestBase.h"
#include "frc2/command/CommandScheduler.h"
#include "frc2/command/RunCommand.h"
#include "frc2/command/WaitUntilCommand.h"
@@ -190,3 +192,19 @@ TEST_F(ButtonTest, RValueButton) {
scheduler.Run();
EXPECT_EQ(counter, 1);
}
TEST_F(ButtonTest, DebounceTest) {
auto& scheduler = CommandScheduler::GetInstance();
bool pressed = false;
RunCommand command([] {});
Trigger([&pressed] { return pressed; }).Debounce(100_ms).WhenActive(&command);
pressed = true;
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&command));
frc::sim::StepTiming(300_ms);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(&command));
}