mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-01 14:50:35 +08:00
hysteresis: we needed different hysteresis
Sometimes, we only need a histeresis in one direction.
This commit is contained in:
@@ -61,12 +61,13 @@ Hysteresis::set_state_and_update(const bool new_state)
|
||||
void
|
||||
Hysteresis::update()
|
||||
{
|
||||
if (_requested_state != _state) {
|
||||
|
||||
|
||||
if (_requested_state != _state &&
|
||||
hrt_elapsed_time(&_last_time_to_change_state) >= _hysteresis_time_us) {
|
||||
|
||||
_state = _requested_state;
|
||||
if (hrt_elapsed_time(&_last_time_to_change_state) >= (_state ?
|
||||
_hysteresis_time_from_true_us :
|
||||
_hysteresis_time_from_false_us)) {
|
||||
_state = _requested_state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,16 +48,25 @@ namespace systemlib {
|
||||
class Hysteresis
|
||||
{
|
||||
public:
|
||||
Hysteresis(unsigned hysteresis_time_us, bool init_state) :
|
||||
_hysteresis_time_us(hysteresis_time_us),
|
||||
Hysteresis(bool init_state) :
|
||||
_state(init_state),
|
||||
_requested_state(init_state),
|
||||
_hysteresis_time_from_true_us(0),
|
||||
_hysteresis_time_from_false_us(0),
|
||||
_last_time_to_change_state(0)
|
||||
{}
|
||||
|
||||
~Hysteresis()
|
||||
{}
|
||||
|
||||
void set_hysteresis_time_from(const bool from_state, const unsigned new_hysteresis_time_us) {
|
||||
if (from_state == true) {
|
||||
_hysteresis_time_from_true_us = new_hysteresis_time_us;
|
||||
} else {
|
||||
_hysteresis_time_from_false_us = new_hysteresis_time_us;
|
||||
}
|
||||
}
|
||||
|
||||
bool get_state() const {
|
||||
return _state;
|
||||
}
|
||||
@@ -68,10 +77,10 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
unsigned _hysteresis_time_us;
|
||||
bool _state;
|
||||
|
||||
bool _requested_state;
|
||||
unsigned _hysteresis_time_from_true_us;
|
||||
unsigned _hysteresis_time_from_false_us;
|
||||
hrt_abstime _last_time_to_change_state;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user