bw-mantis-sdk 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 BlueWorm-EAI-Tech
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,433 @@
1
+ Metadata-Version: 2.4
2
+ Name: bw-mantis-sdk
3
+ Version: 1.0.0
4
+ Summary: Mantis 机器人 Python SDK,基于 Zenoh 通信,无需安装 ROS2
5
+ Author: BlueWorm-EAI-Tech
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/BlueWorm-EAI-Tech/mantis-sdk
8
+ Project-URL: Repository, https://github.com/BlueWorm-EAI-Tech/mantis-sdk
9
+ Keywords: robot,mantis,zenoh,ros2,sdk,sim2real
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering
21
+ Requires-Python: >=3.8
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: eclipse-zenoh>=1.0.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest; extra == "dev"
27
+ Requires-Dist: build; extra == "dev"
28
+ Requires-Dist: twine; extra == "dev"
29
+ Dynamic: license-file
30
+
31
+ # Mantis Robot SDK
32
+
33
+ [![Version](https://img.shields.io/badge/version-1.0.0-blue.svg)](./VERSION)
34
+ [![Python](https://img.shields.io/badge/python-3.8+-green.svg)](https://www.python.org/)
35
+ [![License](https://img.shields.io/badge/license-MIT-orange.svg)](./LICENSE)
36
+
37
+ 基于 Zenoh 的 Mantis 机器人控制 SDK,**无需安装 ROS2**。
38
+
39
+ > **V1.0.0** | 2025-12-30 | [Release Notes](./CHANGELOG.md)
40
+
41
+ ## 特性
42
+
43
+ - 🚀 **无 ROS2 依赖**: 客户端只需 Python + Zenoh
44
+ - 🤖 **完整控制**: 双臂、夹爪、头部、底盘
45
+ - 🔒 **安全限位**: 自动限制在 URDF 定义范围内
46
+ - 🎯 **仿真预览**: RViz 实时预览(带平滑)
47
+ - 📚 **完整文档**: Google 风格 docstring
48
+
49
+ ## 安装
50
+
51
+ ```bash
52
+ pip install eclipse-zenoh
53
+ pip install -e .
54
+ ```
55
+
56
+ ## 快速开始
57
+
58
+ ```python
59
+ from mantis import Mantis
60
+
61
+ # 控制实机
62
+ with Mantis(ip="192.168.1.100") as robot:
63
+ robot.left_arm.set_shoulder_pitch(-0.5)
64
+ robot.left_gripper.open()
65
+ robot.head.look_up()
66
+ robot.chassis.forward(0.1)
67
+ ```
68
+
69
+ ## 连接方式
70
+
71
+ ```python
72
+ # 方式1:指定 IP 连接实机
73
+ robot = Mantis(ip="192.168.1.100")
74
+
75
+ # 方式2:自动发现(同一局域网)
76
+ robot = Mantis()
77
+
78
+ # 方式3:指定 IP 和端口
79
+ robot = Mantis(ip="192.168.1.100", port=7447)
80
+
81
+ # 方式4:仿真预览模式(在 RViz 中显示)
82
+ robot = Mantis(sim=True)
83
+ ```
84
+
85
+ ## 仿真预览模式
86
+
87
+ 仿真模式可以在 RViz 中预览机器人动作,无需连接实机:
88
+
89
+ ```python
90
+ from mantis import Mantis
91
+ import time
92
+
93
+ # 启用仿真模式
94
+ with Mantis(sim=True) as robot:
95
+ # 可选:调整平滑参数
96
+ robot.set_smoothing(alpha=0.1) # 默认值
97
+
98
+ # 控制手臂(在 RViz 中实时显示)
99
+ robot.left_arm.set_shoulder_pitch(-0.5)
100
+ robot.right_arm.set_elbow_pitch(0.8)
101
+
102
+ # 控制头部
103
+ robot.head.look_left()
104
+
105
+ time.sleep(3)
106
+ ```
107
+
108
+ **启动仿真环境:**
109
+
110
+ ```bash
111
+ # 终端 1: 启动仿真环境
112
+ ros2 launch bw_sim2real sdk_sim.launch.py
113
+
114
+ # 终端 2: 启动 zenoh 桥接
115
+ zenoh-bridge-ros2dds -d 99
116
+
117
+ # 终端 3: 运行 SDK
118
+ python test_sim.py
119
+ ```
120
+
121
+ ---
122
+
123
+ ## API 概览
124
+
125
+ ### Mantis (主类)
126
+
127
+ | 属性 | 类型 | 说明 |
128
+ |------|------|------|
129
+ | `left_arm` | Arm | 左臂控制器 |
130
+ | `right_arm` | Arm | 右臂控制器 |
131
+ | `left_gripper` | Gripper | 左夹爪控制器 |
132
+ | `right_gripper` | Gripper | 右夹爪控制器 |
133
+ | `head` | Head | 头部控制器 |
134
+ | `chassis` | Chassis | 底盘控制器 |
135
+ | `is_sim_mode` | bool | 是否为仿真模式 |
136
+
137
+ | 方法 | 说明 |
138
+ |------|------|
139
+ | `connect(timeout=5.0, verify=True)` | 连接机器人 |
140
+ | `disconnect()` | 断开连接 |
141
+ | `on_feedback(callback)` | 注册关节反馈回调 |
142
+ | `home()` | 所有关节归零 |
143
+ | `stop()` | 停止运动 |
144
+
145
+ ### Arm (手臂)
146
+
147
+ 每只手臂 7 个关节,**所有角度自动限制在安全范围内**:
148
+
149
+ | 索引 | 关节 | 方法 | 左臂限位 (rad) | 右臂限位 (rad) |
150
+ |------|------|------|----------------|----------------|
151
+ | 0 | 肩俯仰 | `set_shoulder_pitch(angle)` | -2.61 ~ 0.78 | -2.61 ~ 0.78 |
152
+ | 1 | 肩偏航 | `set_shoulder_yaw(angle)` | 0.08 ~ 1.04 | -1.04 ~ -0.08 |
153
+ | 2 | 肩翻滚 | `set_shoulder_roll(angle)` | -1.57 ~ 1.57 | -1.57 ~ 1.57 |
154
+ | 3 | 肘俯仰 | `set_elbow_pitch(angle)` | -0.78 ~ 1.57 | -0.78 ~ 1.57 |
155
+ | 4 | 腕翻滚 | `set_wrist_roll(angle)` | -1.57 ~ 1.57 | -1.57 ~ 1.57 |
156
+ | 5 | 腕俯仰 | `set_wrist_pitch(angle)` | -0.52 ~ 0.52 | -0.52 ~ 0.52 |
157
+ | 6 | 腕偏航 | `set_wrist_yaw(angle)` | -1.57 ~ 1.57 | -1.57 ~ 1.57 |
158
+
159
+ 其他方法:
160
+ - `set_joints([j0, j1, j2, j3, j4, j5, j6])` - 设置全部 7 个关节(弧度)
161
+ - `set_joint(index, angle)` - 设置单个关节(索引 0-6)
162
+ - `get_limit(index)` - 获取指定关节限位 `(lower, upper)`
163
+ - `limits` - 获取所有关节限位列表
164
+ - `home()` - 回到零位
165
+
166
+ ### Gripper (夹爪)
167
+
168
+ | 方法 | 说明 |
169
+ |------|------|
170
+ | `set_position(pos)` | 设置位置 (0.0=闭合, 1.0=张开) |
171
+ | `open()` | 完全张开 |
172
+ | `close()` | 完全闭合 |
173
+ | `half_open()` | 半开 |
174
+
175
+ ### Head (头部)
176
+
177
+ 头部有限位保护:
178
+ - **pitch (俯仰)**: -0.7 ~ 0.2 rad
179
+ - **yaw (偏航)**: -1.57 ~ 1.57 rad
180
+
181
+ | 方法 | 说明 |
182
+ |------|------|
183
+ | `set_pose(pitch, yaw)` | 设置姿态(弧度) |
184
+ | `set_pitch(angle)` | 设置俯仰角 |
185
+ | `set_yaw(angle)` | 设置偏航角 |
186
+ | `look_left(angle=0.5)` | 向左看 |
187
+ | `look_right(angle=0.5)` | 向右看 |
188
+ | `look_up(angle=0.3)` | 向上看 |
189
+ | `look_down(angle=0.3)` | 向下看 |
190
+ | `center()` | 回中 |
191
+ | `limits` | 获取限位 `{'pitch': (min, max), 'yaw': (min, max)}` |
192
+
193
+ ### Chassis (底盘)
194
+
195
+ | 方法 | 说明 |
196
+ |------|------|
197
+ | `set_velocity(vx, vy, omega)` | 设置速度 (m/s, rad/s) |
198
+ | `forward(speed=0.1)` | 前进 |
199
+ | `backward(speed=0.1)` | 后退 |
200
+ | `strafe_left(speed=0.1)` | 左移 |
201
+ | `strafe_right(speed=0.1)` | 右移 |
202
+ | `turn_left(speed=0.3)` | 左转 |
203
+ | `turn_right(speed=0.3)` | 右转 |
204
+ | `stop()` | 停止 |
205
+
206
+ ---
207
+
208
+ ## 完整示例
209
+
210
+ ### 1. 手臂控制
211
+
212
+ ```python
213
+ from mantis_sdk import Mantis
214
+ import time
215
+
216
+ with Mantis(ip="192.168.1.100") as robot:
217
+ # 设置左臂各关节
218
+ robot.left_arm.set_shoulder_pitch(0.5) # 肩俯仰
219
+ robot.left_arm.set_shoulder_yaw(0.2) # 肩偏航
220
+ robot.left_arm.set_shoulder_roll(0.1) # 肩翻滚
221
+ robot.left_arm.set_elbow_pitch(0.8) # 肘俯仰
222
+ robot.left_arm.set_wrist_roll(0.0) # 腕翻滚
223
+ robot.left_arm.set_wrist_pitch(0.3) # 腕俯仰
224
+ robot.left_arm.set_wrist_yaw(0.0) # 腕偏航
225
+ time.sleep(2)
226
+
227
+ # 一次性设置全部关节
228
+ robot.left_arm.set_joints([0.5, 0.2, 0.1, 0.8, 0.0, 0.3, 0.0])
229
+ time.sleep(2)
230
+
231
+ # 回到零位
232
+ robot.left_arm.home()
233
+ robot.right_arm.home()
234
+ time.sleep(1)
235
+ ```
236
+
237
+ ### 2. 夹爪控制
238
+
239
+ ```python
240
+ from mantis_sdk import Mantis
241
+ import time
242
+
243
+ with Mantis(ip="192.168.1.100") as robot:
244
+ # 张开夹爪
245
+ robot.left_gripper.open()
246
+ robot.right_gripper.open()
247
+ time.sleep(1)
248
+
249
+ # 半开
250
+ robot.left_gripper.half_open()
251
+ time.sleep(1)
252
+
253
+ # 闭合
254
+ robot.left_gripper.close()
255
+ robot.right_gripper.close()
256
+ time.sleep(1)
257
+
258
+ # 自定义位置 (0.0 ~ 1.0)
259
+ robot.left_gripper.set_position(0.7)
260
+ time.sleep(1)
261
+ ```
262
+
263
+ ### 3. 头部控制
264
+
265
+ ```python
266
+ from mantis_sdk import Mantis
267
+ import time
268
+
269
+ with Mantis(ip="192.168.1.100") as robot:
270
+ # 向左看
271
+ robot.head.look_left()
272
+ time.sleep(1)
273
+
274
+ # 向右看
275
+ robot.head.look_right()
276
+ time.sleep(1)
277
+
278
+ # 向上看
279
+ robot.head.look_up()
280
+ time.sleep(1)
281
+
282
+ # 向下看
283
+ robot.head.look_down()
284
+ time.sleep(1)
285
+
286
+ # 回中
287
+ robot.head.center()
288
+ time.sleep(1)
289
+
290
+ # 自定义角度
291
+ robot.head.set_pose(pitch=0.2, yaw=-0.3)
292
+ time.sleep(1)
293
+ ```
294
+
295
+ ### 4. 底盘控制
296
+
297
+ ```python
298
+ from mantis_sdk import Mantis
299
+ import time
300
+
301
+ with Mantis(ip="192.168.1.100") as robot:
302
+ # 前进
303
+ robot.chassis.forward(0.1)
304
+ time.sleep(2)
305
+
306
+ # 后退
307
+ robot.chassis.backward(0.1)
308
+ time.sleep(2)
309
+
310
+ # 左移
311
+ robot.chassis.strafe_left(0.1)
312
+ time.sleep(2)
313
+
314
+ # 右移
315
+ robot.chassis.strafe_right(0.1)
316
+ time.sleep(2)
317
+
318
+ # 左转
319
+ robot.chassis.turn_left(0.3)
320
+ time.sleep(2)
321
+
322
+ # 右转
323
+ robot.chassis.turn_right(0.3)
324
+ time.sleep(2)
325
+
326
+ # 停止
327
+ robot.chassis.stop()
328
+
329
+ # 自定义速度
330
+ robot.chassis.set_velocity(vx=0.1, vy=0.05, omega=0.1)
331
+ time.sleep(2)
332
+ robot.chassis.stop()
333
+ ```
334
+
335
+ ### 5. 关节反馈
336
+
337
+ ```python
338
+ from mantis_sdk import Mantis
339
+ import time
340
+
341
+ def on_feedback(joint_names, positions):
342
+ print(f"关节反馈: {len(positions)} 个关节")
343
+ for name, pos in zip(joint_names, positions):
344
+ print(f" {name}: {pos:.3f}")
345
+
346
+ with Mantis(ip="192.168.1.100") as robot:
347
+ # 注册反馈回调
348
+ robot.on_feedback(on_feedback)
349
+
350
+ # 保持运行,接收反馈
351
+ time.sleep(10)
352
+ ```
353
+
354
+ ### 6. 综合示例
355
+
356
+ ```python
357
+ from mantis_sdk import Mantis
358
+ import time
359
+
360
+ with Mantis(ip="192.168.1.100") as robot:
361
+ print("开始综合演示...")
362
+
363
+ # 1. 头部环顾
364
+ robot.head.look_left()
365
+ time.sleep(0.5)
366
+ robot.head.look_right()
367
+ time.sleep(0.5)
368
+ robot.head.center()
369
+
370
+ # 2. 双臂抬起
371
+ robot.left_arm.set_shoulder_pitch(0.5)
372
+ robot.right_arm.set_shoulder_pitch(0.5)
373
+ time.sleep(1)
374
+
375
+ # 3. 夹爪开合
376
+ robot.left_gripper.open()
377
+ robot.right_gripper.open()
378
+ time.sleep(0.5)
379
+ robot.left_gripper.close()
380
+ robot.right_gripper.close()
381
+ time.sleep(0.5)
382
+
383
+ # 4. 前进后退
384
+ robot.chassis.forward(0.1)
385
+ time.sleep(1)
386
+ robot.chassis.backward(0.1)
387
+ time.sleep(1)
388
+ robot.chassis.stop()
389
+
390
+ # 5. 回到初始位置
391
+ robot.left_arm.home()
392
+ robot.right_arm.home()
393
+ robot.head.center()
394
+
395
+ print("演示完成!")
396
+ ```
397
+
398
+ ---
399
+
400
+ ## 机器人端配置
401
+
402
+ 启动 Zenoh-ROS2 桥接(根据你的 ROS_DOMAIN_ID 设置 -d 参数):
403
+
404
+ ```bash
405
+ ~/zenoh_ros2/zenoh-bridge-ros2dds -d 99
406
+ ```
407
+
408
+ ## 文件结构
409
+
410
+ ```
411
+ mantis/
412
+ ├── mantis_sdk/
413
+ │ ├── __init__.py # 模块入口
414
+ │ ├── mantis.py # 主控制类
415
+ │ ├── arm.py # 手臂控制
416
+ │ ├── gripper.py # 夹爪控制
417
+ │ ├── head.py # 头部控制
418
+ │ ├── chassis.py # 底盘控制
419
+ │ ├── cdr.py # CDR编解码
420
+ │ └── constants.py # 常量定义
421
+ └── README.md
422
+ ```
423
+
424
+ ## 注意事项
425
+
426
+ 1. **角度单位**:所有角度均为弧度(rad)
427
+ 2. **速度单位**:线速度 m/s,角速度 rad/s
428
+ 3. **夹爪范围**:0.0(闭合)到 1.0(张开)
429
+ 4. **连接超时**:默认 5 秒,可通过 `connect(timeout=10)` 调整
430
+
431
+ ---
432
+
433
+ **BlueWorm-EAI-Tech**