mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-21 23:44:48 +08:00
Change Interval to Increment
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
Endstop::Endstop(Endstop::Config_t& config)
|
||||
: config_(config) {
|
||||
update_config();
|
||||
debounceTimer_.setInterval(current_meas_period);
|
||||
debounceTimer_.setIncrement(current_meas_period);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ bool Endstop::get_state() {
|
||||
|
||||
void Endstop::update_config() {
|
||||
set_enabled(config_.enabled);
|
||||
debounceTimer_.setInterval(config_.debounce_ms * 0.001f);
|
||||
debounceTimer_.setIncrement(config_.debounce_ms * 0.001f);
|
||||
}
|
||||
|
||||
void Endstop::set_enabled(bool enable) {
|
||||
|
||||
@@ -8,8 +8,8 @@ class Timer {
|
||||
timeout_ = timeout;
|
||||
}
|
||||
|
||||
void setInterval(const T interval) {
|
||||
interval_ = interval;
|
||||
void setIncrement(const T increment) {
|
||||
increment_ = increment;
|
||||
}
|
||||
|
||||
void start() {
|
||||
@@ -20,9 +20,10 @@ class Timer {
|
||||
running_ = false;
|
||||
}
|
||||
|
||||
// If the timer is started, increment the timer
|
||||
void update() {
|
||||
if (running_)
|
||||
timer_ = std::min<T>(timer_ + interval_, timeout_);
|
||||
timer_ = std::min<T>(timer_ + increment_, timeout_);
|
||||
}
|
||||
|
||||
void reset() {
|
||||
@@ -36,6 +37,6 @@ class Timer {
|
||||
private:
|
||||
T timer_ = static_cast<T>(0); // Current state
|
||||
T timeout_ = static_cast<T>(0); // Time to count
|
||||
T interval_ = static_cast<T>(0); // Amount to increment each time update() is called
|
||||
T increment_ = static_cast<T>(0); // Amount to increment each time update() is called
|
||||
bool running_ = false; // update() only increments if runing_ is true
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
TEST_CASE_TEMPLATE("Timer2", T, float, int, char, uint32_t){
|
||||
Timer<T> myTimer;
|
||||
myTimer.setTimeout(10);
|
||||
myTimer.setInterval(1);
|
||||
myTimer.setIncrement(1);
|
||||
CHECK(!myTimer.expired());
|
||||
|
||||
myTimer.start();
|
||||
|
||||
Reference in New Issue
Block a user