diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 423208b..0bb5920 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,8 @@ name: CI on: push: - branches: [master] + # v2.0-alpha is the integration branch until it merges to master. + branches: [master, v2.0-alpha] pull_request: # A second push to the same PR makes the first run's result irrelevant. @@ -21,14 +22,14 @@ jobs: with: submodules: recursive - - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/nix-installer-action@v23 + - uses: DeterminateSystems/magic-nix-cache-action@v15 - name: Build all targets run: | nix develop --command bash -c ' cmake -B build . - make -C build -j"$(nproc)" vision_processor geometry_benchmark blob_benchmark + make -C build -j"$(nproc)" ssl-vision-processor geometry_benchmark blob_benchmark ' build-apt: @@ -53,7 +54,7 @@ jobs: - name: Build all targets run: | cmake -B build . - make -C build -j"$(nproc)" vision_processor geometry_benchmark blob_benchmark + make -C build -j"$(nproc)" ssl-vision-processor geometry_benchmark blob_benchmark gui-go: name: Go (gui) @@ -67,8 +68,8 @@ jobs: with: submodules: recursive - - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/nix-installer-action@v23 + - uses: DeterminateSystems/magic-nix-cache-action@v15 # The socket tests send real multicast over loopback, which Ubuntu # ships with multicast off. They fail rather than skip under CI, so a @@ -76,17 +77,24 @@ jobs: - name: Enable loopback multicast run: sudo scripts/lo-multicast.sh on - - name: Format, vet, build, test + - name: Format, vet, lint, build, test run: | nix develop --command bash -c ' cd gui make fmt-check make vet + make lint make build make go-test make generate-check ' + # Reported, not enforced: a new advisory shouldn't fail an unrelated + # PR. Read it before tagging a release. + - name: Known vulnerabilities + continue-on-error: true + run: nix develop --command bash -c 'cd gui && make vulncheck' + gui-apt: name: Go and frontend (gui, Ubuntu 24.04, no nix) # The non-nix counterpart of gui-go and frontend: the same make targets, @@ -119,7 +127,7 @@ jobs: # Ubuntu doesn't package buf. Keep the version in step with the flake's # (nix develop -c buf --version) and gui/DEVELOPMENT.md. - name: Install buf - run: go install github.com/bufbuild/buf/cmd/buf@v1.72.0 + run: go install github.com/bufbuild/buf/cmd/buf@v1.75.0 - name: Enable loopback multicast run: sudo scripts/lo-multicast.sh on @@ -144,8 +152,8 @@ jobs: with: submodules: recursive - - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/nix-installer-action@v23 + - uses: DeterminateSystems/magic-nix-cache-action@v15 # A first run publishes nothing, so this can't disturb anything. - name: Build it and run it as a new user would @@ -163,8 +171,8 @@ jobs: submodules: recursive fetch-depth: 0 - - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/nix-installer-action@v23 + - uses: DeterminateSystems/magic-nix-cache-action@v15 - name: Build run: nix develop --command bash -c 'cd gui && make deb' @@ -189,8 +197,8 @@ jobs: with: submodules: recursive - - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/nix-installer-action@v23 + - uses: DeterminateSystems/magic-nix-cache-action@v15 - name: Lint, check, build run: | @@ -211,8 +219,8 @@ jobs: with: submodules: recursive - - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/nix-installer-action@v23 + - uses: DeterminateSystems/magic-nix-cache-action@v15 - name: Smoke tests run: | diff --git a/.github/workflows/cv-deb.yml b/.github/workflows/cv-deb.yml new file mode 100644 index 0000000..8c039b2 --- /dev/null +++ b/.github/workflows/cv-deb.yml @@ -0,0 +1,62 @@ +name: CV package + +# ssl-vision-processor's .deb, for each Ubuntu LTS. Its own workflow, so it runs +# only when what goes into the package changes: each run builds three Docker +# images from scratch, ssl-vision-processor three times, and checks each package +# under systemd. The release workflow builds and checks them again for a tag. +on: + push: + branches: [master, v2.0-alpha] + paths: &paths + - .github/workflows/cv-deb.yml + # What build-in-container.sh compiles. + - CMakeLists.txt + - cmake/** + - kernel/** + - src/** + - tools/** + - proto + # What nfpm.yaml installs from outside packaging/. + - packaging/** + - robot-heights.yml + - README.md + - camera_ids.png + - line_corners.png + - config/legacy/** + pull_request: + paths: *paths + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + cv-deb: + name: Debian package (Ubuntu ${{ matrix.release }}) + # Each release's package is built in a stock container of that release, so + # it links against that release's libraries, then installed and checked in + # another, running systemd (packaging/README.md). + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + release: ["24.04", "26.04"] + steps: + # The package version counts commits, which needs the history. + - uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + # For nfpm, pinned in packaging/go.mod. Not nix: this build is the + # distribution's, not nix's. + - uses: actions/setup-go@v5 + with: + go-version-file: packaging/go.mod + cache-dependency-path: packaging/go.sum + + - name: Build + run: packaging/build-deb.sh "${{ matrix.release }}" + + - name: Install and check the services + run: packaging/deb-check-container.sh "${{ matrix.release }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2c52593..495c018 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,10 @@ name: Release -# Pushing a v* tag publishes that version of the GUI host: the static binary, -# its tarball, the .deb packages and SHA256SUMS, as a GitHub Release. +# Pushing a v* tag builds that version of the GUI host (the static binary, its +# tarball and .deb packages) and of ssl-vision-processor (a .deb per Ubuntu LTS), +# with SHA256SUMS, as a draft GitHub Release. Only +# maintainers see a draft: install it, then publish it by hand. A tag with a +# suffix (v2.0.0-alpha.1, -rc.1) is marked as a pre-release. on: push: tags: ["v*"] @@ -10,8 +13,39 @@ permissions: contents: write jobs: + cv: + name: Release (ssl-vision-processor, Ubuntu ${{ matrix.release }}) + runs-on: ubuntu-24.04 + strategy: + matrix: + release: ["24.04", "26.04"] + steps: + # The version comes from git describe, which needs the tags. + - uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - uses: actions/setup-go@v5 + with: + go-version-file: packaging/go.mod + cache-dependency-path: packaging/go.sum + + - name: Build and check + run: | + packaging/build-deb.sh "${{ matrix.release }}" + packaging/deb-check-container.sh "${{ matrix.release }}" + + - uses: actions/upload-artifact@v4 + with: + name: cv-deb-${{ matrix.release }} + path: build-deb/*.deb + if-no-files-found: error + gui: name: Release (gui) + # Drafts the release with every package, so it waits for ssl-vision-processor's. + needs: cv runs-on: ubuntu-24.04 steps: # The version comes from git describe, which needs the tags. @@ -20,8 +54,18 @@ jobs: submodules: recursive fetch-depth: 0 - - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/nix-installer-action@v23 + - uses: DeterminateSystems/magic-nix-cache-action@v15 + + - name: Enable loopback multicast + run: sudo scripts/lo-multicast.sh on + + # Everything CI checks, on the tagged commit itself: a tag can point at + # one CI never ran on. + - name: Check + run: | + google-chrome --version # make check skips the browser tests without it + nix develop --command bash -c 'cd gui && make check' - name: Build and check run: nix develop --command bash -c 'cd gui && make release-check VERSION="$GITHUB_REF_NAME"' @@ -34,11 +78,37 @@ jobs: lintian --fail-on error,warning gui/bin/deb/*.deb sudo gui/scripts/deb-check.sh gui/bin/deb/*_amd64.deb "$GITHUB_REF_NAME" cp gui/bin/deb/*.deb gui/bin/release/ - cd gui/bin/release && sha256sum *.tar.gz *-bin *.deb > SHA256SUMS - - name: Publish + - uses: actions/download-artifact@v4 + with: + pattern: cv-deb-* + path: gui/bin/release + merge-multiple: true + + # GitHub renames a ~ in an asset's name to a dot, which would leave + # SHA256SUMS naming files nobody can download. The packages' own + # version keeps its ~, so 2.0.0~alpha.1 still sorts before 2.0.0. + - name: Checksums + run: | + cd gui/bin/release + for f in *~*; do if [ -e "$f" ]; then mv "$f" "${f//\~/-}"; fi; done + sha256sum *.tar.gz *-bin *.deb > SHA256SUMS + + - name: Draft the release env: GH_TOKEN: ${{ github.token }} run: | - gh release create "$GITHUB_REF_NAME" --generate-notes \ + prerelease=() + case "$GITHUB_REF_NAME" in *-*) prerelease=(--prerelease) ;; esac + # Links in the notes open this release's files, not master's. + sed "s#/blob/master/#/blob/$GITHUB_REF_NAME/#g" gui/packaging/release-notes.md > "$RUNNER_TEMP/notes.md" + # Our notes, then GitHub's list of merged PRs since the last + # release. The first has no last release, and GitHub would list + # every PR in the repository's history, so it gets our notes only. + notes=(--notes-file "$RUNNER_TEMP/notes.md") + if last=$(git describe --tags --abbrev=0 --match 'v*' "$GITHUB_REF_NAME^" 2>/dev/null); then + notes+=(--generate-notes --notes-start-tag "$last") + fi + gh release create "$GITHUB_REF_NAME" --draft "${prerelease[@]}" --verify-tag \ + "${notes[@]}" \ gui/bin/release/*.tar.gz gui/bin/release/*-bin gui/bin/release/*.deb gui/bin/release/SHA256SUMS diff --git a/.gitignore b/.gitignore index 7a8528f..11ffff2 100644 --- a/.gitignore +++ b/.gitignore @@ -32,15 +32,14 @@ __pycache__ # The GUI's backup of a config.yml it imported and now regenerates. *.yml.orig !/config/**/*.yml -# Not configs: test fixtures, CI, and vision_processor's default robot height +# Not configs: test fixtures, CI, and ssl-vision-processor's default robot height # table, which it reads from the working directory. !**/testdata/**/*.yml -!/.gitlab-ci.yml !/.github/**/*.yml !/robot-heights.yml #Output binaries -vision_processor +ssl-vision-processor blob_benchmark geometry_benchmark /gui/bin diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 3973c64..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,15 +0,0 @@ -image: ubuntu:latest - -variables: - GIT_SUBMODULE_STRATEGY: recursive - -stages: - - build - -build: - stage: build - script: - - apt -qq update - - DEBIAN_FRONTEND=noninteractive apt -y install --no-install-recommends build-essential cmake pkg-config libyaml-cpp-dev ocl-icd-opencl-dev libeigen3-dev libopencv-dev protobuf-compiler libprotobuf-dev ffmpeg libavcodec-dev libavformat-dev libavutil-dev libdc1394-dev > /dev/null - - cmake -B build . - - make -C build -j vision_processor diff --git a/.gitmodules b/.gitmodules index 95300df..5ffd80a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "proto"] path = proto url = https://github.com/RoboCup-SSL/ssl-protocol-defs.git - branch = main + branch = dev/vision-processor diff --git a/CMakeLists.txt b/CMakeLists.txt index 28bbb78..8fbcda6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ if(TOOLCHAIN_CHECK AND DEFINED CACHE{CMAKE_CXX_COMPILER}) include("${CMAKE_SOURCE_DIR}/cmake/CheckToolchain.cmake") endif() -project(vision_processor) +project(ssl-vision-processor) enable_language(ASM) option(WITH_SPINNAKER "Build with Spinnaker support (if library available)" ON) @@ -131,6 +131,8 @@ foreach(input_file IN LISTS CL_KERNELS) string(APPEND CL_KERNEL_ASM ".global kernel_${input_filename_cname}\n.type kernel_${input_filename_cname}, @object\nkernel_${input_filename_cname}:\n\t.incbin \"${CMAKE_SOURCE_DIR}/${input_file}\"\n\t.byte 0\n\n") string(APPEND CL_KERNEL_HEADER "extern const char kernel_${input_filename_cname}[];\n") endforeach() +# Without this note the linker gives the whole program an executable stack. +string(APPEND CL_KERNEL_ASM ".section .note.GNU-stack,\"\",@progbits\n") # Don't override cl_kernels.h or cl_kernels.S if already up-to-date to prevent unnecessary recompilation set(CL_KERNEL_H "${GENERATED_DIR}/cl_kernels.h") diff --git a/README.md b/README.md index 1cf7c85..884e0cd 100644 --- a/README.md +++ b/README.md @@ -6,18 +6,32 @@ It currently supports Teledyne FLIR (Spinnaker), Matrix Vision (Bluefox3/mvIMPAC ![Software architecture](architecture.png) -The `vision_processor` is the image processing component that processes a camera feed +The `ssl-vision-processor` is the image processing component that processes a camera feed to multicast the detected robot and ball positions and a debug video livestream. The geometry publisher `geom_publisher.py` publishes the field geometry -for all vision_processors, teams and the game controller. -`cam_viewer.py` opens the `mpv` video player with the camera streams from the vision_processor instances. +for all ssl-vision-processors, teams and the game controller. +`cam_viewer.py` opens the `mpv` video player with the camera streams from the ssl-vision-processor instances. ## GUI -A Go host plus a browser UI, replacing `geom_publisher.py` for anyone running it: +`gui/` is a browser interface that replaces `geom_publisher.py`: it holds the field geometry and camera settings, +locks in calibrations, and publishes the geometry. To use it, see [`gui/README.md`](gui/README.md); to work on it, +see [`gui/DEVELOPMENT.md`](gui/DEVELOPMENT.md). -- `gui/` — Go host (`cmd/ssl-vision-processor-gui`). Owns the field geometry, absorbs calibrations from vision processors over multicast, and serves the embedded frontend, JSON API, a WebSocket for live updates, and debug snapshot images all on one port. A single binary you can download and run: see [`gui/README.md`](gui/README.md). To work on it, run `cd gui && make run` and see [`gui/DEVELOPMENT.md`](gui/DEVELOPMENT.md); [`gui/ARCHITECTURE.md`](gui/ARCHITECTURE.md) covers its design. -- `gui/frontend/` — Svelte 5 + TypeScript + Vite, embedded into the Go binary. Run standalone with `cd gui && make proto && cd frontend && npm install && npm run dev` (proxies `/api` and `/ws` to the Go host), or serve it from the Go host directly with `make run`. `make proto` regenerates the protobuf bindings the frontend imports (not committed to git; needs `buf`, or use `nix develop`, see [`gui/CLAUDE.md`](gui/CLAUDE.md)) and only needs to be rerun after the `proto/` submodule changes. See [`gui/frontend/README.md`](gui/frontend/README.md). +## Installing from packages (Ubuntu 24.04, 26.04) + +Each release has a `.deb` of ssl-vision-processor per Ubuntu LTS, `ssl-vision-processor_*-ubuntu_amd64.deb`, +with FireWire and V4L support (not Spinnaker or mvIMPACT). It runs each camera as its own service: + + sudo apt install ./ssl-vision-processor_*-ubuntu24.04_amd64.deb + ssl-vision-processor-cameras devices # the cameras plugged in + sudo ssl-vision-processor-cameras add 0 /dev/v4l/by-id/usb-...-video-index0 + ssl-vision-processor-cameras opencl # is the GPU's OpenCL driver installed? + +It needs an OpenCL driver. Without a GPU's it falls back to the CPU (PoCL), which doesn't work yet on Ubuntu 26.04: there +it needs a GPU's OpenCL driver. See `man ssl-vision-processor-cameras`, and +[packaging/README.md](packaging/README.md) for how it's built. The GUI is +packaged separately, as `ssl-vision-processor-gui`: see [gui/README.md](gui/README.md). ## Dependency installation and compilation @@ -31,7 +45,7 @@ Arch based distributions: `pacman -S make python-protobuf python-yaml mpv` Installation with PIP: `pip install protobuf pyyaml` -### vision_processor automatic (recommended) +### ssl-vision-processor automatic (recommended) 1. Install the camera SDK required for your camera type (Arch user repository mvIMPACT: `mvimpact-acquire` Spinnaker: `spinnaker-sdk`) @@ -40,7 +54,7 @@ Installation with PIP: `pip install protobuf pyyaml` or you want, need or have a different OpenCL driver skip the driver installation with `SKIP_DRIVERS=1 ./setup.sh`. -### vision_processor manual +### ssl-vision-processor manual 1. Install the camera SDK required for your camera type (Arch user repository mvIMPACT: `mvimpact-acquire` Spinnaker: `spinnaker-sdk`) @@ -56,11 +70,11 @@ Installation with PIP: `pip install protobuf pyyaml` - yaml-cpp - libdc1394 (optional, for FireWire cameras) -3. Compile vision_processor: +3. Compile ssl-vision-processor: git submodule update --init --recursive cmake -B build . - make -C build vision_processor + make -C build ssl-vision-processor The same works inside `nix develop` (see `flake.nix`). A build directory belongs to the toolchain that configured it: to switch between nix and the distro packages, delete `build` first, or CMake stops with an error. @@ -73,13 +87,13 @@ Installation with PIP: `pip install protobuf pyyaml` `config[X].yml` for each camera, and fill it in. Skip the `geometry` section for now. The camera ids are assigned like in ssl-vision: ![Camera id pattern](camera_ids.png) -3. Start `build/vision_processor config[X].yml` for each camera. +3. Start `build/ssl-vision-processor config[X].yml` for each camera. 4. Tune the orientation and position of each camera. You can view the camera feeds with `python/cam_viewer.py --cameras `. -5. Restart the `vision_processor`s for the generation of a new sample image `img/[X].raw.jpg` +5. Restart the `ssl-vision-processor`s for the generation of a new sample image `img/[X].raw.jpg` and complete the `geometry` section of each camera config with it. Visual explanation how to determine `line_corners`: ![Line corner example](line_corners.png) -6. Restart all `vision_processor`s to pick up the new `geometry` section. +6. Restart all `ssl-vision-processor`s to pick up the new `geometry` section. Subsequent edits to thresholds, tracking limits and color references in `config[X].yml` are picked up live (within ~0.5 s) without a restart; camera, geometry, network and stream sections still require a restart. @@ -155,7 +169,7 @@ H.264 RTSP streams can silently produce corrupted frames on slower or throttled With Spinnaker available, the build also produces `build/spinnaker_probe`, a binary that creates a dump of a camera's settings (GenICam node maps) as JSON, including the pixel format the driver will select on that camera. -It never changes camera settings. Stop the `vision_processor` using the camera first. +It never changes camera settings. Stop the `ssl-vision-processor` using the camera first. build/spinnaker_probe --list # connected cameras build/spinnaker_probe --serial -o cam.json # dump one camera diff --git a/config/README.md b/config/README.md index 5271c59..57b4b01 100644 --- a/config/README.md +++ b/config/README.md @@ -11,8 +11,8 @@ accident. | File | What it is | | --- | --- | | `vision.yml` | The unified config the GUI host owns: field, shared and per-camera settings, locked calibrations. Start here. | -| `legacy/config.yml` | vision_processor's own config, with every setting and its default documented. The GUI generates one of these per local camera from `vision.yml`. | -| `legacy/config-minimal.yml` | The smallest vision_processor config: just what has no usable default. | +| `legacy/config.yml` | ssl-vision-processor's own config, with every setting and its default documented. The GUI generates one of these per local camera from `vision.yml`. | +| `legacy/config-minimal.yml` | The smallest ssl-vision-processor config: just what has no usable default. | | `legacy/geometry-divA.yml` | Division A field (12 x 9 m). Embedded as the GUI's Division A preset. | | `legacy/geometry-divB.yml` | Division B field (9 x 6 m). Embedded as the GUI's Division B preset. | @@ -23,11 +23,11 @@ cp config/vision.yml vision.yml cd gui && make run ``` -For a vision_processor run by hand, without the GUI: +For an ssl-vision-processor run by hand, without the GUI: ```sh cp config/legacy/config.yml config.yml -./build/vision_processor config.yml +./build/ssl-vision-processor config.yml ``` ## Read-only diff --git a/config/legacy/config-minimal.yml b/config/legacy/config-minimal.yml index f4c0d2f..14c991d 100644 --- a/config/legacy/config-minimal.yml +++ b/config/legacy/config-minimal.yml @@ -1,6 +1,6 @@ -# Minimal vision_processor configuration +# Minimal ssl-vision-processor configuration -# Vision camera ID handled by this vision_processor instance. +# Vision camera ID handled by this ssl-vision-processor instance. # On multi camera fields the IDs have to be ordered according to camera_ids.png. cam_id: 0 diff --git a/config/vision.yml b/config/vision.yml index 07db12f..25482c4 100644 --- a/config/vision.yml +++ b/config/vision.yml @@ -63,12 +63,12 @@ layout: # A match setup with a game controller, rather than lab use. Changes how the # GUI keeps robot height choices and how loudly it reports missing setup; -# vision_processor doesn't read it. +# ssl-vision-processor doesn't read it. # competition_field: true # Robot height choices. A team or color without one uses bot_heights_file, # looked up by the game controller's team name. Shown in the GUI only for -# now; vision_processor still uses the game controller and the table. +# now; ssl-vision-processor still uses the game controller and the table. # teams: # # On a competition field: by the game controller's team name, so each # # follows its team if the colors are switched. @@ -80,7 +80,7 @@ layout: # yellow: { height: 150 } # blue: { name: ER-Force } -# Settings every camera shares, in vision_processor's own config.yml layout +# Settings every camera shares, in ssl-vision-processor's own config.yml layout # (see legacy/config.yml for every key and its default). A camera's own # `config` below overrides these key by key. defaults: @@ -118,10 +118,10 @@ defaults: # host running four cameras appears four times. cameras: - camera_id: 0 - # The machine running this camera's vision_processor. + # The machine running this camera's ssl-vision-processor. instance: lab-pc - # A config.yml on this host the GUI regenerates from this file, for a - # vision_processor on the same machine. Omit for a remote one. Use a + # A config.yml on this host the GUI regenerates from this file, for an + # ssl-vision-processor on the same machine. Omit for a remote one. Use a # git-ignored name such as config-local.yml. config_path: config-local.yml # This camera's overrides of `defaults`, same layout. @@ -149,7 +149,7 @@ cameras: # display: { rotate: 0, mirror: false } # The group autorefs send their tracker output to (TrackerWrapperPacket). Only -# the GUI host listens, for the Live Field page; vision_processor doesn't read +# the GUI host listens, for the Live Field page; ssl-vision-processor doesn't read # it. Unset keys take the standard group. # tracker: # ip: 224.5.23.2 diff --git a/flake.lock b/flake.lock index 66621c9..1b51811 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1788179007, - "narHash": "sha256-hn1oU2rue2SYK8dAr8+WNZWtbsz1S2W5mnHlSEuh3bo=", + "lastModified": 1795234589, + "narHash": "sha256-f/VVvxf5RsQgWVhUtefoca5ktVg0DA2bnkMOcmSnozo=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "34ab99075ac4f7e40cf037eef32cb1c360bb85e9", + "rev": "2786a2a72088ecf32aea5b3ec52099e6a7cff78f", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index f2a294b..f14b001 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "SSL vision_processor build environment"; + description = "ssl-vision-processor build environment"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; @@ -34,7 +34,7 @@ # default shell because ROCm is a multi-gigabyte download nobody # without an AMD card needs. The host's own /etc/OpenCL/vendors can't # be used instead: those drivers link against the distro's libraries, - # not nixpkgs'. vision_processor takes the first GPU it finds; ROCm + # not nixpkgs'. ssl-vision-processor takes the first GPU it finds; ROCm # lists integrated GPUs too (Ryzen 9000's gfx1036 shows up after a # discrete gfx1201), so if the "Using device" log line names the # wrong one, ROCR_VISIBLE_DEVICES=0 (or the right index, from @@ -73,7 +73,7 @@ opencv # core imgproc imgcodecs videoio yaml-cpp # Must match the ffmpeg nixpkgs built opencv against, currently - # 8.1.2. The default `ffmpeg` is 9.x, which links fine but loads a + # 8.1.3. The default `ffmpeg` is 9.x, which links fine but loads a # second set of libav* sonames alongside the ones opencv's videoio # pulls in -- two copies of ffmpeg's global state in one process. ffmpeg_8 # libavformat libavcodec libavutil @@ -90,7 +90,7 @@ ]; # The ICD loader finds runtimes through this. Without it the loader - # reports zero platforms and vision_processor exits at startup. + # reports zero platforms and ssl-vision-processor exits at startup. OCL_ICD_VENDORS = "${openclRuntime}/etc/OpenCL/vendors"; # The other league Go tools carry a `toolchain` line newer than the @@ -101,7 +101,7 @@ GOTOOLCHAIN = "local"; shellHook = '' - echo "vision_processor dev shell" + echo "ssl-vision-processor dev shell" echo " eigen ${pkgs.eigen.version}" echo " opencv ${pkgs.opencv.version}" echo " ffmpeg ${pkgs.ffmpeg_8.version}" @@ -110,7 +110,7 @@ echo " node ${pkgs.nodejs_22.version}" echo " buf ${pkgs.buf.version}" echo - echo " cmake -B build . && make -C build -j vision_processor" + echo " cmake -B build . && make -C build -j ssl-vision-processor" echo echo "Camera SDKs (Spinnaker, mvIMPACT) are proprietary and not" echo "packaged here; the OpenCV and DC1394 backends are available." diff --git a/gui/AGENTS.md b/gui/AGENTS.md new file mode 100644 index 0000000..67c51a9 --- /dev/null +++ b/gui/AGENTS.md @@ -0,0 +1,77 @@ +# Agent instructions: gui/ + +For coding agents working in `gui/`, the Go host and browser interface for ssl-vision-processor. The human docs are +the source of truth; this file is the short list of rules an agent must not miss. `CLAUDE.md` imports it. + +- [ARCHITECTURE.md](ARCHITECTURE.md): how the host and frontend are built. Read it before changing design. +- [DEVELOPMENT.md](DEVELOPMENT.md): commands, testing, adding routes, topics and alerts, releasing. +- [README.md](README.md): what users see: flags, files, setup. Keep it in step with user-facing changes. +- [frontend/README.md](frontend/README.md) and [frontend/src/lib/text/README.md](frontend/src/lib/text/README.md): + the frontend's layout, and where its words live. + +## Commands + +Run from `gui/`, inside `nix develop` (from the repository root) unless the machine has the tools itself. + +``` +make test # go test -race, frontend type checks, lint, unit tests, format +make check # everything CI checks, browser tests included +make run # build and run the host on :8080 (ARGS="..." for flags) +make generate # regenerate the alert code list after adding an alert +make release-check # build the static release and run it as a new user would +``` + +- Test Go with `go test ./cmd/... ./internal/... ./frontend`, never `go test ./...`: a package in + `frontend/node_modules` ships Go source that doesn't build. +- Always `-race`. The host is concurrent by design. +- Generated code (protobuf bindings, the OpenAPI spec, the frontend's API types, the Redoc bundle) isn't committed; + `make` builds it. Don't commit it, and don't edit it by hand. + +## Safety + +- **Never run a host on a test fixture with the league's multicast addresses.** It publishes the fixture's + calibration to every real host on the network. Use `frontend/e2e/serve.mjs`'s private group and ports, or a + config whose `first_run` is still true. +- Don't delete `python/geom_publisher.py`: `setup.sh` and other Python tools still use it. +- Every file name the API takes goes through `config.ValidName`. Don't add a file reference that skips it. +- ssl-go-tools is GPL-3.0 and this repository is Apache-2.0: don't import it or copy from it. + +## Go Rules + +- Protobuf to a browser is `protojson`, never `encoding/json` on a generated message. Raw protobuf goes only on the + multicast wire. +- The SSL messages are proto2: read through `Get...()`, write through `proto.String(...)` and the like. A missing + required field failing to encode is relied on, not worked around. +- Routes go through `api.Route` or `api.Raw`, never `mux.Handle`. A handler's doc comment is its API documentation: + first sentence short. List every error code a route returns in its `api.Doc`. +- Responses never send `null` for a slice, array, map or `omitempty` field. Fixed-value strings carry an `enum:` tag. +- WebSocket topics are added in `cmd/ssl-vision-processor-gui/topics.go` with `newTopic`, and published through it. +- Don't set `WriteTimeout` on the HTTP server: it would cut every WebSocket and video stream. +- An `internal/hub` unsubscribe closes the topic's channel: call it exactly once. +- `GOTOOLCHAIN=local` is set by the root `flake.nix`. Don't work around it; it stops Go fetching a toolchain. +- Anything shipped is built with `CGO_ENABLED=0` (`make release`). +- Integration tests over mocks where the real thing is cheap (real `httptest.Server`, real fixtures, loopback + multicast). + +## Frontend Rules + +- Svelte 5 runes only, no stores. Shared state is a module-level `$state` object. +- Live state comes from `bus.svelte.ts` (`topicState`, `onTopic`). API calls go through `lib/api.ts`, with types + imported by name from `lib/apiTypes.ts`. Never a hand-written copy of a host type, a hand-written API URL, or a raw + `fetch`. +- Every UI element is a flowbite-svelte component where one exists, laid out with Tailwind utilities. Settings forms + use `FormRow.svelte` inside `SettingsCard.svelte`. Raw ` - - {#if subscribed} - {#if wrapperPacket} -
{JSON.stringify(wrapperPacket, null, 2)}
- {:else} -

Waiting for first frame…

- {/if} - {/if} - - {/snippet} - + - - + diff --git a/gui/frontend/src/app.css b/gui/frontend/src/app.css index 1b170dc..d4e4ef0 100644 --- a/gui/frontend/src/app.css +++ b/gui/frontend/src/app.css @@ -53,6 +53,13 @@ Required for flowbite-svelte, confirmed against the library's own app.css --line-strong: var(--color-gray-500); } +/* Drawing colors, the same in both themes: the field's green in sketches and + previews, and the excluded zone in the weights triangle. */ +:root { + --field-green: #0a5c2e; + --danger-stroke: #b00020; +} + /* Also required, confirmed against flowbite-svelte's own "Colors" doc page (flowbite-svelte.com/docs/pages/colors): a default-colored Button (no `color` diff --git a/gui/frontend/src/lib/CornerPicker.svelte b/gui/frontend/src/lib/CornerPicker.svelte index 0da83f1..7dab9c8 100644 --- a/gui/frontend/src/lib/CornerPicker.svelte +++ b/gui/frontend/src/lib/CornerPicker.svelte @@ -4,14 +4,18 @@ const text = geometry.cornerPicker; import SettingsCard from "./SettingsCard.svelte"; import { Button, P } from "flowbite-svelte"; + import { api, apiPath, unwrap } from "./api"; import { untrack } from "svelte"; import { config, cameraDoc } from "./config.svelte"; import { cameraCount, regionLabel, slotSlice } from "./cameraLayout"; import { - aroundFirst, + clampToImage, clockwiseFromFirst, goalMarkings, homography, + initialCorners, + rescaleCorners, + resolutionStatus as compareResolution, rotateTo, type Point, } from "./corners"; @@ -37,6 +41,9 @@ const view = "geomcalib_input"; // GeomModel.cpp's calibration input snapshot let cacheBuster = $state(Date.now()); + // Whether the host lists the frame, so a missing one shows a message rather + // than a broken image and a 404. Unknown until the first listing. + let hasFrame = $state(null); let imageWidth = $state(0); let imageHeight = $state(0); @@ -81,30 +88,10 @@ lastCommitted = json; originIndex = 0; - const saved = (seed?.lineCorners ?? []).map(([x, y]) => ({ x, y })); - if (saved.length === 4 && fitsImage(saved)) { - corners = aroundFirst(saved); - - return; - } - - const marginX = imageWidth * 0.15; - const marginY = imageHeight * 0.15; - corners = [ - { x: marginX, y: marginY }, - { x: imageWidth - marginX, y: marginY }, - { x: imageWidth - marginX, y: imageHeight - marginY }, - { x: marginX, y: imageHeight - marginY }, - ]; + corners = initialCorners(seed?.lineCorners, imageWidth, imageHeight); }); }); - function fitsImage(points: Point[]): boolean { - return points.every( - (p) => p.x >= 0 && p.x <= imageWidth && p.y >= 0 && p.y <= imageHeight, - ); - } - // Writes the markers to the document, origin first, with the resolution // they were placed against. function commit(): void { @@ -151,10 +138,7 @@ if (draggingIndex === null) return; const p = toImagePoint(event.clientX, event.clientY); - corners[draggingIndex] = { - x: Math.round(Math.max(0, Math.min(imageWidth, p.x))), - y: Math.round(Math.max(0, Math.min(imageHeight, p.y))), - }; + corners[draggingIndex] = clampToImage(p, imageWidth, imageHeight); } function endDrag(): void { @@ -169,10 +153,20 @@ commit(); } - function refreshFrame(): void { + async function refreshFrame(): Promise { + try { + const all = await unwrap(api.GET("/api/snapshots")); + hasFrame = all.some((s) => s.cameraId === cameraId && s.view === view); + } catch { + hasFrame = false; + } cacheBuster = Date.now(); } + $effect(() => { + void untrack(refreshFrame); + }); + // The chosen origin corner first, the other three following it around the // quadrilateral. Any order of those three is correct per the note above, // but the polygon is drawn in this order once it's re-seated, so moving @@ -200,7 +194,7 @@ : undefined, ); // The goals and penalty areas of this camera's region, drawn through the - // corners as vision_processor will match them: the first to the region's + // corners as ssl-vision-processor will match them: the first to the region's // (minX, minY) corner, the rest clockwise. If they don't land on the real // ones, the wrong corner is marked first. let markings = $derived.by(() => { @@ -232,11 +226,7 @@ return "ok"; } - const [w, h] = seed.resolution; - if (w === 0 || h === 0) return "unknown"; - if (w === imageWidth && h === imageHeight) return "ok"; - - return w * imageHeight === h * imageWidth ? "rescalable" : "aspect"; + return compareResolution(seed.resolution, imageWidth, imageHeight); }); // Same aspect ratio, so the saved corners map onto the new image by a @@ -244,11 +234,7 @@ function rescaleSeed(): void { if (!seed) return; - const factor = imageWidth / seed.resolution[0]; - corners = seed.lineCorners.map(([x, y]) => ({ - x: Math.round(x * factor), - y: Math.round(y * factor), - })); + corners = rescaleCorners(seed.lineCorners, seed.resolution, imageWidth); originIndex = 0; commit(); } @@ -305,10 +291,17 @@ size="sm" color="alternative" class="self-start" - onclick={refreshFrame}>Refresh frame void refreshFrame()}>{text.refresh} + {#if hasFrame === false} +

{text.noFrame(cameraId)}

+ {/if} + + {/if} diff --git a/gui/frontend/src/lib/config/HostInterfaces.svelte b/gui/frontend/src/lib/config/HostInterfaces.svelte index 83168e2..2e62740 100644 --- a/gui/frontend/src/lib/config/HostInterfaces.svelte +++ b/gui/frontend/src/lib/config/HostInterfaces.svelte @@ -13,7 +13,7 @@ } from "../network.svelte"; // Which interfaces the GUI host's own sockets use. Host only: interface - // names mean nothing on another machine, and vision_processor always uses + // names mean nothing on another machine, and ssl-vision-processor always uses // the system's default route. let selection = $derived(interfaceSelection()); let ifaces = $derived(network.state?.interfaces ?? []); @@ -31,7 +31,7 @@ return { name: i.name, detail: detail(i.address, i.autoReason), - checked: i.autoUse, + checked: i.used, disabled: true, }; } @@ -50,14 +50,12 @@ ? [] : selection.skip .filter((name) => !ifaces.some((i) => i.name === name)) - .map( - (name): Row => ({ - name, - detail: detail(undefined, "not present"), - checked: false, - disabled: false, - }), - ); + .map((name): Row => ({ + name, + detail: detail(undefined, "not present"), + checked: false, + disabled: false, + })); return [...present, ...missing]; }); @@ -80,7 +78,7 @@ // the switch itself changes nothing. const skip = !auto && selection.skip.length === 0 - ? ifaces.filter((i) => i.usable && !i.autoUse).map((i) => i.name) + ? ifaces.filter((i) => i.usable && !i.used).map((i) => i.name) : selection.skip; writeInterfaces(auto, skip); @@ -93,8 +91,11 @@ writeInterfaces(false, skip); } + // Only matters with no network in use, as in the host's alert. let loopbackOff = $derived( - network.state !== null && !network.state.loopbackMulticast, + network.state !== null && + !network.state.loopbackMulticast && + !ifaces.some((i) => i.used && i.autoReason !== "loopback"), ); diff --git a/gui/frontend/src/lib/config/LayoutMap.svelte b/gui/frontend/src/lib/config/LayoutMap.svelte index ff122b3..0a36ee0 100644 --- a/gui/frontend/src/lib/config/LayoutMap.svelte +++ b/gui/frontend/src/lib/config/LayoutMap.svelte @@ -2,11 +2,12 @@ import FieldSketch from "../FieldSketch.svelte"; import { SKETCH_MARGIN } from "../fieldSplit"; import { virtualField } from "../geometry.svelte"; - import type { ConfigDocument, CameraDoc } from "../config.svelte"; + import type { ConfigDocument } from "../config.svelte"; import VideoPlayer from "../video/VideoPlayer.svelte"; import { layoutView, flips } from "../layoutView.svelte"; import { video as videoText } from "../text/video"; import type { StreamStatus } from "../video/videoStream"; + import { detailsCorner, placement, videoOrientation } from "./layoutTiles"; import { slots, cameraDevice, @@ -30,9 +31,6 @@ let halfLength = $derived(length / 2 + SKETCH_MARGIN); let halfWidth = $derived(width / 2 + SKETCH_MARGIN); - // Inset per side, in percent, so neighbouring tiles' borders don't touch. - const GAP = 0.4; - let flip = $derived(flips()); // The latest received frame rate per camera, from each tile's video status @@ -70,51 +68,11 @@ : undefined; } - // Field mm to percent of the sketch: +x right and +y up, unless the view - // is turned around or mirrored. - function placement(slot: SlotInfo): string { - const { minX, maxX, minY, maxY } = slot.slice; - const fromLeft = flip.x ? halfLength - maxX : minX + halfLength; - const fromTop = flip.y ? minY + halfWidth : halfWidth - maxY; - const left = (fromLeft / (2 * halfLength)) * 100 + GAP; - const top = (fromTop / (2 * halfWidth)) * 100 + GAP; - const w = ((maxX - minX) / (2 * halfLength)) * 100 - 2 * GAP; - const h = ((maxY - minY) / (2 * halfWidth)) * 100 - 2 * GAP; - - return `left:${String(left)}%;top:${String(top)}%;width:${String(w)}%;height:${String(h)}%`; - } - - // The tile corner the details go in: the outer one on screen, preferring - // the top and the left. A tile spanning the whole width or height counts as - // left or top, so one camera is top-left, two are top-left and top-right, - // and four take all four corners. - function corner(slot: SlotInfo): { top: boolean; left: boolean } { - const { minX, maxX, minY, maxY } = slot.slice; - const centerX = (minX + maxX) / 2; - const centerY = (minY + maxY) / 2; - const fullWidth = maxX - minX >= length; - const fullHeight = maxY - minY >= width; - - return { - left: fullWidth || (flip.x ? centerX > 0 : centerX < 0), - top: fullHeight || (flip.y ? centerY < 0 : centerY > 0), - }; - } + // The tile's box, as a style; see placement. + function tileStyle(slot: SlotInfo): string { + const box = placement(slot.slice, { halfLength, halfWidth }, flip); - // The camera's own orientation (how it's mounted), then the view's. A - // mirror before a rotation equals the opposite rotation after it, so the - // result is still one rotation and an optional mirror. - function videoOrientation(camera: CameraDoc): { - rotate: number; - mirror: boolean; - } { - const turn = - (camera.display?.rotate ?? 0) + (layoutView.rotate180 ? 180 : 0); - const mirror = camera.display?.mirror ?? false; - - return layoutView.mirror - ? { rotate: -turn, mirror: !mirror } - : { rotate: turn, mirror }; + return `left:${String(box.left)}%;top:${String(box.top)}%;width:${String(box.width)}%;height:${String(box.height)}%`; } @@ -134,7 +92,7 @@ {#each slots(doc) as slot (slot.cameraId)} {@const camera = slot.camera} {@const video = camera !== undefined && layoutView.feeds !== "off"} - {@const at = corner(slot)} + {@const at = detailsCorner(slot.slice, { length, width }, flip)}