AverageValueCheck
AverageValueCheck measures the true average of a signal over a fixed duration, on demand, and compares that average against four levels.7 minute read
AverageValueCheck measures the true average of a signal over a fixed
duration, on demand, and compares that average against four levels.
Use it for a bounded test rather than continuous supervision: sample a pressure for two seconds after a valve closes, or a torque after a move settles, and decide whether the result is acceptable.
flowchart LR
i1(["input"]) --> B["AverageValueCheck"]
i2(["activate"]) --> B
p1(["duration"]) --> B
p2(["tooLow, low, high, tooHigh"]) --> B
B --> o1(["average"])
B --> o2(["sum"])
B --> o3(["counter"])
B --> o4(["busy"])
B --> o5(["isTooLow, isLow, isHigh, isTooHigh"])
The average is exact, not filtered — every sample over the window carries equal weight.
sumandcounterare published so you can check the arithmetic yourself.
All four levels default to 0. Until you set them,
isHighandisTooHighare true for any positive average. Set all four before reading any flag.
The result persists after the measurement ends, which is what makes the block useful — but the flags are also computed before any measurement has run, from an average of zero. Read
counteralongside them: acounterof 0 means no measurement has happened.
Signals
Inputs
| Path | Unit | Range | Description |
|---|---|---|---|
input |
signal unit | unbounded | Sampled once per cycle while the measurement runs. A value that is not a number spoils the whole measurement and makes all four flags read false — see Limits. |
activate |
- | true or false | A rising edge starts a measurement. Holding it true does not start another. The block does not clear it — lower it yourself, or no further measurement can ever be triggered. |
Outputs
| Path | Unit | Description |
|---|---|---|
average |
signal unit | The average so far, and the final result once busy falls. Readable while the measurement runs. Holds the last result until the next measurement. |
sum |
signal unit | The running total. |
counter |
- | How many samples have been taken. 0 means no measurement has ever run — check this before trusting the flags. |
busy |
- | The measurement is running. Falls when the duration elapses. |
isTooLow |
- | average is below tooLow. Does not latch — it always describes the current average. |
isLow |
- | Below low. Also true whenever isTooLow is. |
isHigh |
- | Above high. |
isTooHigh |
- | Above tooHigh. Also raises isHigh. |
Parameters
| Path | Unit | Default | Range | Effect |
|---|---|---|---|---|
duration |
s | 1.0 | above 0 | How long a measurement runs. The number of samples is the duration divided by the task period, rounded up. A value of 0 or below is not rejected: the measurement ends immediately, counter and sum read 0, and average keeps its previous value. |
tooLow |
signal unit | 0.0 | unbounded | Lower error level. |
low |
signal unit | 0.0 | unbounded | Lower warning level. |
high |
signal unit | 0.0 | unbounded | Upper warning level. |
tooHigh |
signal unit | 0.0 | unbounded | Upper error level. |
All are persistent and survive a controller restart. Nothing checks that the four levels are in order. No parameters exist below this block.
The bands are nested: with the intended ordering, an error also raises its
warning. For “warning but not error”, test isLow and not isTooLow.
Setup
- Connect the signal you want to measure to
input. - Set
durationto how long you want to sample for. - Set all four levels. They default to 0, and until you set them the flags are meaningless.
- Bring the machine to the state you want to measure.
- Raise
activatefrom false to true and confirmbusygoes true. - Lower
activateagain. The block will not clear it for you, and a second measurement needs a fresh rising edge. - Wait for
busyto fall, then readaverageandcounter. Confirmcountermatches the duration divided by your task period.
This block only measures and compares. It does not move anything and cannot be made to.
Tuning
- Set
durationfrom the physics, not from convenience. It must be long enough to average out the noise and short enough that the quantity has not changed by the end. - Trigger a measurement with the machine in a known-good state and record the
average. Repeat it a few times to see the spread between runs. - Set the error levels outside that spread, with margin.
- Set the warning levels inside them, where you want to be told early.
- Trigger with the machine in a known-bad state and confirm the right flags come up.
- If the spread between runs is too wide to place levels, lengthen
duration— the spread falls roughly with the square root of the sample count. - Watch
averagewhile a measurement runs to see how quickly it settles. If it is still moving at the end,durationis too short. durationis in seconds, so a task-rate change does not move it — butcounterwill change, because the sample count depends on the rate.
The average is readable while the measurement runs. Only the value once busy
falls is the result.
| Symptom | Cause | Action |
|---|---|---|
| The flags are set and nothing has been measured | The levels default to 0, and the flags describe an average of 0 | Check counter — 0 means no measurement. Set the four levels |
| A second measurement never started | activate is still true; the trigger is a rising edge |
Lower activate before raising it again |
counter reads 0 after triggering |
duration is 0 or negative |
Set it above 0 |
average looks stale and counter is 0 |
Same cause: the measurement ended immediately and left the old result | Set duration above 0 |
average is still moving when busy falls |
duration is too short for the signal |
Lengthen it |
| Results vary a lot between runs | The window is too short to average out the noise | Lengthen duration |
isLow and isTooLow are both true |
Expected: the bands are nested | Test isLow and not isTooLow |
| The flags cleared by themselves | Expected: they do not latch, they follow average |
Use WindowDetector if you need latching |
| All four flags are false and the reading looks wrong | A sample that was not a valid number spoiled the measurement | Fix the upstream signal; check average |
| A measurement carried on after a restart | The block does not clear its state at startup | Trigger a fresh measurement after every start |
counter changed after a task-rate change |
Expected: the sample count depends on the rate, the duration does not | Nothing |
| I need continuous supervision, not a one-shot test | Wrong block | Use WindowDetector |
| I need a continuously updating average | Wrong block | Use MovingAverageFilter |
| I need to suspend it | Not possible — there is no enable | Leave activate low |
| I need to measure several signals | Not possible — this block is single channel | Use one instance per signal |
A starting point for a settled-torque check:
duration = 2.0
tooLow = -5.0
low = -2.0
high = 2.0
tooHigh = 5.0
Limits and errors
| Limit | Set by | What happens | Reported |
|---|---|---|---|
| Measurement window | duration |
Runs for that long, then stops on its own | busy, counter |
duration at 0 or below |
Nothing | Not checked. The measurement ends immediately, counter and sum read 0, and average keeps its previous value |
counter reads 0 |
| Trigger | activate |
Rising edge only. The block never clears it, so a stuck-true input prevents all further measurements | busy |
| Averaging | Fixed | The exact arithmetic mean, every sample weighted equally | sum, counter |
| Level ordering | Nothing | Not checked. The bands are nested by design | Not reported |
| Level defaults | Fixed at 0 | Every flag is meaningful from startup, describing an average of zero | counter reads 0 |
| Flag latching | Fixed | The flags do not latch — they always describe the current average |
Not reported |
| Values that are not numbers | Nothing | Not checked. One bad sample spoils the whole average, and all four flags then read false — a broken sensor reads as acceptable | average |
| Startup | Fixed | No state is cleared. A measurement interrupted by a restart resumes and keeps accumulating into the same total | busy, counter |
| Enable | None | There is no enable, disable or isEnabled | Not applicable |
| 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).