mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 10:03:33 +08:00
hysteresis: remove dependency/side effect on time
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2016 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2016-2019 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -54,27 +54,27 @@ Hysteresis::set_hysteresis_time_from(const bool from_state, const hrt_abstime ne
|
||||
}
|
||||
|
||||
void
|
||||
Hysteresis::set_state_and_update(const bool new_state)
|
||||
Hysteresis::set_state_and_update(const bool new_state, const hrt_abstime &now_us)
|
||||
{
|
||||
if (new_state != _state) {
|
||||
if (new_state != _requested_state) {
|
||||
_requested_state = new_state;
|
||||
_last_time_to_change_state = hrt_absolute_time();
|
||||
_last_time_to_change_state = now_us;
|
||||
}
|
||||
|
||||
} else {
|
||||
_requested_state = _state;
|
||||
}
|
||||
|
||||
update();
|
||||
update(now_us);
|
||||
}
|
||||
|
||||
void
|
||||
Hysteresis::update()
|
||||
Hysteresis::update(const hrt_abstime &now_us)
|
||||
{
|
||||
if (_requested_state != _state) {
|
||||
|
||||
const hrt_abstime elapsed = hrt_elapsed_time(&_last_time_to_change_state);
|
||||
const hrt_abstime elapsed = now_us - _last_time_to_change_state;
|
||||
|
||||
if (_state && !_requested_state) {
|
||||
// true -> false
|
||||
|
||||
Reference in New Issue
Block a user