kuavo-humanoid-sdk-ws 1.3.1b4184__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.
Files changed (48) hide show
  1. kuavo_humanoid_sdk_ws-1.3.1b4184/PKG-INFO +271 -0
  2. kuavo_humanoid_sdk_ws-1.3.1b4184/README.md +79 -0
  3. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/__init__.py +6 -0
  4. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/common/launch_robot_tool.py +170 -0
  5. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/common/logger.py +45 -0
  6. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/common/websocket_kuavo_sdk.py +26 -0
  7. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/interfaces/__init__.py +4 -0
  8. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/interfaces/data_types.py +293 -0
  9. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/interfaces/end_effector.py +62 -0
  10. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/interfaces/robot.py +22 -0
  11. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/interfaces/robot_info.py +56 -0
  12. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/__init__.py +12 -0
  13. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/core/audio.py +32 -0
  14. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/core/core.py +755 -0
  15. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/core/dex_hand_control.py +114 -0
  16. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/core/leju_claw_control.py +67 -0
  17. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/core/ros/audio.py +86 -0
  18. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/core/ros/control.py +1325 -0
  19. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/core/ros/observation.py +125 -0
  20. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/core/ros/param.py +335 -0
  21. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/core/ros/sat_utils.py +103 -0
  22. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/core/ros/state.py +426 -0
  23. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/core/ros/tools.py +197 -0
  24. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/core/ros/vision.py +280 -0
  25. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/core/ros_env.py +236 -0
  26. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/dexterous_hand.py +198 -0
  27. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/leju_claw.py +232 -0
  28. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/robot.py +550 -0
  29. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/robot_arm.py +235 -0
  30. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/robot_audio.py +39 -0
  31. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/robot_head.py +39 -0
  32. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/robot_info.py +235 -0
  33. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/robot_observation.py +69 -0
  34. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/robot_state.py +346 -0
  35. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/robot_tool.py +58 -0
  36. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/robot_vision.py +82 -0
  37. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo/robot_waist.py +53 -0
  38. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo_strategy/__init__.py +2 -0
  39. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo_strategy/grasp_box/grasp_box_strategy.py +418 -0
  40. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/kuavo_strategy/kuavo_strategy.py +63 -0
  41. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk/msg/__init__.py +4 -0
  42. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk_ws.egg-info/PKG-INFO +271 -0
  43. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk_ws.egg-info/SOURCES.txt +46 -0
  44. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk_ws.egg-info/dependency_links.txt +1 -0
  45. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk_ws.egg-info/requires.txt +5 -0
  46. kuavo_humanoid_sdk_ws-1.3.1b4184/kuavo_humanoid_sdk_ws.egg-info/top_level.txt +1 -0
  47. kuavo_humanoid_sdk_ws-1.3.1b4184/setup.cfg +4 -0
  48. kuavo_humanoid_sdk_ws-1.3.1b4184/setup.py +72 -0
@@ -0,0 +1,271 @@
1
+ Metadata-Version: 2.1
2
+ Name: kuavo_humanoid_sdk_ws
3
+ Version: 1.3.1b4184
4
+ Summary: A Python SDK for kuavo humanoid robot.
5
+ Home-page: https://gitee.com/leju-robot/kuavo-ros-opensource/
6
+ Author: ['lejurobot']
7
+ Author-email: edu@lejurobot.com
8
+ License: MIT
9
+ Project-URL: Documentation, https://gitee.com/leju-robot/kuavo-ros-opensource/
10
+ Project-URL: Source Code, https://gitee.com/leju-robot/kuavo-ros-opensource/
11
+ Keywords: kuavo,humanoid,robot,robotics,lejurobot,ros
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.8
22
+ Description-Content-Type: text/markdown
23
+
24
+ # Kuavo Humanoid SDK
25
+
26
+ A comprehensive Python SDK for controlling Kuavo humanoid robots. This SDK provides interfaces for robot state management, arm and head control, and end-effector operations. It is designed to work with ROS (Robot Operating System) environments.
27
+
28
+ **Warning**: This SDK currently only supports **ROS1**. ROS2 support is not available.
29
+
30
+ **Warning**: **This SDK can only be used on the onboard NUC computer located in the robot's torso.**
31
+
32
+ ![Kuavo 4Pro Robot](https://kuavo.lejurobot.com/manual/assets/images/kuavo_4pro-cf84d43f1c370666c6e810d2807ae3e4.png)
33
+
34
+ ## Features
35
+
36
+ - Robot State Management
37
+ - IMU data (acceleration, angular velocity, euler angles)
38
+ - Joint/motor states (position, velocity, torque)
39
+ - Torso state (position, orientation, velocity)
40
+ - Odometry information
41
+ - End-effector states:
42
+ - Gripper(lejuclaw): position, velocity, torque, grasp status
43
+ - Dexterous hand(qiangnao): position, velocity, torque
44
+ - Touch Dexterous hand(qiangnao_touch): position, velocity, torque, touch state
45
+ - End-effector position and orientation
46
+ - Motion states: stand, walk, step_control, trot
47
+
48
+ - Motion Control
49
+ - Arm Control
50
+ - Joint position control
51
+ - End-effector 6D control via inverse kinematics
52
+ - Forward kinematics (FK) for computing end-effector pose
53
+ - Keyframe sequence control for complex motions
54
+ - End-effector Control
55
+ - Gripper control (position control with configurable velocity and torque)
56
+ - Dexterous hand control
57
+ - Position control
58
+ - Pre-defined hand gestures (OK, 666, fist, etc.)
59
+ - Head Control
60
+ - Position control
61
+ - Torso Control
62
+ - Height control (squatting)
63
+ - Forward/backward tilt control
64
+ - Dynamic Motion Control
65
+ - Stance
66
+ - Trot
67
+ - Walking (xy and yaw velocity control)
68
+ - Stepping (gait switching)
69
+
70
+ - Robot Basic Information
71
+ - Robot type (kuavo)
72
+ - Robot version
73
+ - End-effector type
74
+ - Joint names
75
+ - Total degrees of freedom (28)
76
+ - Arm degrees of freedom (7 per arm)
77
+ - Head degrees of freedom (2)
78
+ - Leg degrees of freedom (12)
79
+
80
+ ## Installation
81
+
82
+ **Note: There are currently two versions of this SDK, the stable version and the beta version. Their differences are:**
83
+
84
+ - stable version: corresponding to the functionality provided by the `master` branch of [kuavo-ros-opensource](https://gitee.com/leju-robot/kuavo-ros-opensource/).
85
+ - Beta version: This version is more aggressive than the official version and also provides richer functionality, corresponding to the functionality provided by the `beta` branch of [kuavo-ros-opensource](https://gitee.com/leju-robot/kuavo-ros-opensource/).
86
+
87
+ **Friendly reminder: Please be clear about which version you need to install. If your SDK version does not match `kuavo-ros-opensource`, some features may not be available.**
88
+
89
+ Install the latest **​stable version** of Kuavo Humanoid SDK using pip:
90
+ ```bash
91
+ pip install kuavo-humanoid-sdk-ws
92
+ ```
93
+
94
+ Install the latest **​beta version** of Kuavo Humanoid SDK using pip:
95
+ ```bash
96
+ pip install --pre kuavo-humanoid-sdk-ws
97
+ ```
98
+
99
+ For local development installation (editable mode), use:
100
+ ```bash
101
+ cd src/kuavo_humanoid_sdk_ws
102
+ chmod +x install.sh
103
+ ./install.sh
104
+ ```
105
+ ## Upgrade Instructions
106
+ Before upgrading, you can check the currently installed version with:
107
+ ```bash
108
+ pip show kuavo-humanoid-sdk-ws
109
+ # Output:
110
+ Name: kuavo-humanoid-sdk-ws
111
+ Version: 0.1.2
112
+ ...
113
+ ```
114
+
115
+ **Note: If the version number contains the letter b, it indicates a beta version, e.g., Version: 0.1.2b113**
116
+
117
+ To upgrade from a stable version to the latest stable version:
118
+ ```bash
119
+ pip install --upgrade kuavo-humanoid-sdk-ws
120
+ ```
121
+
122
+ To upgrade from a beta version to the latest stable version:
123
+ ```bash
124
+ pip install --upgrade --force-reinstall kuavo-humanoid-sdk-ws
125
+ # or
126
+ pip uninstall kuavo-humanoid-sdk-ws && pip install kuavo-humanoid-sdk-ws
127
+ ```
128
+
129
+ To upgrade from a stable/beta version to the latest beta version:
130
+ ```bash
131
+ pip install --upgrade --pre kuavo-humanoid-sdk-ws
132
+ ```
133
+
134
+ ## Package Information
135
+
136
+ You can check the package information using pip:
137
+ ```bash
138
+ pip show kuavo-humanoid-sdk-ws
139
+ ```
140
+
141
+ ## Quick Start
142
+
143
+ Here's a simple example to get started with Kuavo Humanoid SDK:
144
+
145
+ > **Warning**: Before running any code, make sure to start the robot first by executing either:
146
+ > - For simulation: `roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch` (Example command)
147
+ > - For real robot: `roslaunch humanoid_controllers load_kuavo_real.launch` (Example command)
148
+ ```python3
149
+ # Copyright (c) 2025 Leju Robotics. Licensed under the MIT License.
150
+ import time
151
+ from kuavo_humanoid_sdk import KuavoSDK, KuavoRobot
152
+
153
+ def main():
154
+ if not KuavoSDK().Init(): # Init! !!! IMPORTANT !!!
155
+ print("Init KuavoSDK failed, exit!")
156
+ exit(1)
157
+ robot = KuavoRobot()
158
+
159
+ """ arm reset """
160
+ print("Switching to arm reset mode...")
161
+ robot.arm_reset()
162
+
163
+ """ stance """
164
+ print("Switching to stance mode...")
165
+ robot.stance()
166
+
167
+ """ trot """
168
+ print("Switching to trot mode...")
169
+ robot.trot()
170
+
171
+ """ walk forward """
172
+ print("Starting forward walk...")
173
+ duration = 4.0 # seconds
174
+ speed = 0.3 # m/s
175
+ start_time = time.time()
176
+ while (time.time() - start_time < duration):
177
+ robot.walk(linear_x=speed, linear_y=0.0, angular_z=0.0)
178
+ time.sleep(0.1) # Small sleep to prevent busy loop
179
+
180
+ if __name__ == "__main__":
181
+ main()
182
+ ```
183
+
184
+ ## Docs
185
+ The documentation is available in two formats:
186
+ - HTML format: [docs/html](docs/html), **needs to be generated by running the script**
187
+ - Markdown format: [docs/markdown](docs/markdown)
188
+
189
+ We recommend that you generate the documentation locally by running the documentation script. The documentation will be output to the `docs/html` and `docs/markdown` folders:
190
+ ```bash
191
+ cd <kuavo-ros-opensource>/src/kuavo_humanoid_sdk_ws
192
+ chmod +x gen_docs.sh
193
+ ./gen_docs.sh
194
+ ```
195
+
196
+ **We recommend that you view the documentation using `html` for a better experience.**
197
+
198
+ For Markdown documentation at:
199
+
200
+ https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/docs/markdown/index.md
201
+
202
+ ## Examples
203
+
204
+ #### WARNING
205
+ Before running any code examples, make sure to start the robot first by executing either:
206
+
207
+ - For simulation: `roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch` (Example command)
208
+ - For real robot: `roslaunch humanoid_controllers load_kuavo_real.launch` (Example command)
209
+
210
+ ### Robot Info
211
+
212
+ Examples showing how to get basic robot information.
213
+
214
+ [https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/robot_info_example.py](https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/robot_info_example.py)
215
+
216
+ ### Basic Robot Control
217
+
218
+ A basic example showing how to initialize the SDK and control the robot’s movement.
219
+
220
+ [https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/motion_example.py](https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/motion_example.py)
221
+
222
+ ### End Effector Control
223
+
224
+ #### LejuClaw Gripper
225
+
226
+ Examples demonstrating how to control the LejuClaw gripper end effector, including position, velocity and torque control.
227
+
228
+ [https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/lejuclaw_example.py](https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/lejuclaw_example.py)
229
+
230
+ #### QiangNao DexHand
231
+
232
+ Examples showing how to control the QiangNao DexHand, a dexterous robotic hand with multiple degrees of freedom for complex manipulation tasks.
233
+
234
+ [https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/dexhand_example.py](https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/dexhand_example.py)
235
+
236
+ ### Arm Control
237
+
238
+ Examples showing arm trajectory control and target pose control.
239
+
240
+ [https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/ctrl_arm_example.py](https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/ctrl_arm_example.py)
241
+
242
+ ### Forward and Inverse Kinematics
243
+
244
+ Examples demonstrating how to use forward kinematics (FK) to compute end-effector positions from joint angles, and inverse kinematics (IK) to calculate joint angles needed to achieve desired end-effector poses.
245
+
246
+ [https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/arm_ik_example.py](https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/arm_ik_example.py)
247
+
248
+ ### Head Control
249
+
250
+ Examples showing how to control the robot’s head movements, including nodding (pitch) and shaking (yaw) motions.
251
+
252
+ [https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/ctrl_head_example.py](https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/ctrl_head_example.py)
253
+
254
+ ### Step-by-Step Control
255
+
256
+ Examples showing how to control the robot’s movements step by step, including individual foot placement and trajectory control.
257
+
258
+ [https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/step_control_example.py](https://gitee.com/leju-robot/kuavo-ros-opensource/tree/master/src/kuavo_humanoid_sdk/examples/step_control_example.py)
259
+
260
+
261
+ ## License
262
+
263
+ This project is licensed under the MIT License - see the LICENSE file for details.
264
+
265
+ ## Contact & Support
266
+
267
+ For any questions, support, or bug reports, please contact:
268
+ - Email: edu@lejurobot.com
269
+ - Website: https://gitee.com/leju-robot/kuavo-ros-opensource/
270
+ - Source Code: https://gitee.com/leju-robot/kuavo-ros-opensource/
271
+ - Issue Tracker: https://gitee.com/leju-robot/kuavo-ros-opensource/issues
@@ -0,0 +1,79 @@
1
+ # Kuavo Humanoid SDK
2
+ [![Version](https://img.shields.io/pypi/v/kuavo-humanoid-sdk-ws.svg)](https://pypi.org/project/kuavo-humanoid-sdk-ws/)[![License](https://img.shields.io/pypi/l/kuavo-humanoid-sdk-ws.svg)](#)[![Supported Python Versions](https://img.shields.io/pypi/pyversions/kuavo-humanoid-sdk-ws.svg)](https://pypi.python.org/pypi/kuavo-humanoid-sdk-ws)
3
+
4
+ 一个全面的 Python SDK,用于控制 Kuavo 人形机器人。该 SDK 提供了机器人状态管理、手臂和头部控制以及末端执行器操作的接口。它设计用于与 ROS(机器人操作系统)环境一起工作。
5
+
6
+ **警告**:该 SDK 目前仅支持 **ROS1**。不支持 ROS2。
7
+
8
+ PyPI 项目地址: https://pypi.org/project/kuavo-humanoid-sdk-ws/
9
+
10
+ ## 安装
11
+ **提示:对于本 SDK 目前存在两个版本,正式发布版与beta内测版, 他们的区别是:**
12
+ - 正式发布版:稳定版,对应[kuavo-ros-opensource](https://gitee.com/leju-robot/kuavo-ros-opensource/)的`master` 分支提供的功能,
13
+ - beta内测版:该版本较正式版会激进一些,同时也会提供更丰富的功能,对应[kuavo-ros-opensource](https://gitee.com/leju-robot/kuavo-ros-opensource/)的`beta` 分支提供的功能。
14
+
15
+ **温馨提示:请务必明确您需要安装的版本,如果您的SDK版本与`kuavo-ros-opensource`未匹配,可能会出现某些功能不可用的错误。**
16
+
17
+ 安装最新的**正式版** Kuavo Humanoid SDK,可以使用 pip:
18
+ ```bash
19
+ pip install kuavo-humanoid-sdk-ws
20
+ ```
21
+
22
+ 安装最新的**beta版** Kuavo Humanoid SDK,可以使用 pip:
23
+ ```bash
24
+ pip install --pre kuavo-humanoid-sdk-ws
25
+
26
+ ```
27
+ 对于本地开发安装(可编辑模式),请使用:
28
+ ```bash
29
+ cd src/kuavo_humanoid_sdk_ws
30
+ chmod +x install.sh
31
+ ./install.sh
32
+ ```
33
+
34
+ ## 升级更新
35
+
36
+ 在升级更新之前,您可以先执行以下命令来查看当前安装的版本:
37
+ ```bash
38
+ pip show kuavo-humanoid-sdk-ws
39
+ # Output:
40
+ Name: kuavo-humanoid-sdk-ws
41
+ Version: 0.1.2
42
+ ...
43
+ ```
44
+ **提示:如果您的版本号中包含字母`b`,则表示该版本为测试版, 比如`Version: 0.1.2b113`**
45
+
46
+ **当前为正式版**,升级到最新正式版:
47
+ ```bash
48
+ pip install --upgrade kuavo-humanoid-sdk-ws
49
+ ```
50
+ **当前为beta版**,升级到最新正式版:
51
+ ```bash
52
+ pip install --upgrade --force-reinstall kuavo-humanoid-sdk-ws
53
+ # 或者
54
+ pip uninstall kuavo-humanoid-sdk-ws && pip install kuavo-humanoid-sdk-ws
55
+ ```
56
+ **当前为正式版/beta版**,升级到最新beta版:
57
+ ```bash
58
+ pip install --upgrade --pre kuavo-humanoid-sdk-ws
59
+ ```
60
+
61
+ ## 描述
62
+
63
+ 有关详细的 SDK 文档和使用示例,请参阅 [sdk_description.md](sdk_description.md)。
64
+
65
+ ## 文档
66
+ 文档提供两种格式:
67
+ - HTML 格式:[docs/html](docs/html), **需要自己执行脚本生成**
68
+ - Markdown 格式:[docs/markdown](docs/markdown)
69
+
70
+ 我们推荐您自己执行文档脚本生成文档到本地, 文档会输出到`docs/html`和`docs/markdown`文件夹:
71
+ ```bash
72
+ chmod +x ./gen_docs.sh
73
+ ./gen_docs.sh
74
+ ```
75
+
76
+ 我们推荐您使用`html`查看文档更加方便,比如:
77
+ ![](docs/images/image.png)
78
+
79
+
@@ -0,0 +1,6 @@
1
+ from .msg import *
2
+ from .interfaces import *
3
+ from .kuavo import *
4
+ #from .kuavo_strategy import *
5
+ #from .kuavo_strategy.grasp_box import *
6
+ from kuavo_humanoid_sdk.common.logger import SDKLogger, disable_sdk_logging
@@ -0,0 +1,170 @@
1
+ import roslibpy
2
+ import time
3
+ from typing import Tuple
4
+ from kuavo_humanoid_sdk.common.logger import SDKLogger
5
+ from kuavo_humanoid_sdk.common.websocket_kuavo_sdk import WebSocketKuavoSDK
6
+
7
+
8
+ class LaunchRobotStatus:
9
+ # 与硬件节点保持一致
10
+ UNLAUNCH = 'unlaunch'
11
+ INITING = 'initing'
12
+ UNKNOWN = 'unknown'
13
+ READY_STANCE = 'ready_stance'
14
+ CALIBRATE = 'calibrate'
15
+ LAUNCHED = 'launched'
16
+
17
+ class LaunchRobotTool:
18
+ def __init__(self):
19
+ self._websocket = WebSocketKuavoSDK()
20
+ self._stand_timeout = 10.0
21
+ self._srv_robot_start = roslibpy.Service(self._websocket.client, '/websocket_sdk_srv/start_robot', 'std_srvs/Trigger')
22
+ self._srv_robot_stand = roslibpy.Service(self._websocket.client, '/websocket_sdk_srv/stand_robot', 'std_srvs/Trigger')
23
+ self._srv_get_robot_launch_status = roslibpy.Service(self._websocket.client, '/websocket_sdk_srv/get_robot_launch_status', 'std_srvs/Trigger')
24
+ self._srv_robot_stop = roslibpy.Service(self._websocket.client, '/websocket_sdk_srv/stop_robot', 'std_srvs/Trigger')
25
+
26
+ def is_unlaunch(self, status:str)->bool:
27
+ return status == LaunchRobotStatus.UNLAUNCH or status == LaunchRobotStatus.UNKNOWN
28
+
29
+ def is_launched(self, status:str)->bool:
30
+ return status == LaunchRobotStatus.LAUNCHED
31
+
32
+ def is_launching(self, status:str)->bool:
33
+ return self.is_calibrate(status) or self.is_ready_stance(status)
34
+
35
+ def is_calibrate(self, status:str)->bool:
36
+ return status == LaunchRobotStatus.CALIBRATE
37
+
38
+ def is_ready_stance(self, status:str)->bool:
39
+ return status == LaunchRobotStatus.READY_STANCE
40
+
41
+ def robot_start(self) -> bool:
42
+ # launch robot
43
+ if not self.pub_start_command():
44
+ return False
45
+ try:
46
+ timeout = 120 # 120s 等待进入校准或准备姿态
47
+ start_time = time.time()
48
+ last_print = time.time()
49
+ print("\033[32m>_ 机器人启动中\033[0m", end="", flush=True)
50
+ while True:
51
+ if time.time() - start_time > timeout:
52
+ SDKLogger.error("Robot launch timed out")
53
+ return False
54
+ success, status = self.get_robot_launch_status()
55
+ # 如果机器人启动成功,已经进入校准或准备状态或者launched状态,则启动成功
56
+ if success and (self.is_launched(status) or self.is_launching(status)):
57
+ print("\n")
58
+ return True
59
+
60
+ current_time = time.time()
61
+ if current_time - last_print >= 0.8:
62
+ print("\033[32m.\033[0m", end="", flush=True)
63
+ last_print = current_time
64
+ time.sleep(0.2)
65
+ except KeyboardInterrupt:
66
+ print("\n")
67
+ SDKLogger.info("Received keyboard interrupt, stopping robot launch")
68
+ return False
69
+
70
+ def robot_stop(self)->bool:
71
+ """
72
+ 停止机器人
73
+ """
74
+ try:
75
+ request = roslibpy.ServiceRequest({})
76
+ response = self._srv_robot_stop.call(request)
77
+ return response.get('success', False)
78
+ except Exception as e:
79
+ SDKLogger.error(f"[Error] calling stop robot service: {e}")
80
+ return False
81
+
82
+ def robot_stand(self)->bool:
83
+ try:
84
+ while True:
85
+ # 获取当前启动状态, 如果已启动则返回
86
+ success, status = self.get_robot_launch_status()
87
+ if not success:
88
+ SDKLogger.error(f"[Error] Failed to get robot launch status: {status}")
89
+ return False
90
+ if self.is_launched(status):
91
+ return True
92
+
93
+ # 从当前状态确认下一个状态
94
+ next_state = None
95
+ if self.is_calibrate(status):
96
+ print("\033[32m>_ [校准状态]: 机器人当前处于校准状态,确认无误,请输入 y 键进入准备姿态\033[0m")
97
+ next_state = LaunchRobotStatus.READY_STANCE
98
+ elif self.is_ready_stance(status):
99
+ print("\033[32m>_ [准备姿态]: 请等待机器人缩腿到下蹲姿势,并将其下降到距离地面 2cm 处,确认无误后,请输入 y 键\033[0m")
100
+ next_state = LaunchRobotStatus.LAUNCHED
101
+
102
+ if self.is_calibrate(status) or self.is_ready_stance(status):
103
+ while True:
104
+ try:
105
+ choice = input().lower()
106
+ if choice == 'y':
107
+ break
108
+ elif choice == 'n':
109
+ return False
110
+ else:
111
+ SDKLogger.error("输入错误,请输入 y 键")
112
+ except KeyboardInterrupt:
113
+ return False
114
+
115
+ # 发布站立命令
116
+ if not self.pub_stand_command():
117
+ return False
118
+
119
+ # 等待进入下一个状态
120
+ start_time = time.time()
121
+ while True:
122
+ if time.time() - start_time > self._stand_timeout:
123
+ break
124
+ success, current_status = self.get_robot_launch_status()
125
+ if not success:
126
+ SDKLogger.error(f"[Error] Wait next state Failed to get robot launch status: {current_status}")
127
+ return False
128
+ if self.is_launched(current_status):
129
+ return True
130
+ elif current_status == next_state:
131
+ # 成功进入下一个状态
132
+ break
133
+ time.sleep(0.2)
134
+ time.sleep(0.2)
135
+ except KeyboardInterrupt:
136
+ SDKLogger.info("Received keyboard interrupt, stopping robot stand")
137
+ return False
138
+
139
+ def pub_start_command(self) -> bool:
140
+ try:
141
+ request = roslibpy.ServiceRequest({})
142
+ response = self._srv_robot_start.call(request)
143
+ result = response.get('success', False)
144
+ return result
145
+ except Exception as e:
146
+ SDKLogger.error(f"[Error] calling start service: {e}")
147
+ return False
148
+
149
+ def pub_stand_command(self) -> bool:
150
+ try:
151
+ request = {}
152
+ response = self._srv_robot_stand.call(request)
153
+ if not response.get('success', False):
154
+ SDKLogger.error(f"Failed to make robot stand: {response.get('message', '')}")
155
+ return response.get('success', False)
156
+ except Exception as e:
157
+ SDKLogger.error(f"[Error] calling stand service: {e}")
158
+ return False
159
+
160
+
161
+ def get_robot_launch_status(self)->Tuple[bool, str]:
162
+ try:
163
+ request = roslibpy.ServiceRequest({})
164
+ response = self._srv_get_robot_launch_status.call(request)
165
+ success = response.get('success', False)
166
+ status = response.get('message', 'unknown')
167
+ return success, status
168
+ except Exception as e:
169
+ SDKLogger.error(f"[Error] calling get robot launch status service: {e}")
170
+ return False, "unknown"
@@ -0,0 +1,45 @@
1
+ import logging
2
+ import os
3
+ from pathlib import Path
4
+ from logging.handlers import RotatingFileHandler
5
+ def setup_logger():
6
+ logger = logging.getLogger('kuavo-humanoid-sdk')
7
+ logger.setLevel(logging.DEBUG)
8
+ log_suffix = f'log/kuavo_humanoid_sdk'
9
+ log_dir = f'/var/{log_suffix}'
10
+ try:
11
+ # Check if we have write permission for /var directory
12
+ if not os.access('/var/log/', os.W_OK):
13
+ log_dir = f'./{log_suffix}'
14
+ Path(log_dir).mkdir(parents=True, exist_ok=True)
15
+ except Exception as e:
16
+ # If creation in /var fails, create in current directory
17
+ log_dir = f'./{log_suffix}'
18
+ Path(log_dir).mkdir(parents=True, exist_ok=True)
19
+ log_file = f'{log_dir}/kuavo_humanoid_sdk.log'
20
+
21
+ print(f'kuavo-humanoid-sdk log_file: {log_file}')
22
+
23
+ fh = RotatingFileHandler(log_file, maxBytes=2*1024*1024, backupCount=5) # 每个日志文件最大 2 MB,保留 5 个备份文件
24
+ fh.setLevel(logging.DEBUG)
25
+
26
+ ch = logging.StreamHandler()
27
+ ch.setLevel(logging.DEBUG)
28
+
29
+ formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
30
+ fh.setFormatter(formatter)
31
+ ch.setFormatter(formatter)
32
+
33
+ logger.addHandler(fh)
34
+ logger.addHandler(ch)
35
+ return logger
36
+
37
+ def disable_sdk_logging():
38
+ """
39
+ Disable SDK logging.
40
+ """
41
+ logging.disable()
42
+
43
+
44
+ """ Logger """
45
+ SDKLogger = setup_logger()
@@ -0,0 +1,26 @@
1
+ import roslibpy
2
+
3
+ class WebSocketKuavoSDK:
4
+
5
+ _instance = None
6
+ _initialized = False
7
+
8
+ websocket_host = '127.0.0.1'
9
+ websocket_port = 9090
10
+ websocket_timeout = 5.0
11
+
12
+ def __new__(cls, *args, **kwargs):
13
+ if cls._instance is None:
14
+ cls._instance = super().__new__(cls)
15
+ return cls._instance
16
+
17
+ def __init__(self):
18
+ if not self._initialized:
19
+ self._initialized = True
20
+ self.client = roslibpy.Ros(host=WebSocketKuavoSDK.websocket_host, port=WebSocketKuavoSDK.websocket_port)
21
+ self.client.run(timeout=WebSocketKuavoSDK.websocket_timeout)
22
+
23
+
24
+ def __del__(self):
25
+ self.client.terminate()
26
+ self.instance = None
@@ -0,0 +1,4 @@
1
+ from .data_types import *
2
+ from .robot import *
3
+ from .end_effector import *
4
+ from .robot_info import *