Hysteresis Control
The Adapnex SDK provides blocks for switching boolean outputs based on analog input thresholds. These blocks implement Hysteresis, a technique crucial for preventing "chattering" (rapid, unwanted switching) when a signal fluctuates near a specific threshold.
These templates are generic and work with any comparable type (e.g., float, double, int).
Standard Hysteresis
The Hysteresis block switches an output OUT based on two defined thresholds: SET and RESET.
Behavior:
The block automatically adapts its logic based on the relationship between SET and RESET:
-
Direct (e.g. Cooling/High-Alarm): If
SET > RESET:-
OUTbecomestruewhenINrises aboveSET. -
OUTbecomesfalsewhenINfalls belowRESET.
-
-
Inverse (e.g. Heating/Low-Alarm): If
SET ⇐ RESET:-
OUTbecomestruewhenINfalls belowSET. -
OUTbecomesfalsewhenINrises aboveRESET.
-
| Parameter | Type | Direction | Description |
|---|---|---|---|
|
template |
Input |
The analog signal to be evaluated. |
|
template |
Input |
Crossing this threshold sets |
|
template |
Input |
Crossing this threshold resets |
|
|
Output |
The switching result based on the hysteresis logic. |
Common Use Case: A thermostat controlling a cooling fan. The fan turns on at 30°C and shouldn’t turn off until the temperature drops to 25°C to prevent short-cycling.
#include "adapnex.h"
class CoolingSystem : public Task {
public:
float current_temp = 0.0f; // Input
bool fan_active = false; // Output
private:
// Declare hysteresis block for float type
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);
}
};
Hysteresis With Delay
The HysteresisWithDelay block adds a time filter to the standard hysteresis logic.
Behavior:
This block functions identically to the standard Hysteresis, but with an added On-Delay for both transitions.
The input IN must cross and stay beyond the threshold for the duration PT before the output OUT switches state.
| Parameter | Type | Direction | Description |
|---|---|---|---|
|
template |
Input |
The analog signal to be evaluated. |
|
template |
Input |
Sets |
|
template |
Input |
Resets |
|
|
Input |
The delay duration required to confirm a state change. |
|
|
Output |
The filtered switching result. |
Common Use Case: Liquid level control in a tank with surface turbulence. The delay ensures that splashing or waves do not trigger false refilling cycles.
#include "adapnex.h"
class RefillTask : public Task {
public:
double tank_level = 0.0; // Input: 0.0 to 100.0%
bool valve_open = false; // Output
private:
HysteresisWithDelay<double> level_switch;
void Update() override {
// SET < RESET implies "Low Threshold" logic (Refill).
// Open Valve (True) when level drops <= 10%
// Close Valve (False) when level rises >= 90%
// Signal must be stable for 2 seconds (PT) to ignore waves.
level_switch(tank_level, 10.0, 90.0, 2s, valve_open);
}
};