WindowDetector
WindowDetector watches one signal against four levels and raises a flag for each.7 minute read
WindowDetector watches one signal against four levels and raises a flag
for each. The inner pair — low and high — is a warning band; the outer pair
— tooLow and tooHigh — is an error band. A time window stops noise from
tripping them.
Use it to supervise a pressure, a temperature, a torque or a following error, and to distinguish “worth knowing about” from “stop now”.
flowchart LR
i1(["input"]) --> B["WindowDetector"]
i2(["reset"]) --> B
i3(["disable"]) --> B
p1(["tooLow, low, high, tooHigh"]) --> B
p2(["timeWindow, enable, autoreset, id"]) --> B
B --> o1(["isTooLow, isLow, isHigh, isTooHigh"])
B --> o2(["noWarning, noError"])
B --> o3(["isEnabled"])
B --> o4(["state"])
The bands are nested, not exclusive. A signal below
tooLowis also belowlow, soisTooLowandisLoware both true. For “warning but not error”, testisLowand notisTooLowyourself.
The flags latch. Once raised they stay raised until you reset, disable, or turn
autoreseton. That is what you want for a fault you might otherwise miss between polls.
A signal that is not a number trips all four flags and clears both summaries. This is deliberate: a broken sensor reads as an error rather than as perfectly in range.
Signals
Inputs
| Path | Unit | Range | Description |
|---|---|---|---|
input |
signal unit | unbounded | The signal to watch. A value that is not a number raises every flag. |
reset |
- | true or false | Clears all four flags and their timers. You do not need to write it back to false — the block notices when you stop writing it and clears it for you. |
disable |
- | true or false | Suspends detection and clears the flags. Re-enabling starts clean. |
Outputs
| Path | Unit | Description |
|---|---|---|
isTooLow |
- | The input has been at or below tooLow for timeWindow. Error level. Latches. |
isLow |
- | At or below low. Warning level. Latches. Also true whenever isTooLow is. |
isHigh |
- | At or above high. Warning level. Latches. |
isTooHigh |
- | At or above tooHigh. Error level. Latches. Also raises isHigh. |
noWarning |
- | Neither warning flag is raised. Starts true. |
noError |
- | Neither error flag is raised. Starts true. Test this one to decide whether to stop. |
isEnabled |
- | Detection is running. |
state |
- | All of the above as a single signal, plus id. Subscribe to this instead of seven separate flags when a supervising task needs the whole picture. |
Parameters
| Path | Unit | Default | Range | Effect |
|---|---|---|---|---|
tooLow |
signal unit | -0.05 | unbounded | Lower error level. Trips at or below. |
low |
signal unit | -0.02 | unbounded | Lower warning level. |
high |
signal unit | 0.02 | unbounded | Upper warning level. Trips at or above. |
tooHigh |
signal unit | 0.05 | unbounded | Upper error level. |
timeWindow |
s | 0.0 | 0 upward | How long the input must stay out of range before the flag latches. At the default of 0 a single sample trips it, so a noisy signal will chatter. Each band times independently. |
enable |
- | true | - | Turns detection on. When off, the flags are held clear. |
autoreset |
- | false | - | Clears the flags every cycle, so they follow the current condition instead of latching. Useful when a supervising task polls faster than the condition changes. |
id |
- | 0 | 0 upward | A number carried inside state, so a task receiving several detectors' states can tell them apart. |
All are persistent and survive a controller restart. Nothing checks that the four levels are in order — an inverted pair is accepted and is a legitimate way to disable a band. No parameters exist below this block.
Setup
- Connect the signal you want to supervise to
input. - Set the two error levels first, from what the machine cannot tolerate.
- Set the two warning levels inside them, from what you want to know about early.
- Leave
timeWindowat 0 and watch the machine run normally. If any flag trips, either a level is too tight or the signal is noisy. - Set
timeWindow— go to Tuning. - Confirm
noErroris true during normal operation and goes false when you deliberately push the signal past an error level. - Pulse
resetand confirm all four flags clear.
This block only watches a signal and raises flags. It does not move anything
and cannot be made to — but whatever acts on noError downstream will act the
moment it goes false.
Tuning
- Trace
inputfor a full normal cycle of the machine, including startup. Note the largest excursion that is not a fault — startup spikes are the usual culprit. - Set the error levels outside that, with margin.
- Set the warning levels where you want to be told early. There is no rule here; halfway between normal and the error level is a reasonable start.
- Set
timeWindowlonger than the longest spike you want to ignore and shorter than the fastest fault you must catch. For a noisy signal this is usually tens of milliseconds. - Re-run and confirm the flags stay clear through the normal cycle.
- Push the signal past each level in turn and confirm the right flag latches,
after roughly
timeWindow. - If you cannot find a
timeWindowthat ignores the noise and still catches the fault, filter the input upstream instead of widening the levels. timeWindowis in seconds, so a task-rate change does not move it.
The time window is what separates a spike from an excursion.
| Symptom | Cause | Action |
|---|---|---|
| A flag trips on noise | timeWindow is 0 or too short |
Lengthen it, or filter the input |
| A flag tripped during startup | A startup spike crossed a level | Lengthen timeWindow, or hold disable true until the machine is running |
isLow and isTooLow are both true |
Expected: the bands are nested | Test isLow and not isTooLow for warning only |
| A flag will not clear | Expected: the flags latch | Pulse reset, or set autoreset |
| The flags clear on their own | autoreset is on |
Turn it off if you need latching |
I wrote reset and it went back to false |
Expected: the block clears it once you stop writing | Nothing |
| Nothing is ever detected | enable is false, disable is true, or the levels are outside anything the signal reaches |
Check isEnabled first |
| The flags cleared when I disabled it | Expected: disabling clears them and re-enabling starts clean | Read them before disabling |
| Everything trips at once and stays tripped | The input is not a valid number | Fix the upstream signal; this is the block telling you so |
A flag trips later than timeWindow |
Expected: the window is rounded up to a whole number of cycles | Nothing |
| The flags disagree with the levels I set | The levels may be inverted — nothing checks their order | Read all four back |
| A flag tripped one cycle after I disabled it | Expected: the check runs once more, and the result is then cleared | Nothing |
| The timers seem stale right after a restart | The flags clear at startup but the timers do not | Pulse reset after starting |
| I need to watch several signals | Not possible — this block is single channel | Use one instance per signal, each with its own id |
A starting point for a following error in metres:
tooLow = -0.05
low = -0.02
high = 0.02
tooHigh = 0.05
timeWindow = 0.02
enable = true
autoreset = false
Those are also the defaults for the four levels, so an unconfigured detector already watches a symmetric band around zero.
Limits and errors
| Limit | Set by | What happens | Reported |
|---|---|---|---|
| Warning band | low, high |
Flags latch at or beyond the level, after timeWindow |
isLow, isHigh, noWarning |
| Error band | tooLow, tooHigh |
Same, at the outer levels | isTooLow, isTooHigh, noError |
| Band nesting | Fixed | The bands overlap by design: an error also raises its warning | Not reported |
| Level ordering | Nothing | Not checked. Inverted levels are accepted and produce overlapping bands | Not reported |
| Debounce | timeWindow |
Each band times independently. The window is rounded up to a whole number of cycles | Not reported |
| Latching | Fixed, unless autoreset |
Flags stay raised until reset, disabled, or auto-reset | Not reported |
| Values that are not numbers | Checked | All four flags are raised and both summaries cleared | The flags themselves |
| Reset | reset |
Clears the flags and the timers. Clears itself when you stop writing it | Not reported |
| Disable | disable, enable |
Detection stops and the flags clear. Re-enabling starts clean | isEnabled |
| Startup | Fixed | The flags clear, the timers do not | Not reported |
| Channel count | Fixed | One signal per instance, always | Not reported |
This block logs nothing, ever. Every condition above shows as a value on a trace, or not at all.
Verified against motorcortex-control3 3.30.0 (bc348fd).