adapnex::core::Hysteresis

Switches a boolean output based on two analog thresholds.

Synopsis

Declared in <adapnex/core/hysteresis.h>

template<typename T>
class Hysteresis;

Description

Implements hysteresis to prevent rapid switching when an input signal fluctuates near a threshold.

The block automatically adapts its logic based on the relationship between SET and RESET:

  • Direct (e.g. Cooling/High‐Alarm): If SET > RESET, OUT becomes true when IN rises above SET, and false when IN falls below RESET.

  • Inverse (e.g. Heating/Low‐Alarm): If SET <= RESET, OUT becomes true when IN falls below SET, and false when IN rises above RESET.

Hysteresis Logic Diagram

Parameter Type Direction Description

IN

T

Input

The signal to evaluate.

SET

T

Input

Crossing this threshold sets OUT to true.

RESET

T

Input

Crossing this threshold resets OUT to false.

OUT

bool

Output

The switching result based on the hysteresis logic.

Common Use Case

Thermostat controlling a cooling fan or heating system to prevent short cycling.

Example: Temperature Control

class CoolingSystem : public Task {
public:
    float current_temp = 0.0f;
    bool fan_active = false;

private:
    Hysteresis<float> temp_switch;

    void Update() override {
        // SET > RESET implies high threshold logic (turn ON at 30.0, turn OFF at 25.0).
        temp_switch(current_temp, 30.0f, 25.0f, fan_active);
    }
};

Both SET > RESET and SET < RESET are allowed. The implementation adapts the comparisons accordingly.

Hysteresis blocks maintain state across cycles and must be instantiated as member variables of a task rather than locally within Update().

Member Functions

Name

Description

operator()

Function call operators

Data Members

Name

Description

IN

Input value that is evaluated.

OUT

Output that switches between true and false depending on the input value and thresholds.

RESET

Input threshold that resets the output OUT to false when crossed.

SET

Input threshold that sets the output OUT to true when crossed.

Created with MrDocs