Skip to main content

Mantis 机器人 Python SDK,基于 Zenoh 通信,无需安装 ROS2

Project description

Mantis Robot SDK

Version Python License

基于 Zenoh 的 Mantis 机器人控制 SDK,无需安装 ROS2

V1.0.0 | 2025-12-30 | Release Notes

特性

  • 🚀 无 ROS2 依赖: 客户端只需 Python + Zenoh
  • 🤖 完整控制: 双臂、夹爪、头部、底盘
  • 🔒 安全限位: 自动限制在 URDF 定义范围内
  • 🎯 仿真预览: RViz 实时预览(带平滑)
  • 📚 完整文档: Google 风格 docstring

安装

pip install eclipse-zenoh
pip install -e .

快速开始

from mantis import Mantis

# 控制实机
with Mantis(ip="192.168.1.100") as robot:
    robot.left_arm.set_shoulder_pitch(-0.5)
    robot.left_gripper.open()
    robot.head.look_up()
    robot.chassis.forward(0.1)

连接方式

# 方式1:指定 IP 连接实机
robot = Mantis(ip="192.168.1.100")

# 方式2:自动发现(同一局域网)
robot = Mantis()

# 方式3:指定 IP 和端口
robot = Mantis(ip="192.168.1.100", port=7447)

# 方式4:仿真预览模式(在 RViz 中显示)
robot = Mantis(sim=True)

仿真预览模式

仿真模式可以在 RViz 中预览机器人动作,无需连接实机:

from mantis import Mantis
import time

# 启用仿真模式
with Mantis(sim=True) as robot:
    # 可选:调整平滑参数
    robot.set_smoothing(alpha=0.1)  # 默认值
    
    # 控制手臂(在 RViz 中实时显示)
    robot.left_arm.set_shoulder_pitch(-0.5)
    robot.right_arm.set_elbow_pitch(0.8)
    
    # 控制头部
    robot.head.look_left()
    
    time.sleep(3)

启动仿真环境:

# 终端 1: 启动仿真环境
ros2 launch bw_sim2real sdk_sim.launch.py

# 终端 2: 启动 zenoh 桥接
zenoh-bridge-ros2dds -d 99

# 终端 3: 运行 SDK
python test_sim.py

API 概览

Mantis (主类)

属性 类型 说明
left_arm Arm 左臂控制器
right_arm Arm 右臂控制器
left_gripper Gripper 左夹爪控制器
right_gripper Gripper 右夹爪控制器
head Head 头部控制器
chassis Chassis 底盘控制器
is_sim_mode bool 是否为仿真模式
方法 说明
connect(timeout=5.0, verify=True) 连接机器人
disconnect() 断开连接
on_feedback(callback) 注册关节反馈回调
home() 所有关节归零
stop() 停止运动

Arm (手臂)

每只手臂 7 个关节,所有角度自动限制在安全范围内

索引 关节 方法 左臂限位 (rad) 右臂限位 (rad)
0 肩俯仰 set_shoulder_pitch(angle) -2.61 ~ 0.78 -2.61 ~ 0.78
1 肩偏航 set_shoulder_yaw(angle) 0.08 ~ 1.04 -1.04 ~ -0.08
2 肩翻滚 set_shoulder_roll(angle) -1.57 ~ 1.57 -1.57 ~ 1.57
3 肘俯仰 set_elbow_pitch(angle) -0.78 ~ 1.57 -0.78 ~ 1.57
4 腕翻滚 set_wrist_roll(angle) -1.57 ~ 1.57 -1.57 ~ 1.57
5 腕俯仰 set_wrist_pitch(angle) -0.52 ~ 0.52 -0.52 ~ 0.52
6 腕偏航 set_wrist_yaw(angle) -1.57 ~ 1.57 -1.57 ~ 1.57

其他方法:

  • set_joints([j0, j1, j2, j3, j4, j5, j6]) - 设置全部 7 个关节(弧度)
  • set_joint(index, angle) - 设置单个关节(索引 0-6)
  • get_limit(index) - 获取指定关节限位 (lower, upper)
  • limits - 获取所有关节限位列表
  • home() - 回到零位

Gripper (夹爪)

方法 说明
set_position(pos) 设置位置 (0.0=闭合, 1.0=张开)
open() 完全张开
close() 完全闭合
half_open() 半开

Head (头部)

头部有限位保护:

  • pitch (俯仰): -0.7 ~ 0.2 rad
  • yaw (偏航): -1.57 ~ 1.57 rad
方法 说明
set_pose(pitch, yaw) 设置姿态(弧度)
set_pitch(angle) 设置俯仰角
set_yaw(angle) 设置偏航角
look_left(angle=0.5) 向左看
look_right(angle=0.5) 向右看
look_up(angle=0.3) 向上看
look_down(angle=0.3) 向下看
center() 回中
limits 获取限位 {'pitch': (min, max), 'yaw': (min, max)}

Chassis (底盘)

方法 说明
set_velocity(vx, vy, omega) 设置速度 (m/s, rad/s)
forward(speed=0.1) 前进
backward(speed=0.1) 后退
strafe_left(speed=0.1) 左移
strafe_right(speed=0.1) 右移
turn_left(speed=0.3) 左转
turn_right(speed=0.3) 右转
stop() 停止

完整示例

1. 手臂控制

from mantis_sdk import Mantis
import time

with Mantis(ip="192.168.1.100") as robot:
    # 设置左臂各关节
    robot.left_arm.set_shoulder_pitch(0.5)   # 肩俯仰
    robot.left_arm.set_shoulder_yaw(0.2)     # 肩偏航
    robot.left_arm.set_shoulder_roll(0.1)    # 肩翻滚
    robot.left_arm.set_elbow_pitch(0.8)      # 肘俯仰
    robot.left_arm.set_wrist_roll(0.0)       # 腕翻滚
    robot.left_arm.set_wrist_pitch(0.3)      # 腕俯仰
    robot.left_arm.set_wrist_yaw(0.0)        # 腕偏航
    time.sleep(2)
    
    # 一次性设置全部关节
    robot.left_arm.set_joints([0.5, 0.2, 0.1, 0.8, 0.0, 0.3, 0.0])
    time.sleep(2)
    
    # 回到零位
    robot.left_arm.home()
    robot.right_arm.home()
    time.sleep(1)

2. 夹爪控制

from mantis_sdk import Mantis
import time

with Mantis(ip="192.168.1.100") as robot:
    # 张开夹爪
    robot.left_gripper.open()
    robot.right_gripper.open()
    time.sleep(1)
    
    # 半开
    robot.left_gripper.half_open()
    time.sleep(1)
    
    # 闭合
    robot.left_gripper.close()
    robot.right_gripper.close()
    time.sleep(1)
    
    # 自定义位置 (0.0 ~ 1.0)
    robot.left_gripper.set_position(0.7)
    time.sleep(1)

3. 头部控制

from mantis_sdk import Mantis
import time

with Mantis(ip="192.168.1.100") as robot:
    # 向左看
    robot.head.look_left()
    time.sleep(1)
    
    # 向右看
    robot.head.look_right()
    time.sleep(1)
    
    # 向上看
    robot.head.look_up()
    time.sleep(1)
    
    # 向下看
    robot.head.look_down()
    time.sleep(1)
    
    # 回中
    robot.head.center()
    time.sleep(1)
    
    # 自定义角度
    robot.head.set_pose(pitch=0.2, yaw=-0.3)
    time.sleep(1)

4. 底盘控制

from mantis_sdk import Mantis
import time

with Mantis(ip="192.168.1.100") as robot:
    # 前进
    robot.chassis.forward(0.1)
    time.sleep(2)
    
    # 后退
    robot.chassis.backward(0.1)
    time.sleep(2)
    
    # 左移
    robot.chassis.strafe_left(0.1)
    time.sleep(2)
    
    # 右移
    robot.chassis.strafe_right(0.1)
    time.sleep(2)
    
    # 左转
    robot.chassis.turn_left(0.3)
    time.sleep(2)
    
    # 右转
    robot.chassis.turn_right(0.3)
    time.sleep(2)
    
    # 停止
    robot.chassis.stop()
    
    # 自定义速度
    robot.chassis.set_velocity(vx=0.1, vy=0.05, omega=0.1)
    time.sleep(2)
    robot.chassis.stop()

5. 关节反馈

from mantis_sdk import Mantis
import time

def on_feedback(joint_names, positions):
    print(f"关节反馈: {len(positions)} 个关节")
    for name, pos in zip(joint_names, positions):
        print(f"  {name}: {pos:.3f}")

with Mantis(ip="192.168.1.100") as robot:
    # 注册反馈回调
    robot.on_feedback(on_feedback)
    
    # 保持运行,接收反馈
    time.sleep(10)

6. 综合示例

from mantis_sdk import Mantis
import time

with Mantis(ip="192.168.1.100") as robot:
    print("开始综合演示...")
    
    # 1. 头部环顾
    robot.head.look_left()
    time.sleep(0.5)
    robot.head.look_right()
    time.sleep(0.5)
    robot.head.center()
    
    # 2. 双臂抬起
    robot.left_arm.set_shoulder_pitch(0.5)
    robot.right_arm.set_shoulder_pitch(0.5)
    time.sleep(1)
    
    # 3. 夹爪开合
    robot.left_gripper.open()
    robot.right_gripper.open()
    time.sleep(0.5)
    robot.left_gripper.close()
    robot.right_gripper.close()
    time.sleep(0.5)
    
    # 4. 前进后退
    robot.chassis.forward(0.1)
    time.sleep(1)
    robot.chassis.backward(0.1)
    time.sleep(1)
    robot.chassis.stop()
    
    # 5. 回到初始位置
    robot.left_arm.home()
    robot.right_arm.home()
    robot.head.center()
    
    print("演示完成!")

机器人端配置

启动 Zenoh-ROS2 桥接(根据你的 ROS_DOMAIN_ID 设置 -d 参数):

~/zenoh_ros2/zenoh-bridge-ros2dds -d 99

文件结构

mantis/
├── mantis_sdk/
│   ├── __init__.py     # 模块入口
│   ├── mantis.py       # 主控制类
│   ├── arm.py          # 手臂控制
│   ├── gripper.py      # 夹爪控制
│   ├── head.py         # 头部控制
│   ├── chassis.py      # 底盘控制
│   ├── cdr.py          # CDR编解码
│   └── constants.py    # 常量定义
└── README.md

注意事项

  1. 角度单位:所有角度均为弧度(rad)
  2. 速度单位:线速度 m/s,角速度 rad/s
  3. 夹爪范围:0.0(闭合)到 1.0(张开)
  4. 连接超时:默认 5 秒,可通过 connect(timeout=10) 调整

BlueWorm-EAI-Tech

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bw_mantis_sdk-1.0.0.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bw_mantis_sdk-1.0.0-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file bw_mantis_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: bw_mantis_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for bw_mantis_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8cc2cc578fd4ff8045dd317bbe19b9a090a598b65691fdc7fb5957790049f08c
MD5 486db95c4265b03959210687fe1e547c
BLAKE2b-256 492f2b1ba9f794a761478c0fd387bfc3b81e14f122fd3ebf1d5d6cb4b2eb7ed4

See more details on using hashes here.

File details

Details for the file bw_mantis_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: bw_mantis_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for bw_mantis_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a8e364011a2e1dc17c17bcbe9c7f6f81634f1de4fae430a9edfe0c1ce1a54358
MD5 bf94ba83b6446211f03d3e4ead458d23
BLAKE2b-256 cac0a4fdcb14d885feeba3ba738c207547421549e6fc999b1ed3ba8b0b6f928b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page