hysteresis: remove dependency/side effect on time

This commit is contained in:
Julian Oes
2019-05-27 09:57:50 +02:00
parent 7b9562e3b1
commit b29e5e3adb
8 changed files with 92 additions and 87 deletions
+6 -6
View File
@@ -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