mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
hysteresis: avoid subtracting unsigned integers
- avoid potential errors with timestamp passed in from different sources
This commit is contained in:
parent
06f2004580
commit
16f8adb4b3
@ -74,17 +74,15 @@ Hysteresis::update(const hrt_abstime &now_us)
|
||||
{
|
||||
if (_requested_state != _state) {
|
||||
|
||||
const hrt_abstime elapsed = now_us - _last_time_to_change_state;
|
||||
|
||||
if (_state && !_requested_state) {
|
||||
// true -> false
|
||||
if (elapsed >= _time_from_true_us) {
|
||||
if (now_us >= _last_time_to_change_state + _time_from_true_us) {
|
||||
_state = false;
|
||||
}
|
||||
|
||||
} else if (!_state && _requested_state) {
|
||||
// false -> true
|
||||
if (elapsed >= _time_from_false_us) {
|
||||
if (now_us >= _last_time_to_change_state + _time_from_false_us) {
|
||||
_state = true;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user