Zıplama Önleyici
Zıplama önleyici, (“sıçramalar” olarak adlandırılan, başta bir şalterin inmesiyle oluşan fiziksel titreşimlerinden adını alan) istenmeyen hızlı açma/kapama döngülerini ortadan kaldırmak için kullanılan bir filtredir. Bu döngüler genellikle sensörün kaydetmeye çalıştığı asıl olaydan değil, gürültü veya yansımalar gibi bir sensör hatalarından kaynaklanmaktadır.
Debouncing is implemented in WPILib by the Debouncer class (Java, C++, Python), which filters a boolean stream so that the output only changes if the input sustains a change for some nominal time period.
Modes
The WPILib Debouncer can be configured in three different modes:
Rising (default): Debounces rising edges (transitions from false to true) only.
Falling: Debounces falling edges (transitions from true to false) only.
Both: Debounces all transitions.
Usage
// Initializes a DigitalInput on DIO 0
DigitalInput input = new DigitalInput(0);
// Creates a Debouncer in "both" mode.
Debouncer m_debouncer = new Debouncer(0.1, Debouncer.DebounceType.kBoth);
// So if currently false the signal must go true for at least .1 seconds before being read as a True signal.
if (m_debouncer.calculate(input.get())) {
// Do something now that the DI is True.
}
// Initializes a DigitalInput on DIO 0
frc::DigitalInput input{0};
// Creates a Debouncer in "both" mode.
frc::Debouncer m_debouncer{100_ms, frc::Debouncer::DebounceType::kBoth};
// So if currently false the signal must go true for at least .1 seconds before being read as a True signal.
if (m_debouncer.calculate(input.Get())) {
// Do something now that the DI is True.
}
from wpilib import DigitalInput
from wpimath.filter import Debouncer
# Initializes a DigitalInput on DIO 0
self.input = DigitalInput(0)
# Creates a Debouncer in "both" mode with a debounce time of 0.1 seconds
self.debouncer = Debouncer(0.1, Debouncer.DebounceType.kBoth)
# If currently false, the signal must go true for at least 0.1 seconds before being read as a True signal.
if self.debouncer.calculate(self.input.get()):
# Do something now that the DI is True.
pass