Skip to content

feat: add Q7 goto position - #1042

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

ramon-angosto wants to merge 5 commits into
Python-roborock:mainfrom
ramon-angosto:q7/5-goto-position

Conversation

@ramon-angosto

Copy link
Copy Markdown

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

Summary

Adds Q7PropertiesApi.goto_position(target: Q7RoborockPoint). This is what Home Assistant needs for vacuum.set_vacuum_goto_position.

The Q7 firmware has no goto command, so, as on the Q10, it is emulated:

  1. A 50 × 50 cm zone-clean task is started around the target.
  2. While the goto is active, the live map is requested every 3 s to track the position. cur_path pushes are used too, but the device does not always stream them.
  3. When the robot is within 30 cm of the target, the zone task is stopped (set_zone_clean ctrl_value 0) and the robot stays there.

If the robot is already within 30 cm of the target, nothing is sent.

State machine

The decisions live in a pure GotoAction class (goto.py), which owns no tasks and sends no commands. It is fed with the position and the work_mode from device pushes:

Situation Action
Zone task running (PLAN_AREA) and near the target Stop the zone task
Zone finished and robot heading home (PLAN_AREA_GO_HOME) before a close position arrived Stop, since it already reached the target
Zone task ended or replaced in any other way Complete without commands
300 s safety timeout with the zone task still running Stop the zone task

A failed stop is retried. Any other cleaning command (start_clean, clean_segments, clean_zones, pause_clean, stop_clean, return_to_dock) cancels the goto, and so does close().

Testing

  • Unit tests for the state machine and the API integration: stop at the target, already at the target, cancelled by another command.
  • Verified on a Q7 TF+ (roborock.vacuum.sc05, firmware 03.01.80). Two runs ended 15 cm and 12 cm from the target. The second run went through the "zone finished, heading home" path. In both, the robot stayed idle at the target.

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.
Add `Q7PropertiesApi.goto_position`. The Q7 firmware has no goto command, so
(like the Q10) it is emulated with a small zone-clean task around the target
that is stopped once the live position is within 30 cm, leaving the robot
there.

A `GotoAction` state machine decides when to stop, based on the robot
position and the `work_mode` reported in device pushes:

- near the target while the zone task runs: stop the task;
- the zone finished and the robot heads home (`PLAN_AREA_GO_HOME`) before a
  close position arrived: stop, since it already reached the target;
- the zone task ended or was replaced any other way: complete silently.

While a goto is active the live map is requested every 3 s, because
`cur_path` pushes are not always streamed. A 300 s safety timeout stops a
zone task that is still running. Any other cleaning command cancels the goto.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant