-
Notifications
You must be signed in to change notification settings - Fork 611
Nav pt2: Alfred #2100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+303
−6
Merged
Nav pt2: Alfred #2100
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
1cf0045
make model_path optional
jeff-hykin c9a426a
add flowbase robot
jeff-hykin 272833c
add alfred
jeff-hykin 0863ad1
add blueprint
jeff-hykin 9020415
naming
jeff-hykin 6ea0251
name fix
jeff-hykin 8e9c445
mypy
jeff-hykin 277cd29
mypy
jeff-hykin f6010b0
-
jeff-hykin 4f43322
-
jeff-hykin 2d77b76
Merge branch 'main' into jeff/feat/flowbase
jeff-hykin ac17686
-
jeff-hykin 1d76b35
Merge branch 'jeff/feat/flowbase' of github.com:dimensionalOS/dimos i…
jeff-hykin 98a79a5
-
jeff-hykin 86d2cc9
-
jeff-hykin 037f0c7
-
jeff-hykin ca977fa
-
jeff-hykin f5063b8
ci: bump self-hosted-tests timeout from 30 to 45 minutes
jeff-hykin 8b5275f
Merge branch 'main' into jeff/feat/flowbase
jeff-hykin 8d3d768
Update dimos/navigation/nav_stack/main.py
jeff-hykin abc78e4
fix: address greptile review on nav_stack/main.py max_hz block
jeff-hykin 957dc68
review: address greptile on effector_high_level.py:125
jeff-hykin 3f6bee3
review: address greptile on bin/ci-check:1
jeff-hykin b62ea9c
Merge remote-tracking branch 'origin/main' into jeff/clean/nav0
jeff-hykin fd87028
Merge remote-tracking branch 'origin/main' into jeff/feat/flowbase
jeff-hykin 24f649a
-
jeff-hykin bf9ebce
Merge branch 'jeff/feat/flowbase' of github.com:dimensionalOS/dimos i…
jeff-hykin a62988a
Merge branch 'jeff/clean/nav0' into jeff/feat/flowbase
jeff-hykin e2305e0
-
jeff-hykin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # Copyright 2025-2026 Dimensional Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from typing import Any | ||
|
|
||
| from dimos.core.coordination.blueprints import autoconnect | ||
| from dimos.core.global_config import global_config | ||
| from dimos.hardware.sensors.lidar.fastlio2.module import FastLio2 | ||
| from dimos.navigation.movement_manager.movement_manager import MovementManager | ||
| from dimos.navigation.nav_stack.main import create_nav_stack, nav_stack_rerun_config | ||
| from dimos.robot.diy.alfred.config import ALFRED, LOCAL_PLANNER_PRECOMPUTED_PATHS | ||
| from dimos.robot.diy.alfred.effector_high_level import AlfredHighLevel | ||
| from dimos.visualization.vis_module import vis_module | ||
|
|
||
| nav_config: dict[str, Any] = dict( | ||
| planner="simple", | ||
| vehicle_height=0.5, | ||
| max_speed=0.8, | ||
| terrain_analysis={ | ||
| "obstacle_height_threshold": 0.15, | ||
| "ground_height_threshold": 0.10, | ||
| "sensor_range": 20, | ||
| }, | ||
| local_planner={ | ||
| "paths_dir": str(LOCAL_PLANNER_PRECOMPUTED_PATHS), | ||
| "publish_free_paths": False, | ||
|
jeff-hykin marked this conversation as resolved.
|
||
| }, | ||
| simple_planner={ | ||
| "cell_size": 0.2, | ||
| "obstacle_height_threshold": 0.15, | ||
| "inflation_radius": 0.3, | ||
| "lookahead_distance": 2.0, | ||
| "replan_rate": 5.0, | ||
| "replan_cooldown": 2.0, | ||
| }, | ||
|
jeff-hykin marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| alfred_nav = ( | ||
| autoconnect( | ||
| FastLio2.blueprint( | ||
| host_ip=os.getenv("LIDAR_HOST_IP", "192.168.1.5"), | ||
| lidar_ip=os.getenv("LIDAR_IP", "192.168.1.189"), | ||
| mount=ALFRED.internal_odom_offsets["mid360_link"], | ||
| map_freq=1.0, | ||
| config="default.yaml", | ||
| ), | ||
| create_nav_stack(**nav_config), | ||
| MovementManager.blueprint(), | ||
| AlfredHighLevel.blueprint(), | ||
| vis_module( | ||
| global_config.viewer, | ||
| rerun_config={ | ||
| **nav_stack_rerun_config({"memory_limit": "1GB"}, vis_throttle=0.5), | ||
| "rerun_open": "native", | ||
| }, | ||
| ), | ||
| ) | ||
| .remappings( | ||
| [ | ||
| # nav stack needs "registered_scan" | ||
| (FastLio2, "lidar", "registered_scan"), | ||
| (FastLio2, "global_map", "global_map_fastlio"), | ||
| # SimplePlanner / FarPlanner owns way_point — disconnect MovementManager's | ||
| (MovementManager, "way_point", "_mgr_way_point_unused"), | ||
| ] | ||
| ) | ||
| .global_config(n_workers=8) | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Copyright 2025-2026 Dimensional Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dimos.msgs.geometry_msgs.Pose import Pose | ||
| from dimos.msgs.geometry_msgs.Quaternion import Quaternion | ||
| from dimos.msgs.geometry_msgs.Vector3 import Vector3 | ||
| from dimos.robot.config import RobotConfig | ||
| from dimos.robot.unitree.g1.config import G1_LOCAL_PLANNER_PRECOMPUTED_PATHS | ||
|
|
||
| DEFAULT_ADDRESS = "172.6.2.20:11323" | ||
|
|
||
| # just as a starting point. May re-compute these later. In principle robot-specific | ||
| LOCAL_PLANNER_PRECOMPUTED_PATHS = G1_LOCAL_PLANNER_PRECOMPUTED_PATHS | ||
|
|
||
| ALFRED = RobotConfig( | ||
| name="alfred", | ||
| height_clearance=2.0, # meters | ||
| width_clearance=1.0, | ||
| internal_odom_offsets={ | ||
| # Mid-360 lidar: a bit forward, and a bit to the right of base center, above ground. | ||
| "mid360_link": Pose(0.20, -0.20, 0.30, *Quaternion.from_euler(Vector3(0, 0, 0))), | ||
|
jeff-hykin marked this conversation as resolved.
|
||
| }, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| # Copyright 2025-2026 Dimensional Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Alfred high-level control via Portal RPC. | ||
|
|
||
| Subscribes to ``cmd_vel`` and forwards each Twist to the Alfred controller | ||
| as a holonomic target velocity. The controller performs the wheel-level | ||
| kinematics on-board, so this module hands off ``(vx, vy, wz)`` rather than | ||
| computing per-wheel speeds locally. | ||
|
|
||
| Frame convention: Alfred uses an inverted Y-axis vs. ROS, so ``vy`` and | ||
| ``wz`` are negated before being sent to the hardware. | ||
|
|
||
| Standard (ROS): Alfred: | ||
| +Y -Y | ||
| ↑ ↑ | ||
| ───┼──→ +X ───┼──→ +X | ||
| | | | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| from collections.abc import AsyncGenerator | ||
| from typing import Any | ||
|
|
||
| import numpy as np | ||
| import portal | ||
|
|
||
| from dimos.agents.annotation import skill | ||
| from dimos.core.core import rpc | ||
| from dimos.core.module import Module, ModuleConfig | ||
| from dimos.core.stream import In | ||
| from dimos.msgs.geometry_msgs.Twist import Twist | ||
| from dimos.msgs.geometry_msgs.Vector3 import Vector3 | ||
| from dimos.robot.diy.alfred.config import DEFAULT_ADDRESS | ||
| from dimos.utils.logging_config import setup_logger | ||
|
|
||
| logger = setup_logger() | ||
|
|
||
|
|
||
| class AlfredHighLevelConfig(ModuleConfig): | ||
| address: str = DEFAULT_ADDRESS | ||
| cmd_vel_timeout: float = 0.2 | ||
|
|
||
|
|
||
| class AlfredHighLevel(Module): | ||
| cmd_vel: In[Twist] | ||
| config: AlfredHighLevelConfig | ||
|
|
||
| def __init__(self, *args: Any, **kwargs: Any) -> None: | ||
| super().__init__(*args, **kwargs) | ||
| self._client: portal.Client | None = None | ||
| self._stop_task: asyncio.Task[None] | None = None | ||
| self._last_velocities = [0.0, 0.0, 0.0] | ||
|
|
||
| async def main(self) -> AsyncGenerator[None, None]: | ||
| self._client = portal.Client(self.config.address) | ||
| logger.info(f"Connected to Alfred at {self.config.address}") | ||
| try: | ||
| yield | ||
| finally: | ||
| if self._stop_task is not None and not self._stop_task.done(): | ||
| self._stop_task.cancel() | ||
| try: | ||
| await self._send_velocity(0.0, 0.0, 0.0) | ||
| except Exception as e: | ||
| logger.error(f"Error stopping Alfred: {e}") | ||
| if self._client is not None: | ||
| try: | ||
| self._client.close() | ||
| except Exception: | ||
| pass | ||
| self._client = None | ||
| logger.info("Alfred high-level connection stopped") | ||
|
|
||
| async def handle_cmd_vel(self, msg: Twist) -> None: | ||
| await self.move(msg) | ||
|
jeff-hykin marked this conversation as resolved.
|
||
|
|
||
| @rpc | ||
| async def move(self, twist: Twist, duration: float = 0.0) -> bool: | ||
| """Send a Twist as a holonomic velocity command. | ||
|
|
||
| With ``duration > 0`` the command runs for that many seconds before | ||
| auto-stop. With ``duration == 0`` each call rearms a ``cmd_vel_timeout`` | ||
| watchdog; if the stream stalls, the platform stops automatically. | ||
| """ | ||
| if self._client is None: | ||
| logger.warning("Alfred not connected; ignoring move") | ||
| return False | ||
|
|
||
| vx, vy, wz = twist.linear.x, twist.linear.y, twist.angular.z | ||
|
|
||
| if self._stop_task is not None and not self._stop_task.done(): | ||
| self._stop_task.cancel() | ||
|
|
||
| # Negate vy and wz for Alfred's inverted Y-axis frame. | ||
| # Send before scheduling the watchdog — otherwise it could fire first. | ||
| if not await self._send_velocity(vx, -vy, -wz): | ||
| return False | ||
|
|
||
| self._last_velocities = [vx, vy, wz] | ||
| timeout = duration if duration > 0 else self.config.cmd_vel_timeout | ||
| self._stop_task = asyncio.create_task(self._auto_stop_movement(timeout)) | ||
|
jeff-hykin marked this conversation as resolved.
|
||
| return True | ||
|
|
||
| async def _auto_stop_movement(self, delay: float) -> None: | ||
| try: | ||
| await asyncio.sleep(delay) | ||
| except asyncio.CancelledError: | ||
| return | ||
| try: | ||
| if await self._send_velocity(0.0, 0.0, 0.0): | ||
| self._last_velocities = [0.0, 0.0, 0.0] | ||
| except Exception as e: | ||
| logger.error(f"Auto-stop failed: {e}") | ||
|
jeff-hykin marked this conversation as resolved.
|
||
|
|
||
| @rpc | ||
| async def get_state(self) -> str: | ||
| if self._client is None: | ||
| return "DISCONNECTED" | ||
| moving = any(abs(v) > 1e-6 for v in self._last_velocities) | ||
| return "MOVING" if moving else "STOPPED" | ||
|
|
||
| @skill | ||
| async def move_velocity( | ||
| self, x: float, y: float = 0.0, yaw: float = 0.0, duration: float = 0.0 | ||
| ) -> str: | ||
| """Move the Alfred at the given velocity for ``duration`` seconds.""" | ||
| twist = Twist(linear=Vector3(x, y, 0), angular=Vector3(0, 0, yaw)) | ||
| await self.move(twist, duration=duration) | ||
| return f"Started moving with velocity=({x}, {y}, {yaw}) for {duration} seconds" | ||
|
jeff-hykin marked this conversation as resolved.
|
||
|
|
||
| async def _send_velocity(self, vx: float, vy: float, wz: float) -> bool: | ||
| """Send a raw velocity (already in Alfred frame) via Portal RPC.""" | ||
| if self._client is None: | ||
| return False | ||
| try: | ||
| command = { | ||
| "target_velocity": np.array([vx, vy, wz]), | ||
| "frame": "local", | ||
| } | ||
| future = self._client.set_target_velocity(command) | ||
| await asyncio.to_thread(future.result) | ||
| return True | ||
|
jeff-hykin marked this conversation as resolved.
|
||
| except Exception as e: | ||
| logger.error(f"Error sending Alfred velocity: {e}") | ||
| return False | ||
|
|
||
|
|
||
| __all__ = ["AlfredHighLevel", "AlfredHighLevelConfig"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.