Repository navigation
refactor: reuse shared grid layers in Q7 parser - #882
tubededentifrice wants to merge 5 commits into
Conversation
allenporter
left a comment
There was a problem hiding this comment.
I know this is draft still and not ready but giving early feedback in the name of quick iteration
| map_data: MapData | None = None | ||
| """Parsed map data (metadata for points on the map).""" | ||
|
|
||
| layers: GridLayers | None = None |
There was a problem hiding this comment.
These don't seem like data points we want or need to expose to callers, and are more like internal map rendering details.
| self.image_content = parsed_data.image_content | ||
| self.map_data = parsed_data.map_data | ||
| self.raw_api_response = raw_payload | ||
| try: |
There was a problem hiding this comment.
Once parsed, these don't appear to be used by anything.
is there a specifc reason we're parsing the raw payload again? I would expect this to all be behind the existing self._map_parser.parse call above where the map parser parses the raw content and pulls out useful data points.
Is it because in q10 these come as a separate channel, therefore we need to change the map interface from working in raw payload to be raw payload + layers + calibration data?
Lash-L
left a comment
There was a problem hiding this comment.
Automated code review by Gemini 4 Argon in Antigravity using our /review (/code-review) skill (.agents/skills/code-review/SKILL.md / AGENTS.md).
Summary by Architectural Priority
- Priority 1 — Public API & Trait Surfaces: Clean. Earlier review feedback to avoid exposing internal
GridLayersandcalibrationfields onMapContentTrait/MapContenthas been addressed. - Priority 2 — Internal Abstractions &
mainEvolution:- Now that
GridLayersis no longer returned fromB01MapParser.parse(), callingdecompose_grid(size_x, size_y, grid, [], classify_q7_cell)builds an intermediateGridLayersobject solely to pass into_render_occupancy_image(), replacing a single C-levelbytes.translate()call with two full Python passes overgrid(decompose_grid+layers.cell_class(value)per pixel) while discardingclass_counts,rooms, and allGridLayershelper methods. - In addition,
mainhas since evolved in #911 to render Q7 maps using room-outline flood-fill (roomDataInfo[*].roomOutline+roomNamePost), carpet stippling (carpetInfo), the shared V1 RGBA palette (ColorsPalette), andvacuum_map_parser_baseoverlay generators (_create_image_generator). Because Q7SCMapgrids do not encode per-room IDs in cell values (unlike Q10, whichb01_grid_layers.pytargets), this greyscaleGridLayerspath is superseded by the flood-fill renderer onmain.
- Now that
- Priority 3 — Protocol & Parser Correctness:
_Q7_WALL_VALUE = 127and_Q7_FLOOR_VALUE = 128are inverted: in Q7SCMap(RobotMap.mapData.mapData), cell byte127(0x7F, signed+127) encodes floor / free space and128(0x80, signed-128) encodes wall / obstacle (with0for unknown/outside). In the real capture fixture (tests/map/testdata/raw-mqtt-map301.bin.inflated.bin.gz),127makes up the interior room area (25,841cells, containing all 10roomNamePostroom label coordinates) and128forms the surrounding walls (3,784cells). This was also corrected onmainin #911 (_FLOOR = 127,_WALL = 128).
| # The Q7 occupancy grid encodes only these classes (no per-room segmentation in | ||
| # the raster -- room ids/names live in the protobuf metadata, not the pixels). | ||
| _Q7_WALL_VALUE = 127 | ||
| _Q7_FLOOR_VALUE = 128 |
There was a problem hiding this comment.
Protocol / Parser Correctness (Priority 3): _Q7_WALL_VALUE and _Q7_FLOOR_VALUE are inverted
In Q7 SCMap occupancy grids (RobotMap.mapData.mapData), cells are binarized from signed int8 occupancy values where:
127(0x7F, signed+127) = floor / free space128(0x80, signed-128) = wall / obstacle0= outside / unknown
You can also verify this directly in tests/map/testdata/raw-mqtt-map301.bin.inflated.bin.gz, where 127 is the interior floor (25,841 cells, and every room's roomNamePost label coordinate lands on a 127 cell) while 128 forms the 1–2px perimeter walls (3,784 cells). This was updated on main in #911 as _FLOOR = 127 and _WALL = 128.
| _Q7_FLOOR_VALUE = 128 | |
| _Q7_FLOOR_VALUE = 127 | |
| _Q7_WALL_VALUE = 128 |
| parsed = _parse_scmap_payload(payload) | ||
| size_x, size_y, grid = _extract_grid(parsed) | ||
| room_names = _extract_room_names(parsed) | ||
| layers = decompose_grid(size_x, size_y, grid, [], classify_q7_cell) |
There was a problem hiding this comment.
Internal Design & Conflict with main (Priority 2): decompose_grid / GridLayers is constructed and immediately discarded
Now that layers is no longer exposed on ParsedMapData / MapContent, decompose_grid(size_x, size_y, grid, [], classify_q7_cell) allocates a GridLayers instance with rooms=[] and iterates over every byte in grid in Python to compute class_counts (which are never read), only for _render_occupancy_image() to iterate over layers.grid in Python a second time (bytes(_Q7_RENDER_INTENSITY[layers.cell_class(value)] for value in layers.grid)). On a typical 340×300 map (102,000 cells), this replaces a single C-level grid.translate(...) lookup with two Python loops per frame without using any GridLayers capabilities.
Additionally, note that main (#911) has since replaced _render_occupancy_image in roborock/map/b01_map_parser.py with full room-outline flood-fill (_assign_room_pixels), carpet stippling, V1 palette coloring, and overlay rendering (_create_image_generator). Because Q7 SCMap rasters do not encode room IDs in cell bytes (unlike Q10), b01_grid_layers.py does not fit the room-outline flood-fill pipeline now on main.
Summary
Keeps the Q7 shared-grid reuse from #848 as a small parser-internal refactor. The draft no longer expands the Q7 trait API and remains independent of the Q10 map stack.
Changes
GridLayersonce insideB01MapParser.parsefrom the already-parsed protobuf payload.MapContentTraitunchanged: callers continue to receive onlyimage_content,map_data, andraw_api_response.Review feedback addressed
Validation
pytest -q— 792 passed, 86 snapshots passedpre-commit run --show-diff-on-failure --color=always --all-files— all hooks passed, including Ruff and mypy