MOSS: a small, mostly 3D-printed litter-picking rover. Cleaner streets, one maker at a time.
Python
Add Orange Pi and MightyCam experimental load-test package (#13)
metr0x6e0617aecb74
diff --git a/README.md b/README.mdindex 82f9da5..b167ed5 100644--- a/README.md+++ b/README.md@@ -40,6 +40,7 @@ I pick up litter by hand on my walks. MOSS is the robot I want next to me doing## News+- 27 October 2026: **[Orange Pi + MightyCam experiment](experiments/orange-pi-mightycam/)** — dimOS, YOLO on the NPU and a first memory/load test with simulated rover I/O. Code, cockpit image and the limits of this early bench demo.- 27 October 2026: **[SO-101 dual-servo shoulder R2: complete upgrade guide](hardware/mechanical/dual-shoulder-r2/)** — editable CAD, two printable parts, screws, assembly, paired-servo setup and testing in one place.- 24 October 2026: **BOM and print plates updated.** Hoco HB1 four-port hub, GameSir Nova 2 Lite controller, all 38 spacers on one plate, and one tensioner-slider reference (print four). [Updated package](https://github.com/metrox-eth/moss/releases/download/v0.6-r92/MOSS_R92_Mechanical_20261024.zip) · [Print plates](https://www.showrobotics.ai/moss/build/print-plates.html).- 18 October 2026: **Ready-to-print plates are available.** [H2S: one-piece hull and cover](https://github.com/metrox-eth/moss/releases/download/v0.6-r92/MOSS_V06_R92_H2S_Print_Plates.3mf) or [P1 / P2: split hull and cover](https://github.com/metrox-eth/moss/releases/download/v0.6-r92/MOSS_V06_R92_256mm_Split_Print_Plates.3mf). The [updated package](https://github.com/metrox-eth/moss/releases/download/v0.6-r92/MOSS_R92_Mechanical_20261018.zip) includes both Jetson retaining tabs, grouped STLs with quantities, and both 3MF projects. [Choose your plates](https://www.showrobotics.ai/moss/build/print-plates.html).diff --git a/experiments/README.md b/experiments/README.mdnew file mode 100644index 0000000..d6e4908--- /dev/null+++ b/experiments/README.md@@ -0,0 +1,5 @@+# MOSS experiments++Bench work and early ideas for MOSS, the litter-picking rover. These folders are separate from the supported build instructions and describe their own limits.++- **[Orange Pi + MightyCam](orange-pi-mightycam/)** — a $60 computer, an $80 camera, dimOS and YOLO on the NPU. First load measurements, source code and a cockpit image; camera accuracy and robot autonomy remain unvalidated.diff --git a/experiments/orange-pi-mightycam/.gitignore b/experiments/orange-pi-mightycam/.gitignorenew file mode 100644index 0000000..6004a5c--- /dev/null+++ b/experiments/orange-pi-mightycam/.gitignore@@ -0,0 +1,7 @@+runtime/+.venv/+build/+dist/+*.egg-info/+__pycache__/+*.pycdiff --git a/experiments/orange-pi-mightycam/README.md b/experiments/orange-pi-mightycam/README.mdnew file mode 100644index 0000000..a18ea59--- /dev/null+++ b/experiments/orange-pi-mightycam/README.md@@ -0,0 +1,58 @@+# dimOS × $60 Orange Pi × $80 MightyCam++Fresh hardware on the bench, and a question: how cheap can we make the brains and perception for **MOSS, the litter-picking rover**?++This is our first experiment with an **Orange Pi Zero 3W, 6 GB**, and a **MightyCam**, carried around the workshop on a power bank. We loaded MOSS/dimOS and ran YOLO on the Orange Pi's NPU. Whole-system memory use was around **1.6–1.7 GiB**.++**This is a load-test demo, not a working autonomous rover configuration.** No real motors or servos were driven. The trajectory drifted badly, calibration still needs investigating, and the detector recognizes everyday objects rather than litter.++++*A frame from the first recording on 27 October 2026. The trajectory is the camera's reported path; it is not a validated map or distance measurement.*++## What we tested++- Real MightyCam images and pose messages over USB. **VIO runs in the camera**, and dimOS receives its output on the Orange Pi.+- YOLOv5 with ordinary COCO classes, running through the **A733 NPU / VIPLite** backend. This is not our litter detector.+- MOSS modules loaded together: base and arm controllers, LiDAR odometry, costmap, planner, exploration, recording and the mission module. LiDAR scans and actuator buses are simulated; the planner and mission are not completing a physical task.+- A browser cockpit with two camera views, the reported trajectory, eight CPU meters, RAM, NPU timing and temperature. **Record** saves a silent 1080p landscape video, up to 30 seconds. **Reset path** clears/rebases the displayed trace only.++## First measurements++| Measurement | Observed on this setup |+|---|---|+| Whole-system RAM, loaded bench | About 1.6–1.7 GiB used, out of 5.7 GiB usable |+| Swap during the checked samples | 0 |+| NPU network inference, YOLOv5 at 640 × 640 | About 26–30 ms |+| Complete detector pipeline | About 330–390 ms per image |+| Displayed detection throughput | About 2.6–2.8 images/s |++The NPU number is **only the network execution time**. Image handling, model setup, output conversion and drawing take additional time. RAM is Linux `MemTotal - MemAvailable`, including the operating system; it is not just one Python process. CPU meters use per-core `/proc/stat` deltas. See the [measurement snapshot](results/2026-10-27.json) for the conditions and stream counts.++The $60 and $80 figures are the component prices used for this experiment, not the price of a complete rover. The power bank, SD card and cooling kit are additional.++## What did not work++The first path looked plausible, but it failed to return to the starting point. Later, the camera reported much more travel than the real movement, and a restart produced wildly diverging coordinates. A `TRACKING` status did **not** establish accurate scale or position.++The camera's calibration request returned `calib.yaml not found`. That is an unresolved finding, not proof of the sole cause: initialization, camera/IMU calibration, synchronization and firmware still need checking. We have not calibrated this setup or validated navigation or pickup. See [Mighty's calibration guide](https://mightycamera.com/docs/calibration) and [pose-usability documentation](https://mightycamera.com/docs/sdk/pose).++The camera also once resumed images with VIO stopped after a stream interruption. The current adapter starts VIO at launch but does not automatically recover every stopped-tracking case. Resetting the drawn path cannot fix that or correct drift.++## Code and running it++Start with [SETUP.md](SETUP.md). Three profiles are included:++| Profile | Contents |+|---|---|+| `mighty` | Camera, VIO messages and cockpit |+| `demo` | Camera + NPU detector + cockpit |+| `full-bench` | The above plus MOSS modules with simulated rover I/O |++Only run one profile at a time: they share the dimOS coordinator and LCM bus. `full-bench` forces simulated motor/servo interfaces. It is intended for this tabletop experiment, not installation on a moving rover.++The Python package is in [`moss_mighty/`](moss_mighty/). The cockpit lives beside it. [`scripts/`](scripts/) contains the launcher and a pinned downloader/build helper for the upstream NPU example. [`tests/`](tests/) contains software checks; passing them does not validate camera accuracy.++Tested platform: Orange Pi **Zero 3W / Allwinner A733**, Armbian 26.8.1 / Debian 13, vendor kernel 6.6.98, Python 3.12. This is not the older H618 Orange Pi Zero 3. [Exact source revisions and credits](SOURCES.md).++Next: establish a reliable camera/IMU calibration, measure a known distance and a return-to-start path, then look at a litter-specific detector. For now, this gives us a first look at what fits on a small, inexpensive computer.diff --git a/experiments/orange-pi-mightycam/SETUP.md b/experiments/orange-pi-mightycam/SETUP.mdnew file mode 100644index 0000000..af8ec30--- /dev/null+++ b/experiments/orange-pi-mightycam/SETUP.md@@ -0,0 +1,77 @@+# Running the experimental bench++This is a source snapshot of the first bench session, not a ready-to-flash OS image. It does not provision Wi-Fi, change SSH access, flash firmware or configure a real rover.++## Board and camera++Use the **A733 Orange Pi Zero 3W**, with its cooler installed, a suitable power supply, and an ARM64 vendor image that provides `/dev/vipcore`. The measured system used Armbian 26.8.1 / Debian 13 with kernel `6.6.98-vendor-sun60iw2`. The NPU helper below supplies user-space libraries, not a kernel driver.++Connect MightyCam with a **USB data cable**. Its USB network interface should have an address on the camera's subnet. Our camera is served at `http://192.168.7.1`; check it from the Orange Pi. No extra camera stream needs to be opened in another application.++## Python environment++These commands are run on the Orange Pi from the **MOSS repository root**. They use `uv` and a Python 3.12 virtual environment.++```sh+sudo apt-get install build-essential pkg-config git python3-venv \+ libgl1 libegl1 libglib2.0-0 libgomp1 libturbojpeg0 libusb-1.0-0 \+ libsdl2-2.0-0 libsdl2-image-2.0-0 libsdl2-mixer-2.0-0 libsdl2-ttf-2.0-0 \+ libopencv-core-dev libopencv-imgcodecs-dev libopencv-imgproc-dev libjpeg-dev++uv venv --python 3.12 .venv+DIMOS_ALLOW_MISSING_COCKPIT=1 uv pip install --python .venv/bin/python \+ -r experiments/orange-pi-mightycam/requirements.txt+uv pip install --python .venv/bin/python -e '.[nav,gamepad]' \+ -e ./experiments/orange-pi-mightycam+```++The dimOS and Mighty SDK revisions are pinned. Current upstream versions may change the blueprint APIs. Use the LCM loopback configuration in [MOSS software setup](../../Software.md) if multicast transport is not already configured.++## Build the NPU example++The vendor libraries, pretrained model and example sources are **not included in this repository**. This downloads the small set of required files from the pinned upstream revision, checks their SHA-256 hashes, then builds the example on the board:++```sh+python3 experiments/orange-pi-mightycam/scripts/fetch_npu.py+bash experiments/orange-pi-mightycam/scripts/build_npu.sh+```++Files go under this experiment's ignored `runtime/npu-sdk/` directory. The helper replaces an unused HighGUI include with `imgcodecs` and corrects the end iterator of the sample's output-vector copies. It does not install libraries globally. Upstream components retain their own terms; see [SOURCES.md](SOURCES.md).++## Start one profile++```sh+bash experiments/orange-pi-mightycam/scripts/run.sh demo+```++For the additional simulated rover load, stop the first process with Ctrl-C, then run:++```sh+bash experiments/orange-pi-mightycam/scripts/run.sh full-bench+```++Open **`http://<orange-pi-ip>:8905/`** in a browser on the same LAN. Include the port. If a Mac browser cannot reach the board while other applications can, check that browser's macOS **Local Network** permission.++`Record` saves the current camera views, trajectory and measurements as a 1920 × 1080 video, using the browser's available encoder (MP4 or WebM). It stops after 30 seconds or when you press `Stop`. It records no audio and sends no video to a cloud service. Reset the displayed path before a new take if desired; this does not reset or calibrate Mighty VIO.++Settings may be overridden with `MOSS_MIGHTY_URL`, `MOSS_MIGHTY_WEB_PORT`, `MOSS_MIGHTY_DATA_DIR`, `MOSS_NPU_SDK`, `MOSS_YOLO_FPS` and `MOSS_DIMOS`. The launcher defaults to experiment-local runtime storage. The package alone defaults to `~/.local/share/moss-mighty/`.++The CPU detector fallback is retained in the source but is not the measured NPU profile. It additionally needs CPU builds of PyTorch/torchvision, Ultralytics, and a local model selected by `MOSS_YOLO_MODEL`; those weights and dependencies are not bundled.++## Checks++Standard-library tests, without hardware or the full dimOS environment:++```sh+PYTHONPATH=experiments/orange-pi-mightycam python3 -m unittest discover \+ -s experiments/orange-pi-mightycam/tests -p 'test_core.py' -v+```++With the installed environment, the message, SDK and HTTP tests can also run:++```sh+.venv/bin/python -m unittest discover \+ -s experiments/orange-pi-mightycam/tests -p 'test_integration.py' -v+```++The original bench passed 14 software checks. Physical VIO accuracy failed during the handheld trial and remains unvalidated; a passing software test is not a substitute for calibration and a measured trajectory.diff --git a/experiments/orange-pi-mightycam/SOURCES.md b/experiments/orange-pi-mightycam/SOURCES.mdnew file mode 100644index 0000000..80c5118--- /dev/null+++ b/experiments/orange-pi-mightycam/SOURCES.md@@ -0,0 +1,25 @@+# Sources and measurement provenance++Session: **27 October 2026**, Show Robotics workshop. Code and screenshot are part of the MOSS experimental collection.++| Component | Revision / version used |+|---|---|+| MOSS runtime | `1590dcb1c4c58181c037738d44a22e3940f982db` |+| [dimOS](https://github.com/dimensionalOS/dimos) | `a7d19f76158b01739b26e7a17390f89764aaef83` (`0.0.14b1`) |+| [Mighty SDK](https://github.com/asadm/mighty-protocol) | `aeb060e36a6cc25edae9153b4806dbfa99c343a4` |+| Mighty camera firmware | `Mighty v.2026-10-01-e2aac61` |+| [A733 NPU example / libraries](https://github.com/ZIFENG278/ai-sdk) | `fc90006d0f6569da2f6726c2d8395877686f5aca` |+| VIPLite runtime reported by the board | `2.0.3.2-AW-2024-08-30` |+| NPU model | Upstream `examples/yolov5/model/v3/yolov5.nb`, COCO classes, 640 × 640 |++The A733 NPU route was taken from the [Radxa A733 documentation](https://docs.radxa.com/en/cubie/a7s/app-dev/npu-dev/cubie-vpm-run), then tested on this Orange Pi. No Rockchip RKNN or Jetson CUDA runtime is used for this NPU path.++The NPU wrapper runs the native example once per processed frame. Model setup, JPEG I/O, preprocessing, output copies and postprocessing explain why total pipeline time is much longer than network execution. A persistent native worker is a possible later optimization, not part of these measurements.++The 20.42-second integration sample used a 1 Hz detector cap and a CPU quota equivalent to four cores. The handheld recording used a 3 Hz cap. Both had the cooler installed and the same live camera. Synthetic scans exercised odometry and costmap generation; planner and mission modules were loaded but idle, and controllers used in-memory/mock interfaces.++The cockpit derives from MOSS's existing cockpit, with **Space Grotesk** and MOSS assets. Font copyright: The Space Grotesk Project Authors; the [SIL OFL license](moss_mighty/cockpit/fonts/SpaceGrotesk-OFL.txt) is included. New code follows the repository's Apache-2.0 license. Documentation and the demo frame follow the repository's CC BY 4.0 media terms.++The downloader references upstream model weights and VIPLite binaries; their licenses are not changed by this repository. These files are not redistributed in Git. The [file manifest](scripts/npu-files.json) records the exact upstream inputs and hashes.++No OS image, workshop network configuration, SSH setup, private credentials or complete camera recordings are included.diff --git a/experiments/orange-pi-mightycam/assets/first-load-test.jpg b/experiments/orange-pi-mightycam/assets/first-load-test.jpgnew file mode 100644index 0000000..c0f9c5dBinary files /dev/null and b/experiments/orange-pi-mightycam/assets/first-load-test.jpg differdiff --git a/experiments/orange-pi-mightycam/moss_mighty/__init__.py b/experiments/orange-pi-mightycam/moss_mighty/__init__.pynew file mode 100644index 0000000..bdbaae9--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/__init__.py@@ -0,0 +1 @@+"""MightyCam-only MOSS bench: no actuator dependencies or commands."""diff --git a/experiments/orange-pi-mightycam/moss_mighty/cockpit/UPSTREAM.json b/experiments/orange-pi-mightycam/moss_mighty/cockpit/UPSTREAM.jsonnew file mode 100644index 0000000..e26124a--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/cockpit/UPSTREAM.json@@ -0,0 +1,11 @@+{+ "source": "metrox-eth/moss",+ "revision": "1590dcb1c4c58181c037738d44a22e3940f982db",+ "paths": [+ "tools/moss_cockpit/index.html",+ "tools/moss_cockpit/tokens.css",+ "tools/moss_cockpit/assets/",+ "tools/moss_cockpit/fonts/"+ ],+ "adaptation": "Mighty/Orange Pi tabletop profile; existing cockpit style and layout, dedicated camera/VIO/resource bindings."+}diff --git a/experiments/orange-pi-mightycam/moss_mighty/cockpit/assets/mark-mint.svg b/experiments/orange-pi-mightycam/moss_mighty/cockpit/assets/mark-mint.svgnew file mode 100644index 0000000..edc26c1--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/cockpit/assets/mark-mint.svg@@ -0,0 +1 @@+<svg xmlns="http://www.w3.org/2000/svg" width="393" height="353" viewBox="16.0 16.0 393.0 353.0" role="img"><title>mark-mint</title><polygon points="32.000000,352.000000 32.000000,32.000000 112.000000,32.000000 212.000000,212.000000 312.000000,32.000000 392.000000,32.000000 392.000000,352.000000 312.000000,352.000000 312.000000,172.000000 212.000000,332.000000 112.000000,172.000000 112.000000,352.000000" fill="#6cf8c7"/></svg>diff --git a/experiments/orange-pi-mightycam/moss_mighty/cockpit/assets/wordmark-white.svg b/experiments/orange-pi-mightycam/moss_mighty/cockpit/assets/wordmark-white.svgnew file mode 100644index 0000000..00e3313--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/cockpit/assets/wordmark-white.svg@@ -0,0 +1 @@+<svg xmlns="http://www.w3.org/2000/svg" width="675" height="219" viewBox="33.0 13.0 675.0 219.0" role="img"><title>wordmark-white</title><path fill="#eaf0ef" d="M48.896 212.0V32.79999999999998H111.616L142.59199999999998 188.96H147.2L178.17600000000002 32.79999999999998H240.89600000000002V212.0H208.12800000000001V57.632000000000005H203.52L172.8 212.0H116.992L86.27199999999999 57.632000000000005H81.664V212.0Z"/><path fill="#eaf0ef" d="M330.528 215.584Q296.736 215.584 276.76800000000003 197.024Q256.8 178.464 256.8 143.904V100.896Q256.8 66.33599999999998 276.76800000000003 47.775999999999996Q296.736 29.216000000000008 330.528 29.216000000000008Q364.32 29.216000000000008 384.288 47.775999999999996Q404.256 66.33599999999998 404.256 100.896V143.904Q404.256 178.464 384.288 197.024Q364.32 215.584 330.528 215.584ZM330.528 185.376Q349.472 185.376 359.96799999999996 174.368Q370.464 163.36 370.464 144.928V99.872Q370.464 81.44 359.96799999999996 70.432Q349.472 59.42400000000001 330.528 59.42400000000001Q311.84000000000003 59.42400000000001 301.216 70.432Q290.592 81.44 290.592 99.872V144.928Q290.592 163.36 301.216 174.368Q311.84000000000003 185.376 330.528 185.376Z"/><path fill="#eaf0ef" d="M483.104 215.584Q462.368 215.584 446.496 208.16Q430.624 200.736 421.664 186.91199999999998Q412.704 173.088 412.704 153.632V146.464H445.984V153.632Q445.984 169.76 455.96799999999996 177.824Q465.952 185.888 483.104 185.888Q500.512 185.888 509.08799999999997 178.976Q517.664 172.064 517.664 161.312Q517.664 153.888 513.44 149.28Q509.216 144.672 501.15200000000004 141.728Q493.088 138.784 481.568 136.224L475.68 134.94400000000002Q457.248 130.848 444.06399999999996 124.57600000000001Q430.88 118.304 423.84000000000003 108.064Q416.8 97.824 416.8 81.44Q416.8 65.05599999999998 424.608 53.40799999999999Q432.416 41.75999999999999 446.624 35.488Q460.832 29.216000000000008 480.032 29.216000000000008Q499.23199999999997 29.216000000000008 514.208 35.744Q529.184 42.27199999999999 537.76 55.19999999999999Q546.336 68.12799999999999 546.336 87.584V95.264H513.056V87.584Q513.056 77.344 509.088 71.07199999999999Q505.12 64.79999999999998 497.696 61.855999999999995Q490.272 58.912000000000006 480.032 58.912000000000006Q464.672 58.912000000000006 457.376 64.672Q450.08 70.43199999999999 450.08 80.416Q450.08 87.072 453.536 91.68Q456.992 96.288 463.904 99.36Q470.81600000000003 102.432 481.568 104.736L487.456 106.01599999999999Q506.656 110.112 520.864 116.512Q535.072 122.91199999999999 543.008 133.408Q550.944 143.904 550.944 160.288Q550.944 176.672 542.624 189.088Q534.304 201.504 519.072 208.54399999999998Q503.84000000000003 215.584 483.104 215.584Z"/><path fill="#eaf0ef" d="M624.104 215.584Q603.368 215.584 587.4960000000001 208.16Q571.624 200.736 562.664 186.91199999999998Q553.704 173.088 553.704 153.632V146.464H586.984V153.632Q586.984 169.76 596.9680000000001 177.824Q606.952 185.888 624.104 185.888Q641.512 185.888 650.088 178.976Q658.664 172.064 658.664 161.312Q658.664 153.888 654.44 149.28Q650.216 144.672 642.152 141.728Q634.088 138.784 622.568 136.224L616.6800000000001 134.94400000000002Q598.248 130.848 585.0640000000001 124.57600000000001Q571.88 118.304 564.8399999999999 108.064Q557.8 97.824 557.8 81.44Q557.8 65.05599999999998 565.608 53.40799999999999Q573.416 41.75999999999999 587.624 35.488Q601.832 29.216000000000008 621.032 29.216000000000008Q640.232 29.216000000000008 655.208 35.744Q670.184 42.27199999999999 678.76 55.19999999999999Q687.336 68.12799999999999 687.336 87.584V95.264H654.056V87.584Q654.056 77.344 650.088 71.07199999999999Q646.12 64.79999999999998 638.696 61.855999999999995Q631.272 58.912000000000006 621.032 58.912000000000006Q605.672 58.912000000000006 598.376 64.672Q591.08 70.43199999999999 591.08 80.416Q591.08 87.072 594.5360000000001 91.68Q597.992 96.288 604.904 99.36Q611.816 102.432 622.568 104.736L628.456 106.01599999999999Q647.656 110.112 661.864 116.512Q676.072 122.91199999999999 684.008 133.408Q691.944 143.904 691.944 160.288Q691.944 176.672 683.624 189.088Q675.304 201.504 660.072 208.54399999999998Q644.84 215.584 624.104 215.584Z"/></svg>diff --git a/experiments/orange-pi-mightycam/moss_mighty/cockpit/capture.js b/experiments/orange-pi-mightycam/moss_mighty/cockpit/capture.jsnew file mode 100644index 0000000..677f670--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/cockpit/capture.js@@ -0,0 +1,55 @@+/* Local-only composition: a landscape video regardless of browser/sidebar width. */+'use strict';+let recorder=null,recordTimer=null,recordStart=0,recordChunks=[],recordStream=null;+const recordCanvas=document.createElement('canvas');recordCanvas.width=1920;recordCanvas.height=1080;+const recordContext=recordCanvas.getContext('2d');+// Keep the last decoded image while the next HTTP image is loading.+const cameraBuffers={};+for(const id of ['raw','detector']){+ const buffer=document.createElement('canvas');cameraBuffers[id]=buffer;+ const retain=()=>{const img=$(id);if(!img.naturalWidth)return;buffer.width=img.naturalWidth;buffer.height=img.naturalHeight;buffer.getContext('2d').drawImage(img,0,0);buffer.ready=true};+ $(id).addEventListener('load',retain);if($(id).complete&&$(id).naturalWidth)retain();+}+function caption(value,x,y,size=20,color=colors.white,weight=500){recordContext.fillStyle=color;recordContext.font=`${weight} ${size}px "Space Grotesk", sans-serif`;recordContext.fillText(value,x,y)}+function videoImage(id,x,y,w,h,label,detail,valid){+ const g=recordContext,img=cameraBuffers[id];g.fillStyle=colors.navy;g.fillRect(x,y,w,h);+ if(img.ready){const s=Math.max(w/img.width,h/img.height);g.save();g.beginPath();g.rect(x,y,w,h);g.clip();g.globalAlpha=valid?1:.2;g.drawImage(img,x+(w-img.width*s)/2,y+(h-img.height*s)/2,img.width*s,img.height*s);g.restore()}+ g.fillStyle='rgba(8,15,26,.8)';g.fillRect(x+12,y+12,Math.min(w-24,500),38);caption(label,x+24,y+38,19,colors.white,600);+ if(detail){g.fillStyle='rgba(8,15,26,.8)';g.fillRect(x+12,y+h-45,w-24,33);caption(detail,x+24,y+h-22,16,valid?colors.mint:colors.salmon)}+}+function composeRecording(){+ const g=recordContext;g.fillStyle=colors.studio;g.fillRect(0,0,1920,1080);+ const logo=$('wordmark');if(logo.complete&&logo.naturalWidth)g.drawImage(logo,48,40,160,160*logo.naturalHeight/logo.naturalWidth);+ caption('dimOS × $60 Orange Pi × $80 MightyCam',250,54,37,colors.white,600);caption('Zero 3W · 6 GB RAM · NPU',251,95,19,'#c3d2d7');caption(online?'LIVE':'OFFLINE',1775,96,18,online?colors.mint:colors.salmon,600);+ caption('CPU LOAD',1260,28,13,'#c3d2d7',600);+ (resources?.cpu?.cores||[]).forEach((c,i)=>{const x=1260+i*63,value=online?c.usage_percent:null;g.fillStyle='rgba(234,240,239,.12)';g.fillRect(x,35,43,35);g.fillStyle=colors.mint;if(value!=null)g.fillRect(x,70-35*value/100,43,35*value/100);caption(value==null?'—':Math.round(value)+'%',x,91,13,'#c3d2d7')});+ g.fillStyle='rgba(8,15,26,.12)';g.fillRect(48,130,1100,750);caption('LIVE TRAJECTORY',72,164,18,colors.mint,600);caption($('tracking').textContent,760,164,15,'#c3d2d7');+ g.save();g.translate(48,178);g.beginPath();g.rect(0,0,1100,650);g.clip();drawPath(g,1100,650,false);g.restore();+ if(!state?.trajectory?.length)caption('Move the camera to begin.',390,510,24,'#c3d2d7');+ caption('VIO path · 1 m grid',72,855,18,'#c3d2d7');caption($('position').textContent,650,855,18,'#c3d2d7');+ videoImage('raw',1172,130,700,363,'MIGHTYCAM · VIO CAMERA',online&&state?.image_age_s<2?'LIVE':'WAITING',online&&state?.image_age_s<2);+ videoImage('detector',1172,517,700,363,'YOLO · '+$('backend').textContent,$('detected').textContent,online&&vision?.active);+ g.strokeStyle='#6A8797';g.beginPath();g.moveTo(48,906);g.lineTo(1872,906);g.stroke();+ const metrics=[['MEMORY USED',$('ram').textContent+' '+$('ram-total').textContent,48],['NPU INFERENCE',$('npu-ms').textContent+' ms',590],['DETECTION RATE',$('fps').textContent+' fps',1050],['TEMPERATURE',$('temperature').textContent+' °C',1510]];+ for(const [label,value,x] of metrics){caption(label,x,940,17,'#c3d2d7',600);caption(online?value:'—',x,998,45,label==='NPU INFERENCE'?colors.mint:colors.white)}+ caption($('stack').textContent,48,1055,17,colors.mint);caption('Live camera + VIO + YOLO · no obstacle map',1300,1055,17,'#c3d2d7');+}+function stopRecording(){if(recorder?.state==='recording')recorder.stop()}+$('record').onclick=async()=>{+ if(recorder?.state==='recording'){stopRecording();return}+ if(!online){text('notice','Connect to the Orange Pi before recording.');return}+ try{+ await document.fonts.ready;+ const type=['video/mp4;codecs=avc1.42001E','video/mp4','video/webm;codecs=vp9','video/webm;codecs=vp8','video/webm'].find(t=>MediaRecorder.isTypeSupported(t));+ if(!type)throw Error('No supported video encoder');+ composeRecording();recordStream=recordCanvas.captureStream(20);recordChunks=[];+ recorder=new MediaRecorder(recordStream,{mimeType:type,videoBitsPerSecond:6000000});+ recorder.ondataavailable=e=>{if(e.data.size)recordChunks.push(e.data)};+ recorder.onstop=()=>{clearInterval(recordTimer);recordStream.getTracks().forEach(t=>t.stop());const blob=new Blob(recordChunks,{type}),url=URL.createObjectURL(blob),link=document.createElement('a');link.href=url;link.download='MOSS-OrangePi-MightyCam-'+new Date().toISOString().replace(/[:.]/g,'-')+(type.includes('mp4')?'.mp4':'.webm');document.body.appendChild(link);link.click();link.remove();setTimeout(()=>URL.revokeObjectURL(url),60000);$('record').classList.remove('recording');text('record','Record');text('notice','Video saved · 1920 × 1080 · no audio');recordChunks=[]};+ recorder.onerror=()=>{text('notice','Recording failed. Use your screen recorder.');stopRecording()};+ recordStart=performance.now();recorder.start(1000);$('record').classList.add('recording');+ recordTimer=setInterval(()=>{composeRecording();const elapsed=(performance.now()-recordStart)/1000;text('record','Stop · '+Math.floor(elapsed)+'s');if(elapsed>=30)stopRecording()},50);+ text('notice','Recording locally · stops after 30 seconds');+ }catch(e){recordStream?.getTracks().forEach(t=>t.stop());text('notice','Recording unavailable here. Open this page in Chrome.');text('record','Record');$('record').classList.remove('recording')}+};+if(!window.MediaRecorder||!recordCanvas.captureStream){$('record').disabled=true;$('record').title='Use Chrome or a screen recorder'}diff --git a/experiments/orange-pi-mightycam/moss_mighty/cockpit/fonts/SpaceGrotesk-OFL.txt b/experiments/orange-pi-mightycam/moss_mighty/cockpit/fonts/SpaceGrotesk-OFL.txtnew file mode 100644index 0000000..d5666d7--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/cockpit/fonts/SpaceGrotesk-OFL.txt@@ -0,0 +1,93 @@+Copyright 2020 The Space Grotesk Project Authors (https://github.com/floriankarsten/space-grotesk)++This Font Software is licensed under the SIL Open Font License, Version 1.1.+This license is copied below, and is also available with a FAQ at:+http://scripts.sil.org/OFL+++-----------------------------------------------------------+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007+-----------------------------------------------------------++PREAMBLE+The goals of the Open Font License (OFL) are to stimulate worldwide+development of collaborative font projects, to support the font creation+efforts of academic and linguistic communities, and to provide a free and+open framework in which fonts may be shared and improved in partnership+with others.++The OFL allows the licensed fonts to be used, studied, modified and+redistributed freely as long as they are not sold by themselves. The+fonts, including any derivative works, can be bundled, embedded,+redistributed and/or sold with any software provided that any reserved+names are not used by derivative works. The fonts and derivatives,+however, cannot be released under any other type of license. The+requirement for fonts to remain under this license does not apply+to any document created using the fonts or their derivatives.++DEFINITIONS+"Font Software" refers to the set of files released by the Copyright+Holder(s) under this license and clearly marked as such. This may+include source files, build scripts and documentation.++"Reserved Font Name" refers to any names specified as such after the+copyright statement(s).++"Original Version" refers to the collection of Font Software components as+distributed by the Copyright Holder(s).++"Modified Version" refers to any derivative made by adding to, deleting,+or substituting -- in part or in whole -- any of the components of the+Original Version, by changing formats or by porting the Font Software to a+new environment.++"Author" refers to any designer, engineer, programmer, technical+writer or other person who contributed to the Font Software.++PERMISSION & CONDITIONS+Permission is hereby granted, free of charge, to any person obtaining+a copy of the Font Software, to use, study, copy, merge, embed, modify,+redistribute, and sell modified and unmodified copies of the Font+Software, subject to the following conditions:++1) Neither the Font Software nor any of its individual components,+in Original or Modified Versions, may be sold by itself.++2) Original or Modified Versions of the Font Software may be bundled,+redistributed and/or sold with any software, provided that each copy+contains the above copyright notice and this license. These can be+included either as stand-alone text files, human-readable headers or+in the appropriate machine-readable metadata fields within text or+binary files as long as those fields can be easily viewed by the user.++3) No Modified Version of the Font Software may use the Reserved Font+Name(s) unless explicit written permission is granted by the corresponding+Copyright Holder. This restriction only applies to the primary font name as+presented to the users.++4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font+Software shall not be used to promote, endorse or advertise any+Modified Version, except to acknowledge the contribution(s) of the+Copyright Holder(s) and the Author(s) or with their explicit written+permission.++5) The Font Software, modified or unmodified, in part or in whole,+must be distributed entirely under this license, and must not be+distributed under any other license. The requirement for fonts to+remain under this license does not apply to any document created+using the Font Software.++TERMINATION+This license becomes null and void if any of the above conditions are+not met.++DISCLAIMER+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM+OTHER DEALINGS IN THE FONT SOFTWARE.diff --git a/experiments/orange-pi-mightycam/moss_mighty/cockpit/fonts/SpaceGrotesk.ttf b/experiments/orange-pi-mightycam/moss_mighty/cockpit/fonts/SpaceGrotesk.ttfnew file mode 100644index 0000000..a1b2e6cBinary files /dev/null and b/experiments/orange-pi-mightycam/moss_mighty/cockpit/fonts/SpaceGrotesk.ttf differdiff --git a/experiments/orange-pi-mightycam/moss_mighty/cockpit/mighty.js b/experiments/orange-pi-mightycam/moss_mighty/cockpit/mighty.jsnew file mode 100644index 0000000..d26bebd--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/cockpit/mighty.js@@ -0,0 +1,109 @@+'use strict';+const $=id=>document.getElementById(id),text=(id,value)=>{$(id).textContent=value};+const map=$('map'),mapContext=map.getContext('2d');+let state=null,resources=null,vision=null,online=false,is3d=true,azimuth=.65,elevation=.65,zoom=1,drag=null;+let rateHistory=[],detectionRate=0;+let freshRoute=null;+const colors={mint:'#6CF8C7',salmon:'#FF947E',white:'#EAF0EF',navy:'#080F1A',studio:'#3D576A'};+function project(p){+ if(!is3d)return [p[0],p[1]];+ const a=p[0]*Math.cos(azimuth)+p[1]*Math.sin(azimuth),b=-p[0]*Math.sin(azimuth)+p[1]*Math.cos(azimuth);+ return [a,b*Math.sin(elevation)+p[2]*Math.cos(elevation)];+}+function drawPath(ctx,w,h,clear=true){+ if(clear)ctx.clearRect(0,0,w,h);+ const points=state?.trajectory||[],all=points.length?points:[[0,0,0]],view=all.map(project);+ const xs=view.map(p=>p[0]),ys=view.map(p=>p[1]),minx=Math.min(...xs),maxx=Math.max(...xs),miny=Math.min(...ys),maxy=Math.max(...ys);+ const cx=(minx+maxx)/2,cy=(miny+maxy)/2,scale=Math.min((w-70)/Math.max(3,maxx-minx),(h-100)/Math.max(3,maxy-miny))*zoom;+ const screen=p=>{const q=project(p);return [w/2+(q[0]-cx)*scale,h/2+12-(q[1]-cy)*scale]};+ const center=all.at(-1),extent=Math.min(60,Math.ceil(Math.max(5,maxx-minx,maxy-miny)+3));+ ctx.lineWidth=1;+ for(let k=-extent;k<=extent;k++){+ ctx.strokeStyle=k%5===0?'rgba(234,240,239,.16)':'rgba(234,240,239,.065)';+ for(let axis=0;axis<2;axis++){+ let a=[Math.floor(center[0])-extent,Math.floor(center[1])+k,0],b=[Math.floor(center[0])+extent,Math.floor(center[1])+k,0];+ if(axis){a=[Math.floor(center[0])+k,Math.floor(center[1])-extent,0];b=[Math.floor(center[0])+k,Math.floor(center[1])+extent,0]}+ ctx.beginPath();ctx.moveTo(...screen(a));ctx.lineTo(...screen(b));ctx.stroke();+ }+ }+ if(!points.length)return;+ const active=online&&state.tracking;+ ctx.beginPath();points.forEach((p,i)=>i?ctx.lineTo(...screen(p)):ctx.moveTo(...screen(p)));+ ctx.strokeStyle=active?colors.mint:'rgba(108,248,199,.4)';ctx.lineWidth=3;ctx.lineJoin='round';ctx.lineCap='round';+ ctx.shadowColor=colors.mint;ctx.shadowBlur=active?8:0;ctx.stroke();ctx.shadowBlur=0;+ const first=screen(points[0]),last=screen(points.at(-1));+ ctx.strokeStyle=colors.salmon;ctx.lineWidth=2;ctx.strokeRect(first[0]-5,first[1]-5,10,10);+ ctx.fillStyle=active?colors.mint:colors.salmon;ctx.beginPath();ctx.arc(last[0],last[1],6,0,Math.PI*2);ctx.fill();+ if(state.pose){+ const [x,y,z,a]=state.pose.orientation_xyzw,p=state.pose.position_m;+ const forward=[1-2*(y*y+z*z),2*(x*y+a*z),2*(x*z-a*y)];+ const target=screen(p.map((v,i)=>v+forward[i]*.4)),angle=Math.atan2(target[1]-last[1],target[0]-last[0]);+ ctx.save();ctx.translate(...last);ctx.rotate(angle);ctx.beginPath();ctx.moveTo(0,0);ctx.lineTo(32,-13);ctx.lineTo(32,13);ctx.closePath();+ ctx.fillStyle=active?'rgba(108,248,199,.18)':'rgba(255,148,126,.12)';ctx.fill();ctx.strokeStyle=active?colors.mint:colors.salmon;ctx.lineWidth=1;ctx.stroke();ctx.restore();+ }+}+function draw(){const d=window.devicePixelRatio||1,w=map.clientWidth,h=map.clientHeight;if(!w||!h)return;map.width=w*d;map.height=h*d;mapContext.setTransform(d,0,0,d,0,0);drawPath(mapContext,w,h);$('map-empty').hidden=!!state?.trajectory?.length;}+async function get(path){const controller=new AbortController(),timer=setTimeout(()=>controller.abort(),3000);try{const response=await fetch(path,{cache:'no-store',signal:controller.signal});if(!response.ok)throw Error(response.status);return await response.json()}finally{clearTimeout(timer)}}+function update(){+ document.body.classList.toggle('offline',!online);text('connection',online?'LIVE':'OFFLINE');$('connection').className='status '+(online?'live':'offline');+ const labels={0:'TRACKING STOPPED',1:'INITIALIZING',2:'6DOF OUTPUT',3:'TRACKING DEGRADED',4:'TRACKING LOST',5:'LOW LIGHT',6:'RECOVERING'};+ text('tracking',!online?'CONNECTION LOST':(labels[state?.vio_state?.state]||'WAITING FOR CAMERA'));+ text('map-empty',state?.tracking?'Move the camera to begin.':state?.vio_state?.state===0?'VIO is stopped.':state?.vio_state?.state===1?'Initializing — keep the camera still.':'Position unavailable.');+ const p=state?.pose?.position_m;text('position',p?`X ${p[0].toFixed(2)} · Y ${p[1].toFixed(2)} · Z ${p[2].toFixed(2)} m`:'X — · Y — · Z —');+ const raw=online&&state?.image_age_s!==null&&state?.image_age_s<2,det=online&&vision?.active;+ $('raw-wrap').classList.toggle('stale',!raw);$('detector-wrap').classList.toggle('stale',!det);+ text('raw-state',raw?'LIVE':'WAITING');text('backend',vision?.backend?.includes('NPU')?'A733 NPU':vision?.backend||'ON-DEVICE');+ text('detected',det?((vision.detections||[]).slice(0,3).map(b=>`${b.label} ${Math.round(b.confidence*100)}%`).join(' · ')||'NO OBJECTS DETECTED'):'WAITING');+ const m=resources?.memory;+ if(m){text('ram',(m.used_mib/1024).toFixed(2));text('ram-total','/ '+(m.total_mib/1024).toFixed(1)+' GB');$('ram-bar').style.width=m.used_mib/m.total_mib*100+'%';text('swap','Swap '+m.swap_used_mib.toFixed(0)+' MB')}+ text('temperature',online&&resources?.temperature_c!=null?resources.temperature_c.toFixed(0):'—');+ text('npu-ms',det&&vision.npu_network_ms!=null?vision.npu_network_ms.toFixed(0):'—');text('fps',det?detectionRate.toFixed(1):'—');+ text('pipeline',det&&vision.median_ms?Math.round(vision.median_ms)+' ms total pipeline':'Live camera pipeline');+ const cores=resources?.cpu?.cores||[];+ if($('cpu-cores').children.length!==cores.length){+ $('cpu-cores').replaceChildren(...cores.map(c=>{const el=document.createElement('div');el.className='core';el.innerHTML='<div class="core-bar"><i></i></div><span>—</span>';el.title='Core '+c.id;return el}));+ }+ cores.forEach((c,i)=>{const el=$('cpu-cores').children[i],value=online?c.usage_percent:null;el.querySelector('i').style.height=(value??0)+'%';el.querySelector('span').textContent=value==null?'—':Math.round(value)+'%';el.setAttribute('aria-label','Core '+c.id+': '+(value==null?'unavailable':value+' percent'));});+ const full=resources?.profile==='full-bench'||resources?.services?.['moss-full-bench']?.running;+ text('stack',full?'dimOS + MOSS · rover I/O simulated':'dimOS + MOSS · perception');draw();+}+async function poll(){+ try{+ const result=await Promise.all([get('/status'),get('/resources'),get('/detections')]);[state,resources,vision]=result;online=true;+ if(freshRoute){+ const p=state.pose;+ if(p){+ if(!freshRoute.origin)freshRoute.origin=p.position_m.slice();+ const position=p.position_m.map((v,i)=>v-freshRoute.origin[i]);+ if(state.tracking&&p.received_at!==freshRoute.last){freshRoute.points.push(position);freshRoute.last=p.received_at;}+ state.pose={...p,position_m:position};+ }+ state.trajectory=freshRoute.points;+ }+ const now=Date.now(),n=vision.frames_processed||0;+ if(rateHistory.length&&n<rateHistory.at(-1).n)rateHistory=[];+ rateHistory.push({t:now,n});rateHistory=rateHistory.filter(x=>now-x.t<5000);+ detectionRate=rateHistory.length>1?(n-rateHistory[0].n)/((now-rateHistory[0].t)/1000):0;+ if(state.image_age_s!=null&&state.image_age_s<2)$('raw').src='/image.jpg?t='+now;+ if(vision.active)$('detector').src='/vision.jpg?t='+now;+ }catch(error){online=false;detectionRate=0}+ update();setTimeout(poll,350);+}+$('view2').onclick=()=>{is3d=false;$('view2').classList.add('selected');$('view3').classList.remove('selected');draw()};+$('view3').onclick=()=>{is3d=true;$('view3').classList.add('selected');$('view2').classList.remove('selected');draw()};+$('fit').onclick=()=>{zoom=1;draw()};+const resetPath=document.createElement('button');resetPath.id='reset-path';resetPath.textContent='Reset path';resetPath.title='Clear the displayed route and start at zero without restarting VIO';+document.querySelector('.view-tools').appendChild(resetPath);+resetPath.onclick=()=>{+ const relative=state?.pose?.position_m;+ const origin=relative?(freshRoute?.origin?relative.map((v,i)=>v+freshRoute.origin[i]):relative.slice()):null;+ freshRoute={origin,points:[],last:state?.pose?.received_at};zoom=1;+ if(state){state.trajectory=[];if(state.pose)state.pose={...state.pose,position_m:[0,0,0]};}+ update();+};+$('fullscreen').onclick=async()=>{try{if(document.fullscreenElement)await document.exitFullscreen();else await document.documentElement.requestFullscreen()}catch(e){text('notice','Use the browser fullscreen control.')}};+map.onpointerdown=e=>{drag=[e.clientX,e.clientY];map.setPointerCapture(e.pointerId)};+map.onpointermove=e=>{if(drag&&is3d){azimuth+=(e.clientX-drag[0])*.008;elevation=Math.max(.12,Math.min(1.5,elevation+(e.clientY-drag[1])*.006));drag=[e.clientX,e.clientY];draw()}};+map.onpointerup=map.onpointercancel=()=>drag=null;+map.addEventListener('wheel',e=>{e.preventDefault();zoom=Math.max(.3,Math.min(5,zoom*Math.exp(-e.deltaY*.001)));draw()},{passive:false});+new ResizeObserver(draw).observe(map);poll();diff --git a/experiments/orange-pi-mightycam/moss_mighty/cockpit/showcase.css b/experiments/orange-pi-mightycam/moss_mighty/cockpit/showcase.cssnew file mode 100644index 0000000..9c928ec--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/cockpit/showcase.css@@ -0,0 +1,16 @@+*{box-sizing:border-box}html,body{margin:0;height:100%;background:var(--moss-studio);color:var(--moss-white);font-family:var(--moss-font);font-weight:500}button{font:inherit;color:inherit;cursor:pointer}h1,h2,p{margin:0}button{background:transparent;border:1px solid var(--moss-hairline);border-radius:2px;padding:7px 12px;font-size:12px}button:hover,button.selected{border-color:var(--moss-mint);color:var(--moss-mint)}button:focus-visible{outline:2px solid var(--moss-mint);outline-offset:3px}button:disabled{opacity:.4;cursor:default}[hidden]{display:none!important}+#app{height:100vh;height:100dvh;min-height:480px;padding:0 clamp(16px,2.4vw,48px);display:grid;grid-template-rows:88px minmax(0,1fr) 124px 32px;gap:16px;overflow:hidden}header{display:flex;align-items:center;gap:26px;border-bottom:1px solid var(--moss-hairline)}#wordmark{width:100px;height:auto}.identity{min-width:0}h1{font-size:clamp(17px,1.7vw,27px);font-weight:600;line-height:1.1}h1 span{color:var(--moss-mint)}.identity p{font-size:12px;color:var(--ui-dim);margin-top:6px}.status{margin-left:auto;font-size:11px;letter-spacing:.12em;white-space:nowrap}.status::before{display:inline-block;content:'';width:6px;height:6px;background:currentColor;margin-right:7px;border-radius:50%}.status.live{color:var(--moss-mint)}.status.offline{color:var(--moss-salmon)}.actions{display:flex;gap:8px}#record.recording{background:var(--moss-salmon);border-color:var(--moss-salmon);color:var(--moss-navy)}+main{display:grid;grid-template-columns:minmax(0,1.4fr) minmax(0,1fr);gap:20px;min-height:0}.path-panel{min-width:0;display:flex;flex-direction:column;min-height:0;background:rgba(8,15,26,.12)}.panel-title{display:flex;justify-content:space-between;gap:8px;padding:15px 18px 0;align-items:center;flex:none}h2,.panel-title span{font-size:11px;letter-spacing:.1em;font-weight:600}h2{color:var(--moss-mint)}.panel-title span{color:var(--ui-dim);font-size:10px}#map-wrap{position:relative;flex:1;min-height:0;overflow:hidden}#map{position:absolute;inset:0;width:100%;height:100%;touch-action:none;cursor:grab}.view-tools{position:absolute;top:16px;right:16px;display:flex;gap:6px}.view-tools button{padding:5px 10px;background:var(--moss-studio);font-size:11px}.map-meta{position:absolute;bottom:13px;left:18px;right:18px;display:flex;justify-content:space-between;gap:12px;font-size:11px;color:var(--ui-dim);font-variant-numeric:tabular-nums}#map-empty{position:absolute;top:44%;left:0;right:0;text-align:center;color:var(--ui-dim);font-size:14px;pointer-events:none}+.cameras{display:grid;grid-template-rows:1fr 1fr;gap:12px;min-height:0}.camera{position:relative;overflow:hidden;background:var(--moss-navy);min-height:0}.camera img{width:100%;height:100%;position:absolute;inset:0;object-fit:cover;display:block}.camera img:not([src]){display:none}.camera.stale img{opacity:.2}.camera-label{position:absolute;top:10px;left:12px;background:rgba(8,15,26,.78);padding:5px 7px;font-size:11px;letter-spacing:.08em;font-weight:600}.camera-label span{margin-left:12px;color:var(--moss-mint);font-size:10px}.camera-state,.detections{position:absolute;bottom:10px;right:12px;background:rgba(8,15,26,.78);padding:5px 7px;font-size:11px;color:var(--moss-mint);max-width:calc(100% - 24px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}+.metrics{display:grid;grid-template-columns:1.4fr 1fr 1fr 1fr;gap:24px;align-items:start;border-top:1px solid var(--moss-hairline);padding-top:15px;font-variant-numeric:tabular-nums}.metric>p{color:var(--ui-dim);letter-spacing:.1em;font-size:10px;font-weight:600}.metric>div{display:flex;gap:7px;align-items:baseline;margin:4px 0}.metric strong{font-size:clamp(26px,3.2vw,48px);font-weight:500;letter-spacing:-.04em;line-height:1.1}.metric span{font-size:14px;color:var(--ui-dim)}.metric small{display:block;font-size:11px;color:var(--ui-dim);margin-top:4px}.memory-bar{height:3px;background:rgba(234,240,239,.12);position:relative;max-width:280px;margin-top:14px!important}.memory-bar i{position:absolute;left:0;top:0;height:100%;width:0;background:var(--moss-mint);transition:width .5s}.metric:nth-child(2) strong{color:var(--moss-mint)}footer{display:flex;justify-content:space-between;gap:16px;font-size:10px;color:var(--ui-dim);align-items:start}footer span:first-child{color:var(--moss-mint)}body.offline .metrics{opacity:.4}+@media(max-width:1000px){#app{grid-template-rows:75px minmax(0,1fr) 106px 28px;gap:12px}header{gap:16px}#wordmark{width:74px}.identity p{font-size:10px}.actions button{font-size:11px;padding:6px 8px}main{gap:12px}.metrics{gap:14px}.camera-label span{margin-left:6px}}+@media(max-width:690px){#app{min-height:650px;grid-template-rows:84px minmax(0,1fr) 90px 30px;gap:10px}header{position:relative;align-items:flex-start;padding-top:16px;gap:14px}#wordmark{width:64px;margin-top:4px}h1{font-size:17px}.identity p{font-size:9px}.actions{position:absolute;bottom:8px;right:0;gap:6px}.actions button{padding:2px 6px;font-size:10px}.status{position:absolute;bottom:13px;left:0;font-size:9px}main{grid-template-columns:1fr;grid-template-rows:1.45fr 1fr;gap:10px}.cameras{grid-template-rows:1fr;grid-template-columns:1fr 1fr;gap:10px}.panel-title{padding:12px 12px 0}.panel-title span{font-size:9px}h2{font-size:10px}.camera-label{left:5px;top:5px;padding:3px 4px;font-size:9px}.camera-label span{display:none}.camera-state,.detections{bottom:5px;right:5px;font-size:9px;max-width:calc(100% - 10px);padding:3px 4px}.view-tools{top:12px;right:12px}.view-tools button{padding:3px 7px;font-size:10px}.map-meta{font-size:9px;left:12px;right:12px;bottom:10px}.metrics{grid-template-columns:1.2fr 1fr 1fr 1fr;gap:10px;padding-top:10px}.metric>p{font-size:8px;letter-spacing:.03em}.metric strong{font-size:27px}.metric span{font-size:10px}.metric>div{gap:3px}.metric small{font-size:8px}.memory-bar{margin-top:10px!important}footer{font-size:8px;gap:10px}footer span{max-width:52%}}++.cpu-widget{flex:1;max-width:250px;min-width:200px;margin-left:auto}.cpu-title{font-size:9px;letter-spacing:.1em;color:var(--ui-dim);display:block;margin-bottom:4px}#cpu-cores{display:grid;grid-template-columns:repeat(8,1fr);gap:7px}.core{text-align:center;font-variant-numeric:tabular-nums}.core-bar{height:24px;position:relative;background:rgba(234,240,239,.1)}.core-bar i{position:absolute;bottom:0;left:0;right:0;background:var(--moss-mint);height:0;transition:height .6s}.core span{display:block;font-size:9px;margin-top:3px;color:var(--ui-dim)}.status{margin-left:0}+@media(max-width:1150px){#app{grid-template-rows:112px minmax(0,1fr) 106px 28px}header{position:relative;align-items:flex-start;padding-top:18px}.cpu-widget{position:absolute;bottom:9px;left:100px;width:240px}.cpu-title{position:absolute;left:-75px;top:8px}.actions{margin-left:auto}.status{margin-left:auto;margin-top:9px}}+@media(max-width:690px){#app{grid-template-rows:130px minmax(0,1fr) 90px 30px}.cpu-widget{left:0;bottom:12px;width:218px;min-width:0}.cpu-title{left:0;top:-17px}.actions{bottom:12px}.status{left:auto;right:0;bottom:52px;margin:0}.core-bar{height:20px}.core span{font-size:8px}.identity p{font-size:10px}}++/* Keep the demo headline prominent, with the live core meters below it. */+#app{grid-template-rows:132px minmax(0,1fr) 112px 28px}header{position:relative;align-items:flex-start;padding-top:23px}h1{font-size:clamp(19px,2vw,28px);white-space:nowrap}h1 b{color:var(--moss-mint);font-weight:600}.cpu-widget{position:absolute;left:150px;bottom:10px;width:300px;max-width:none;margin:0}.cpu-title{position:absolute;left:-80px;top:8px}.core-bar{height:19px}.status{margin-top:10px;margin-left:auto}.actions{position:absolute;right:0;bottom:14px}.identity p{font-size:11px}#wordmark{width:98px}+@media(max-width:1000px){#app{grid-template-rows:126px minmax(0,1fr) 106px 28px}header{gap:16px}#wordmark{width:70px}h1{font-size:20px}.cpu-widget{left:90px;width:280px}.identity p{font-size:10px}.status{position:absolute;right:0;top:52px;font-size:9px;margin:0}}+@media(max-width:690px){#app{grid-template-rows:155px minmax(0,1fr) 90px 30px}header{padding-top:14px;gap:12px}#wordmark{width:52px;align-self:flex-start}h1{font-size:20px;white-space:normal;line-height:1.2;max-width:340px}.identity p{font-size:9px}.cpu-widget{left:0;bottom:12px;width:210px}.cpu-title{left:0;top:-17px}.actions{bottom:12px}.status{top:auto;bottom:53px;right:0}.core-bar{height:18px}}diff --git a/experiments/orange-pi-mightycam/moss_mighty/cockpit/tokens.css b/experiments/orange-pi-mightycam/moss_mighty/cockpit/tokens.cssnew file mode 100644index 0000000..83a66e7--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/cockpit/tokens.css@@ -0,0 +1,85 @@+/* MOSS brand tokens for the cockpit.+ *+ * Colours, font and spacing are the MOSS brand tokens: flat studio blue,+ * three thin arcs, mint accent, salmon as a counterpoint, Space Grotesk,+ * hairlines instead of boxes. Sizes are set for a 1440 px canvas. Lines+ * marked ADAPT are cockpit-only additions.+ */++/* Variable font, weight axis 300-700, file default 300: the weight RANGE is+ required, otherwise the browser synthesises 600 from the 300 master. */+@font-face {+ font-family: "Space Grotesk";+ src: url("fonts/SpaceGrotesk.ttf") format("truetype");+ font-weight: 300 700;+ font-style: normal;+ font-display: swap;+}++:root {+ /* palette */+ --moss-white: #EAF0EF;+ --moss-mint: #6CF8C7;+ --moss-salmon: #FF947E;+ --moss-navy: #080F1A;+ --moss-studio: #3D576A;++ /* lines */+ --moss-hairline: #6A8797; /* card and closing hairlines */+ --moss-rule: rgba(234, 240, 239, .235); /* caption bottom rule (WHITE alpha 60/255) */+ --moss-fade: linear-gradient(to bottom, rgba(8, 15, 26, 0), rgba(8, 15, 26, .902));++ /* type */+ --moss-font: "Space Grotesk", system-ui, sans-serif;+ --moss-w-body: 500;+ --moss-w-title: 600;+ --moss-w-display: 700;+ --moss-w-kicker: 600;+ --moss-track-kicker: .12em;++ /* display sizes at 1440 px */+ --moss-fs-numeral: 55.5px;+ --moss-fs-title: 49.5px;+ --moss-fs-sub: 23.25px;+ --moss-fs-kicker: 18.75px;+ --moss-fs-kicker-sm: 17.25px;+ --moss-fs-meta: 15.75px;+ --moss-fs-micro: 13.5px;++ /* ADAPT: a dense instrument tier for telemetry: a smaller scale with the+ same hierarchy (caps kicker > sentence-case title > body) and weights. */+ --ui-fs-kicker: 13.5px; /* = --moss-fs-micro, the smallest display size */+ --ui-fs-title: 22px;+ --ui-fs-body: 15px;+ --ui-fs-small: 13px;+ --ui-fs-big: 40px; /* battery and other headline numerals */++ /* grid at 1440: 84 px margin, 84 px columns, 24 px gutters */+ --moss-margin: clamp(16px, 5.834vw, 112px);+ --moss-gutter: 24px;+ --moss-accent-len: 70.5px;+ --moss-accent-w: 2.25px;+ --moss-vrule-w: 3px;+ --moss-progress-w: 2.25px;++ /* motion: ease(x) = x*x*(3-2x) */+ --moss-ease: cubic-bezier(.3333, 0, .6667, 1);+ --moss-fade-in: 300ms;+ --moss-fade-out: 280ms;++ /* ADAPT, UI-only status colours. In the brand tokens the mint/salmon+ alternation carries no status, so this mapping is cockpit-only:+ ok = mint text+ attention = salmon text+ failure = salmon badge with navy text+ caution = amber text+ unknown = white at 0.6 */+ --ui-ok: var(--moss-mint);+ --ui-attention: var(--moss-salmon);+ --ui-fail-bg: var(--moss-salmon);+ --ui-fail-fg: var(--moss-navy);+ --ui-unknown: rgba(234, 240, 239, .6);+ --ui-caution: #FFC15E; /* the depth camera's dots on the map; obstacle / replan in the decision feed */+ --ui-dim: rgba(234, 240, 239, .78); /* secondary text: 4.74:1 on studio */+ --ui-control-line: rgba(234, 240, 239, .5); /* button borders: >= 3:1 on studio */+}diff --git a/experiments/orange-pi-mightycam/moss_mighty/core.py b/experiments/orange-pi-mightycam/moss_mighty/core.pynew file mode 100644index 0000000..9740e7f--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/core.py@@ -0,0 +1,335 @@+"""SDK-facing bench state. The sensor's IMU frame is not the rover base frame."""+import io+import json+import math+import os+import threading+import time+from collections import deque+from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer+from pathlib import Path++from .paths import RUNTIME++++def cpu_percent(before, after):+ """Linux counters: guest time is already included in user/nice."""+ delta = [b-a for a,b in zip(before[:8], after[:8])]+ if len(delta) < 5 or any(d < 0 for d in delta) or sum(delta) <= 0:+ return None+ idle = delta[3] + delta[4] # idle + iowait+ return round(max(0, min(100, 100*(sum(delta)-idle)/sum(delta))), 1)+++class CpuUsage:+ def __init__(self):+ self.lock = threading.Lock()+ self.previous = {}+ self.last = None+ self.result = {'cores': [], 'average_percent': None, 'interval_s': None}++ def sample(self):+ with self.lock:+ now = time.monotonic()+ # Share a sampling interval across all browser clients.+ if self.last is not None and now-self.last < .8:+ return self.result+ try:+ rows = [line.split() for line in Path('/proc/stat').read_text().splitlines()]+ current = {r[0]: list(map(int,r[1:])) for r in rows+ if r and r[0].startswith('cpu') and r[0][3:].isdigit()}+ except (OSError, ValueError):+ return {'cores': [], 'average_percent': None, 'interval_s': None}+ cores = [{'id': int(name[3:]), 'usage_percent': cpu_percent(self.previous[name],values)+ if name in self.previous else None}+ for name,values in sorted(current.items(), key=lambda p:int(p[0][3:]))]+ valid = [c['usage_percent'] for c in cores if c['usage_percent'] is not None]+ self.result = {'cores':cores, 'average_percent':round(sum(valid)/len(valid),1) if valid else None,+ 'interval_s':round(now-self.last,2) if self.last is not None else None}+ self.previous, self.last = current, now+ return self.result+++CPU_USAGE = CpuUsage()+++def resources():+ """Whole-board available RAM includes reclaimable cache, as Linux free does."""+ result = {'memory': None, 'temperature_c': None, 'services': {}, 'cpu': CPU_USAGE.sample(),+ 'profile': os.environ.get('MOSS_MIGHTY_PROFILE', 'mighty'),+ 'hardware': {'name': 'Orange Pi Zero 3W', 'soc': 'Allwinner A733',+ 'cores': os.cpu_count(), 'ram_nominal_gb': 6,+ 'npu_driver_present': Path('/dev/vipcore').exists()}}+ try:+ mem = {line.split(':')[0]: int(line.split()[1]) for line in Path('/proc/meminfo').read_text().splitlines()}+ result['memory'] = {'total_mib': round(mem['MemTotal']/1024, 1),+ 'used_mib': round((mem['MemTotal']-mem['MemAvailable'])/1024, 1),+ 'available_mib': round(mem['MemAvailable']/1024, 1),+ 'swap_used_mib': round((mem['SwapTotal']-mem['SwapFree'])/1024, 1)}+ except (OSError, KeyError, ValueError):+ pass+ temps=[]+ for f in Path('/sys/class/thermal').glob('thermal_zone*/temp'):+ try: temps.append(float(f.read_text())/1000)+ except (OSError, ValueError): pass+ if temps: result['temperature_c']=round(max(temps), 1)+ for name in ['moss-mighty', 'moss-vision', 'moss-full-bench']:+ group=Path('/sys/fs/cgroup/system.slice')/(name+'.service')+ try:+ result['services'][name]={'running':int((group/'pids.current').read_text())>0,+ 'memory_mib':round(int((group/'memory.current').read_text())/(1024**2), 1)}+ except (OSError, ValueError): result['services'][name]={'running':False,'memory_mib':0}+ return result+++def vision_status():+ try:+ result=json.loads((RUNTIME/'vision.json').read_text())+ result['age_s']=max(0, time.time()-result.get('source_timestamp',result.get('updated_at',0)))+ result['active']=result['age_s']<3 and not result.get('error')+ return result+ except (OSError, ValueError, TypeError):+ return {'active':False,'error':'Detection not running','detections':[]}+++def validate_pose(pose):+ if not pose.get("is_public", True) or pose.get("packet_type", "POSE") != "POSE":+ raise ValueError("Non-public pose")+ xyz = [float(x) for x in pose["position_m"]]+ q = [float(x) for x in pose["orientation_xyzw"]]+ confidence = float(pose.get("confidence", 0))+ if len(xyz) != 3 or len(q) != 4 or not all(map(math.isfinite, xyz + q + [confidence])):+ raise ValueError("Invalid pose values")+ norm = math.sqrt(sum(x*x for x in q))+ if not 0.9 <= norm <= 1.1:+ raise ValueError("Invalid quaternion")+ return {"position_m": xyz, "orientation_xyzw": [x/norm for x in q],+ "confidence": max(0, min(1, confidence)),+ "sensor_timestamp_ns": int(pose.get("timestamp_ns", 0)),+ "frame_id": "mighty_odom", "child_frame_id": "mighty_imu",+ "received_at": time.time()}+++class BenchState:+ def __init__(self):+ self.lock = threading.RLock()+ self.pose = None+ self.pose_monotonic = None+ self.jpeg = None+ self.image_monotonic = None+ self.poses = 0+ self.images = 0+ self.error = "Waiting for MightyCam USB"+ self.vio_state = {}+ self.trajectory = deque(maxlen=1200)+ self.last_point = 0+ self.reset_count = 0+ self.features = []+ self.features_monotonic = None+ self.distance_m = 0.0+ self.started_at = time.time()++ def accept_pose(self, raw):+ pose = validate_pose(raw)+ with self.lock:+ self.pose = pose+ self.pose_monotonic = time.monotonic()+ self.poses += 1+ self.error = ""+ if pose["confidence"] >= .5 and self.vio_state.get('state',2)==2 and self.pose_monotonic - self.last_point >= .2:+ if self.trajectory:+ d=math.dist(self.trajectory[-1],pose['position_m'])+ if .02 < d < 1.0:self.distance_m+=d+ self.trajectory.append(pose["position_m"])+ self.last_point = self.pose_monotonic+ return pose++ def reset(self):+ with self.lock:+ self.pose = None+ self.pose_monotonic = None+ self.trajectory.clear()+ self.distance_m = 0.0+ self.started_at = time.time()+ self.reset_count += 1++ def snapshot(self):+ with self.lock:+ age = None if self.pose_monotonic is None else time.monotonic()-self.pose_monotonic+ image_age = None if self.image_monotonic is None else time.monotonic()-self.image_monotonic+ good = age is not None and age < 1 and self.pose["confidence"] >= .5 and self.vio_state.get('state',2)==2+ return {"mode": "tabletop — camera only", "pose": self.pose,+ "pose_age_s": age, "image_age_s": image_age,+ "tracking": good, "poses_received": self.poses,+ "images_received": self.images, "error": self.error,+ "vio_state": self.vio_state, "resets": self.reset_count,+ "trajectory": list(self.trajectory), 'distance_m': self.distance_m,+ 'started_at': self.started_at,+ 'features': self.features if self.features_monotonic and time.monotonic()-self.features_monotonic<1 else []}+++def image_pixels(event):+ from mighty_sdk import image_to_raw+ from PIL import Image+ import mighty_protocol as mp+ raw = image_to_raw(event)+ if raw is None:+ return None+ modes = {mp.RAW_FORMAT["GRAY8"]: "L", mp.RAW_FORMAT["RGB24"]: "RGB",+ mp.RAW_FORMAT["RGBA32"]: "RGBA"}+ mode = modes.get(raw["format"])+ if mode is None:+ raise ValueError("Unsupported Mighty image format")+ width, height = int(raw["width"]), int(raw["height"])+ if not (0 < width <= 4096 and 0 < height <= 4096):+ raise ValueError("Invalid image dimensions")+ return Image.frombytes(mode, (width, height), bytes(raw["data"])).convert("RGB")+++class Receiver:+ def __init__(self, state, url, on_pose=None, on_image=None):+ from mighty_sdk import MightyClient, MightyWebDevice+ self.state, self.on_pose, self.on_image = state, on_pose, on_image+ self.stop_event = threading.Event()+ self.latest_image = None+ self.image_lock = threading.Lock()+ self.client = MightyClient(MightyWebDevice(base_url=url, read_chunk_size=4096),+ auto_reconnect=True, reconnect_delay_s=2)+ self.client.on_pose(self._pose)+ self.client.on_image(self._queue_image)+ self.client.on_error(self._error)+ self.client.on_reset(lambda _: state.reset())+ self.client.on_vio_state(self._vio_state)+ self.client.on_viz(self._viz)++ def _viz(self, event):+ if event.get('subtype') != 'features': return+ with self.state.lock:+ self.state.features = [{k:f[k] for k in ('x','y','status','id') if k in f}+ for f in event.get('features',[])[:1000]]+ self.state.features_monotonic = time.monotonic()++ def _pose(self, raw):+ try:+ p = self.state.accept_pose(raw)+ if p["confidence"] >= .5 and self.state.vio_state.get('state',2)==2 and self.on_pose:+ self.on_pose(p)+ except Exception as e:+ self._error({"message": str(e)})++ def _error(self, event):+ with self.state.lock:+ self.state.error = str(event.get("message", event))[:400]++ def _vio_state(self, event):+ with self.state.lock:+ # Unavailable firmware diagnostics may be NaN/Inf during startup.+ # Keep them explicitly unknown rather than breaking JSON/status.+ self.state.vio_state = {k: (None if isinstance(v, float) and not math.isfinite(v) else v)+ for k,v in event.items()+ if isinstance(v, (str, int, float, bool, type(None)))}++ def _queue_image(self, event):+ if not event.get("dropped"):+ with self.image_lock:+ self.latest_image = event++ def _images(self):+ while not self.stop_event.wait(.2):+ with self.image_lock:+ event, self.latest_image = self.latest_image, None+ if event is None:+ continue+ try:+ pixels = image_pixels(event)+ if pixels is None:+ continue+ pixels.thumbnail((640, 480))+ output = io.BytesIO()+ pixels.save(output, "JPEG", quality=75)+ with self.state.lock:+ self.state.jpeg = output.getvalue()+ self.state.image_monotonic = time.monotonic()+ self.state.images += 1+ if self.on_image:+ self.on_image(pixels, time.time())+ except Exception as e:+ self._error({"message": "Image: " + str(e)})++ def _start_vio(self):+ # Retry only until a start succeeds. Never reset a healthy VIO stream.+ while not self.stop_event.is_set():+ result = self.client.start_vio()+ if result.get("ok"):+ return+ self._error(result)+ self.stop_event.wait(5)++ def start(self):+ self.client.connect()+ self.threads = [threading.Thread(target=f, daemon=True)+ for f in (self._images, self._start_vio)]+ for thread in self.threads:+ thread.start()++ def stop(self):+ self.stop_event.set()+ self.client.disconnect()+ for thread in getattr(self, "threads", []):+ thread.join(timeout=4)+++def serve(state, port):+ page = Path(__file__).with_name("dashboard.html").read_bytes()+ class Handler(BaseHTTPRequestHandler):+ def do_GET(self):+ path = self.path.split("?", 1)[0]+ if path == "/":+ body, kind = page, "text/html; charset=utf-8"+ elif path.startswith('/static/'):+ base=Path(__file__).with_name('cockpit').resolve()+ target=(base/path[len('/static/'):]).resolve()+ if base not in target.parents or not target.is_file():+ self.send_error(404)+ return+ body=target.read_bytes()+ kind={'.css':'text/css','.js':'text/javascript','.svg':'image/svg+xml',+ '.ttf':'font/ttf'}.get(target.suffix,'application/octet-stream')+ elif path == "/status":+ body = json.dumps(state.snapshot(), allow_nan=False).encode()+ kind = "application/json"+ elif path == "/resources":+ body, kind = json.dumps(resources(), allow_nan=False).encode(), 'application/json'+ elif path == "/detections":+ body, kind = json.dumps(vision_status(), allow_nan=False).encode(), 'application/json'+ elif path == "/vision.jpg":+ try: body = (RUNTIME/'vision.jpg').read_bytes()+ except OSError:+ self.send_error(503, 'Waiting for detector')+ return+ kind = 'image/jpeg'+ elif path == "/image.jpg":+ with state.lock:+ body = state.jpeg+ kind = "image/jpeg"+ if body is None:+ self.send_error(503, "Waiting for camera")+ return+ else:+ self.send_error(404)+ return+ self.send_response(200)+ self.send_header("Content-Type", kind)+ self.send_header("Content-Length", str(len(body)))+ self.send_header("Cache-Control", "no-store")+ self.end_headers()+ try:+ self.wfile.write(body)+ except (BrokenPipeError, ConnectionResetError):+ pass+ def log_message(self, *args):+ pass+ server = ThreadingHTTPServer(("0.0.0.0", port), Handler)+ threading.Thread(target=server.serve_forever, daemon=True).start()+ return serverdiff --git a/experiments/orange-pi-mightycam/moss_mighty/dashboard.html b/experiments/orange-pi-mightycam/moss_mighty/dashboard.htmlnew file mode 100644index 0000000..4cdb115--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/dashboard.html@@ -0,0 +1,10 @@+<!doctype html><html lang="en"><head>+<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>dimOS × $60 Orange Pi × $80 MightyCam · MOSS</title>+<link rel="icon" href="/static/assets/mark-mint.svg" type="image/svg+xml"><link rel="stylesheet" href="/static/tokens.css"><link rel="stylesheet" href="/static/showcase.css">+</head><body><div id="app">+<header><img id="wordmark" src="/static/assets/wordmark-white.svg" alt="MOSS"><div class="identity"><h1>dimOS <span>×</span> <b>$60</b> Orange Pi <span>×</span> <b>$80</b> MightyCam</h1><p>Zero 3W · 6 GB RAM · NPU</p></div><div class="cpu-widget" aria-label="Live CPU usage per core"><span class="cpu-title">CPU LOAD</span><div id="cpu-cores"></div></div><span id="connection" class="status">CONNECTING</span><div class="actions"><button id="record" title="Save a 30-second 1080p demo video">Record</button><button id="fullscreen">Fullscreen</button></div></header>+<main><section class="path-panel"><div class="panel-title"><h2>LIVE TRAJECTORY</h2><span id="tracking">WAITING FOR CAMERA</span></div><div id="map-wrap"><canvas id="map" aria-label="Live MightyCam VIO trajectory"></canvas><div class="view-tools"><button id="view2">Floor</button><button id="view3" class="selected">3D</button><button id="fit">Fit</button></div><div id="map-empty">Move the camera to begin.</div><div class="map-meta"><span>VIO path · 1 m grid</span><span id="position">X — · Y — · Z —</span></div></div></section>+<section class="cameras" aria-label="Live camera and object detection"><div class="camera stale" id="raw-wrap"><img id="raw" alt="Live monochrome MightyCam image"><span class="camera-label">MIGHTYCAM <span>VIO CAMERA</span></span><span id="raw-state" class="camera-state">WAITING</span></div><div class="camera stale" id="detector-wrap"><img id="detector" alt="Live YOLO detections"><span class="camera-label">YOLO <span id="backend">ON-DEVICE DETECTION</span></span><span id="detected" class="detections">WAITING</span></div></section></main>+<section class="metrics" aria-label="Live system measurements"><div class="metric memory"><p>MEMORY USED</p><div><strong id="ram">—</strong><span id="ram-total">/ 5.7 GB</span></div><div class="memory-bar"><i id="ram-bar"></i></div></div><div class="metric"><p>NPU INFERENCE</p><div><strong id="npu-ms">—</strong><span>ms</span></div><small id="model">YOLOv5 · 640 × 640</small></div><div class="metric"><p>DETECTION RATE</p><div><strong id="fps">—</strong><span>fps</span></div><small id="pipeline">Live camera pipeline</small></div><div class="metric"><p>TEMPERATURE</p><div><strong id="temperature">—</strong><span>°C</span></div><small id="swap">Swap —</small></div></section>+<footer><span id="stack">dimOS + MOSS</span><span id="notice">Live camera + VIO + YOLO · no obstacle map</span></footer>+</div><script src="/static/mighty.js"></script><script src="/static/capture.js"></script></body></html>diff --git a/experiments/orange-pi-mightycam/moss_mighty/full_bench.py b/experiments/orange-pi-mightycam/moss_mighty/full_bench.pynew file mode 100644index 0000000..1d617a4--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/full_bench.py@@ -0,0 +1,124 @@+"""MOSS navigation/mission/arm load variant. All range data and actuators are simulated.++The real Mighty/YOLO modules run inside this same graph. Synthetic room data never+enters the live Mighty trajectory and is not presented as a measured workshop map.+"""+import os+import threading+import time+import numpy as np+# Load the real Open3D bindings before dimOS starts recorder/scan threads.+# The ARM wheel registers open3d.core while importing its parent package;+# concurrent lazy imports otherwise see a partially initialized package.+import open3d.core++# This module cannot open a motor or servo port, even if devices are later added.+os.environ.update(MOSS_MOCK_BUS='1', MOSS_CAMERA='0', MOSS_IMU='0',+ MOSS_WRIST='0', MOSS_SOUNDS='0', MOSS_RERUN='0',+ MOSS_MISSION_AUTOSTART='0', MOSS_PICK_CMD='none')+from .paths import STATE_DIR+os.environ['MOSS_STATE_DIR'] = str(STATE_DIR)++from dimos.core.core import rpc+from dimos.core.module import Module+from dimos.core.stream import Out+from dimos.core.coordination.blueprints import autoconnect+from dimos.control.coordinator import ControlCoordinator+from dimos.msgs.sensor_msgs.PointCloud2 import PointCloud2+from moss_dimos import blueprints as B, arm as A, arm_feetech as F+from moss_dimos.mission import LitterMission+from moss_dimos.rplidar_c1 import RPLidarC1+from dimos.hardware.manipulators.registry import adapter_registry+++class SyntheticRoom(Module):+ pointcloud: Out[PointCloud2]++ @rpc+ def start(self):+ super().start()+ self.done=threading.Event()+ self.worker=threading.Thread(target=self.feed,daemon=True)+ self.worker.start()++ def feed(self):+ n=180+ x=np.linspace(-4,4,n)+ y=np.linspace(-3,3,n)+ world=np.concatenate([np.c_[x,np.full(n,-3),np.zeros(n)],+ np.c_[x,np.full(n,3),np.zeros(n)],+ np.c_[np.full(n,-4),y,np.zeros(n)],+ np.c_[np.full(n,4),y,np.zeros(n)]])+ t0=time.monotonic()+ while not self.done.wait(.1):+ t=time.monotonic()-t0+ # Small deterministic movement exercises ICP and map updates.+ p=world.copy()+ p[:,0]-=.4*np.sin(t*.12)+ p[:,1]-=.3*np.sin(t*.08)+ self.pointcloud.publish(PointCloud2.from_numpy(p.astype(np.float32),frame_id='lidar_link',timestamp=time.time()))++ @rpc+ def stop(self):+ if hasattr(self,'done'):+ self.done.set();self.worker.join(timeout=2)+ super().stop()+++class SimServoBus:+ """Feetech register interface in memory; never owns a serial device."""+ def __init__(self):+ self.pos={1:2857.,2:860.,3:3206.,4:868.,5:3221.,6:3674.}+ self.reg={sid:{F.REG_GOAL:int(p),F.REG_TORQUE:0,F.REG_SPEED:400} for sid,p in self.pos.items()}+ self.last=time.monotonic()+ def open(self): return True+ def close(self): pass+ def tick(self):+ now=time.monotonic();dt=now-self.last;self.last=now+ for sid,p in self.pos.items():+ r=self.reg[sid]+ if r[F.REG_TORQUE]:+ self.pos[sid]+=float(np.clip(r[F.REG_GOAL]-p,-dt*(r[F.REG_SPEED] or 400),dt*(r[F.REG_SPEED] or 400)))+ def read2(self,sid,addr):+ self.tick()+ if sid not in self.pos:return None+ return int(round(self.pos[sid])) if addr==F.REG_PRESENT else self.reg[sid].get(addr,0)+ def write1(self,sid,addr,value):+ self.tick();self.reg[sid][addr]=int(value);return True+ write2=write1+++class BenchArmAdapter(F.FeetechSo101Adapter):+ def __init__(self,**kwargs):+ kwargs['bus']=SimServoBus()+ kwargs['address']='memory-only'+ super().__init__(**kwargs)+++class BenchArmCoordinator(ControlCoordinator):+ """Import this module in the worker too, so its memory-only adapter is registered."""+ pass+++try:adapter_registry.register_path('moss_bench_arm','moss_mighty.full_bench:BenchArmAdapter')+except ValueError:pass+++def build():+ from .module import blueprint as camera+ from .vision import blueprint as vision+ profile=B.robot_profile.current()+ parts=B._explore_parts(profile,{'base':'memory-only','lidar':'synthetic-only'})+ parts=[p for p in parts if not any(a.module is RPLidarC1 for a in p.blueprints)]+ parts += [SyntheticRoom.blueprint(),LitterMission.blueprint(autostart=False,pick_cmd='none'),camera,vision]+ hw=A.arm_hardware(sim=False,address='memory-only')+ hw.adapter_type='moss_bench_arm'+ parts.append(BenchArmCoordinator.blueprint(hardware=[hw],tasks=[A.arm_trajectory_task()],+ tick_rate=50.,instance_name='ArmCoordinator').remappings([+ (BenchArmCoordinator,'coordinator_joint_state','arm_joint_state'),+ (BenchArmCoordinator,'twist_command','unused_arm_twist')]))+ return B._jpeg_camera(autoconnect(*parts)).remappings([+ (B.MossControlCoordinator,'twist_command','cmd_vel')])+++blueprint=build()diff --git a/experiments/orange-pi-mightycam/moss_mighty/module.py b/experiments/orange-pi-mightycam/moss_mighty/module.pynew file mode 100644index 0000000..3dc9d00--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/module.py@@ -0,0 +1,70 @@+import json+import os+import threading+import numpy as np+from dimos.core.core import rpc+from dimos.core.module import Module+from dimos.core.stream import Out+from dimos.core.transport import LCMTransport, JpegLcmTransport+from dimos.core.coordination.blueprints import autoconnect+from dimos.msgs.geometry_msgs.PoseStamped import PoseStamped+from dimos.msgs.sensor_msgs.Image import Image, ImageFormat+from dimos.msgs.std_msgs.String import String+from .core import BenchState, Receiver, serve+++class MightyBench(Module):+ dedicated_worker = True+ mighty_pose: Out[PoseStamped]+ mighty_image: Out[Image]+ mighty_status: Out[String]++ def __init__(self, **kwargs):+ super().__init__(**kwargs)+ self.bench = BenchState()+ self.end_status = threading.Event()++ @rpc+ def start(self):+ super().start()+ self.server = serve(self.bench, int(os.environ.get("MOSS_MIGHTY_WEB_PORT", "8905")))+ self.receiver = Receiver(self.bench, os.environ.get("MOSS_MIGHTY_URL", "http://192.168.7.1"),+ on_pose=self._publish_pose, on_image=self._publish_image)+ self.receiver.start()+ self.status_thread = threading.Thread(target=self._status_worker, daemon=True)+ self.status_thread.start()++ def _publish_pose(self, p):+ # Host receipt time is intentional. Raw sensor ns are exposed in status;+ # no uncalibrated device clock is presented as Unix time.+ self.mighty_pose.publish(PoseStamped(ts=p["received_at"], frame_id="mighty_odom",+ position=p["position_m"], orientation=p["orientation_xyzw"]))++ def _publish_image(self, pixels, timestamp):+ self.mighty_image.publish(Image.from_numpy(np.asarray(pixels), format=ImageFormat.RGB,+ frame_id="mighty_camera", ts=timestamp))++ def _status_worker(self):+ while not self.end_status.wait(1):+ status = self.bench.snapshot()+ status.pop("trajectory", None)+ self.mighty_status.publish(String(json.dumps(status, allow_nan=False)))++ @rpc+ def stop(self):+ self.end_status.set()+ if hasattr(self, "receiver"):+ self.receiver.stop()+ if hasattr(self, "server"):+ self.server.shutdown()+ self.server.server_close()+ if hasattr(self, "status_thread"):+ self.status_thread.join(timeout=2)+ super().stop()+++blueprint = autoconnect(MightyBench.blueprint()).transports({+ ("mighty_pose", PoseStamped): LCMTransport("/moss/mighty/pose", PoseStamped),+ ("mighty_image", Image): JpegLcmTransport("/moss/mighty/image", Image),+ ("mighty_status", String): LCMTransport("/moss/mighty/status", String),+})diff --git a/experiments/orange-pi-mightycam/moss_mighty/npu.py b/experiments/orange-pi-mightycam/moss_mighty/npu.pynew file mode 100644index 0000000..89973c2--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/npu.py@@ -0,0 +1,64 @@+"""A733 VIPLite backend; model and runtime stay on the Orange Pi.++Uses the vendor SDK's YOLOv5 preprocessing, inference and postprocessing.+The subprocess is bounded and consumes only the latest camera frame.+"""+import os+import re+import subprocess+import time+from pathlib import Path++DETECTION = re.compile(r'^\s*(\d+):\s*(\d+)%,\s*\[\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)\],\s*(.+)$', re.M)+NETWORK_MS = re.compile(r'vip_run_network:\s*([\d.]+) ms')+++def parse_result(output):+ boxes = []+ for item in DETECTION.finditer(output):+ cls, confidence, x1, y1, x2, y2, label = item.groups()+ boxes.append({'label': label.strip(), 'class_id': int(cls),+ 'confidence': int(confidence)/100,+ 'xyxy': list(map(int, (x1, y1, x2, y2))), 'track_id': None})+ timing = NETWORK_MS.search(output)+ return boxes, float(timing.group(1)) if timing else None+++class NpuDetector:+ def __init__(self, runtime):+ from .paths import NPU_SDK+ self.sdk = NPU_SDK+ self.binary = self.sdk/'examples/yolov5/yolov5'+ self.model = self.sdk/'examples/yolov5/model/v3/yolov5.nb'+ self.work = Path(runtime)/'npu'+ self.work.mkdir(parents=True, exist_ok=True)+ if not self.binary.is_file() or not self.model.is_file():+ raise RuntimeError('Compiled A733 YOLOv5 backend or model is missing')+ self.env = dict(os.environ)+ self.env['LD_LIBRARY_PATH'] = str(self.sdk/'viplite-tina/lib/aarch64-none-linux-gnu/v2.0')++ def predict(self, image):+ import cv2+ before = time.monotonic()+ source = self.work/'input.jpg'+ if not cv2.imwrite(str(source), image, [cv2.IMWRITE_JPEG_QUALITY, 92]):+ raise RuntimeError('Cannot prepare NPU input')+ result = subprocess.run([str(self.binary), str(self.model), str(source)],+ cwd=self.work, env=self.env, capture_output=True,+ text=True, timeout=4, check=False)+ output = result.stdout+'\n'+result.stderr+ if result.returncode:+ raise RuntimeError(f'NPU inference exited {result.returncode}: {output[-400:]}')+ boxes, npu_ms = parse_result(output)+ if npu_ms is None or 'detection num:' not in output:+ raise RuntimeError('NPU did not return a completed inference')+ annotated = image.copy()+ for b in boxes:+ x1,y1,x2,y2 = b['xyxy']+ cv2.rectangle(annotated, (x1,y1), (x2,y2), (199,248,108), 2)+ cv2.putText(annotated, f"{b['label']} {b['confidence']:.0%}",+ (x1,max(18,y1-6)), cv2.FONT_HERSHEY_SIMPLEX, .5, (199,248,108), 1, cv2.LINE_AA)+ return annotated, boxes, npu_ms, (time.monotonic()-before)*1000++ def stop(self):+ passdiff --git a/experiments/orange-pi-mightycam/moss_mighty/paths.py b/experiments/orange-pi-mightycam/moss_mighty/paths.pynew file mode 100644index 0000000..762c8a6--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/paths.py@@ -0,0 +1,10 @@+"""User-owned data locations for this experimental profile."""+import os+from pathlib import Path++DATA_DIR = Path(os.environ.get('MOSS_MIGHTY_DATA_DIR',+ str(Path.home()/'.local/share/moss-mighty'))).expanduser()+RUNTIME = Path(os.environ.get('MOSS_VISION_RUNTIME', str(DATA_DIR/'runtime'))).expanduser()+NPU_SDK = Path(os.environ.get('MOSS_NPU_SDK', str(DATA_DIR/'npu-sdk'))).expanduser()+MODELS_DIR = DATA_DIR/'models'+STATE_DIR = Path(os.environ.get('MOSS_STATE_DIR', str(DATA_DIR/'bench-state'))).expanduser()diff --git a/experiments/orange-pi-mightycam/moss_mighty/vision.py b/experiments/orange-pi-mightycam/moss_mighty/vision.pynew file mode 100644index 0000000..b4e1494--- /dev/null+++ b/experiments/orange-pi-mightycam/moss_mighty/vision.py@@ -0,0 +1,136 @@+"""Latest-frame YOLO worker on the real dimOS Mighty image stream."""+import json+import os+import threading+import time+from collections import deque+from pathlib import Path++from dimos.core.core import rpc+from dimos.core.module import Module+from dimos.core.stream import In, Out+from dimos.core.transport import LCMTransport, JpegLcmTransport+from dimos.core.coordination.blueprints import autoconnect+from dimos.msgs.sensor_msgs.Image import Image, ImageFormat+from dimos.msgs.std_msgs.String import String++from .paths import RUNTIME++++def atomic_write(path,data):+ temporary=path.with_suffix(path.suffix+'.new')+ temporary.write_bytes(data)+ temporary.replace(path)+++class MightyYolo(Module):+ dedicated_worker=True+ mighty_image: In[Image]+ detections: Out[String]+ annotated_image: Out[Image]++ @rpc+ def start(self):+ super().start()+ import cv2+ self.threads=int(os.environ.get('MOSS_YOLO_THREADS','2'))+ cv2.setNumThreads(1)+ self.size=int(os.environ.get('MOSS_YOLO_SIZE','320'))+ self.rate=float(os.environ.get('MOSS_YOLO_FPS','3'))+ self.backend=os.environ.get('MOSS_YOLO_BACKEND','npu')+ if self.backend=='npu':+ from .npu import NpuDetector+ self.detector=NpuDetector(RUNTIME)+ self.size=640+ self.model_name='YOLOv5 · COCO'+ self.backend_name='A733 NPU · VIPLite'+ else:+ import torch+ from dimos.perception.detection.detectors.yolo import Yolo2DDetector+ torch.set_num_threads(self.threads)+ from .paths import MODELS_DIR+ path=Path(os.environ.get('MOSS_YOLO_MODEL',str(MODELS_DIR/'yolo11n.pt')))+ self.detector=Yolo2DDetector(model_path=str(path.parent),model_name=path.name,device='cpu')+ self.model_name=path.name+ self.backend_name='PyTorch CPU'+ self.latest=None+ self.lock=threading.Lock()+ self.end=threading.Event()+ self.count=0+ self.timings=deque(maxlen=30)+ RUNTIME.mkdir(parents=True,exist_ok=True)+ self.subscription=self.mighty_image.subscribe(self.accept)+ self.worker=threading.Thread(target=self.infer,daemon=True)+ self.worker.start()++ def accept(self,image):+ # No accumulation: overwrite frames while the CPU is busy.+ with self.lock:self.latest=image++ def infer(self):+ import cv2+ import numpy as np+ while not self.end.is_set():+ start=time.monotonic()+ with self.lock:+ frame,self.latest=self.latest,None+ if frame is None:+ self.end.wait(.05)+ continue+ try:+ npu_ms=None+ if self.backend=='npu':+ annotated,boxes,npu_ms,elapsed=self.detector.predict(frame.to_opencv())+ else:+ import torch+ results=self.detector.model.track(frame.to_opencv(),imgsz=self.size,+ device='cpu',conf=.35,iou=.6,persist=True,tracker='bytetrack.yaml',verbose=False)+ torch.set_num_threads(self.threads)+ elapsed=(time.monotonic()-start)*1000+ result=results[0]+ boxes=[]+ if result.boxes is not None:+ ids=result.boxes.id+ for i,b in enumerate(result.boxes):+ cls=int(b.cls.item())+ boxes.append({'label':result.names[cls],'confidence':float(b.conf.item()),+ 'xyxy':b.xyxy[0].tolist(),'track_id':int(ids[i]) if ids is not None else None})+ annotated=result.plot()+ self.timings.append(elapsed)+ self.count+=1+ now=time.time()+ info={'model':self.model_name,'backend':self.backend_name,'input_size':self.size,+ 'npu_network_ms':npu_ms,+ 'inference_ms':round(elapsed,1),'median_ms':round(float(np.median(self.timings)),1),+ 'frames_processed':self.count,'source_timestamp':float(frame.ts),+ 'updated_at':now,'detections':boxes,'error':'',+ 'note':'2D detections on a monochrome camera; no object depth or distance measured.'}+ _,jpg=cv2.imencode('.jpg',annotated,[cv2.IMWRITE_JPEG_QUALITY,80])+ atomic_write(RUNTIME/'vision.jpg',jpg.tobytes())+ data=json.dumps(info,allow_nan=False)+ atomic_write(RUNTIME/'vision.json',data.encode())+ self.detections.publish(String(data=data))+ self.annotated_image.publish(Image.from_numpy(cv2.cvtColor(annotated,cv2.COLOR_BGR2RGB),+ format=ImageFormat.RGB,frame_id='mighty_camera',ts=frame.ts))+ except Exception as exc:+ atomic_write(RUNTIME/'vision.json',json.dumps({'updated_at':time.time(),+ 'error':str(exc),'model':self.model_name,'detections':[]}).encode())+ self.end.wait(max(.01,1/self.rate-(time.monotonic()-start)))++ @rpc+ def stop(self):+ if hasattr(self,'end'):+ self.end.set();self.worker.join(timeout=5)+ self.detector.stop()+ super().stop()+++blueprint=autoconnect(MightyYolo.blueprint()).transports({+ ('mighty_image',Image):JpegLcmTransport('/moss/mighty/image',Image),+ ('detections',String):LCMTransport('/moss/mighty/detections',String),+ ('annotated_image',Image):JpegLcmTransport('/moss/mighty/annotated',Image),+})++from .module import blueprint as camera_blueprint+demo=autoconnect(camera_blueprint, blueprint)diff --git a/experiments/orange-pi-mightycam/pyproject.toml b/experiments/orange-pi-mightycam/pyproject.tomlnew file mode 100644index 0000000..e57196d--- /dev/null+++ b/experiments/orange-pi-mightycam/pyproject.toml@@ -0,0 +1,24 @@+[build-system]+requires = ["setuptools>=68", "wheel"]+build-backend = "setuptools.build_meta"++[project]+name = "moss-mighty"+version = "0.1.0"+description = "Experimental Orange Pi A733 load test for MOSS/dimOS and MightyCam"+readme = "README.md"+license = {text = "Apache-2.0"}+requires-python = ">=3.10,<3.13"+dependencies = ["mighty-protocol", "Pillow>=9", "numpy"]++[project.entry-points."dimos.blueprints"]+mighty = "moss_mighty.module:blueprint"+full-bench = "moss_mighty.full_bench:blueprint"+vision = "moss_mighty.vision:blueprint"+demo = "moss_mighty.vision:demo"++[tool.setuptools]+packages = ["moss_mighty"]++[tool.setuptools.package-data]+moss_mighty = ["dashboard.html", "cockpit/*.css", "cockpit/*.js", "cockpit/*.json", "cockpit/assets/*.svg", "cockpit/fonts/*"]diff --git a/experiments/orange-pi-mightycam/requirements.txt b/experiments/orange-pi-mightycam/requirements.txtnew file mode 100644index 0000000..483cf44--- /dev/null+++ b/experiments/orange-pi-mightycam/requirements.txt@@ -0,0 +1,5 @@+# The dimOS revision used by MOSS Software.md and this experiment.+dimos @ git+https://github.com/dimensionalOS/dimos.git@a7d19f76158b01739b26e7a17390f89764aaef83+mighty-protocol @ git+https://github.com/asadm/mighty-protocol.git@aeb060e36a6cc25edae9153b4806dbfa99c343a4+opencv-python==4.11.0.86+Pillow>=9diff --git a/experiments/orange-pi-mightycam/results/2026-10-27.json b/experiments/orange-pi-mightycam/results/2026-10-27.jsonnew file mode 100644index 0000000..065258e--- /dev/null+++ b/experiments/orange-pi-mightycam/results/2026-10-27.json@@ -0,0 +1,70 @@+{+ "date": "2026-10-27",+ "purpose": "Whole-board load and fit experiment; no real robot autonomy validation",+ "board": "Orange Pi Zero 3W / Allwinner A733 / 6 GB",+ "os": "Armbian 26.8.1 Debian 13",+ "kernel": "6.6.98-vendor-sun60iw2",+ "camera": "MightyCam VIO",+ "cooler": "Official cooler fitted for these measurements",+ "memory": {+ "definition": "MemTotal - MemAvailable",+ "total_mib": 5844.3,+ "observed_used_gib_approx": [+ 1.6,+ 1.7+ ],+ "swap_used_mib": 0+ },+ "vision": {+ "model": "YOLOv5 COCO 640x640",+ "backend": "A733 VIPLite NPU",+ "network_ms_approx": [+ 26,+ 30+ ],+ "complete_pipeline_ms_approx": [+ 330,+ 390+ ],+ "recorded_throughput_fps_approx": [+ 2.6,+ 2.8+ ],+ "litter_specific": false+ },+ "integration_sample": {+ "duration_s": 20.42,+ "detector_cap_hz": 1,+ "cpu_quota_percent": 400,+ "memory_used_mib": 1725.5,+ "temperature_c": 61.1,+ "stream_counts": {+ "synthetic_lidar_odometry": 201,+ "simulated_base_joint_state": 2037,+ "simulated_arm_joint_state": 1003,+ "synthetic_global_costmap": 100,+ "real_mighty_pose": 1225,+ "real_npu_detections_messages": 20+ }+ },+ "handheld_recording": {+ "detector_cap_hz": 3,+ "approx_temperature_c": [+ 61,+ 67+ ]+ },+ "active_inputs": "Real camera image and VIO. Synthetic LiDAR and mock/in-memory actuator buses.",+ "loaded_but_not_task_validated": [+ "planner",+ "explorer",+ "litter mission"+ ],+ "failures": [+ "VIO path drifted and did not return to start",+ "Severe coordinate divergence on a subsequent restart",+ "Camera calibration query returned calib.yaml not found",+ "Image stream resumed once with VIO OFF; automatic restart is not implemented"+ ],+ "interpretation": "Calibration, synchronization, initialization and firmware need investigation. Missing saved calibration is not a proven sole cause. CPU/NPU compute fit was demonstrated; metric camera accuracy and autonomous collection were not."+}diff --git a/experiments/orange-pi-mightycam/scripts/build_npu.sh b/experiments/orange-pi-mightycam/scripts/build_npu.shnew file mode 100755index 0000000..497494e--- /dev/null+++ b/experiments/orange-pi-mightycam/scripts/build_npu.sh@@ -0,0 +1,10 @@+#!/usr/bin/env bash+set -euo pipefail+experiment_dir="$(cd "$(dirname "$0")/.." && pwd)"+data_dir="${MOSS_MIGHTY_DATA_DIR:-$experiment_dir/runtime}"+sdk_dir="${MOSS_NPU_SDK:-$data_dir/npu-sdk}"+[[ "$(uname -s)" == Linux ]] || { echo 'Build on the Linux A733 board.' >&2; exit 1; }+case "$(uname -m)" in aarch64|arm64) ;; *) echo 'Build on the A733 ARM64 board.' >&2; exit 1;; esac+make -C "$sdk_dir/examples/yolov5" AI_SDK_PLATFORM=a733 STAGING_DIR=/ \+ CFLAGS='-O2 -DNPU_SW_VERSION=2' yolov5+echo "Built: $sdk_dir/examples/yolov5/yolov5"diff --git a/experiments/orange-pi-mightycam/scripts/fetch_npu.py b/experiments/orange-pi-mightycam/scripts/fetch_npu.pynew file mode 100644index 0000000..9a1ec4f--- /dev/null+++ b/experiments/orange-pi-mightycam/scripts/fetch_npu.py@@ -0,0 +1,50 @@+#!/usr/bin/env python3+"""Fetch the pinned vendor example into ignored runtime storage; verify every file."""+import argparse+import hashlib+import json+import os+import urllib.request+from pathlib import Path++HERE = Path(__file__).resolve().parent+++def main():+ default = Path(os.environ.get('MOSS_MIGHTY_DATA_DIR', str(HERE.parent/'runtime')))/'npu-sdk'+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument('--destination', type=Path, default=default)+ args = parser.parse_args()+ manifest = json.loads((HERE/'npu-files.json').read_text())+ destination = args.destination.expanduser().resolve()+ upstream = manifest['repository'].removeprefix('https://github.com/')+ for name, checksum in manifest['sha256'].items():+ target = (destination/name).resolve()+ if destination not in target.parents:+ raise ValueError('Invalid manifest path')+ if target.is_file() and hashlib.sha256(target.read_bytes()).hexdigest() == checksum:+ continue+ url = f"https://raw.githubusercontent.com/{upstream}/{manifest['revision']}/{name}"+ with urllib.request.urlopen(url, timeout=45) as response:+ data = response.read()+ if hashlib.sha256(data).hexdigest() != checksum:+ raise ValueError(f'Checksum mismatch: {name}')+ target.parent.mkdir(parents=True, exist_ok=True)+ temporary = target.with_suffix(target.suffix+'.download')+ temporary.write_bytes(data)+ temporary.replace(target)+ print(name, flush=True)+ # The sample does not use highgui. Keep the build headless.+ for name in ('yolov5_pre_process.cpp', 'yolov5_post_process.cpp'):+ path = destination/'examples/yolov5'/name+ text = path.read_text().replace('#include <opencv2/highgui/highgui.hpp>',+ '#include <opencv2/imgcodecs.hpp>')+ # vector's end is exclusive; preserve the last output element too.+ for i in range(3):+ text = text.replace(f'&output[{i}][size{i}-1]', f'output[{i}] + size{i}')+ path.write_text(text)+ print(f'Ready: {destination}')+++if __name__ == '__main__':+ main()diff --git a/experiments/orange-pi-mightycam/scripts/npu-files.json b/experiments/orange-pi-mightycam/scripts/npu-files.jsonnew file mode 100644index 0000000..3462d27--- /dev/null+++ b/experiments/orange-pi-mightycam/scripts/npu-files.json@@ -0,0 +1,29 @@+{+ "repository": "https://github.com/ZIFENG278/ai-sdk",+ "revision": "fc90006d0f6569da2f6726c2d8395877686f5aca",+ "sha256": {+ "examples/libawnn_viplite/awnn_internal.h": "9c1a653d70e46bc63a7b53f56a8d5b03e2a2b03e5f635e4484cc983f48363380",+ "examples/libawnn_viplite/awnn_lib.c": "cd5887d5ed7a46235c7ad79366ad83ec0aa2368bc487848c57e1726b220b7e30",+ "examples/libawnn_viplite/awnn_lib.h": "5f59b1ee572ca445b9b8d2f9abbb96ce50b352c653cd59841c2c4feb78b02624",+ "examples/libawnn_viplite/awnn_quantize.c": "aa23ce3dd31785fc798ffeeca8f9aa473d327c9f7dca8fd062cfeede018c7f6f",+ "examples/libawnn_viplite/awnn_quantize.h": "853d82b643d0392759cc3ab515b49509b5e036d1694233ac0ca4156233e72bc7",+ "examples/libawutils/image_utils.c": "4323b109a77fd80326dfd9f6c0fbbad0f393f0abb7efb12afe6fea7bd19b48de",+ "examples/libawutils/image_utils.h": "3a1eac1ac02cfa0c3be15d64a3bf8ab28c6da9203792ba792a0e065e3bd17302",+ "examples/yolov5/Makefile": "2072d44c44d7437ab18df09b77f8fe92e12cb0f9c3ce39921ac2eac0047122a8",+ "examples/yolov5/README.md": "a52fcb51ac7f452af7d638cdd6fa18452ade80dad9a93a1d754ad10f6a387801",+ "examples/yolov5/input_data/dog.jpg": "5a9522051c3cec2bbd2f6323fccba32e8fbf3ddcc2b3e2fd46b04c720bc6f866",+ "examples/yolov5/main.c": "53b1b2748690c6b3126656d0e193e4e768c1a5adba6d1d428cc7f4ca51ee840c",+ "examples/yolov5/model/v3/yolov5.nb": "6c6cb261f41fcc774134b90d0e1f2a17675cd6da1e8f1c6d2b61460cfd584158",+ "examples/yolov5/yolov5.sh": "a5a0330a9730b44cbb3b181634393551250b99d3ba8143bb0456afebdfbb5bcb",+ "examples/yolov5/yolov5_post_process.cpp": "ceb3429c19fc3f925fce69cd848ac58d8ee5de39205d4c070e1eb35a1995286c",+ "examples/yolov5/yolov5_post_process.h": "d4d1b48e6b5672da488890b17912694a47d543cfbd9fa0d602ed2a0a7af5d8bc",+ "examples/yolov5/yolov5_pre_process.cpp": "caf1cfc88850c9c0e02a8fb9b1ba4ca41480210f63f3774cc7b9ca190884ebdc",+ "examples/yolov5/yolov5_pre_process.h": "153fbcf00d9387bec06101c4b60d0031b770dac6864734f1afe788c1b86d5075",+ "machinfo/a733/config.mk": "d495c5f468775dca2504158dc7cae5735b4005dfa5623a9b685563a0ac8e6ea0",+ "viplite-tina/lib/aarch64-none-linux-gnu/v2.0/inc/vip_lite.h": "33fee8f985210cb34f14b7e2b0614096e6972718f87d8107497521d561d9df41",+ "viplite-tina/lib/aarch64-none-linux-gnu/v2.0/inc/vip_lite_common.h": "d807216e8376de4729de074ecb1b91cd5ccab279ef18543acd3adb61b1a1518e",+ "viplite-tina/lib/aarch64-none-linux-gnu/v2.0/libNBGlinker.so": "82f049b0ed0065dd4d443e37eeb1edfcbef24457c9c24e36170d64d5b748ca66",+ "viplite-tina/lib/aarch64-none-linux-gnu/v2.0/libVIPhal.so": "3ed5357b26bd6c4fb68fbdc0b21d637227dda711d1fe67b9e28accdc48bb11f2",+ "log/log.h": "d831146829a9092c5e8faac5878aa70a6eee3c7fa0bc2f566a5250db06eac84a"+ }+}diff --git a/experiments/orange-pi-mightycam/scripts/run.sh b/experiments/orange-pi-mightycam/scripts/run.shnew file mode 100755index 0000000..5a0484d--- /dev/null+++ b/experiments/orange-pi-mightycam/scripts/run.sh@@ -0,0 +1,18 @@+#!/usr/bin/env bash+set -euo pipefail+experiment_dir="$(cd "$(dirname "$0")/.." && pwd)"+repo_dir="$(cd "$experiment_dir/../.." && pwd)"+profile="${1:-demo}"+case "$profile" in mighty|demo|full-bench) ;; *) echo 'Usage: run.sh [mighty|demo|full-bench]' >&2; exit 2;; esac+export MOSS_MIGHTY_DATA_DIR="${MOSS_MIGHTY_DATA_DIR:-$experiment_dir/runtime}"+export MOSS_MIGHTY_PROFILE="$profile"+export MOSS_MIGHTY_URL="${MOSS_MIGHTY_URL:-http://192.168.7.1}"+export MOSS_YOLO_BACKEND="${MOSS_YOLO_BACKEND:-npu}"+export MOSS_YOLO_FPS="${MOSS_YOLO_FPS:-3}"+export OPENBLAS_NUM_THREADS=2 OMP_NUM_THREADS=2 NUMBA_NUM_THREADS=2+export YOLO_AUTOINSTALL=false+export YOLO_CONFIG_DIR="$MOSS_MIGHTY_DATA_DIR/yolo-config"+export PATH="/usr/sbin:/sbin:$PATH"+mkdir -p "$MOSS_MIGHTY_DATA_DIR"+cd "$repo_dir"+exec "${MOSS_DIMOS:-$repo_dir/.venv/bin/dimos}" run "moss-mighty.$profile"diff --git a/experiments/orange-pi-mightycam/tests/test_core.py b/experiments/orange-pi-mightycam/tests/test_core.pynew file mode 100644index 0000000..e2d1f73--- /dev/null+++ b/experiments/orange-pi-mightycam/tests/test_core.py@@ -0,0 +1,71 @@+"""Portable checks for data validity; no board, SDK or actuator required."""+import math+import unittest+from unittest.mock import patch++from moss_mighty.core import BenchState, CpuUsage, cpu_percent, validate_pose+from moss_mighty.npu import parse_result++POSE = {'position_m':[1.,2.,3.], 'orientation_xyzw':[0.,0.,0.,1.],+ 'confidence':.9, 'timestamp_ns':123, 'is_public':True, 'packet_type':'POSE'}+++class CoreTests(unittest.TestCase):+ def test_invalid_or_internal_pose_is_rejected(self):+ for changes in ({'position_m':[math.nan,0,0]}, {'confidence':math.inf},+ {'orientation_xyzw':[0,0,0,0]}, {'is_public':False}):+ with self.assertRaises(ValueError):+ validate_pose({**POSE, **changes})++ def test_degraded_pose_never_extends_path(self):+ for code in (0,1,3,4,5,6):+ state=BenchState();state.vio_state={'state':code}+ state.accept_pose(POSE)+ self.assertFalse(state.snapshot()['tracking'])+ self.assertEqual(list(state.trajectory),[])++ def test_low_confidence_pose_never_extends_path(self):+ state=BenchState();state.accept_pose({**POSE,'confidence':.25})+ self.assertFalse(state.snapshot()['tracking'])+ self.assertEqual(list(state.trajectory),[])++ def test_stale_pose_is_not_live(self):+ state=BenchState();state.accept_pose(POSE)+ self.assertTrue(state.snapshot()['tracking'])+ state.pose_monotonic-=2+ self.assertFalse(state.snapshot()['tracking'])++ def test_reset_clears_state_and_trace(self):+ state=BenchState();state.accept_pose(POSE);state.reset()+ self.assertIsNone(state.pose)+ self.assertEqual(list(state.trajectory),[])+ self.assertEqual(state.reset_count,1)++ def test_cpu_iowait_is_idle_guest_is_not_double_counted(self):+ self.assertEqual(cpu_percent([0]*10,[20,0,10,50,20,0,0,0,20,0]),30.0)+ self.assertIsNone(cpu_percent([1]*10,[1]*10))+ self.assertIsNone(cpu_percent([100]*10,[1]*10))++ def test_cpu_samples_are_shared_between_browser_clients(self):+ sampler=CpuUsage()+ with patch('moss_mighty.core.Path.read_text', side_effect=[+ 'cpu 0 0 0 0 0 0 0 0\ncpu0 0 0 0 0 0 0 0 0\ncpu1 0 0 0 0 0 0 0 0',+ 'cpu 0 0 0 0 0 0 0 0\ncpu0 20 0 10 50 20 0 0 0\ncpu1 50 0 0 50 0 0 0 0'+ ]) as reader, patch('moss_mighty.core.time.monotonic',side_effect=[10.,10.3,11.]):+ first=sampler.sample();cached=sampler.sample();last=sampler.sample()+ self.assertEqual(reader.call_count,2)+ self.assertIs(first,cached)+ self.assertIsNone(first['average_percent'])+ self.assertEqual(last['cores'],[{'id':0,'usage_percent':30.0},{'id':1,'usage_percent':50.0}])+ self.assertEqual(last['average_percent'],40.0)++ def test_npu_boxes_and_network_timing(self):+ boxes,timing=parse_result('vip_run_network: 27.03 ms.\n16: 87%, [ 134, 216, 308, 552], dog\n')+ self.assertEqual(timing,27.03)+ self.assertEqual(boxes[0]['xyxy'],[134,216,308,552])+ self.assertEqual(boxes[0]['confidence'],.87)+ self.assertEqual(parse_result('load failed'),([],None))+++if __name__ == '__main__':+ unittest.main()diff --git a/experiments/orange-pi-mightycam/tests/test_integration.py b/experiments/orange-pi-mightycam/tests/test_integration.pynew file mode 100644index 0000000..3ec4ec0--- /dev/null+++ b/experiments/orange-pi-mightycam/tests/test_integration.py@@ -0,0 +1,124 @@+import json+import math+import time+import unittest+import urllib.request+from unittest.mock import patch++from moss_mighty.core import BenchState, Receiver, image_pixels, serve, validate_pose+from moss_mighty.module import MightyBench, blueprint++POSE = {'position_m':[1.,2.,3.], 'orientation_xyzw':[0.,0.,0.,1.],+ 'confidence':.9,'timestamp_ns':1234567,'is_public':True,'packet_type':'POSE'}++class Tests(unittest.TestCase):+ def test_cpu_usage_counts_iowait_as_idle_and_ignores_guest_duplicates(self):+ from moss_mighty.core import cpu_percent+ self.assertEqual(cpu_percent([0]*10,[20,0,10,50,20,0,0,0,20,0]),30.0)+ self.assertIsNone(cpu_percent([1]*10,[1]*10))+ self.assertIsNone(cpu_percent([100]*10,[1]*10))++ def test_public_pose(self):+ p=validate_pose(POSE)+ self.assertEqual(p['sensor_timestamp_ns'],1234567)+ self.assertEqual(p['child_frame_id'],'mighty_imu')+ self.assertEqual(p['position_m'],[1,2,3])++ def test_reject_internal(self):+ with self.assertRaises(ValueError):validate_pose({**POSE,'is_public':False})++ def test_reject_bad_values(self):+ for data in [{'position_m':[math.nan,2,3]},{'orientation_xyzw':[0,0,0,0]},+ {'position_m':[1,2]},{'confidence':math.nan}]:+ with self.assertRaises(ValueError):validate_pose({**POSE,**data})++ def test_stale_not_tracking(self):+ state=BenchState();state.accept_pose(POSE)+ self.assertTrue(state.snapshot()['tracking'])+ state.pose_monotonic-=2+ self.assertFalse(state.snapshot()['tracking'])++ def test_low_confidence_not_tracking(self):+ state=BenchState();state.accept_pose({**POSE,'confidence':.3})+ self.assertFalse(state.snapshot()['tracking'])+ self.assertEqual(len(state.trajectory),0)++ def test_degraded_categorical_state_overrides_confidence(self):+ for status in (0,1,3,4,5,6):+ state=BenchState();got=[]+ r=Receiver(state,'http://127.0.0.1:1',on_pose=got.append)+ r._vio_state({'state':status})+ r._pose({**POSE,'confidence':1.0})+ self.assertFalse(state.snapshot()['tracking'])+ self.assertEqual(list(state.trajectory),[])+ self.assertEqual(got,[])++ def test_npu_results_and_timing(self):+ from moss_mighty.npu import parse_result+ boxes,elapsed=parse_result('vip_run_network: 25.90 ms.\n16: 87%, [ 134, 216, 308, 552], dog\n')+ self.assertEqual(elapsed,25.9)+ self.assertEqual(boxes,[{'label':'dog','class_id':16,'confidence':.87,+ 'xyxy':[134,216,308,552],'track_id':None}])+ self.assertEqual(parse_result('load failed'),([],None))++ def test_reset_drops_trajectory(self):+ state=BenchState();state.accept_pose(POSE);state.reset()+ self.assertIsNone(state.snapshot()['pose'])+ self.assertEqual(list(state.trajectory),[])++ def test_image_and_dropped_frame(self):+ import mighty_protocol as mp+ event={'kind':'raw','width':2,'height':2,'format':mp.RAW_FORMAT['GRAY8'],+ 'data':bytes([0,127,128,255])}+ self.assertEqual(image_pixels(event).size,(2,2))+ self.assertIsNone(image_pixels({**event,'dropped':True}))++ def test_receiver_publishes_only_full_pose(self):+ got=[];r=Receiver(BenchState(),'http://127.0.0.1:1',on_pose=got.append)+ r._pose({**POSE,'confidence':.3});self.assertEqual(len(got),0)+ r._pose(POSE);self.assertEqual(len(got),1)+ r._pose({**POSE,'position_m':[math.inf,0,0]});self.assertEqual(len(got),1)++ def test_real_dimos_message_roundtrip(self):+ from dimos.msgs.geometry_msgs.PoseStamped import PoseStamped+ from dimos.msgs.sensor_msgs.Image import Image+ from PIL import Image as PillowImage+ m=MightyBench();got=[]+ with patch.object(m.mighty_pose,'publish',got.append):+ m._publish_pose(validate_pose(POSE))+ decoded=PoseStamped.lcm_decode(got[0].lcm_encode())+ self.assertAlmostEqual(decoded.x,1)+ self.assertEqual(decoded.frame_id,'mighty_odom')+ got=[]+ with patch.object(m.mighty_image,'publish',got.append):+ m._publish_image(PillowImage.new('RGB',(8,6)),time.time())+ self.assertEqual(Image.lcm_decode(got[0].lcm_encode()).frame_id,'mighty_camera')+ m.stop()++ def test_http_status(self):+ state=BenchState();server=serve(state,0)+ try:+ url=f'http://127.0.0.1:{server.server_port}'+ data=json.load(urllib.request.urlopen(url+'/status',timeout=3))+ self.assertFalse(data['tracking'])+ self.assertIn('MightyCam',urllib.request.urlopen(url,timeout=3).read().decode())+ finally:server.shutdown();server.server_close()++ def test_startup_nonfinite_diagnostics_keep_http_status_working(self):+ state=BenchState();receiver=Receiver(state,'http://127.0.0.1:1')+ receiver._vio_state({'state':'initializing','score':math.nan,+ 'error':math.inf,'other':-math.inf,'features':12})+ server=serve(state,0)+ try:+ data=json.load(urllib.request.urlopen(+ f'http://127.0.0.1:{server.server_port}/status',timeout=3))+ self.assertIsNone(data['vio_state']['score'])+ self.assertIsNone(data['vio_state']['error'])+ self.assertIsNone(data['vio_state']['other'])+ self.assertEqual(data['vio_state']['features'],12)+ self.assertEqual(data['vio_state']['state'],'initializing')+ self.assertFalse(data['tracking'])+ json.dumps(data,allow_nan=False)+ finally:server.shutdown();server.server_close()++if __name__=='__main__':unittest.main(verbosity=2)