本页介绍了如何通过调用接口将本地的复合地图导入机器人系统
本页内容
Sample Code: 可以命令行运行,也可以下载常用的集成开发环境 (IDE) 和 编辑器来运行,例如PyCharm或者Visual Studio Code (VS Code)等
(以下任选其一)
如下说明使用的是以PyCharm作为demo
并通过RoboStudio可以查看是否上传成功
#!/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}") |