Skip to content

Commit

Permalink
Fixes and features for preliminary VSLAM support
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiğit Topcu committed Nov 29, 2022
1 parent bae64b1 commit 1891b83
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 132 deletions.
59 changes: 1 addition & 58 deletions custom_components/dreame_vacuum/dreame/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,67 +874,10 @@ def get_map_for_render(self, map_index: int) -> MapData | None:
map_data.obstacles = None

elif map_data.charger_position and map_data.docked:
# Calculate robot position when it is docked as implemented on the app
if not map_data.robot_position:
map_data.robot_position = copy.deepcopy(
map_data.charger_position)

# Calculate charger angle
charger_angle = map_data.charger_position.a
if self.status.robot_shape != 1:
offset = 150
if (
charger_angle > -45
and charger_angle < 45
):
charger_angle = 0
elif (
charger_angle > -45
and charger_angle <= 45
or charger_angle > 315
and charger_angle <= 405
):
charger_angle = 0
elif (
charger_angle > 45
and charger_angle <= 135
or charger_angle > -315
and charger_angle <= -225
):
charger_angle = 90
elif (
charger_angle > 135
and charger_angle <= 225
or charger_angle > -225
and charger_angle <= -135
):
charger_angle = 180
elif (
charger_angle > 225
and charger_angle <= 315
or charger_angle > -135
and charger_angle <= -45
):
charger_angle = 270
else:
offset = 250

# Calculate new robot position with an offset to the dock
map_data.robot_position.x = (
map_data.charger_position.x
+ offset * math.cos(charger_angle * math.pi / 180)
)
map_data.robot_position.y = (
map_data.charger_position.y
+ offset * math.sin(charger_angle * math.pi / 180)
)

# Robots with self-wash base parks in reverse therefore we don't need to modify the charger angle
if self.status.robot_shape != 2:
map_data.robot_position.a = charger_angle + 180
else:
map_data.robot_position.a = charger_angle

return map_data

def get_map(self, map_index: int) -> MapData | None:
Expand Down Expand Up @@ -1157,7 +1100,7 @@ def call_action(self, action: DreameVacuumAction, parameters: dict[str, Any] = N
self._last_settings_request = 0

# Schedule update for retrieving new properties after action sent
self.schedule_update(2)
self.schedule_update(3)
return result

def send_command(self, command: str, parameters: dict[str, Any]) -> dict[str, Any] | None:
Expand Down
Loading

0 comments on commit 1891b83

Please sign in to comment.