codroid-robot-sdk 1.2.0__tar.gz → 2.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.
- {codroid_robot_sdk-1.2.0 → codroid_robot_sdk-2.0.0}/.gitignore +7 -1
- {codroid_robot_sdk-1.2.0 → codroid_robot_sdk-2.0.0}/PKG-INFO +47 -11
- {codroid_robot_sdk-1.2.0 → codroid_robot_sdk-2.0.0}/README.md +40 -9
- codroid_robot_sdk-2.0.0/examples/01_basic_usage.py +68 -0
- codroid_robot_sdk-2.0.0/examples/02_run_script.py +45 -0
- codroid_robot_sdk-2.0.0/examples/03_run_project.py +66 -0
- codroid_robot_sdk-2.0.0/examples/04_global_value.py +52 -0
- codroid_robot_sdk-2.0.0/examples/05_rs485.py +50 -0
- codroid_robot_sdk-2.0.0/examples/06_jog_mode.py +66 -0
- codroid_robot_sdk-2.0.0/examples/07_move_to.py +88 -0
- codroid_robot_sdk-2.0.0/examples/08_move.py +71 -0
- codroid_robot_sdk-2.0.0/examples/09_move_path.py +73 -0
- codroid_robot_sdk-2.0.0/examples/10_control_commands.py +61 -0
- codroid_robot_sdk-2.0.0/examples/11_io_demo.py +54 -0
- codroid_robot_sdk-2.0.0/examples/12_register_demo.py +45 -0
- codroid_robot_sdk-2.0.0/examples/13_cri_realtime.py +132 -0
- codroid_robot_sdk-2.0.0/examples/codroid_cri_test.py +252 -0
- codroid_robot_sdk-2.0.0/examples/codroid_test.py +260 -0
- codroid_robot_sdk-2.0.0/plan.md +385 -0
- {codroid_robot_sdk-1.2.0 → codroid_robot_sdk-2.0.0}/pyproject.toml +9 -1
- codroid_robot_sdk-1.2.0/src/codroid/CodroidControlInterface.py → codroid_robot_sdk-2.0.0/src/codroid/Codroid.py +281 -197
- {codroid_robot_sdk-1.2.0 → codroid_robot_sdk-2.0.0}/src/codroid/__about__.py +1 -1
- codroid_robot_sdk-2.0.0/src/codroid/__init__.py +73 -0
- codroid_robot_sdk-2.0.0/src/codroid/async_tcp_client.py +229 -0
- codroid_robot_sdk-2.0.0/src/codroid/client.py +108 -0
- codroid_robot_sdk-2.0.0/src/codroid/console.py +80 -0
- codroid_robot_sdk-2.0.0/src/codroid/cri_realtime_dispatcher.py +87 -0
- codroid_robot_sdk-2.0.0/src/codroid/cri_realtime_packet_parser.py +261 -0
- codroid_robot_sdk-1.2.0/src/codroid/models.py → codroid_robot_sdk-2.0.0/src/codroid/define.py +73 -23
- {codroid_robot_sdk-1.2.0 → codroid_robot_sdk-2.0.0}/src/codroid/exceptions.py +5 -0
- codroid_robot_sdk-2.0.0/src/codroid/publish.py +42 -0
- codroid_robot_sdk-2.0.0/src/codroid/trajectory.py +302 -0
- codroid_robot_sdk-2.0.0/src/codroid/types.py +39 -0
- codroid_robot_sdk-1.2.0/examples/01_basic_usage.py +0 -42
- codroid_robot_sdk-1.2.0/examples/02_run_script.py +0 -21
- codroid_robot_sdk-1.2.0/examples/03_run_project.py +0 -49
- codroid_robot_sdk-1.2.0/examples/04_global_value.py +0 -20
- codroid_robot_sdk-1.2.0/examples/05_rs485.py +0 -30
- codroid_robot_sdk-1.2.0/examples/06_jog_mode.py +0 -42
- codroid_robot_sdk-1.2.0/examples/07_move_to.py +0 -92
- codroid_robot_sdk-1.2.0/examples/08_move.py +0 -55
- codroid_robot_sdk-1.2.0/examples/09_move_path.py +0 -24
- codroid_robot_sdk-1.2.0/examples/10_control_commands.py +0 -38
- codroid_robot_sdk-1.2.0/examples/11_io_demo.py +0 -29
- codroid_robot_sdk-1.2.0/examples/12_register_demo.py +0 -21
- codroid_robot_sdk-1.2.0/examples/13_cri_realtime.py +0 -73
- codroid_robot_sdk-1.2.0/src/codroid/__init__.py +0 -34
- codroid_robot_sdk-1.2.0/src/codroid/cri.py +0 -141
- codroid_robot_sdk-1.2.0/src/codroid/network.py +0 -78
- {codroid_robot_sdk-1.2.0 → codroid_robot_sdk-2.0.0}/LICENSE.txt +0 -0
- {codroid_robot_sdk-1.2.0 → codroid_robot_sdk-2.0.0}/mkdocs.yml +0 -0
- {codroid_robot_sdk-1.2.0 → codroid_robot_sdk-2.0.0}/src/codroid/py.typed +0 -0
- {codroid_robot_sdk-1.2.0 → codroid_robot_sdk-2.0.0}/src/codroid/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codroid-robot-sdk
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0
|
|
4
4
|
Project-URL: Documentation, https://guybod.github.io/CodroidSDK/
|
|
5
5
|
Project-URL: Issues, https://github.com/guybod/CodroidSDK/issues
|
|
6
6
|
Project-URL: Source, https://github.com/guybod/CodroidSDK
|
|
@@ -9,14 +9,19 @@ License-Expression: MIT
|
|
|
9
9
|
License-File: LICENSE.txt
|
|
10
10
|
Classifier: Development Status :: 4 - Beta
|
|
11
11
|
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
12
13
|
Classifier: Programming Language :: Python :: 3.8
|
|
13
14
|
Classifier: Programming Language :: Python :: 3.9
|
|
14
15
|
Classifier: Programming Language :: Python :: 3.10
|
|
15
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
16
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
20
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
21
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
19
|
-
Requires-Python: >=3.
|
|
22
|
+
Requires-Python: >=3.7
|
|
23
|
+
Provides-Extra: color
|
|
24
|
+
Requires-Dist: colorama>=0.4.6; extra == 'color'
|
|
20
25
|
Description-Content-Type: text/markdown
|
|
21
26
|
|
|
22
27
|
# Codroid Robot Python SDK
|
|
@@ -60,10 +65,11 @@ pipx install hatch
|
|
|
60
65
|
pip install hatch
|
|
61
66
|
```
|
|
62
67
|
### 2. 获取代码与初始化
|
|
63
|
-
```
|
|
68
|
+
```bash
|
|
64
69
|
git clone <your-repo-url>
|
|
65
|
-
cd
|
|
70
|
+
cd CodroidPython
|
|
66
71
|
```
|
|
72
|
+
若系统仅有 `python3` 命令(常见于 Debian/Ubuntu),下文请将 `python` 换成 `python3`,或使用 `hatch shell` 后按 Hatch 环境内的解释器为准。
|
|
67
73
|
### 3. 运行示例程序
|
|
68
74
|
使用 Hatch 运行示例是最简单的方法,它会自动处理所有依赖和环境路径。
|
|
69
75
|
```Bash
|
|
@@ -81,12 +87,22 @@ pip install codroid-robot-sdk
|
|
|
81
87
|
```python
|
|
82
88
|
from codroid import CodroidControlInterface
|
|
83
89
|
|
|
84
|
-
# Initialize and connect automatically
|
|
90
|
+
# Initialize and connect automatically (CodroidSession + synchronous JsonStreamClient)
|
|
85
91
|
with CodroidControlInterface(host="192.168.1.136") as robot:
|
|
86
92
|
robot.to_remote()
|
|
87
93
|
robot.switch_on()
|
|
88
94
|
```
|
|
89
95
|
|
|
96
|
+
需要 **后台收包、`id` 配对、Publish 按 `ty` 分发** 时,请使用 `CodroidClient`(内部为 `TransportClient`):
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from codroid import CodroidClient
|
|
100
|
+
|
|
101
|
+
with CodroidClient(host="192.168.1.136") as robot:
|
|
102
|
+
robot.to_remote()
|
|
103
|
+
robot.switch_on()
|
|
104
|
+
```
|
|
105
|
+
|
|
90
106
|
# 🛠️ Hatch 开发工作流
|
|
91
107
|
本项目采用了现代 Python 的 src 布局,建议通过以下命令进行开发:
|
|
92
108
|
## 进入开发 Shell
|
|
@@ -108,12 +124,32 @@ hatch build
|
|
|
108
124
|
hatch run docs:serve
|
|
109
125
|
```
|
|
110
126
|
# 📂 目录结构说明
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
127
|
+
|
|
128
|
+
源码布局与 C# SDK(``CodroidSDK/*.cs``)**同名模块一一对应**(Python 为 snake_case + ``.py``)。详细演进见仓库根目录 ``plan.md``。
|
|
129
|
+
|
|
130
|
+
```text
|
|
131
|
+
src/codroid/
|
|
132
|
+
├── __init__.py # 公开 API 聚合导出
|
|
133
|
+
├── __about__.py # 版本号
|
|
134
|
+
├── Codroid.py # CodroidSession;CodroidControlInterface 别名
|
|
135
|
+
├── client.py # CodroidClient(TransportClient + 门面)
|
|
136
|
+
├── async_tcp_client.py # JsonStreamClient、TransportClient / FutureTcpClient
|
|
137
|
+
├── define.py # DTO / 常量(Define.cs)
|
|
138
|
+
├── types.py # DTO 再导出(便于与文档表述一致)
|
|
139
|
+
├── exceptions.py # CodroidCommandException、网络/超时等
|
|
140
|
+
├── utils.py # 共用工具
|
|
141
|
+
├── console.py # PrintBanner 等
|
|
142
|
+
├── publish.py # CodroidPublish.cs
|
|
143
|
+
├── trajectory.py # Trajectory.cs
|
|
144
|
+
├── cri_realtime_packet_parser.py # CriRealtimePacketParser.cs(含 CriStreamHandler)
|
|
145
|
+
└── cri_realtime_dispatcher.py # CriRealtimeDispatcher.cs
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
下列文件在 **2.0 计划** 中与 C# 对齐,业务将从 ``Codroid.py`` 拆出后落盘(当前可能尚未存在):``global_variables.py``、``io.py``、``register.py``、``robot_kinematics.py``、``robot_motion.py``。
|
|
149
|
+
|
|
150
|
+
- ``examples/``: 示例程序。
|
|
151
|
+
- ``pyproject.toml``: Hatch / 构建配置。
|
|
152
|
+
- 契约与算法文档:``AGENTS.md``、``SDK_API_AND_DESIGN.md``、``PROTOCOL_LINE_BY_LINE.md``、``TRAJECTORY_ALGORITHM.md``。
|
|
117
153
|
|
|
118
154
|
|
|
119
155
|
|
|
@@ -39,10 +39,11 @@ pipx install hatch
|
|
|
39
39
|
pip install hatch
|
|
40
40
|
```
|
|
41
41
|
### 2. 获取代码与初始化
|
|
42
|
-
```
|
|
42
|
+
```bash
|
|
43
43
|
git clone <your-repo-url>
|
|
44
|
-
cd
|
|
44
|
+
cd CodroidPython
|
|
45
45
|
```
|
|
46
|
+
若系统仅有 `python3` 命令(常见于 Debian/Ubuntu),下文请将 `python` 换成 `python3`,或使用 `hatch shell` 后按 Hatch 环境内的解释器为准。
|
|
46
47
|
### 3. 运行示例程序
|
|
47
48
|
使用 Hatch 运行示例是最简单的方法,它会自动处理所有依赖和环境路径。
|
|
48
49
|
```Bash
|
|
@@ -60,12 +61,22 @@ pip install codroid-robot-sdk
|
|
|
60
61
|
```python
|
|
61
62
|
from codroid import CodroidControlInterface
|
|
62
63
|
|
|
63
|
-
# Initialize and connect automatically
|
|
64
|
+
# Initialize and connect automatically (CodroidSession + synchronous JsonStreamClient)
|
|
64
65
|
with CodroidControlInterface(host="192.168.1.136") as robot:
|
|
65
66
|
robot.to_remote()
|
|
66
67
|
robot.switch_on()
|
|
67
68
|
```
|
|
68
69
|
|
|
70
|
+
需要 **后台收包、`id` 配对、Publish 按 `ty` 分发** 时,请使用 `CodroidClient`(内部为 `TransportClient`):
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from codroid import CodroidClient
|
|
74
|
+
|
|
75
|
+
with CodroidClient(host="192.168.1.136") as robot:
|
|
76
|
+
robot.to_remote()
|
|
77
|
+
robot.switch_on()
|
|
78
|
+
```
|
|
79
|
+
|
|
69
80
|
# 🛠️ Hatch 开发工作流
|
|
70
81
|
本项目采用了现代 Python 的 src 布局,建议通过以下命令进行开发:
|
|
71
82
|
## 进入开发 Shell
|
|
@@ -87,12 +98,32 @@ hatch build
|
|
|
87
98
|
hatch run docs:serve
|
|
88
99
|
```
|
|
89
100
|
# 📂 目录结构说明
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
|
|
102
|
+
源码布局与 C# SDK(``CodroidSDK/*.cs``)**同名模块一一对应**(Python 为 snake_case + ``.py``)。详细演进见仓库根目录 ``plan.md``。
|
|
103
|
+
|
|
104
|
+
```text
|
|
105
|
+
src/codroid/
|
|
106
|
+
├── __init__.py # 公开 API 聚合导出
|
|
107
|
+
├── __about__.py # 版本号
|
|
108
|
+
├── Codroid.py # CodroidSession;CodroidControlInterface 别名
|
|
109
|
+
├── client.py # CodroidClient(TransportClient + 门面)
|
|
110
|
+
├── async_tcp_client.py # JsonStreamClient、TransportClient / FutureTcpClient
|
|
111
|
+
├── define.py # DTO / 常量(Define.cs)
|
|
112
|
+
├── types.py # DTO 再导出(便于与文档表述一致)
|
|
113
|
+
├── exceptions.py # CodroidCommandException、网络/超时等
|
|
114
|
+
├── utils.py # 共用工具
|
|
115
|
+
├── console.py # PrintBanner 等
|
|
116
|
+
├── publish.py # CodroidPublish.cs
|
|
117
|
+
├── trajectory.py # Trajectory.cs
|
|
118
|
+
├── cri_realtime_packet_parser.py # CriRealtimePacketParser.cs(含 CriStreamHandler)
|
|
119
|
+
└── cri_realtime_dispatcher.py # CriRealtimeDispatcher.cs
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
下列文件在 **2.0 计划** 中与 C# 对齐,业务将从 ``Codroid.py`` 拆出后落盘(当前可能尚未存在):``global_variables.py``、``io.py``、``register.py``、``robot_kinematics.py``、``robot_motion.py``。
|
|
123
|
+
|
|
124
|
+
- ``examples/``: 示例程序。
|
|
125
|
+
- ``pyproject.toml``: Hatch / 构建配置。
|
|
126
|
+
- 契约与算法文档:``AGENTS.md``、``SDK_API_AND_DESIGN.md``、``PROTOCOL_LINE_BY_LINE.md``、``TRAJECTORY_ALGORITHM.md``。
|
|
96
127
|
|
|
97
128
|
|
|
98
129
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
基础示例:连接、远程、上使能、关节运动,并打印 CRI 缓存中的关节角。
|
|
4
|
+
|
|
5
|
+
用法:
|
|
6
|
+
PYTHONPATH=src python examples/01_basic_usage.py
|
|
7
|
+
PYTHONPATH=src python examples/01_basic_usage.py --robot 192.168.8.136
|
|
8
|
+
|
|
9
|
+
彩色横幅(可选): pip install codroid-robot-sdk[color] 或 pip install colorama
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import sys
|
|
15
|
+
import time
|
|
16
|
+
|
|
17
|
+
from codroid import CodroidControlInterface, MovePoint, PrintBanner
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def main(argv: list[str]) -> int:
|
|
21
|
+
p = argparse.ArgumentParser(description="Basic connect, moveJ, CRI cache")
|
|
22
|
+
p.add_argument("--robot", default="192.168.8.136", help="控制器 IP")
|
|
23
|
+
p.add_argument("--local-ip", default="192.168.8.150", help="本机 IP(CRI 推送)")
|
|
24
|
+
p.add_argument(
|
|
25
|
+
"--udp-port",
|
|
26
|
+
type=int,
|
|
27
|
+
default=18888,
|
|
28
|
+
help="本机 UDP 端口(建议 10000–65534)",
|
|
29
|
+
)
|
|
30
|
+
args = p.parse_args(argv)
|
|
31
|
+
|
|
32
|
+
PrintBanner("01 — Basic usage", subtitle=f"{args.robot} CRI → {args.local_ip}:{args.udp_port}")
|
|
33
|
+
|
|
34
|
+
with CodroidControlInterface(
|
|
35
|
+
host=args.robot,
|
|
36
|
+
local_ip=args.local_ip,
|
|
37
|
+
udp_port=args.udp_port,
|
|
38
|
+
) as robot:
|
|
39
|
+
robot.enter_remote_mode_via_auto()
|
|
40
|
+
robot.switch_on()
|
|
41
|
+
robot._start_cri_receiver()
|
|
42
|
+
robot.start_cri_data_push(ip=args.local_ip, port=args.udp_port)
|
|
43
|
+
|
|
44
|
+
try:
|
|
45
|
+
p1 = MovePoint(jp=[0, 0, 90, 0, 90, 0])
|
|
46
|
+
p2 = MovePoint(jp=[0, 0, 0, 0, 0, 0])
|
|
47
|
+
for _ in range(3):
|
|
48
|
+
robot.move_j(p1, 60, 120)
|
|
49
|
+
robot.move_j(p2, 60, 120)
|
|
50
|
+
|
|
51
|
+
PrintBanner("CRI cache loop", subtitle="Ctrl+C 退出")
|
|
52
|
+
while True:
|
|
53
|
+
data = robot.cri_cache
|
|
54
|
+
if data:
|
|
55
|
+
print(f"关节角 / joint_pos: {data.joint_pos}")
|
|
56
|
+
print(f"运动中 / is_moving: {data.status.is_moving}")
|
|
57
|
+
time.sleep(0.1)
|
|
58
|
+
except KeyboardInterrupt:
|
|
59
|
+
print("已中断 / Interrupted", file=sys.stderr)
|
|
60
|
+
return 130
|
|
61
|
+
finally:
|
|
62
|
+
robot.stop_cri_data_push(ip=args.local_ip, port=args.udp_port)
|
|
63
|
+
|
|
64
|
+
return 0
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if __name__ == "__main__":
|
|
68
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
通过 ``project/runScript`` 下发 Lua 与共享变量。
|
|
4
|
+
|
|
5
|
+
用法:
|
|
6
|
+
PYTHONPATH=src python examples/02_run_script.py
|
|
7
|
+
PYTHONPATH=src python examples/02_run_script.py --robot 192.168.8.136
|
|
8
|
+
|
|
9
|
+
彩色横幅(可选): pip install codroid-robot-sdk[color] 或 pip install colorama
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
from codroid import CodroidControlInterface, PrintBanner
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def main(argv: list[str]) -> int:
|
|
20
|
+
p = argparse.ArgumentParser(description="Run remote Lua script")
|
|
21
|
+
p.add_argument("--robot", default="192.168.8.136", help="控制器 IP")
|
|
22
|
+
args = p.parse_args(argv)
|
|
23
|
+
|
|
24
|
+
PrintBanner("02 — Run script", subtitle=args.robot)
|
|
25
|
+
|
|
26
|
+
lua_code = "print('Hello Codroid')\nmovej([0,0,0,0,0,0])"
|
|
27
|
+
vars_data = {"v1": 100, "v2": "test"}
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
with CodroidControlInterface(host=args.robot) as robot:
|
|
31
|
+
robot.enter_remote_mode_via_auto()
|
|
32
|
+
print("发送脚本 / Sending script...")
|
|
33
|
+
res = robot.run_script(lua_code, vars=vars_data)
|
|
34
|
+
if res.is_success:
|
|
35
|
+
print("脚本请求已发送 / Script request sent")
|
|
36
|
+
else:
|
|
37
|
+
print(f"失败 / Failed: {res.err}", file=sys.stderr)
|
|
38
|
+
return 1
|
|
39
|
+
except KeyboardInterrupt:
|
|
40
|
+
return 130
|
|
41
|
+
return 0
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
工程控制:运行、暂停、恢复、停止、按索引启动。
|
|
4
|
+
|
|
5
|
+
用法:
|
|
6
|
+
PYTHONPATH=src python examples/03_run_project.py
|
|
7
|
+
PYTHONPATH=src python examples/03_run_project.py --robot 192.168.8.136
|
|
8
|
+
|
|
9
|
+
彩色横幅(可选): pip install codroid-robot-sdk[color] 或 pip install colorama
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import sys
|
|
15
|
+
import time
|
|
16
|
+
|
|
17
|
+
from codroid import CodroidControlInterface, PrintBanner
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def main(argv: list[str]) -> int:
|
|
21
|
+
p = argparse.ArgumentParser(description="Run / pause / resume / stop project")
|
|
22
|
+
p.add_argument("--robot", default="192.168.8.136", help="控制器 IP")
|
|
23
|
+
p.add_argument(
|
|
24
|
+
"--project-id",
|
|
25
|
+
default="projectluademo",
|
|
26
|
+
help="工程 ID(run_project)",
|
|
27
|
+
)
|
|
28
|
+
p.add_argument("--index", type=int, default=0, help="run_project_by_index 索引")
|
|
29
|
+
p.add_argument("--step-sleep", type=float, default=5.0, help="每步间隔(秒)")
|
|
30
|
+
args = p.parse_args(argv)
|
|
31
|
+
|
|
32
|
+
PrintBanner("03 — Run project", subtitle=f"{args.robot} proj={args.project_id}")
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
with CodroidControlInterface(host=args.robot) as robot:
|
|
36
|
+
robot.enter_remote_mode_via_auto()
|
|
37
|
+
|
|
38
|
+
res = robot.run_project(args.project_id)
|
|
39
|
+
print("运行 / run:", "ok" if res.is_success else res.err)
|
|
40
|
+
time.sleep(args.step_sleep)
|
|
41
|
+
|
|
42
|
+
res = robot.pause_project()
|
|
43
|
+
print("暂停 / pause:", "ok" if res.is_success else res.err)
|
|
44
|
+
time.sleep(args.step_sleep)
|
|
45
|
+
|
|
46
|
+
res = robot.resume_project()
|
|
47
|
+
print("恢复 / resume:", "ok" if res.is_success else res.err)
|
|
48
|
+
time.sleep(args.step_sleep)
|
|
49
|
+
|
|
50
|
+
res = robot.stop_project()
|
|
51
|
+
print("停止 / stop:", "ok" if res.is_success else res.err)
|
|
52
|
+
time.sleep(args.step_sleep)
|
|
53
|
+
|
|
54
|
+
res = robot.run_project_by_index(args.index)
|
|
55
|
+
print("按索引启动 / by_index:", "ok" if res.is_success else res.err)
|
|
56
|
+
time.sleep(args.step_sleep)
|
|
57
|
+
|
|
58
|
+
res = robot.stop_project()
|
|
59
|
+
print("再次停止 / stop:", "ok" if res.is_success else res.err)
|
|
60
|
+
except KeyboardInterrupt:
|
|
61
|
+
return 130
|
|
62
|
+
return 0
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if __name__ == "__main__":
|
|
66
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
增量保存全局变量(整数、字符串、列表、字典)。
|
|
4
|
+
|
|
5
|
+
用法:
|
|
6
|
+
PYTHONPATH=src python examples/04_global_value.py
|
|
7
|
+
PYTHONPATH=src python examples/04_global_value.py --robot 192.168.8.136
|
|
8
|
+
|
|
9
|
+
彩色横幅(可选): pip install codroid-robot-sdk[color] 或 pip install colorama
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
from codroid import CodroidControlInterface, GlobalVariable, PrintBanner
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def main(argv: list[str]) -> int:
|
|
20
|
+
p = argparse.ArgumentParser(description="Save global variables")
|
|
21
|
+
p.add_argument("--robot", default="192.168.8.136", help="控制器 IP")
|
|
22
|
+
args = p.parse_args(argv)
|
|
23
|
+
|
|
24
|
+
PrintBanner("04 — Global variables", subtitle=args.robot)
|
|
25
|
+
|
|
26
|
+
vars_to_save = {
|
|
27
|
+
"v_int": GlobalVariable(value=1024, note="整数示例"),
|
|
28
|
+
"v_str": GlobalVariable(value="Codroid", note="字符串示例"),
|
|
29
|
+
"v_list": GlobalVariable(value=[1.1, 2.2, 3.3], note="数组示例"),
|
|
30
|
+
"v_map": GlobalVariable(
|
|
31
|
+
value={"power": 100, "status": "on"},
|
|
32
|
+
note="Map 示例",
|
|
33
|
+
),
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
with CodroidControlInterface(host=args.robot) as robot:
|
|
38
|
+
robot.enter_remote_mode_via_auto()
|
|
39
|
+
print("增量保存全局变量 / Saving globals...")
|
|
40
|
+
res = robot.save_global_vars(vars_to_save)
|
|
41
|
+
if res.is_success:
|
|
42
|
+
print("保存成功 / Saved")
|
|
43
|
+
else:
|
|
44
|
+
print(f"失败 / Failed: {res.err}", file=sys.stderr)
|
|
45
|
+
return 1
|
|
46
|
+
except KeyboardInterrupt:
|
|
47
|
+
return 130
|
|
48
|
+
return 0
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
RS485:初始化、清空、写入、按长度超时读取(示例 Modbus 帧)。
|
|
4
|
+
|
|
5
|
+
用法:
|
|
6
|
+
PYTHONPATH=src python examples/05_rs485.py
|
|
7
|
+
PYTHONPATH=src python examples/05_rs485.py --robot 192.168.8.136
|
|
8
|
+
|
|
9
|
+
彩色横幅(可选): pip install codroid-robot-sdk[color] 或 pip install colorama
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
from codroid import CodroidControlInterface, RS485BaudRate, PrintBanner
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def main(argv: list[str]) -> int:
|
|
20
|
+
p = argparse.ArgumentParser(description="RS485 init / flush / write / read")
|
|
21
|
+
p.add_argument("--robot", default="192.168.8.136", help="控制器 IP")
|
|
22
|
+
args = p.parse_args(argv)
|
|
23
|
+
|
|
24
|
+
PrintBanner("05 — RS485", subtitle=args.robot)
|
|
25
|
+
|
|
26
|
+
try:
|
|
27
|
+
with CodroidControlInterface(host=args.robot) as robot:
|
|
28
|
+
robot.enter_remote_mode_via_auto()
|
|
29
|
+
print("初始化 115200 N 8 1 / RS485 init")
|
|
30
|
+
robot.rs485_init(baudrate=RS485BaudRate.B115200)
|
|
31
|
+
robot.rs485_flush()
|
|
32
|
+
|
|
33
|
+
cmd = b"\x01\x03\x00\x00\x00\x02\xC4\x0B"
|
|
34
|
+
print(f"发送 / TX: {cmd.hex()}")
|
|
35
|
+
robot.rs485_write(cmd)
|
|
36
|
+
|
|
37
|
+
print("读取响应(7 字节,1s 超时)/ Read...")
|
|
38
|
+
res = robot.rs485_read(length=7, timeout=1000)
|
|
39
|
+
if res.is_success and res.db:
|
|
40
|
+
received = bytes(res.db)
|
|
41
|
+
print(f"收到 / RX (hex): {received.hex()}")
|
|
42
|
+
else:
|
|
43
|
+
print("未收到或失败 / No data or read failed")
|
|
44
|
+
except KeyboardInterrupt:
|
|
45
|
+
return 130
|
|
46
|
+
return 0
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if __name__ == "__main__":
|
|
50
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
点动:设置倍率、关节点动、后台 jog 心跳、停止。
|
|
4
|
+
|
|
5
|
+
用法:
|
|
6
|
+
PYTHONPATH=src python examples/06_jog_mode.py
|
|
7
|
+
PYTHONPATH=src python examples/06_jog_mode.py --robot 192.168.8.136
|
|
8
|
+
|
|
9
|
+
彩色横幅(可选): pip install codroid-robot-sdk[color] 或 pip install colorama
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import sys
|
|
15
|
+
import threading
|
|
16
|
+
import time
|
|
17
|
+
|
|
18
|
+
from codroid import CodroidControlInterface, JogMode, PrintBanner
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def start_heartbeat(robot: CodroidControlInterface, stop_event: threading.Event, interval: float = 0.4) -> None:
|
|
22
|
+
while not stop_event.is_set():
|
|
23
|
+
try:
|
|
24
|
+
robot.jog_heartbeat()
|
|
25
|
+
time.sleep(interval)
|
|
26
|
+
except Exception:
|
|
27
|
+
break
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def main(argv: list[str]) -> int:
|
|
31
|
+
p = argparse.ArgumentParser(description="Jog mode + heartbeat thread")
|
|
32
|
+
p.add_argument("--robot", default="192.168.8.136", help="控制器 IP")
|
|
33
|
+
p.add_argument("--duration", type=float, default=2.0, help="点动持续时间(秒)")
|
|
34
|
+
args = p.parse_args(argv)
|
|
35
|
+
|
|
36
|
+
PrintBanner("06 — Jog mode", subtitle=args.robot)
|
|
37
|
+
|
|
38
|
+
try:
|
|
39
|
+
with CodroidControlInterface(host=args.robot) as robot:
|
|
40
|
+
robot.enter_remote_mode_via_auto()
|
|
41
|
+
robot.switch_on()
|
|
42
|
+
robot.set_manual_move_rate(50)
|
|
43
|
+
|
|
44
|
+
stop_heartbeat = threading.Event()
|
|
45
|
+
heartbeat_thread = threading.Thread(
|
|
46
|
+
target=start_heartbeat,
|
|
47
|
+
args=(robot, stop_heartbeat),
|
|
48
|
+
daemon=True,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
print("关节 1 点动(示例速度)/ Jog joint 1...")
|
|
52
|
+
robot.start_jog(mode=JogMode.JOINT, index=1, speed=-0.5)
|
|
53
|
+
heartbeat_thread.start()
|
|
54
|
+
time.sleep(args.duration)
|
|
55
|
+
|
|
56
|
+
print("停止点动 / Stop jog")
|
|
57
|
+
stop_heartbeat.set()
|
|
58
|
+
heartbeat_thread.join(timeout=2.0)
|
|
59
|
+
robot.stop_jog()
|
|
60
|
+
except KeyboardInterrupt:
|
|
61
|
+
return 130
|
|
62
|
+
return 0
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if __name__ == "__main__":
|
|
66
|
+
raise SystemExit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
MoveTo:Home、关节规划(Type 4)、直线规划(Type 5),配合 move_to_heartbeat 后台线程。
|
|
4
|
+
|
|
5
|
+
用法:
|
|
6
|
+
PYTHONPATH=src python examples/07_move_to.py
|
|
7
|
+
PYTHONPATH=src python examples/07_move_to.py --robot 192.168.8.136
|
|
8
|
+
|
|
9
|
+
彩色横幅(可选): pip install codroid-robot-sdk[color] 或 pip install colorama
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import sys
|
|
15
|
+
import threading
|
|
16
|
+
import time
|
|
17
|
+
|
|
18
|
+
from codroid import CodroidControlInterface, MoveToType, MoveTarget, PrintBanner
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def heartbeat_worker(robot: CodroidControlInterface, stop_event: threading.Event) -> None:
|
|
22
|
+
print("[心跳] 启动 / heartbeat start (~400ms)")
|
|
23
|
+
while not stop_event.is_set():
|
|
24
|
+
try:
|
|
25
|
+
robot.move_to_heartbeat()
|
|
26
|
+
time.sleep(0.4)
|
|
27
|
+
except Exception as e:
|
|
28
|
+
print(f"[心跳] 异常 / error: {e}")
|
|
29
|
+
break
|
|
30
|
+
print("[心跳] 已停止 / heartbeat stop")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def main(argv: list[str]) -> int:
|
|
34
|
+
p = argparse.ArgumentParser(description="moveTo + heartbeat")
|
|
35
|
+
p.add_argument("--robot", default="192.168.8.136", help="控制器 IP")
|
|
36
|
+
args = p.parse_args(argv)
|
|
37
|
+
|
|
38
|
+
PrintBanner("07 — MoveTo", subtitle=args.robot)
|
|
39
|
+
|
|
40
|
+
stop_event = threading.Event()
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
with CodroidControlInterface(host=args.robot) as robot:
|
|
44
|
+
robot.enter_remote_mode_via_auto()
|
|
45
|
+
robot.switch_on()
|
|
46
|
+
|
|
47
|
+
PrintBanner("Scene 1 — HOME", subtitle="MoveToType.HOME")
|
|
48
|
+
robot.move_to(MoveToType.HOME)
|
|
49
|
+
stop_event.clear()
|
|
50
|
+
t = threading.Thread(target=heartbeat_worker, args=(robot, stop_event))
|
|
51
|
+
t.start()
|
|
52
|
+
time.sleep(3)
|
|
53
|
+
stop_event.set()
|
|
54
|
+
t.join(timeout=2.0)
|
|
55
|
+
|
|
56
|
+
PrintBanner("Scene 2 — JOINT (Type 4)", subtitle="关节规划")
|
|
57
|
+
target_joints = MoveTarget(jp=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
|
|
58
|
+
robot.move_to(MoveToType.JOINT, target=target_joints)
|
|
59
|
+
stop_event.clear()
|
|
60
|
+
t = threading.Thread(target=heartbeat_worker, args=(robot, stop_event))
|
|
61
|
+
t.start()
|
|
62
|
+
time.sleep(5)
|
|
63
|
+
stop_event.set()
|
|
64
|
+
t.join(timeout=2.0)
|
|
65
|
+
|
|
66
|
+
PrintBanner("Scene 3 — LINEAR (Type 5)", subtitle="直线规划")
|
|
67
|
+
target_pose = MoveTarget(cp=[350.0, 100.0, 400.0, 180.0, 0.0, 90.0])
|
|
68
|
+
robot.move_to(MoveToType.LINEAR, target=target_pose)
|
|
69
|
+
stop_event.clear()
|
|
70
|
+
t = threading.Thread(target=heartbeat_worker, args=(robot, stop_event))
|
|
71
|
+
t.start()
|
|
72
|
+
time.sleep(4)
|
|
73
|
+
stop_event.set()
|
|
74
|
+
t.join(timeout=2.0)
|
|
75
|
+
|
|
76
|
+
PrintBanner("07 — Done", subtitle="所有场景结束")
|
|
77
|
+
except KeyboardInterrupt:
|
|
78
|
+
stop_event.set()
|
|
79
|
+
return 130
|
|
80
|
+
except Exception as e:
|
|
81
|
+
stop_event.set()
|
|
82
|
+
print(f"错误 / Error: {e}", file=sys.stderr)
|
|
83
|
+
return 1
|
|
84
|
+
return 0
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if __name__ == "__main__":
|
|
88
|
+
raise SystemExit(main(sys.argv[1:]))
|