地图管理

地图的加载、建图和管理功能。

地图操作

加载地图

load_map(map_name, auto_reload=True, block=False, timeout=30)

Load an existing map from the map resource directory.

Parameters:
  • map_name (str) – Name of the map to load (must exist in /root/data/daystar_api/maps)

  • auto_reload (true) – If True, load map permanently; if False, load only for this session (default: True)

  • block (bool) – If True, block until the underlying reload service returns (up to the internal max wait); if False, use timeout (default: False)

  • timeout (int) – Timeout in seconds; only effective when block=False (default: 30)

Return type:

LoadMapResponse

Returns:

LoadMapResponse.

Examples:

# Load map permanently
result = load_map("office_floor1")
if result.success:
    print("Map loaded successfully")

# Load map temporarily for this session only
result = load_map("warehouse_map", auto_reload=False)

# Load map with custom timeout
result = load_map("large_map", auto_reload=True, timeout=60)

# Switch between maps
available = get_available_maps()
for map_name in available.maps:
    print(f"Available: {map_name}")
    load_map("office_floor2", auto_reload=True)

获取可用地图

get_available_maps(timeout=5)

Get all available maps from the map resource directory.

Parameters:

timeout (int) – Timeout in seconds for query (default: 5)

Return type:

GetAvailableMapsResponse

Returns:

GetAvailableMapsResponse.

Examples:

# Get all available maps
result = get_available_maps()
if result.success:
    print("Available maps:")
for map_name in result.maps:
    print(f"  - {map_name}")

# Get maps with custom timeout
result = get_available_maps(timeout=10)

# Check if specific map exists before loading
result = get_available_maps()
if "office_map" in result.maps:
    load_map("office_map")
else:
    print("Map not found")

# List and select map interactively
maps = get_available_maps()
if maps.success:
    for i, name in enumerate(maps.maps):
    print(f"{i+1}. {name}")
load_map(maps.maps[selection])

建图模式

开始建图

start_mapping(timeout=120)

Start SLAM mapping mode to create a new map.

Parameters:

timeout (int) – Timeout in seconds for mapping mode to start (default: 120)

Return type:

StartMappingResponse

Returns:

StartMappingResponse.

Examples:

result = start_mapping()
if result.success:
    print("Mapping mode started")
# Drive robot around to build map
time.sleep(300)
stop_mapping("new_map")

# Start mapping with custom timeout
result = start_mapping(timeout=180)

# Complete mapping workflow
if start_mapping().success:
    print("Drive the robot to map the area...")
stop_mapping("office_map", auto_reload=True)

停止建图

stop_mapping(map_name, auto_reload=False, need_2d_map=True, block=True, timeout=30)

Stop SLAM mapping, save the map, and switch back to MAP mode.

Parameters:
  • map_name (str) – Name for the saved map

  • auto_reload (bool) – If True, automatically load this map after saving; if False, keep current map (default: False)

  • need_2d_map (bool) – If True, generate 2D map in addition to 3D map; if False, only save 3D map (default: True)

  • block (bool) – If True, block until the underlying save service returns (up to the internal max wait); if False, use timeout (default: True)

  • timeout (int) – Timeout in seconds; only effective when block=False (default: 30)

Return type:

StopMappingResponse

Returns:

StopMappingResponse.

Examples:

# Stop mapping and save without reloading (with 2D map)
result = stop_mapping("warehouse_map")
if result.success:
    print(f"Map saved to: {result.map_path}")

# Stop mapping without 2D map generation
result = stop_mapping("new_office_map", auto_reload=True, need_2d_map=False)

# Non-blocking save with custom timeout
result = stop_mapping("quick_map", block=False, timeout=60)

# Complete mapping session with all options
start_mapping()
print("Drive robot to map the area...")
input("Press Enter when done")
result = stop_mapping("my_map", auto_reload=True, need_2d_map=True, block=True)
if result.success:
    print("Mapping complete, new map loaded")

# Fast save without waiting for 2D map generation
result = stop_mapping("temp_map", auto_reload=False, need_2d_map=False, block=False, timeout=30)