Navigation¶
Autonomous navigation and mapping.
Note
robot.navigation does not launch or tear down Nav2 — it only sends goals
and queries the live stack. Start and stop the engine with
client.platform.navigation.start / stop (see
Simple navigation and Platform). Call
robot.navigation.state() to probe NavigateToPose readiness after the
deployment reports ready. Operations report typed errors when their
runtime dependencies are unavailable.
"""SLAM navigation example — saves example-map for navigation-localization."""
import math
import time
from olo import Client
from olo.locomotion import PlanarMotion
from olo.navigation import Nav2ErrorCode, NavigationFeedback
from olo.platform import NavigationMode, NavigationObservedState
from olo.spatial import Pose
EXAMPLE_MAP_NAME = "example-map"
def on_feedback(feedback: NavigationFeedback) -> None:
# Do something with the feedback
pass
with Client() as client:
configs = client.platform.navigation.get_configs(NavigationMode.SLAM)
if not configs:
raise RuntimeError("No navigation configs support SLAM mode")
config = configs[0]
print(f"Using navigation config: {config.name = }, {config.id = }")
# Start navigation engine (namespace resolves like client.robot())
client.platform.navigation.start(mode=NavigationMode.SLAM, config_id=config.id)
last_state = None
deadline = time.time() + 60
while time.time() < deadline:
info = client.platform.navigation.deployment()
state = info.observed.state if info.observed else None
if state != last_state:
print(f"Navigation engine: {state}")
last_state = state
if state == NavigationObservedState.READY:
break
if state == NavigationObservedState.FAILED:
raise RuntimeError(f"Navigation failed to launch: {info.observed.error_message}")
time.sleep(2)
else:
raise TimeoutError(f"Navigation engine did not become ready within 60s (last state: {last_state})")
# Move the robot to build a map
robot = client.robot()
robot.locomotion.move(PlanarMotion(x=1.0, yaw=2 * math.pi))
# Once the map has some substance, send the robot a pose goal
target = Pose.from_xy_yaw(1.5, 0.5, 1.5708)
result = robot.navigation.navigate_to(target, on_feedback=on_feedback)
print(f"Navigation outcome: {result.outcome.value} ({result.reason})")
if result.nav2_error_code:
print(f"Error: {Nav2ErrorCode.name_for(result.nav2_error_code)}")
# Persist the SLAM map for reuse
saved = client.platform.navigation.save_map(EXAMPLE_MAP_NAME)
print(f"Saved map: {saved.name} [{saved.id}]")
/** SLAM navigation example — saves `example-map` for navigation-localization.ts. */
import { connect } from "olo/web";
import { nav2ErrorCodeName, type NavigationFeedback } from "olo/navigation";
import { Pose } from "olo/spatial";
const EXAMPLE_MAP_NAME = "example-map";
function onFeedback(_feedback: NavigationFeedback): void {
// Do something with the feedback
}
const client = connect();
const configs = await client.platform.navigation.getConfigs("slam");
if (configs.length === 0) {
throw new Error("No navigation configs support SLAM mode");
}
const config = configs[0];
console.log(`Using navigation config: name=${config.name}, id=${config.id}`);
// Start navigation engine (namespace resolves like client.robot())
await client.platform.navigation.start({
mode: "slam",
configId: config.id,
});
let lastState: string | undefined;
const deadline = Date.now() + 60_000;
while (Date.now() < deadline) {
const info = await client.platform.navigation.deployment();
const state = info.observed?.state;
if (state !== lastState) {
console.log(`Navigation engine: ${state}`);
lastState = state;
}
if (state === "ready") break;
if (state === "failed") {
throw new Error(`Navigation failed to launch: ${info.observed?.errorMessage}`);
}
await new Promise((r) => setTimeout(r, 2000));
}
if (lastState !== "ready") {
throw new Error(`Navigation engine did not become ready within 60s (last state: ${lastState})`);
}
// Move the robot to build a map
const robot = await client.robot();
await robot.locomotion.move({ x: 1.0, y: 0, yaw: 2 * Math.PI });
// Once the map has some substance, send the robot a pose goal
const target = Pose.fromXyYaw(1.5, 0.5, 1.5708);
const result = await robot.navigation.navigateTo(target, { onFeedback });
console.log(`Navigation outcome: ${result.outcome} (${result.reason})`);
if (result.nav2ErrorCode) {
console.log(`Error: ${nav2ErrorCodeName(result.nav2ErrorCode)}`);
}
// Persist the SLAM map for reuse
const saved = await client.platform.navigation.saveMap(EXAMPLE_MAP_NAME);
console.log(`Saved map: ${saved.name} [${saved.id}]`);
Navigation wrapper over olo.navigation.v1.Navigation.
Client interfaces
- class olo.navigation.Navigation[source]¶
Bases:
objectSync wrapper for the navigation gRPC service.
- cancel_all(robot_namespace='', *, timeout=10.0)[source]¶
Cancel all owned navigation goals for a namespace.
- check_reachability(goal, *, robot_namespace='', frame='map', start=None, use_start=False, planner_id='', timeout=10.0)[source]¶
Ask Nav2 whether a goal pose is planner-reachable.
- get_map(robot_namespace='', *, topic='map', timeout=10.0)[source]¶
Fetch one occupancy-grid snapshot from the robot map topic.
- Return type:
- Parameters:
- handle(namespace=None)[source]¶
Return a namespace-scoped navigation handle.
- Return type:
- Parameters:
namespace (str | None)
- navigate_to(target, *, robot_namespace='', frame='map', navigation_timeout=120.0, on_feedback=None, timeout=10.0)[source]¶
Start navigation and wait for the terminal outcome.
- Return type:
- Parameters:
- send_navigation_goal(target, *, robot_namespace='', frame='map', navigation_timeout=120.0, timeout=10.0)[source]¶
Send a NavigateToPose goal and return a goal handle.
- class olo.navigation.NavigationHandle[source]¶
Bases:
objectNamespace-scoped handle for navigation behavior scripting.
- __init__(client, namespace, session)[source]¶
Bind to a client, resolved namespace, and spatial frames.
- Parameters:
client (Navigation)
namespace (str)
- Return type:
None
- check_reachability(goal, *, frame='map', start=None, use_start=False, planner_id='', timeout=10.0)[source]¶
Ask Nav2 whether a goal pose is planner-reachable for this robot.
- current_pose(*, timeout=10.0)[source]¶
Return the stamped map-to-base transform via spatial TF lookup.
- get_map(*, topic='map', timeout=10.0)[source]¶
Fetch one occupancy-grid snapshot for this robot.
- Return type:
- Parameters:
- navigate_to(target, *, frame='map', navigation_timeout=120.0, on_feedback=None, timeout=10.0)[source]¶
Start navigation and wait for completion.
- Return type:
- Parameters:
- send_navigation_goal(target, *, frame='map', navigation_timeout=120.0, timeout=10.0)[source]¶
Send a NavigateToPose goal without waiting for completion.
- Return type:
- Parameters:
- class olo.navigation.NavigationGoal[source]¶
Bases:
objectHandle for an accepted long-running navigation goal.
- __init__(client, goal_id)[source]¶
Bind to a navigation client and server-generated goal id.
- Parameters:
client (Navigation)
goal_id (str)
- Return type:
None
- wait(*, on_feedback=None, timeout=None)[source]¶
Block until the goal reaches a terminal outcome.
- Return type:
- Parameters:
on_feedback (Callable[[NavigationFeedback], None] | None)
timeout (float | None)
Types
- class olo.navigation.NavigationState[source]¶
Bases:
objectCapability snapshot for a robot namespace.
- __init__(availability=Availability.UNSPECIFIED, activity=Activity.UNSPECIFIED, owned_goal_ids=(), reason='')¶
- Parameters:
availability (Availability)
activity (Activity)
reason (str)
- Return type:
None
- class olo.navigation.NavigationFeedback[source]¶
Bases:
objectProgress update for an active navigation goal.
- class olo.navigation.NavigationResult[source]¶
Bases:
objectTerminal result for a navigation goal.
- __init__(outcome=NavigationOutcome.UNSPECIFIED, reason='', nav2_error_code=0)¶
- Parameters:
outcome (NavigationOutcome)
reason (str)
nav2_error_code (int)
- Return type:
None
- class olo.navigation.OccupancyGrid[source]¶
Bases:
objectDecoded occupancy grid with map-frame metadata.
- __init__(frame_id, resolution, width, height, origin, data, stamp=None)¶
- class olo.navigation.ReachabilityResult[source]¶
Bases:
objectPlanner-backed reachability for a map-frame goal.
Enums
- class olo.navigation.Availability[source]¶
Bases:
EnumWhether NavigateToPose is available for a namespace.
Import from olo/navigation:
Client interfaces
Navigation — service wrapper with state, start, navigate, cancel, and
handle().NavigationHandle — namespace-scoped scripting surface, including
currentPose()via spatial TF.NavigationGoal — accepted goal with async
result(), async iteration, andcancel().
Types