本页介绍了如何通过调用接口将本地的复合地图导入机器人系统


本页内容





运行环境准备

  • 软件平台

  • 硬件平台

          (以下任选其一)

      • Slamware SDP mini 
      • Slamware 套装 (基于Slamware导航方案的用户机器人系统)
      • Apollo/Ares/Athena/Hermes等底盘系统

例程下载

GetStcmMapdemo.py


编译运行

        如下说明使用的是以PyCharm作为demo

  1. 下载例程到本地文件夹中,并使用PyCharm打开此文件夹
  2. 在PyCharm中配置好 Python 解释器


  3. 在终端中传参运行并在代码中指定的文件夹下的地图成功上传到机器人系统

       

          并通过RoboStudio可以查看是否上传成功

               

      


代码描述

  • 如下代码实现了将本地的复合地图在./map文件夹下的map.stcm上传到机器人
#!/usr/bin/python
# -*- coding:utf-8 -*-
import requests
import sys
import os

if len(sys.argv) < 2:
    print("请提供IP地址")
    sys.exit(1)

ip = sys.argv[1]
url = f"http://{ip}:1448/api/core/slam/v1/maps/stcm"
headers = {'Content-Type': 'application/octet-stream'}

file_path = "./map/map.stcm"

# 检查文件是否存在
if not os.path.isfile(file_path):
    print(f"文件 {file_path} 不存在")
    sys.exit(1)

# 读取文件数据
try:
    with open(file_path, "rb") as finput:
        data = finput.read()
except IOError as e:
    print(f"读取文件失败: {e}")
    sys.exit(1)

# 发送 PUT 请求
try:
    response = requests.put(url, headers=headers, data=data, timeout=30)
    response.raise_for_status()  # 如果状态码是4xx或5xx,会抛出HTTPError异常
except requests.exceptions.RequestException as e:
    print(f"请求失败: {e}")
    sys.exit(1)

if response.status_code in [200, 204, 203, 201]:
    print("接口调用成功")
else:
    print(f"请求状态码异常: {response.status_code}")



  • No labels