codroid-robot-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.
- codroid_robot_sdk-1.0.0/.gitignore +88 -0
- codroid_robot_sdk-1.0.0/LICENSE.txt +18 -0
- codroid_robot_sdk-1.0.0/PKG-INFO +42 -0
- codroid_robot_sdk-1.0.0/README.md +21 -0
- codroid_robot_sdk-1.0.0/examples/01_basic_usage.py +27 -0
- codroid_robot_sdk-1.0.0/examples/02_run_script.py +21 -0
- codroid_robot_sdk-1.0.0/examples/03_run_project.py +49 -0
- codroid_robot_sdk-1.0.0/examples/04_global_value.py +20 -0
- codroid_robot_sdk-1.0.0/examples/05_rs485.py +30 -0
- codroid_robot_sdk-1.0.0/examples/06_jog_mode.py +42 -0
- codroid_robot_sdk-1.0.0/examples/07_move_to.py +92 -0
- codroid_robot_sdk-1.0.0/examples/08_move.py +19 -0
- codroid_robot_sdk-1.0.0/examples/09_move_path.py +24 -0
- codroid_robot_sdk-1.0.0/examples/10_control_commands.py +38 -0
- codroid_robot_sdk-1.0.0/examples/11_io_demo.py +29 -0
- codroid_robot_sdk-1.0.0/examples/12_register_demo.py +21 -0
- codroid_robot_sdk-1.0.0/examples/13_cri_realtime.py +73 -0
- codroid_robot_sdk-1.0.0/mkdocs.yml +34 -0
- codroid_robot_sdk-1.0.0/pyproject.toml +79 -0
- codroid_robot_sdk-1.0.0/src/codroid/CodroidControlInterface.py +1075 -0
- codroid_robot_sdk-1.0.0/src/codroid/__about__.py +4 -0
- codroid_robot_sdk-1.0.0/src/codroid/__init__.py +34 -0
- codroid_robot_sdk-1.0.0/src/codroid/cri.py +141 -0
- codroid_robot_sdk-1.0.0/src/codroid/exceptions.py +11 -0
- codroid_robot_sdk-1.0.0/src/codroid/models.py +371 -0
- codroid_robot_sdk-1.0.0/src/codroid/network.py +78 -0
- codroid_robot_sdk-1.0.0/src/codroid/utils.py +76 -0
- codroid_robot_sdk-1.0.0/tests/__init__.py +3 -0
- codroid_robot_sdk-1.0.0/tests/move_test.py +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# === 编译产物目录 (Build Directories) ===
|
|
2
|
+
build/
|
|
3
|
+
build_linux/
|
|
4
|
+
build_windows/
|
|
5
|
+
build_msvc/
|
|
6
|
+
bin/
|
|
7
|
+
lib/
|
|
8
|
+
out/
|
|
9
|
+
docs/
|
|
10
|
+
|
|
11
|
+
# === 编译器产生的中间文件 (Objects & Libraries) ===
|
|
12
|
+
*.o
|
|
13
|
+
*.obj
|
|
14
|
+
*.so
|
|
15
|
+
*.a
|
|
16
|
+
*.lib
|
|
17
|
+
*.dll
|
|
18
|
+
*.exe
|
|
19
|
+
*.pdb
|
|
20
|
+
*.exp
|
|
21
|
+
*.ilk
|
|
22
|
+
|
|
23
|
+
# === CMake 产生的中间文件 (CMake Artifacts) ===
|
|
24
|
+
CMakeCache.txt
|
|
25
|
+
CMakeFiles/
|
|
26
|
+
CMakeScripts/
|
|
27
|
+
cmake_install.cmake
|
|
28
|
+
Makefile
|
|
29
|
+
install_manifest.txt
|
|
30
|
+
compile_commands.json
|
|
31
|
+
# 之前脚本自动生成的交叉编译文件
|
|
32
|
+
mingw-toolchain.cmake
|
|
33
|
+
|
|
34
|
+
# === IDE 配置文件 (IDE Specific) ===
|
|
35
|
+
# VS Code
|
|
36
|
+
.vscode/
|
|
37
|
+
.vscode/settings.json
|
|
38
|
+
.vscode/tasks.json
|
|
39
|
+
.vscode/launch.json
|
|
40
|
+
.vscode/c_cpp_properties.json
|
|
41
|
+
# Visual Studio (MSVC)
|
|
42
|
+
.vs/
|
|
43
|
+
*.sln
|
|
44
|
+
*.vcxproj
|
|
45
|
+
*.filters
|
|
46
|
+
*.user
|
|
47
|
+
*.suo
|
|
48
|
+
*.db
|
|
49
|
+
*.opendb
|
|
50
|
+
|
|
51
|
+
# === 系统与临时文件 (System & Temp) ===
|
|
52
|
+
.DS_Store
|
|
53
|
+
Thumbs.db
|
|
54
|
+
*.tmp
|
|
55
|
+
*.log
|
|
56
|
+
*.bak
|
|
57
|
+
|
|
58
|
+
# Python 字节码
|
|
59
|
+
__pycache__/
|
|
60
|
+
*.py[cod]
|
|
61
|
+
*$py.class
|
|
62
|
+
|
|
63
|
+
# 虚拟环境
|
|
64
|
+
.venv/
|
|
65
|
+
env/
|
|
66
|
+
venv/
|
|
67
|
+
.hatch/
|
|
68
|
+
|
|
69
|
+
# 编译输出
|
|
70
|
+
dist/
|
|
71
|
+
build/
|
|
72
|
+
*.egg-info/
|
|
73
|
+
|
|
74
|
+
# 文档输出
|
|
75
|
+
site/
|
|
76
|
+
|
|
77
|
+
# IDE 设置
|
|
78
|
+
.vscode/
|
|
79
|
+
.idea/
|
|
80
|
+
|
|
81
|
+
# 单元测试与覆盖率
|
|
82
|
+
.pytest_cache/
|
|
83
|
+
.tox/
|
|
84
|
+
.coverage
|
|
85
|
+
htmlcov/
|
|
86
|
+
|
|
87
|
+
# 本地环境配置文件
|
|
88
|
+
.env
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present guybod <b13140185898@outlook.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
6
|
+
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
12
|
+
portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
15
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
16
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
18
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codroid-robot-sdk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Project-URL: Documentation, https://guybod.github.io/CodroidSDK/
|
|
5
|
+
Project-URL: Issues, https://github.com/guybod/CodroidSDK/issues
|
|
6
|
+
Project-URL: Source, https://github.com/guybod/CodroidSDK
|
|
7
|
+
Author-email: guybod <b13140185898@outlook.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE.txt
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# Codroid
|
|
23
|
+
|
|
24
|
+
[](https://pypi.org/project/codroid)
|
|
25
|
+
[](https://pypi.org/project/codroid)
|
|
26
|
+
|
|
27
|
+
-----
|
|
28
|
+
|
|
29
|
+
## Table of Contents
|
|
30
|
+
|
|
31
|
+
- [Installation](#installation)
|
|
32
|
+
- [License](#license)
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```console
|
|
37
|
+
pip install codroid
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
`codroid` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Codroid
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/codroid)
|
|
4
|
+
[](https://pypi.org/project/codroid)
|
|
5
|
+
|
|
6
|
+
-----
|
|
7
|
+
|
|
8
|
+
## Table of Contents
|
|
9
|
+
|
|
10
|
+
- [Installation](#installation)
|
|
11
|
+
- [License](#license)
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```console
|
|
16
|
+
pip install codroid
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## License
|
|
20
|
+
|
|
21
|
+
`codroid` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
基础示例:连接机器人并停止当前工程
|
|
3
|
+
"""
|
|
4
|
+
from codroid import CodroidControlInterface
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
# 初始化接口(默认 IP 192.168.1.136)
|
|
8
|
+
robot = CodroidControlInterface(host="192.168.1.136")
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
# 建立连接
|
|
12
|
+
robot.connect()
|
|
13
|
+
print("连接成功")
|
|
14
|
+
|
|
15
|
+
robot.debug = True
|
|
16
|
+
# 停止当前运行的工程
|
|
17
|
+
print("正在停止工程...")
|
|
18
|
+
response = robot.stop_project()
|
|
19
|
+
print(f"服务器响应: ID={response.id}, 类型={response.ty}")
|
|
20
|
+
|
|
21
|
+
finally:
|
|
22
|
+
# 务必记得断开连接
|
|
23
|
+
robot.disconnect()
|
|
24
|
+
print("已断开连接")
|
|
25
|
+
|
|
26
|
+
if __name__ == "__main__":
|
|
27
|
+
main()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from codroid import CodroidControlInterface
|
|
2
|
+
|
|
3
|
+
def run_demo():
|
|
4
|
+
# 使用 context manager (with) 是最推荐的做法
|
|
5
|
+
with CodroidControlInterface() as robot:
|
|
6
|
+
# 定义 Lua 程序
|
|
7
|
+
lua_code = "print('Hello Codroid')\nmovej([0,0,0,0,0,0])"
|
|
8
|
+
|
|
9
|
+
# 定义共享变量
|
|
10
|
+
vars_data = {"v1": 100, "v2": "test"}
|
|
11
|
+
|
|
12
|
+
print("开始发送脚本...")
|
|
13
|
+
res = robot.__run_script(main_code=lua_code, vars=vars_data)
|
|
14
|
+
|
|
15
|
+
if res.is_success:
|
|
16
|
+
print("脚本执行请求已发送")
|
|
17
|
+
else:
|
|
18
|
+
print(f"发送失败: {res.err}")
|
|
19
|
+
|
|
20
|
+
if __name__ == "__main__":
|
|
21
|
+
run_demo()
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
from codroid import CodroidControlInterface
|
|
4
|
+
|
|
5
|
+
def demo():
|
|
6
|
+
with CodroidControlInterface() as robot:
|
|
7
|
+
# 定义要运行的程序
|
|
8
|
+
projtecid = "projectluademo"
|
|
9
|
+
|
|
10
|
+
index = 0
|
|
11
|
+
|
|
12
|
+
res = robot.run_project(projtecid)
|
|
13
|
+
if res.is_success:
|
|
14
|
+
print("运行成功")
|
|
15
|
+
|
|
16
|
+
time.sleep(5)
|
|
17
|
+
|
|
18
|
+
res = robot.pause_project()
|
|
19
|
+
if res.is_success:
|
|
20
|
+
print("暂停成功")
|
|
21
|
+
|
|
22
|
+
time.sleep(5)
|
|
23
|
+
|
|
24
|
+
res = robot.resume_project()
|
|
25
|
+
if res.is_success:
|
|
26
|
+
print("恢复成功")
|
|
27
|
+
|
|
28
|
+
time.sleep(5)
|
|
29
|
+
|
|
30
|
+
res = robot.stop_project()
|
|
31
|
+
if res.is_success:
|
|
32
|
+
print("停止成功")
|
|
33
|
+
|
|
34
|
+
time.sleep(5)
|
|
35
|
+
|
|
36
|
+
res = robot.run_project_by_index(index)
|
|
37
|
+
if res.is_success:
|
|
38
|
+
print("映射启动成功")
|
|
39
|
+
|
|
40
|
+
time.sleep(5)
|
|
41
|
+
|
|
42
|
+
res = robot.stop_project()
|
|
43
|
+
if res.is_success:
|
|
44
|
+
print("停止成功")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if __name__ == "__main__":
|
|
49
|
+
demo()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from codroid import CodroidControlInterface, GlobalVariable
|
|
2
|
+
|
|
3
|
+
def demo():
|
|
4
|
+
with CodroidControlInterface() as robot:
|
|
5
|
+
# 定义要保存的变量组
|
|
6
|
+
vars_to_save = {
|
|
7
|
+
"v_int": GlobalVariable(value=1024, note="整数示例"),
|
|
8
|
+
"v_str": GlobalVariable(value="Codroid", note="字符串示例"),
|
|
9
|
+
"v_list": GlobalVariable(value=[1.1, 2.2, 3.3], note="数展示例"),
|
|
10
|
+
"v_map": GlobalVariable(value={"power": 100, "status": "on"}, note="Map示例")
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
print("正在增量保存全局变量...")
|
|
14
|
+
res = robot.save_global_variables(vars_to_save)
|
|
15
|
+
|
|
16
|
+
if res.is_success:
|
|
17
|
+
print("保存成功!")
|
|
18
|
+
|
|
19
|
+
if __name__ == "__main__":
|
|
20
|
+
demo()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from codroid import CodroidControlInterface, RS485BaudRate
|
|
2
|
+
|
|
3
|
+
def main():
|
|
4
|
+
# 使用上下文管理器确保连接关闭
|
|
5
|
+
with CodroidControlInterface() as robot:
|
|
6
|
+
# 1. 初始化 485 接口
|
|
7
|
+
print("初始化 485: 115200, N, 8, 1")
|
|
8
|
+
robot.rs485_init(baudrate=RS485BaudRate.B115200)
|
|
9
|
+
|
|
10
|
+
# 2. 清空缓存
|
|
11
|
+
robot.rs485_flush()
|
|
12
|
+
|
|
13
|
+
# 3. 发送数据 (例如控制夹爪的指令)
|
|
14
|
+
cmd = b"\x01\x03\x00\x00\x00\x02\xC4\x0B" # 示例 Modbus 指令
|
|
15
|
+
print(f"发送数据: {cmd.hex()}")
|
|
16
|
+
robot.rs485_write(cmd)
|
|
17
|
+
|
|
18
|
+
# 4. 读取响应
|
|
19
|
+
print("等待响应...")
|
|
20
|
+
res = robot.rs485_read(length=7, timeout=1000)
|
|
21
|
+
|
|
22
|
+
if res.is_success and res.db:
|
|
23
|
+
# 这里的 res.db 是 [1, 3, 4, ...] 这种整数列表
|
|
24
|
+
received_bytes = bytes(res.db)
|
|
25
|
+
print(f"收到数据 (Hex): {received_bytes.hex()}")
|
|
26
|
+
else:
|
|
27
|
+
print("未收到数据或读取失败")
|
|
28
|
+
|
|
29
|
+
if __name__ == "__main__":
|
|
30
|
+
main()
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import threading
|
|
3
|
+
from codroid import CodroidControlInterface, JogMode, JogCoorType
|
|
4
|
+
|
|
5
|
+
def start_heartbeat(robot, stop_event, interval=0.4):
|
|
6
|
+
"""后台心跳线程函数"""
|
|
7
|
+
while not stop_event.is_set():
|
|
8
|
+
try:
|
|
9
|
+
robot.jog_heartbeat()
|
|
10
|
+
time.sleep(interval)
|
|
11
|
+
except Exception:
|
|
12
|
+
break
|
|
13
|
+
|
|
14
|
+
def jog_demo():
|
|
15
|
+
with CodroidControlInterface() as robot:
|
|
16
|
+
# 1. 设置倍率
|
|
17
|
+
robot.set_manual_move_rate(50)
|
|
18
|
+
|
|
19
|
+
# 2. 准备心跳控制
|
|
20
|
+
stop_heartbeat = threading.Event()
|
|
21
|
+
heartbeat_thread = threading.Thread(
|
|
22
|
+
target=start_heartbeat,
|
|
23
|
+
args=(robot, stop_heartbeat)
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
print("开始点动 (轴1,正方向)...")
|
|
27
|
+
robot.jog(mode=JogMode.JOINT, index=1, speed=-0.5)
|
|
28
|
+
|
|
29
|
+
# 启动心跳
|
|
30
|
+
heartbeat_thread.start()
|
|
31
|
+
|
|
32
|
+
# 运动 2 秒
|
|
33
|
+
time.sleep(2)
|
|
34
|
+
|
|
35
|
+
# 3. 停止点动
|
|
36
|
+
print("停止点动")
|
|
37
|
+
stop_heartbeat.set() # 停止心跳
|
|
38
|
+
heartbeat_thread.join()
|
|
39
|
+
robot.stop_jog()
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
jog_demo()
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import threading
|
|
3
|
+
from codroid import CodroidControlInterface, MoveToType, MoveTarget
|
|
4
|
+
|
|
5
|
+
def heartbeat_worker(robot, stop_event):
|
|
6
|
+
"""
|
|
7
|
+
后台心跳线程:每 400ms 发送一次 moveToHeartbeat。
|
|
8
|
+
使用 400ms 是为了留出 100ms 的余量,确保符合 500ms 的协议要求。
|
|
9
|
+
"""
|
|
10
|
+
print("[心跳] 启动运行维持心跳...")
|
|
11
|
+
while not stop_event.is_set():
|
|
12
|
+
try:
|
|
13
|
+
robot.move_to_heartbeat()
|
|
14
|
+
time.sleep(0.4)
|
|
15
|
+
except Exception as e:
|
|
16
|
+
print(f"[心跳] 异常中断: {e}")
|
|
17
|
+
break
|
|
18
|
+
print("[心跳] 已停止")
|
|
19
|
+
|
|
20
|
+
def moveto_demo():
|
|
21
|
+
# 1. 初始化并连接
|
|
22
|
+
with CodroidControlInterface(host="192.168.1.136") as robot:
|
|
23
|
+
|
|
24
|
+
# 准备心跳控制工具
|
|
25
|
+
stop_event = threading.Event()
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
# --- 场景 1: 运动到预设的 Home 位置 ---
|
|
29
|
+
print("\n>>> 场景 1: 运动到 Home 位置")
|
|
30
|
+
robot.move_to(MoveToType.HOME)
|
|
31
|
+
|
|
32
|
+
# 立即启动心跳维持
|
|
33
|
+
stop_event.clear()
|
|
34
|
+
t = threading.Thread(target=heartbeat_worker, args=(robot, stop_event))
|
|
35
|
+
t.start()
|
|
36
|
+
|
|
37
|
+
# 假设运动需要 3 秒
|
|
38
|
+
time.sleep(3)
|
|
39
|
+
|
|
40
|
+
# 停止心跳(模拟运动完成或需要切换指令)
|
|
41
|
+
stop_event.set()
|
|
42
|
+
t.join()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# --- 场景 2: 关节规划运动到指定坐标 (Type 4) ---
|
|
46
|
+
print("\n>>> 场景 2: 关节规划运动 (Type 4)")
|
|
47
|
+
|
|
48
|
+
# 定义目标关节角 [j1, j2, j3, j4, j5, j6] 单位: deg
|
|
49
|
+
target_joints = MoveTarget(jp=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
|
|
50
|
+
|
|
51
|
+
robot.move_to(MoveToType.JOINT, target=target_joints)
|
|
52
|
+
|
|
53
|
+
# 重新启动心跳
|
|
54
|
+
stop_event.clear()
|
|
55
|
+
t = threading.Thread(target=heartbeat_worker, args=(robot, stop_event))
|
|
56
|
+
t.start()
|
|
57
|
+
|
|
58
|
+
# 运行 5 秒
|
|
59
|
+
time.sleep(5)
|
|
60
|
+
|
|
61
|
+
# 结束心跳
|
|
62
|
+
stop_event.set()
|
|
63
|
+
t.join()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# --- 场景 3: 直线规划运动到笛卡尔坐标 (Type 5) ---
|
|
67
|
+
print("\n>>> 场景 3: 直线规划运动 (Type 5)")
|
|
68
|
+
|
|
69
|
+
# 定义目标末端位置 [x, y, z, a, b, c]
|
|
70
|
+
target_pose = MoveTarget(cp=[350.0, 100.0, 400.0, 180.0, 0.0, 90.0])
|
|
71
|
+
|
|
72
|
+
robot.move_to(MoveToType.LINEAR, target=target_pose)
|
|
73
|
+
|
|
74
|
+
# 启动心跳
|
|
75
|
+
stop_event.clear()
|
|
76
|
+
t = threading.Thread(target=heartbeat_worker, args=(robot, stop_event))
|
|
77
|
+
t.start()
|
|
78
|
+
|
|
79
|
+
time.sleep(4)
|
|
80
|
+
|
|
81
|
+
# 结束运动
|
|
82
|
+
stop_event.set()
|
|
83
|
+
t.join()
|
|
84
|
+
|
|
85
|
+
print("\n所有运动演示完成")
|
|
86
|
+
|
|
87
|
+
except Exception as e:
|
|
88
|
+
print(f"执行过程中发生错误: {e}")
|
|
89
|
+
stop_event.set() # 确保线程能关闭
|
|
90
|
+
|
|
91
|
+
if __name__ == "__main__":
|
|
92
|
+
moveto_demo()
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from codroid import CodroidControlInterface, MovePoint
|
|
2
|
+
|
|
3
|
+
def move_demo():
|
|
4
|
+
with CodroidControlInterface() as robot:
|
|
5
|
+
# 1. 关节运动到 A 点
|
|
6
|
+
p1 = MovePoint(jp=[0, -90, 90, 0, 90, 0])
|
|
7
|
+
robot.move_j(p1, speed=50, acc=100)
|
|
8
|
+
|
|
9
|
+
# 2. 直线运动到 B 点 (带平滑过渡)
|
|
10
|
+
p2 = MovePoint(cp=[400, 100, 300, 180, 0, 0])
|
|
11
|
+
robot.move_l(p2, speed=100, acc=200, blend=10)
|
|
12
|
+
|
|
13
|
+
# 3. 圆弧运动 (必须是 cp)
|
|
14
|
+
target_cp = [400, -100, 300, 180, 0, 0]
|
|
15
|
+
middle_cp = [450, 0, 300, 180, 0, 0]
|
|
16
|
+
robot.move_c(target_cp, middle_cp, speed=50, acc=100)
|
|
17
|
+
|
|
18
|
+
if __name__ == "__main__":
|
|
19
|
+
move_demo()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from codroid import CodroidControlInterface, MotionPath, MovePoint
|
|
2
|
+
|
|
3
|
+
def path_demo():
|
|
4
|
+
with CodroidControlInterface() as robot:
|
|
5
|
+
# 1. 创建路径构建器
|
|
6
|
+
path = MotionPath()
|
|
7
|
+
|
|
8
|
+
# 2. 链式添加一系列指令
|
|
9
|
+
path.mov_j(MovePoint(jp=[0, 0, 90, 0, 90, 0]), speed=60, acc=150) \
|
|
10
|
+
.mov_l(MovePoint(cp=[494,191,444,-180,0,-90]), speed=500, acc=1500, blend=30) \
|
|
11
|
+
.mov_l(MovePoint(cp=[294,191,444,-180,0,-90]), speed=500, acc=1500, blend=30) \
|
|
12
|
+
.mov_l(MovePoint(cp=[494,391,444,-180,0,-90]), speed=500, acc=1500, blend=30) \
|
|
13
|
+
.mov_l(MovePoint(cp=[494,191,644,-180,0,-90]), speed=500, acc=1500, blend=30) \
|
|
14
|
+
.mov_j(MovePoint(jp=[0, 0, 90, 0, 90, 0]), speed=60, acc=150, blend=0)
|
|
15
|
+
|
|
16
|
+
# 3. 一次性执行
|
|
17
|
+
print("正在发送连续路径...")
|
|
18
|
+
res = robot.execute_path(path)
|
|
19
|
+
|
|
20
|
+
if res.is_success:
|
|
21
|
+
print("路径指令已送达机器人")
|
|
22
|
+
|
|
23
|
+
if __name__ == "__main__":
|
|
24
|
+
path_demo()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from codroid import CodroidControlInterface, CodroidError
|
|
2
|
+
import time
|
|
3
|
+
|
|
4
|
+
def demo_control():
|
|
5
|
+
# 使用上下文管理器自动连接
|
|
6
|
+
with CodroidControlInterface(host="192.168.1.136") as robot:
|
|
7
|
+
try:
|
|
8
|
+
# 1. 清除可能存在的错误
|
|
9
|
+
print("正在清除错误...")
|
|
10
|
+
robot.clear_error()
|
|
11
|
+
time.sleep(0.5)
|
|
12
|
+
|
|
13
|
+
# 2. 机器人上使能
|
|
14
|
+
print("正在上使能...")
|
|
15
|
+
robot.switch_on()
|
|
16
|
+
time.sleep(1)
|
|
17
|
+
|
|
18
|
+
# 3. 切换到仿真模式进行测试
|
|
19
|
+
print("进入仿真模式...")
|
|
20
|
+
robot.to_simulation()
|
|
21
|
+
|
|
22
|
+
# 4. 尝试进入拖拽模式 (假设当前在允许的模式下)
|
|
23
|
+
print("开启拖拽模式...")
|
|
24
|
+
robot.start_drag()
|
|
25
|
+
time.sleep(5) # 允许用户拖动 5 秒
|
|
26
|
+
|
|
27
|
+
print("关闭拖拽模式...")
|
|
28
|
+
robot.stop_drag()
|
|
29
|
+
|
|
30
|
+
# 5. 下使能
|
|
31
|
+
print("正在下使能...")
|
|
32
|
+
robot.switch_off()
|
|
33
|
+
|
|
34
|
+
except CodroidError as e:
|
|
35
|
+
print(f"操作失败: {e}")
|
|
36
|
+
|
|
37
|
+
if __name__ == "__main__":
|
|
38
|
+
demo_control()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from codroid import CodroidControlInterface
|
|
2
|
+
|
|
3
|
+
def io_demo():
|
|
4
|
+
with CodroidControlInterface() as robot:
|
|
5
|
+
# 1. 设置数字输出
|
|
6
|
+
print("设置 DO 10 为 1")
|
|
7
|
+
robot.set_do(10, 1)
|
|
8
|
+
|
|
9
|
+
# 2. 读取数字输入
|
|
10
|
+
di_val = robot.get_di(0)
|
|
11
|
+
print(f"DI 0 的值为: {di_val}")
|
|
12
|
+
|
|
13
|
+
# 3. 设置模拟输出
|
|
14
|
+
print("设置 AO 2 为 4.44")
|
|
15
|
+
robot.set_ao(2, 4.44)
|
|
16
|
+
|
|
17
|
+
# 4. 读取模拟输入
|
|
18
|
+
ai_val = robot.get_ai(1)
|
|
19
|
+
print(f"AI 1 的值为: {ai_val}")
|
|
20
|
+
|
|
21
|
+
# 5. 批量读取示例
|
|
22
|
+
res = robot.get_io_values([
|
|
23
|
+
{"type": "DI", "port": 0},
|
|
24
|
+
{"type": "AI", "port": 1}
|
|
25
|
+
])
|
|
26
|
+
print(f"批量读取结果: {res.db}")
|
|
27
|
+
|
|
28
|
+
if __name__ == "__main__":
|
|
29
|
+
io_demo()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from codroid import CodroidControlInterface, ExtendArrayType
|
|
2
|
+
|
|
3
|
+
def register_demo():
|
|
4
|
+
with CodroidControlInterface() as robot:
|
|
5
|
+
# 1. 操作基础寄存器
|
|
6
|
+
print("设置寄存器 49300 为 123.45")
|
|
7
|
+
robot.set_register_value(49300, 123.45)
|
|
8
|
+
|
|
9
|
+
val = robot.get_register(49300)
|
|
10
|
+
print(f"寄存器 49300 的值为: {val}")
|
|
11
|
+
|
|
12
|
+
# 2. 操作扩展数组
|
|
13
|
+
print("配置扩展数组索引 999 为 Float32 类型")
|
|
14
|
+
robot.set_extend_array_type(999, ExtendArrayType.FLOAT32)
|
|
15
|
+
|
|
16
|
+
# 3. 删除/重置扩展数组
|
|
17
|
+
print("重置扩展数组索引 999")
|
|
18
|
+
robot.remove_extend_array(999)
|
|
19
|
+
|
|
20
|
+
if __name__ == "__main__":
|
|
21
|
+
register_demo()
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from codroid import CodroidControlInterface, CRIMask, CRIStreamHandler, CRIData
|
|
2
|
+
import time
|
|
3
|
+
|
|
4
|
+
def cri_demo():
|
|
5
|
+
LOCAL_IP = "192.168.1.1"
|
|
6
|
+
LOCAL_PORT = 18888
|
|
7
|
+
ROBOT_IP = "192.168.1.136"
|
|
8
|
+
|
|
9
|
+
# 1. 创建 UDP 接收器
|
|
10
|
+
# 假设我们只需要时间戳、状态和关节位置
|
|
11
|
+
my_mask = CRIMask.TIMESTAMP | CRIMask.STATUS_1 | CRIMask.JOINT_POS
|
|
12
|
+
handler = CRIStreamHandler(high_precision=False, mask=my_mask)
|
|
13
|
+
handler.bind(LOCAL_PORT)
|
|
14
|
+
|
|
15
|
+
with CodroidControlInterface(host=ROBOT_IP) as robot:
|
|
16
|
+
# 2. 通知机器人开始向我推送数据
|
|
17
|
+
res = robot.start_data_push(ip=LOCAL_IP, port=LOCAL_PORT, duration=10, mask=my_mask)
|
|
18
|
+
|
|
19
|
+
print(res)
|
|
20
|
+
print("开始接收实时数据流...")
|
|
21
|
+
try:
|
|
22
|
+
for _ in range(10):
|
|
23
|
+
data, addr = handler._sock.recvfrom(2048)
|
|
24
|
+
parsed = handler.parse_packet(data)
|
|
25
|
+
print("------------------------------------------------------------------------")
|
|
26
|
+
print(f"时间戳: {parsed.timestamp}, 末端线速度: {parsed.tcp_speed}")
|
|
27
|
+
print(f"关节位置: {parsed.joint_pos}, 关节速度: {parsed.joint_vel}")
|
|
28
|
+
print(f"末端位置: {parsed.cartesian_pos}, 末端速度: {parsed.cartesian_vel}")
|
|
29
|
+
print(f"关节力矩: {parsed.joint_torque}, 关节外力: {parsed.external_torque}")
|
|
30
|
+
if parsed.status.project_running:
|
|
31
|
+
print("工程运行")
|
|
32
|
+
if parsed.status.project_paused:
|
|
33
|
+
print("工程暂停")
|
|
34
|
+
if parsed.status.project_stopped:
|
|
35
|
+
print("工程停止")
|
|
36
|
+
if parsed.status.is_enabling:
|
|
37
|
+
print("使能")
|
|
38
|
+
if parsed.status.is_disabled:
|
|
39
|
+
print("未使能")
|
|
40
|
+
if parsed.status.is_manual:
|
|
41
|
+
print("手动模式下")
|
|
42
|
+
if parsed.status.is_dragging:
|
|
43
|
+
print("拖动中")
|
|
44
|
+
else:
|
|
45
|
+
print("未拖动")
|
|
46
|
+
if parsed.status.is_moving:
|
|
47
|
+
print("运动中")
|
|
48
|
+
else:
|
|
49
|
+
print("未运动")
|
|
50
|
+
if parsed.status.collision_stop:
|
|
51
|
+
print("碰撞报警")
|
|
52
|
+
if parsed.status.is_at_safe_pos:
|
|
53
|
+
print("在安全点位")
|
|
54
|
+
if parsed.status.has_alarm:
|
|
55
|
+
print("有报警")
|
|
56
|
+
if parsed.status.is_simulation:
|
|
57
|
+
print("仿真模式")
|
|
58
|
+
if parsed.status.is_emergency_stop:
|
|
59
|
+
print("急停按下")
|
|
60
|
+
if parsed.status.is_rescue:
|
|
61
|
+
print("救援模式")
|
|
62
|
+
if parsed.status.is_auto:
|
|
63
|
+
print("自动模式")
|
|
64
|
+
if parsed.status.is_remote:
|
|
65
|
+
print("远程模式")
|
|
66
|
+
if parsed.status.rt_control_mode:
|
|
67
|
+
print("实施控制模式开启")
|
|
68
|
+
print(f"时间戳: {parsed.timestamp}, 关节: {parsed.joint_pos}")
|
|
69
|
+
finally:
|
|
70
|
+
robot.stop_data_push(ip=LOCAL_IP, port=LOCAL_PORT)
|
|
71
|
+
|
|
72
|
+
if __name__ == "__main__":
|
|
73
|
+
cri_demo()
|