Skip to content

feat: expose Q7 robot position - #1041

Open
ramon-angosto wants to merge 4 commits into
Python-roborock:mainfrom
ramon-angosto:q7/4-robot-position
Open

ramon-angosto wants to merge 4 commits into
Python-roborock:mainfrom
ramon-angosto:q7/4-robot-position

Conversation

@ramon-angosto

@ramon-angosto ramon-angosto commented Nov 13, 2026 •

Copy link
Copy Markdown

Depends on #1040. Only the last commit belongs to this PR.

Summary

Adds MapContentTrait.robot_position for Q7 devices, in common Roborock coordinates (Q7RoborockPoint). It notifies the existing map content listeners when it changes. This is what Home Assistant needs for vacuum.get_current_position.

The position comes from two sources:

  1. Live map frames. The pose in currentPose is used. The firmware reports (1100, 1100) or (0, 0) when the pose is unknown, so poses outside the map bounds or exactly at the origin are ignored and the last known position is kept.
  2. cur_path device pushes. While a task runs, the device sends prop.post pushes with cur_path: [start_index, x, y, phi, kind, ..., timestamp] (world meters). The last sample is used.

Changes

  • Q7DevicePush and decode_device_push() in b01_q7_protocol decode unsolicited *.post messages.
  • Q7PushChannel protocol, implemented by B01Q7Channel.subscribe_device_pushes().
  • Q7PropertiesApi takes a push_channel and subscribes to device pushes in start().
  • B01MapParser.parse() stores the valid live pose (world meters) in map_data.additional_parameters[ROBOT_WORLD_POSITION], next to room_names, so the frame is deserialized only once. The same _valid_current_pose() check decides both the rendered robot glyph and robot_position, so a (0, 0) startup pose no longer draws the robot at the origin; it falls back to the dock like the (1100, 1100) placeholder.
  • MapContentTrait.refresh_live() requests the live map by type (service.upload_by_maptype {"map_type": 0}). Unlike the saved map (upload_by_mapid), it carries the current pose, and it makes the device stream cur_path positions. Integrations can call it while the robot is cleaning to get an up-to-date map and position.

Testing

  • Unit tests for push decoding, the channel subscription, cur_path parsing (including malformed pushes), placeholder poses and refresh_live().
  • Verified on a Q7 TF+ (roborock.vacuum.sc05, firmware 03.01.80) while cleaning rooms and zones.

@Lash-L Lash-L added Feature New feature Q7 B01 Q7 platform labels Nov 15, 2026

@Lash-L Lash-L left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated code review by Gemini 4 Argon in Antigravity using our /review (/code-review) skill (.agents/skills/code-review/SKILL.md / AGENTS.md).

PR Scoping & Branch Stack Note

  • Stacked branch: This PR targets main and includes commits from #1038 (67ce5a1), #1039 (6bbd0cc), and #1040 (63c9290). This review is scoped to the head commit 42e117a8e6c81cc16e602a06454a38cfb2b6bc40 (feat: expose Q7 robot position).
  • Interaction with main / PR #1051: Both main (via #1042) and PR #1051 update roborock/devices/rpc/b01_q7_channel.py and roborock/protocols/b01_q7_protocol.py to use create_map_response_assembler() for multi-part MAP_RESPONSE frames. Q7PushChannel.subscribe_device_pushes and decode_device_push are orthogonal to the map response assembler, so rebasing onto main (and #1051) will only require a straightforward merge resolution in those two files.

Summary by Layer

  • Protocol (roborock/protocols/b01_q7_protocol.py): Cleanly decodes unsolicited *.post messages on DP 10001 (RPC_RESPONSE, B01) into Q7DevicePush(method, params), ignoring command responses (data/code) and non-dict payloads.
  • Channel (roborock/devices/rpc/b01_q7_channel.py, roborock/devices/device_manager.py): Adds the Q7PushChannel protocol and B01Q7Channel.subscribe_device_pushes, wired through create_device_manager and Q7PropertiesApi.start() / close().
  • Trait (roborock/devices/traits/b01/q7/map_content.py, roborock/devices/traits/b01/q7/__init__.py):
    • latest_position_from_cur_path accurately parses [start_index, x, y, phi, kind, ..., timestamp] samples from prop.post cur_path pushes and converts the latest (x, y) world coordinates (meters) via Q7RoborockPoint.from_world.
    • MapContentTrait.refresh_live() requests the live map via service.upload_by_maptype with {"map_type": 0}, serialized under self._map_command_lock.
  • Map Parser (roborock/map/b01_map_parser.py):
    • parse_robot_pose filters out both the out-of-bounds (1100.0, 1100.0) unlocalized placeholder and the (0.0, 0.0) task-startup placeholder. One minor consistency/efficiency suggestion is noted inline regarding _place_poses and double protobuf deserialization.
  • Tests (tests/devices/rpc/test_b01_q7_channel.py, tests/devices/traits/b01/q7/test_map_content.py): Good coverage of subscribe_device_pushes, cur_path sample extraction, malformed/unrelated push filtering, placeholder pose rejection, and refresh_live().

Comment thread roborock/map/b01_map_parser.py Outdated
if not parsed.HasField("mapHead") or not parsed.HasField("currentPose"):
return None
pose = parsed.currentPose
if (pose.x == 0.0 and pose.y == 0.0) or not _WorldToPixel(parsed).in_bounds(pose.x, pose.y):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low — Align (0.0, 0.0) startup pose filtering between parse_robot_pose and _place_poses

parse_robot_pose rejects both out-of-bounds poses ((1100.0, 1100.0)) and the (0.0, 0.0) placeholder emitted while a task is starting, whereas _place_poses (line 191) only checks projector.in_bounds(parsed.currentPose.x, parsed.currentPose.y).

Because (0.0, 0.0) is typically inside mapHead bounds (minX <= 0 <= maxX, minY <= 0 <= maxY), a startup frame carrying currentPose = (0.0, 0.0) will leave MapContent.robot_position untouched here, but _place_poses will still place map_data.vacuum_position (and the rendered vacuum glyph) at world (0.0, 0.0) instead of falling back to map_data.charger.

Sharing a helper (e.g. _has_valid_current_pose(parsed, projector)) between _place_poses and parse_robot_pose would keep map_data.vacuum_position and MapContent.robot_position consistent on startup frames.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 49dd3f8: a shared _valid_current_pose() now decides both map_data.vacuum_position and robot_position, so a (0, 0) startup pose falls back to the dock in the rendered map too. The parser tests cover both placeholders.

self.raw_api_response = raw_payload
# Saved maps and frames without a fix carry no usable pose: keep the last known one.
try:
pose = parse_robot_pose(raw_payload)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low — raw_payload is deserialized twice in _parse_and_store

self._map_parser.parse(raw_payload) on line 166 already deserializes raw_payload into a RobotMap protobuf message (and raises RoborockException if decoding fails or mapHead is missing), and parse_robot_pose(raw_payload) here deserializes the same raw_payload a second time.

Consider either exposing the world robot pose on ParsedMapData / MapData during B01MapParser.parse(), or keeping parse_robot_pose as a fast path when full rendering is not needed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 49dd3f8: B01MapParser.parse() stores the valid live pose (world meters) in map_data.additional_parameters[ROBOT_WORLD_POSITION], next to room_names, and MapContentTrait reads it from there. The separate parse_robot_pose() helper is removed, so each frame is deserialized once.

@Lash-L Lash-L added the /review run Code review skill (/review) has been run label Nov 15, 2026
@Lash-L
Lash-L marked this pull request as draft November 15, 2026 19:57
Add `clean_zone` and `clean_zones` to the Q7 properties API. Zones are given
as two opposite corners in the common Roborock millimetre coordinate space
through a new `Q7RoborockPoint`, which converts to and from the Q7 world
coordinates (meters, origin next to the dock).

The device expects the zone preference type to be selected first
(`service.set_preference_type`), then the zone corners as a flat list
(`service.set_zone_points`), and finally `service.set_zone_clean` to start.
Several zones are concatenated into a single task.
Add a `RemoteTrait` to the Q7 properties API, mirroring the Q10 remote API.
Manual mode is entered with `prop.set sweep_type=5` and the robot is driven
with `service.set_direction` (1 forward, 2 left, 3 right, 0 exit). Each
command moves the robot for a short burst, so callers repeat it while a
direction is held. Leaving remote mode restores `sweep_type=0`.
Add `set_carpet_turbo` and `set_carpet_avoid` to the Q7 properties API. Both
are written individually with `prop.set` (`carpet_turbo` / `carpet_avoid`)
and reported back nested under `privacy`.

Keep the user-visible `name` of each entry returned by
`service.get_map_list`, which was previously dropped.
Add `MapContentTrait.robot_position` (common Roborock coordinates) for Q7
devices, kept up to date from two sources:

- the current pose in live map frames (`currentPose`), ignoring the
  `(1100, 1100)` and `(0, 0)` placeholders the firmware reports when the
  pose is unknown or outside the map;
- `cur_path` samples in unsolicited `prop.post` device pushes, which the
  device streams while a task is running.

To receive those pushes, `B01Q7Channel` now implements a `Q7PushChannel`
protocol that decodes `*.post` messages into `Q7DevicePush`, and
`Q7PropertiesApi.start()` subscribes to them.

Add `MapContentTrait.refresh_live()`, which requests the live map by type
(`service.upload_by_maptype`). Unlike the saved map it carries the current
pose and makes the device stream `cur_path` positions.
@ramon-angosto
ramon-angosto marked this pull request as ready for review November 16, 2026 08:07

This branch has not been deployed

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

Labels

Feature New feature Q7 B01 Q7 platform /review run Code review skill (/review) has been run

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants