Skip to content

Commit 404fe49

Browse files
committed
Added support for Kalman, Debouce, Hysteresis and RateLimit blocks
1 parent df6069c commit 404fe49

33 files changed

Lines changed: 1551 additions & 205 deletions

BLOCKS.md

Lines changed: 142 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Blockly Blocks Documentation
22

3-
**Generated:** 2026-03-06
3+
**Generated:** 2026-03-07
44

5-
This documentation covers all 86 blocks used in the Megahub project, including 38 custom blocks and 48 standard Blockly blocks with custom colors.
5+
This documentation covers all 94 blocks used in the Megahub project, including 46 custom blocks and 48 standard Blockly blocks with custom colors.
66

77
Block images are rendered as high-quality PNG screenshots to accurately show all block features including text inputs, checkboxes, and statement blocks.
88

@@ -20,7 +20,7 @@ Block images are rendered as high-quality PNG screenshots to accurately show all
2020
- [FastLED](#fastled) (4 blocks)
2121
- [IMU](#imu) (1 blocks)
2222
- [UI](#ui) (3 blocks)
23-
- [Algorithms](#algorithms) (11 blocks)
23+
- [Algorithms](#algorithms) (19 blocks)
2424
- [Debug](#debug) (2 blocks)
2525

2626
## Control flow
@@ -1215,6 +1215,142 @@ output: %10 to %11`
12151215

12161216
---
12171217

1218+
### mh_alg_hysteresis_init
1219+
1220+
![mh_alg_hysteresis_init](docs/blocks/algorithms/mh_alg_hysteresis_init.png)
1221+
1222+
**Description:** Creates a new hysteresis (Schmitt trigger) instance and returns a handle. Store in a variable and pass to the Hysteresis block.
1223+
1224+
**Message:** `Initialize hysteresis`
1225+
1226+
---
1227+
1228+
### mh_alg_hysteresis
1229+
1230+
![mh_alg_hysteresis](docs/blocks/algorithms/mh_alg_hysteresis.png)
1231+
1232+
**Description:** Hysteresis (Schmitt trigger) filter. Output switches to 1 when value exceeds high threshold, and back to 0 when value drops below low threshold. Eliminates chatter near a threshold. Returns 0 or 1.
1233+
1234+
**Type:** Custom Value Block
1235+
1236+
**Message:** `Hysteresis %1 %2 value: %3
1237+
%4 low: %5 high: %6`
1238+
1239+
**Inputs:**
1240+
1241+
| Name | Type | Check |
1242+
|------|------|-------|
1243+
| HANDLE | input_value | Any |
1244+
| undefined | input_dummy | Any |
1245+
| VALUE | input_value | Number |
1246+
| undefined | input_dummy | Any |
1247+
| LOW | input_value | Number |
1248+
| HIGH | input_value | Number |
1249+
1250+
---
1251+
1252+
### mh_alg_debounce_init
1253+
1254+
![mh_alg_debounce_init](docs/blocks/algorithms/mh_alg_debounce_init.png)
1255+
1256+
**Description:** Creates a new debounce filter instance and returns a handle. Store in a variable and pass to the Debounce block.
1257+
1258+
**Message:** `Initialize debounce`
1259+
1260+
---
1261+
1262+
### mh_alg_debounce
1263+
1264+
![mh_alg_debounce](docs/blocks/algorithms/mh_alg_debounce.png)
1265+
1266+
**Description:** Debounce filter for buttons and digital sensors. Output only changes when the input has been stable for the specified number of milliseconds. Returns 0 or 1. Typical stable time: 20–50 ms.
1267+
1268+
**Type:** Custom Value Block
1269+
1270+
**Message:** `Debounce %1 %2 signal: %3
1271+
%4 stable ms: %5`
1272+
1273+
**Inputs:**
1274+
1275+
| Name | Type | Check |
1276+
|------|------|-------|
1277+
| HANDLE | input_value | Any |
1278+
| undefined | input_dummy | Any |
1279+
| SIGNAL | input_value | Number |
1280+
| undefined | input_dummy | Any |
1281+
| STABLE_MS | input_value | Number |
1282+
1283+
---
1284+
1285+
### mh_alg_rate_limit_init
1286+
1287+
![mh_alg_rate_limit_init](docs/blocks/algorithms/mh_alg_rate_limit_init.png)
1288+
1289+
**Description:** Creates a new rate limiter instance and returns a handle. Store in a variable and pass to the Rate limiter block.
1290+
1291+
**Message:** `Initialize rate limiter`
1292+
1293+
---
1294+
1295+
### mh_alg_rate_limit
1296+
1297+
![mh_alg_rate_limit](docs/blocks/algorithms/mh_alg_rate_limit.png)
1298+
1299+
**Description:** Rate limiter (slew rate). Limits how fast the output value can change per call to avoid sudden jumps. On first call returns target immediately. The effective rate in units/second depends on how often the block is called.
1300+
1301+
**Type:** Custom Value Block
1302+
1303+
**Message:** `Rate limit %1 %2 target: %3
1304+
%4 max Δ per call: %5`
1305+
1306+
**Inputs:**
1307+
1308+
| Name | Type | Check |
1309+
|------|------|-------|
1310+
| HANDLE | input_value | Any |
1311+
| undefined | input_dummy | Any |
1312+
| TARGET | input_value | Number |
1313+
| undefined | input_dummy | Any |
1314+
| MAX_DELTA | input_value | Number |
1315+
1316+
---
1317+
1318+
### mh_alg_kalman_init
1319+
1320+
![mh_alg_kalman_init](docs/blocks/algorithms/mh_alg_kalman_init.png)
1321+
1322+
**Description:** Creates a new 1D Kalman filter instance and returns a handle. Store in a variable and pass to the Kalman filter block.
1323+
1324+
**Message:** `Initialize Kalman filter`
1325+
1326+
---
1327+
1328+
### mh_alg_kalman
1329+
1330+
![mh_alg_kalman](docs/blocks/algorithms/mh_alg_kalman.png)
1331+
1332+
**Description:** Kalman filter. Weighs measurements by noise characteristics for principled smoothing. Process noise Q: how much the true value drifts per call. Measure noise R: sensor variance. Starting values: color sensor Q=0.01 R=10, IMU Q=0.1 R=1.0.
1333+
1334+
**Type:** Custom Value Block
1335+
1336+
**Message:** `Kalman filter %1 %2 measurement: %3
1337+
%4 process noise: %5
1338+
%6 measure noise: %7`
1339+
1340+
**Inputs:**
1341+
1342+
| Name | Type | Check |
1343+
|------|------|-------|
1344+
| HANDLE | input_value | Any |
1345+
| undefined | input_dummy | Any |
1346+
| MEASUREMENT | input_value | Number |
1347+
| undefined | input_dummy | Any |
1348+
| PROCESS_NOISE | input_value | Number |
1349+
| undefined | input_dummy | Any |
1350+
| MEASURE_NOISE | input_value | Number |
1351+
1352+
---
1353+
12181354
## Debug
12191355

12201356
### mh_debug_free_heap
@@ -1239,10 +1375,10 @@ output: %10 to %11`
12391375

12401376
## Generation Statistics
12411377

1242-
- Total blocks: 86
1243-
- Custom Megahub blocks: 38
1378+
- Total blocks: 94
1379+
- Custom Megahub blocks: 46
12441380
- Standard Blockly blocks: 48
1245-
- PNG images generated: 86
1381+
- PNG images generated: 94
12461382

12471383
---
12481384

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,27 @@ pio device monitor
9696
```
9797
Default baud rate: **115200**.
9898

99+
### Testing the IDE Without Hardware
100+
101+
You can run the Megahub IDE locally in your browser without a physical board. This is useful for exploring the interface, building Blockly programs, and inspecting generated Lua code — no firmware flashing required.
102+
103+
```bash
104+
cd frontend
105+
npm install
106+
npm run dev
107+
```
108+
109+
Vite starts a local development server (typically at `http://localhost:5173`). Open that URL in any browser.
110+
111+
**What works in dev mode:**
112+
- Full IDE UI — project management, Blockly workspace, toolbox
113+
- Blockly drag-and-drop programming and real-time Lua code generation
114+
- Lua Preview panel — inspect the generated code for any program
115+
116+
**What does not work:**
117+
- Connecting to a device (no BLE in dev mode)
118+
- Executing or stopping programs — the **Execute** button requires a live connection to the firmware
119+
99120
---
100121

101122
## Hardware Reference
13.7 KB
Loading
4.36 KB
Loading
16.7 KB
Loading
5.38 KB
Loading
20.8 KB
Loading
4.23 KB
Loading
13.6 KB
Loading
4.24 KB
Loading

0 commit comments

Comments
 (0)