Skip to content

feat: Q10 map layers, calibration, path & no-go zones (+ Q7 layer reuse)#848

Open
tubededentifrice wants to merge 19 commits into
Python-roborock:mainfrom
tubededentifrice:q10-map-layers
Open

feat: Q10 map layers, calibration, path & no-go zones (+ Q7 layer reuse)#848
tubededentifrice wants to merge 19 commits into
Python-roborock:mainfrom
tubededentifrice:q10-map-layers

Conversation

@tubededentifrice

@tubededentifrice tubededentifrice commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds structured Q10 map layers, calibration, path placement, and vector overlays on top of #847. It also reuses the shared B01 grid-layer code for Q7 maps.

This PR is stacked on #847. Until #847 merges, GitHub will show those commits here too; the incremental work starts with feat: decompose Q10 map into separable layers.

Changes

  • Split Q10 occupancy grids into separable background, wall, floor, and per-room layers. Each layer can be rendered as a transparent PNG for frontend compositing.
  • Add GridCalibration and solve_calibration() to fit Q10 world coordinates to grid pixels from an active cleaning path.
  • Populate MapData.path, vacuum_position, and charger position once calibration is available.
  • Decode Q10 restricted-zone blobs into no-go, no-mop, and virtual-wall overlays in MapData.
  • Decode and apply Q10 erase zones from the map packet tail so erased cells are removed from rendered maps and layers.
  • Reuse the shared layer/calibration abstractions for Q7 SCMap payloads.
  • Preserve existing overlays on partial status updates and keep path/position overlays after reparsing a calibrated map.

Notes

  • Virtual walls, zoned-clean areas, and carpets remain best-effort until non-empty captures are available for each data point.
  • Q10 calibration currently needs a sufficiently dense current-session path; no-clean calibration is left for a later PR.

Testing

  • uv run pytest — 543 passed on the rebased stack
  • uv run pre-commit run --all-files
  • Focused coverage for Q10 layers, calibration, overlays, erase zones, parser edge cases, and Q7 layer reuse
  • Live checked against Q10 captures for map layers, calibration fit, path placement, and no-go/no-mop zones

Brings Q10 maps toward parity with V1 devices. Verified end-to-end against two
physical Q10 (roborock.vacuum.ss07) robots.

Protocol (reverse-engineered from live captures):
- Requesting device state (dpRequestDps) makes the robot push its current map as
  a protocol-301 MAP_RESPONSE a few seconds later (firmware throttles to ~once
  per minute).
- The "01 01" map packet carries a u32be map id, u16le grid width, and an
  LZ4-block-compressed occupancy grid followed by 47-byte room records
  (id + ascii name); room cells use value room_id*4. The payload is unencrypted,
  unlike the Q7 SCMap protobuf format.

Changes:
- roborock/map/b01_q10_map_parser.py: clean LZ4 block decoder + packet parser +
  renderer producing a PNG and MapData with room names.
- roborock/devices/rpc/b01_q10_channel.py: request_map() triggers and awaits the
  MAP_RESPONSE push.
- roborock/devices/traits/b01/q10/map.py: MapContentTrait (refresh/parse/image/
  rooms), wired into Q10PropertiesApi.
- cli: `map-image` and `rooms` now work for Q10 devices.
- Tests + a synthetic (no-PII) map fixture.

Map packet format documentation credit: the roborock-qseries-map-bridge project
(GPL-3.0): https://github.com/v1b3c0d3x3r/roborock-qseries-map-bridge
Adds parsing for the Q10 "02 01" live position packet (delivered on the same
protocol-301 channel as the map, only while the robot is moving).

The packet format was reverse-engineered and validated against live ss07
captures (the 18-byte-header layout documented elsewhere did NOT match this
firmware):
- 10-byte header (sequence counter at byte 3, then a constant type/flag).
- big-endian int16 (x, y) point pairs; this firmware sends the current position
  as a single point per packet rather than an accumulated path.
- Confirmed live: as R1 traversed the corridor, the decoded x moved from -163 to
  +169 with y ~0.

The full saved map packet (01 01) was checked too and does NOT carry the live
path (identical across captures during a clean), so position comes from 02 01.

- b01_q10_map_parser: parse_trace_packet() + Q10TracePacket/Q10Point.
- b01_q10_channel: request_trace() (marker-filtered).
- MapContentTrait.refresh_trace() exposes path + robot_position.
- cli: `q10-position` (reports gracefully when the robot is idle).
- Tests use a real captured position packet + a synthetic multi-point packet.
Live capture (R1 corridor run) disproved the earlier 'single current point
per packet' assumption: the same session emitted packets of 1, then 3, then
15 points, each a strict superset. The robot accumulates the full session
path server-side and returns it whole, so a client connecting mid-session
still gets the complete trail (matching the app showing it after a cold
launch). The parser already read all points; this corrects the docs and
adds a real 15-point fixture + test, and clarifies that byte 3 is a session
counter (tracks the device clean count) not a per-packet sequence.
@tubededentifrice tubededentifrice force-pushed the q10-map-layers branch 2 times, most recently from 8af91fe to 0e3af65 Compare June 14, 2026 11:42
@allenporter

Copy link
Copy Markdown
Contributor

If there are low level map parsing parts, you could send them out in parallel without blocking on the other changes if that would be helpful to parallelize review. otherwise, we can mark this in draft until the other blocking parts are reviewed and merged.

The Q10 has no synchronous get-map command. The previous MapContentTrait
faked one: refresh()/refresh_trace() sent a dpRequestDps and blocked awaiting
the next MAP_RESPONSE push with a timeout. That has no request/response
correlation and fights the firmware's ~60-70s push throttle.

Mirror the existing Q10 StatusTrait model instead:
- MapContentTrait is now a push-only TraitUpdateListener. The Q10PropertiesApi
  subscribe loop routes protocol-301 MAP_RESPONSE packets to
  update_from_map_response(), which parses the payload, updates the cached
  fields and notifies listeners.
- Drop request_map()/request_trace() and the trait's refresh()/refresh_trace().
- CLI map-image/rooms/q10-position now nudge the device with refresh() and wait
  on a map-trait update listener for the pushed data.
Adds a device-agnostic grid->layers module (b01_grid_layers) that splits a
single-byte occupancy grid into background/wall/floor/per-room layers via a
caller-supplied classifier, each renderable to a transparent RGBA PNG for
frontend compositing. Wires a Q10 classifier (confirmed against real ss07
captures: 243=background, 249=wall, 240=unsegmented floor, value=room_id*4
for room floor) and exposes layers on MapContentTrait, plus a q10-map-layers
CLI command that lists layers and can export per-layer PNGs. The shared module
is built classifier-first so Q7's 0/127/128 grid can reuse it later.
The Q10 packet carries no calibration (header fields are map-growth metadata;
room records hold flags, not coords), so the world<->pixel transform is solved
from a cleaning path: GridCalibration + solve_calibration() slide the path's
pixel bbox to maximise on-floor overlap. Validated on a live R1 corridor run
(184-pt path, 183/184 on floor; path renders along the corridor with the robot
at its end). MapContentTrait gains calibration, solve_calibration(),
render_path_on_map() and populates MapData.path/vacuum_position in grid-pixel
coords (consistent with the identity img_transformation). Adds a
q10-map-with-path CLI command. Resolution is fit per-map so nothing is
hardcoded; note origin_x landed exactly on header @14, hinting the header may
encode origin.
Reverse-engineered the dpRestrictedZoneUp blob from a live ss07 (7 real zones):
[version][count] + fixed 38-byte records of [type][nverts] + int16-BE vertex
pairs, in world coords. New b01_q10_overlays.parse_zone_blob decodes it
(type 0 = no-go, 3 = no-mop). MapContentTrait.load_overlays() stores zones +
virtual walls and, with calibration, places them as MapData.no_go_areas /
no_mopping_areas / walls in pixel space; the charger is derived from the path
origin (the dock). The property API feeds the overlay DPs to the map trait from
the status stream, and render_path_on_map() draws zones + dock + position.
Validated live on R1: 6 no-go + 1 no-mop zones land squarely inside rooms.

Virtual walls / zoned / carpets are empty on the test device, so their decoders
are best-effort/scaffolded; obstacles were not located on the device channel.
Demonstrates the device-agnostic b01_grid_layers module serves both devices:
the Q7 SCMap parser gains classify_q7_cell / decompose_q7_layers (0=background,
127=wall, 128=floor) and q7_calibration, which reads the world<->pixel transform
straight from the SCMap mapHead (minX/minY/resolution) -- no path fitting needed
(unlike the Q10). Q7's MapContentTrait now exposes layers + calibration.

Q7's raster has no per-room segmentation and its map carries no path or zones,
so Q7 reaches background/wall/floor layers + calibration only; per-room masks,
path and vector overlays remain Q10-only. Validated against the existing Q7
SCMap fixture (no Q7 hardware available to test live).
The map (01 01) packet has a vector section after the compressed grid that the
parser previously ignored: [count][vertices_per] + count polygons of int16-BE
(x,y) pairs = carpet areas (user-defined + auto/self-identifying). Confirmed on
two ss07 devices (R1: 3 carpets, RDC: 2) and explains why the dpCarpetUp DP is
empty -- carpets ride in the map, not a DP. parse_map_packet now returns
packet.carpets; MapContentTrait exposes them and, with calibration, rasterises
them into MapData.carpet_map and draws them. The remaining tail (a run-length
raster + trailing signature) is left for later -- likely the carpet pixel mask
and/or obstacles.
load_overlays(restricted_zone_up=None) treated an absent DP as 'clear', so a
status push carrying only the virtual-wall DP wiped the loaded no-go zones
(caught live: zones loaded as 7, rendered as 0). None now means 'unchanged';
an explicit empty blob still clears. Regression test added.
Two corrections to the Q10 (ss07) map rendering, both verified on live
hardware:

Orientation: the ss07 grid is stored top-down (row 0 = top of the home),
unlike the V1/Q7 bottom-up convention, so the inherited vertical flip
rendered every Q10 map upside down. Make the flip a per-device property
of GridLayers (Q10 = no flip; Q7 keeps flipping, untouched) and drop it
from the Q10 renderer and the path/overlay math so all layers, the
combined map and overlays stay consistent.

Erase zones: a controlled with/without diff on a live device proved the
map-packet tail "carpet" vector section is actually the app's *Erase*
zone list -- removing the two zones in-app dropped its count 2->0 while
the grid and the trailing raster stayed byte-identical (so the earlier
"decode Q10 carpets" commit mislabeled them, and we were drawing them as
purple polygons). Rename Q10Carpet -> Q10EraseZone and, once a
calibration is available, blank the cells inside each erase rectangle to
background and re-render so phantom floor (e.g. lidar seen through
floor-to-ceiling windows) drops out of the map and every layer, matching
the app. Validated on R1: a 57-point corridor path solved the
calibration and the three erase zones removed the three phantom
projections.
Follows the q10-maps push-driven refactor: the map trait no longer has
refresh()/refresh_trace(), so adapt the layers/path CLI commands to nudge the
device (dpRequestDps) and wait on a map-trait update listener, and route the
overlay DPs through the refactored _handle_message dispatch.
@tubededentifrice

Copy link
Copy Markdown
Contributor Author

@allenporter ok, #850 is the standalone part

@andrewlyeats

Copy link
Copy Markdown
Contributor

Really nice to see the Q10 calibration and layer work coming together here.

One thing that might help the no-clean calibration you've flagged as a follow-up: on our Q10 S5+ (ss07, fw 03.11.24) captures, the calibration data appears to be transmitted in the 0101 grid-frame header, so a GridCalibration can be derived without a session path (i.e. without solve_calibration's dense-path requirement). The header fields we see (absolute byte offsets in the 0101 frame, sub-type at 0–1; verified across our captures, scoped to ss07):

  • bytes 11–12 x_min, 13–14 y_min (s16 BE) — the map origin, in 5 mm units (= 0.1 grid-px; ÷10 gives grid-pixel coordinates). This is the value solve_calibration is recovering by fitting.
  • bytes 15–16 resolution (u16 BE) — reads 5 universally for us → 0.05 m/px (the 50 mm/px you use).
  • bytes 17–22 charger x / y / phi — the dock position and orientation, as an alternative to inferring the charger from the path's first point.

On our decode, reading the origin straight from the header lands the path on-floor at the same rate as the auto-fit (they agree on ~29 of 31 captures; the two misses are null/keepalive frames where x_min == y_min == 0, which you'd just skip and fall back to a fit). So a header-derived calibration looks viable docked / pre-clean, which would drop the "needs a dense current-session path" requirement.

Happy to help — I can share scrubbed, annotated header captures, or sketch a PR against this branch if you'd like — and thanks for all the Q10 work. (Separately, the 0201 path header also carries a live SLAM heading field at bytes 10–11 if orientation is ever useful alongside vacuum_position — glad to detail that too.)

Reconciles this branch's Q10 map-layers / calibration / path / overlay
work with the Q10 map support that landed on main via Python-roborock#847. The two
diverged after the branch's 2026-06-15 work; Python-roborock#847 (merged 2026-06-21)
absorbed several @andrewlyeats-validated protocol corrections this
branch predated. Net result is a union, not a one-side win:

Took from main (newer, validated protocol corrections):
- map parser width/height: two consecutive u16be fields (offsets 7/9)
  + _split_with_dims, fixing the 222x261 (cross-256-band) mis-split that
  the older u16le@8 read produced; _infer_layout kept as fallback.
- trace _drop_stray_leading_point hygiene.
- overlay zone-type constants: 0 no-go, 1 virtual-wall, 2 no-mop,
  3 threshold (corrects this branch's earlier 3=no-mop reading).

Kept from this branch (net-new features main lacks):
- erase-zone decode from the packet tail, decompose_layers / classifier,
  GridCalibration usage, push-driven trait (update_from_map_response,
  load_overlays, render_path_on_map), and the q10_map_layers /
  q10_map_with_path CLI commands.
- top-down (no-flip) rendering: the branch's overlay/path/calibration
  placement is built on un-flipped grid-pixel coords, so the base raster
  is rendered un-flipped to keep overlays aligned.

CLI _await_q10_map_push merges both improvements: the early
already-satisfied short-circuit and main's allow_cached_on_timeout.

test_map zone-type test updated to the corrected no-mop constant (2).
Full suite green (576 passed).
Implements @andrewlyeats' suggestion (PR Python-roborock#848 review): the ss07 01 01
grid-frame header carries the calibration, so a GridCalibration origin
can be read straight from the packet instead of being recovered by
solve_calibration's dense-path slide.

- Decode the header calibration fields into Q10MapPacket:
  Q10HeaderCalibration{origin_x, origin_y (5 mm units), resolution,
  charger x/y/phi}. origin_pixels() returns the grid-pixel origin
  (header value / 10, since the grid is 50 mm/px); keepalive frames
  (x_min == y_min == 0) report is_keepalive and yield no origin.
- Add solve_calibration_with_origin(): fits only resolution + Y sign
  around a fixed pixel origin, validated against on-floor points. With
  the 2-D offset slide gone, a short path confirms the fit instead of a
  dense clean.
- MapContentTrait.solve_calibration() now prefers the header origin
  (>= 4 path points) and falls back to the full fit (>= 20) for
  keepalive frames or when the header origin doesn't validate.

The header origin (5 mm units -> /10 px) is the unambiguous, verifiable
part of the report. The GridCalibration resolution still lives in the
path's native units (the branch fits ~13-16/px), so it is confirmed
against a short path here rather than read from the header's 50 mm/px
field; a fully path-free resolution awaits the annotated ss07 captures
@andrewlyeats offered.

Tests: header field decode + keepalive, solve_calibration_with_origin
(short path / off-floor reject / no points), and trait-level header vs
fallback paths. Full suite green (584 passed).
@tubededentifrice

Copy link
Copy Markdown
Contributor Author

Thanks @andrewlyeats, this was really useful! I've implemented the header-origin part on this branch.

The 01 01 header now decodes into a Q10HeaderCalibration (x_min/y_min @11–14, resolution @15–16, charger @17–22), and origin_pixels() returns the grid-pixel origin (÷10, since the grid is 50 mm/px). Keep alive frames (x_min == y_min == 0) are detected and skipped > fall back to the path-fit, exactly as you described.

To use it, I added solve_calibration_with_origin(): with the origin fixed from the header, only the resolution + Y sign are fit, so it now confirms from a short path instead of needing a dense clean (the trait prefers the header origin at >=4 points, falls back to the full fit at ≥20).

One thing I couldn't pin down without your data: the header resolution reads 50 mm/px, but my path-fit lands at ~13-16 per pixel, i.e. the path coordinates don't look like millimeters, so I can't yet turn the header's 50 mm/px straight into the GridCalibration resolution. That's the only reason it isn't fully path-free yet (origin is exact; resolution still gets a quick on-floor validation against a short path).

So I'd love those scrubbed, annotated header captures, especially a few where you've noted the path/trace coordinate units alongside x_min/resolution. If I can confirm the path-unit <=> pixel relationship, I think the docked/pre-clean (zero-path) case falls out directly. And yes, please do detail the 0201 SLAM heading field too, orientation alongside vacuum_position would be nice to have.

Thanks again for the cross-capture validation here.

Virtual walls (dpVirtualWallUp 57) use a different on-wire frame from the
restricted-zone DPs: a bare [count] byte (no version, no per-record
type/pad) then 8-byte (y, x) int16-BE records. Feeding such a blob to
parse_zone_blob mis-frames it (leading 0x01 read as a version, the next
coordinate byte as a record count), so virtual_walls silently came back
empty and the wall overlay never rendered.

Add parse_virtual_wall_blob (axes un-swapped to (x, y) so walls share the
restricted-zone coordinate order), point load_overlays at it for DP 57,
and correct the overlay module's docs that wrongly claimed parse_zone_blob
handled DP 57. Tested against a real ss07 read-back from the PR Python-roborock#850 thread.
Read back from our RDC robot after drawing two Invisible Walls in the
official app. Verified end-to-end through the map trait's load_overlays;
the previous parse_zone_blob path returned [] for this exact blob.
Read back from RDC with three No-Go Zones drawn; exercises the 38-byte
slot walk at count=3 against real device bytes.
@tubededentifrice tubededentifrice marked this pull request as ready for review June 23, 2026 16:45
@andrewlyeats

Copy link
Copy Markdown
Contributor

Glad the header origin helped. On your two questions:

1. Path-unit ↔ pixel. On our end res = 20 path-units/px lines the path up on the grid (~99.8% on floor), and our
byte-14 coords drop into your world_to_pixel as-is — per-axis scale + Y-flip, no transpose. So that's the resolution
that registers everything here, no fit needed.

The one open piece is the absolute scale: a path-unit isn't a millimeter, and we've only ever anchored 20 internally —
never ruler-measured it — so a constant scale factor could move the real-world number. Your 13–16/px isn't necessarily
wrong
, it may just be that factor. Either way the divisor is a fixed constant, so once it's pinned the docked case
falls out; a single ruler-measured drive would settle the absolute. The captures let you check whether 20 registers your
path too.

2. I think that "stray leading point" is the robot's heading. Your 10-byte trace header starts the points at byte 10, so the
"first point" reads as bytes 10–13 = (heading, 0) — far enough from the real points (byte 14) that
_drop_stray_leading_point removes it. Bytes 10–11 are the 0201 SLAM heading (i16; 0 = +x / +90 = +y / ±180 = −x / −90 = −y); read it there, keep points from byte 14, and you recover orientation for free.

Two captures (ss07, fw 03.11.24). The code blocks are raw frame bytes; the two tables below decode every header byte
(A and B side by side).

Capture A — 2026-06-22.

0101 grid frame (header bytes 0–22; the rest of the frame is the LZ4-compressed grid):

01 01 6a 2b 59 80 01 00 db 00 fe 06 73 01 b2 00 05 03 82 03 3d 00 a7

0201 path frame (one stream — header, then (x,y) points from byte 14; first 110 of 5682 bytes):

02 01 00 a3 00 02 00 00 05 89 00 a8 00 00 00 05 00 4c f9 41 fc d8 f9 38 fc c7 f9 2c fc af f9 24 fc 9b f9 18 fc 87 f9 10 fc 77 f9 04 fc 63 f8 f8 fc 4f f8 f0 fc 3b f8 e8 fc 27 f8 dc fc 17 f8 d4 fc 03 f8 cc fb ef f8 cc fb db f8 c8 fb c3 f8 c8 fb af f8 c8 fb 97 f8 c8 fb 83 f8 c8 fb 6b f8 c4 fb 57 f8 c8 fb 3f f8 d4 fb 2f f8 e4 fb 23

Capture B — 2026-06-20.

0101 grid frame (header bytes 0–22):

01 01 6a 2b 59 80 01 00 dc 00 ff 06 73 01 bc 00 05 03 7f 03 3c 00 b1

0201 path frame (first 110 of 9862 bytes):

02 01 00 9b 00 02 00 00 09 9e 00 ac 00 00 ff fd 00 00 f9 55 fd 1c f9 68 fd 1b f9 7c fd 23 f9 94 fd 28 f9 b8 fd 28 f9 bc fd 3c f9 b8 fd 50 f9 a4 fd 58 f9 90 fd 58 f9 78 fd 58 f9 64 fd 58 f9 54 fd 64 f9 48 fd 78 f9 48 fd 88 f9 48 fd a0 f9 48 fd b4 f9 40 fd c4 f9 2c fd d0 f9 18 fd d0 f9 04 fd c8 f8 f0 fd c4 f8 f4 fd b0 f8 f0 fd 9c

0101 grid-frame header (all BE):

bytes field A B note
0–1 sub_type 0101 0101 grid-frame magic
2–5 map_id 6a2b5980 6a2b5980 per-map id (same map for both)
6 map_segmented 1 1 1 once finalized into rooms (0 while building)
7–8 width 219 220 grid px
9–10 height 254 255 grid px
11–12 x_min 1651 1651 origin; oy = −2·x_min = −3302
13–14 y_min 434 444 origin; ox = 2·y_min = 868 / 888
15–16 resolution 5 5 → 50 mm/px
17–18 charge_x 898 895 dock X (same units as x_min)
19–20 charge_y 829 828 dock Y
21–22 charge_phi −167° −177° dock heading (raw s16 negated)

0201 path-frame header (all BE; points then run from byte 14):

bytes field A B note
0–1 sub_type 0201 0201 path-frame magic
2–3 epoch 163 155 +1 per traversal (not per clean); power-cycle resets
4–7 const 00020000 00020000 constant; semantics unknown
8–9 point_count 1417 2462 may read one high
10–11 heading 168° 172° i16; 0=+x / +90=+y / ±180=−x / −90=−y
12–13 const 0000 0000 constant
14 … points (5,76)* (−1727,−808) … (−3,0)* (−1707,−740) … BE int16 (x,y) path-units; *~origin sentinel; robot = last pt (A −1592,−753 → col 85,row 81 · B −1600,−761 → col 85,row 82)

3. One to glance at when the overlays render. On our ss07 a no-go (DP-55) and a wall (DP-57) only place right when
both keep their first wire coordinate on the same axis; your parse_virtual_wall_blob swaps DP-57 but parse_zone_blob
leaves DP-55, so if your device matches ours they'd come out transposed relative to each other. Easy to check once they
render — the #850 before/after is yours if it helps.

Thanks for folding the origin work so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants