Skip to content

Commit 3418ae8

Browse files
committed
Working on documentation, added debounce, hysteresis, kalman and rate_limit blocks
1 parent 404fe49 commit 3418ae8

10 files changed

Lines changed: 582 additions & 9 deletions

FILTERS.md

Lines changed: 561 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ The toolbox is divided into these categories:
198198
| **FastLED** | Initialize LED strip, set individual LED colour, show, clear |
199199
| **IMU** | Read yaw, pitch, roll, or acceleration from the on-board sensor |
200200
| **UI** | Display a labelled value in the IDE Logger panel, map visualization (plot position, clear) |
201-
| **Algorithms** | PID controller (init/compute/reset), dead reckoning (init/update/get/reset/set pose), moving average filter, map/scale |
201+
| **Algorithms** | PID controller (init/compute/reset), dead reckoning (init/update/get/reset/set pose), moving average filter, map/scale, hysteresis, debounce, rate limiter, 1D Kalman filter |
202202
| **Debug** | Free heap memory, milliseconds since boot |
203203

204204
> **Common gotcha:** The **Set motor speed** block is in the **I/O** category — not **LEGO©**. The **LEGO©** category only contains sensor blocks (selecting a measurement mode and reading the sensor dataset). If you want to drive a motor, open **I/O**.
@@ -369,6 +369,17 @@ Store the handle from `Init PID` in a variable and pass it to `PID compute` in y
369369

370370
For a full explanation including the math, calibration procedure, coordinate conventions, and example programs, see [DEADRECKONING.md](DEADRECKONING.md).
371371

372+
**Signal conditioning filters:** Four filters for cleaning up noisy or jerky signals before they reach your control logic. All use the same explicit handle pattern as PID and DR.
373+
374+
| Block pair | Description |
375+
|-----------|-------------|
376+
| `Initialize hysteresis` + `Hysteresis` | Schmitt trigger — output latches to 0 or 1, only switching when the input crosses a high or low threshold. Eliminates chatter at sensor boundaries. |
377+
| `Initialize debounce` + `Debounce` | Waits for a digital signal to be stable for a minimum number of milliseconds before updating output. Eliminates mechanical button bounce and contact noise. |
378+
| `Initialize rate limiter` + `Rate limit` | Limits how fast the output value can change per call, producing smooth acceleration ramps. Prevents wheel slip and encoder errors from sudden motor commands. |
379+
| `Initialize Kalman filter` + `Kalman filter` | 1D Kalman filter — weighted sensor smoothing based on process noise Q and measurement noise R. More principled than moving average for sensors with known noise characteristics. |
380+
381+
For intuition, math, tuning guidance, and pipeline examples, see [FILTERS.md](FILTERS.md).
382+
372383
### Map Visualization
373384

374385
The IDE sidebar includes a **live map panel** that renders the robot's trail as it moves. Use the **UI** category blocks to drive it:
@@ -470,3 +481,4 @@ The log (115200 baud) shows boot messages, port detection results, BLE connectio
470481
| [LUMP.md](LUMP.md) | LEGO Powered Up UART protocol technical specification |
471482
| [MEGAHUBIDE.md](MEGAHUBIDE.md) | Frontend IDE architecture — module structure, state, events, components, testing |
472483
| [DEADRECKONING.md](DEADRECKONING.md) | Dead reckoning guide — intuition, kinematics, math, coordinate conventions, Blockly usage, and calibration |
484+
| [FILTERS.md](FILTERS.md) | Signal conditioning filters guide — hysteresis, debounce, rate limiter, and 1D Kalman filter: intuition, math, tuning, and pipeline patterns |

frontend/src/components/blockly/mh_alg_debounce.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const definition = {
5959
tooltip:
6060
'Debounce filter for buttons and digital sensors. Output only changes when the input has been stable ' +
6161
'for the specified number of milliseconds. Returns 0 or 1. Typical stable time: 20–50 ms.',
62-
helpUrl: '',
62+
helpUrl: 'https://github.com/mirkosertic/Megahub/FILTERS.md',
6363
},
6464
generator: (block, generator) => {
6565
const handle = generator.valueToCode(block, 'HANDLE', 0) || '"db_0"';

frontend/src/components/blockly/mh_alg_debounce_init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const definition = {
1313
tooltip:
1414
'Creates a new debounce filter instance and returns a handle. ' +
1515
'Store in a variable and pass to the Debounce block.',
16-
helpUrl: '',
16+
helpUrl: 'https://github.com/mirkosertic/Megahub/FILTERS.md',
1717
},
1818
generator: (_block, _generator) => {
1919
return [`alg.initDebounce()`, 0];

frontend/src/components/blockly/mh_alg_hysteresis.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const definition = {
7070
tooltip:
7171
'Hysteresis (Schmitt trigger) filter. Output switches to 1 when value exceeds high threshold, ' +
7272
'and back to 0 when value drops below low threshold. Eliminates chatter near a threshold. Returns 0 or 1.',
73-
helpUrl: '',
73+
helpUrl: 'https://github.com/mirkosertic/Megahub/FILTERS.md',
7474
},
7575
generator: (block, generator) => {
7676
const handle = generator.valueToCode(block, 'HANDLE', 0) || '"hy_0"';

frontend/src/components/blockly/mh_alg_hysteresis_init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const definition = {
1313
tooltip:
1414
'Creates a new hysteresis (Schmitt trigger) instance and returns a handle. ' +
1515
'Store in a variable and pass to the Hysteresis block.',
16-
helpUrl: '',
16+
helpUrl: 'https://github.com/mirkosertic/Megahub/FILTERS.md',
1717
},
1818
generator: (_block, _generator) => {
1919
return [`alg.initHysteresis()`, 0];

frontend/src/components/blockly/mh_alg_kalman.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const definition = {
7474
'Kalman filter. Weighs measurements by noise characteristics for principled smoothing. ' +
7575
'Process noise Q: how much the true value drifts per call. Measure noise R: sensor variance. ' +
7676
'Starting values: color sensor Q=0.01 R=10, IMU Q=0.1 R=1.0.',
77-
helpUrl: '',
77+
helpUrl: 'https://github.com/mirkosertic/Megahub/FILTERS.md',
7878
},
7979
generator: (block, generator) => {
8080
const handle = generator.valueToCode(block, 'HANDLE', 0) || '"kf_0"';

frontend/src/components/blockly/mh_alg_kalman_init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const definition = {
1313
tooltip:
1414
'Creates a new 1D Kalman filter instance and returns a handle. ' +
1515
'Store in a variable and pass to the Kalman filter block.',
16-
helpUrl: '',
16+
helpUrl: 'https://github.com/mirkosertic/Megahub/FILTERS.md',
1717
},
1818
generator: (_block, _generator) => {
1919
return [`alg.initKalman()`, 0];

frontend/src/components/blockly/mh_alg_rate_limit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const definition = {
5959
tooltip:
6060
'Rate limiter (slew rate). Limits how fast the output value can change per call to avoid sudden jumps. ' +
6161
'On first call returns target immediately. The effective rate in units/second depends on how often the block is called.',
62-
helpUrl: '',
62+
helpUrl: 'https://github.com/mirkosertic/Megahub/FILTERS.md',
6363
},
6464
generator: (block, generator) => {
6565
const handle = generator.valueToCode(block, 'HANDLE', 0) || '"rl_0"';

frontend/src/components/blockly/mh_alg_rate_limit_init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const definition = {
1313
tooltip:
1414
'Creates a new rate limiter instance and returns a handle. ' +
1515
'Store in a variable and pass to the Rate limiter block.',
16-
helpUrl: '',
16+
helpUrl: 'https://github.com/mirkosertic/Megahub/FILTERS.md',
1717
},
1818
generator: (_block, _generator) => {
1919
return [`alg.initRateLimit()`, 0];

0 commit comments

Comments
 (0)