codroid-robot-sdk 2.1.0__tar.gz → 2.1.1__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 (44) hide show
  1. codroid_robot_sdk-2.1.1/CHANGELOG.md +52 -0
  2. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/PKG-INFO +10 -6
  3. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/README.md +9 -5
  4. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/examples/01_basic_usage.py +4 -4
  5. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/examples/02_run_script.py +2 -2
  6. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/examples/03_run_project.py +7 -7
  7. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/examples/04_global_value.py +2 -2
  8. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/examples/05_rs485.py +5 -5
  9. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/examples/06_jog_mode.py +6 -6
  10. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/examples/07_move_to.py +6 -6
  11. codroid_robot_sdk-2.1.1/examples/08_move.py +167 -0
  12. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/examples/09_move_path.py +2 -2
  13. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/examples/10_control_commands.py +7 -7
  14. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/examples/11_io_demo.py +6 -6
  15. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/examples/12_register_demo.py +5 -5
  16. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/examples/13_cri_realtime.py +3 -3
  17. codroid_robot_sdk-2.1.1/examples/14_robot_parameters.py +202 -0
  18. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/examples/codroid_cri_test.py +21 -21
  19. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/examples/codroid_test.py +55 -33
  20. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/Codroid.py +250 -259
  21. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/__about__.py +1 -1
  22. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/__init__.py +4 -1
  23. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/client.py +0 -8
  24. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/cri_realtime_dispatcher.py +3 -5
  25. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/define.py +6 -10
  26. codroid_robot_sdk-2.1.1/src/codroid/robot_settings.py +243 -0
  27. codroid_robot_sdk-2.1.0/CHANGELOG.md +0 -30
  28. codroid_robot_sdk-2.1.0/examples/08_move.py +0 -124
  29. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/.gitignore +0 -0
  30. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/LICENSE.txt +0 -0
  31. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/mkdocs.yml +0 -0
  32. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/pyproject.toml +0 -0
  33. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/async_tcp_client.py +0 -0
  34. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/console.py +0 -0
  35. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/console_utf8.py +0 -0
  36. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/cri_realtime_packet_parser.py +0 -0
  37. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/exceptions.py +0 -0
  38. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/publish.py +0 -0
  39. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/py.typed +0 -0
  40. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/robot_motion.py +0 -0
  41. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/trajectory.py +0 -0
  42. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/types.py +0 -0
  43. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/src/codroid/utils.py +0 -0
  44. {codroid_robot_sdk-2.1.0 → codroid_robot_sdk-2.1.1}/update1.md +0 -0
@@ -0,0 +1,52 @@
1
+ # Changelog
2
+
3
+ ## 2.1.1 — 机器人设置 API(协议 19.x)
4
+
5
+ ### Added
6
+
7
+ - `robot_settings.py`:`RobotFrame`、`RobotPayloadFrame`、`RobotParameters`
8
+ - `SetCollisionSensitivity`、`GetRobotParameters`
9
+ - 仅改默认编号:`SetDefaultPayloadId`、`SetDefaultToolId`、`SetDefaultUserCoordinateId`
10
+ - 先读后改:`SetToolFrame`、`SetPayloadFrame`、`SetUserCoordinateFrame`
11
+ - 整表下发:`SaveToolFrames`、`SavePayloadFrames`、`SaveUserCoordinateFrames`
12
+ - 示例:`examples/14_robot_parameters.py`;`codroid_test.py robotparam`
13
+
14
+ ### Changed / Breaking
15
+
16
+ - 运动门面仅保留 C# 同名:`MovJ`、`MovL`、`MovC`、`MovCircle`、`Move`、`MoveTo`、`MoveToHeartbeat`
17
+ - 移除 `move_j` / `move_l` / `move_c` / `move_circle` / `execute_path` / `move` / `move_to` / `move_to_heartbeat`
18
+ - `MoveTarget` 更名为 `MoveToTarget`(与 C# 一致);`MotionPath.mov_*` 更名为 `MovJ` / `MovL` / `MovC`
19
+ - **`CodroidSession` / `CodroidClient` 全部公开方法改为 PascalCase**(`Connect`、`SwitchOn`、`GetDi`、`StartCriDataPush` 等);移除文件末尾历史 snake_case 别名
20
+ - `get_cri_data()` 改为属性 **`CriData`**(对齐 C#)
21
+ - `close` / `disconnect` 合并为 **`Disconnect`**
22
+ - `CriRealtimeDispatcher.send_command` → **`SendCommand`**,`send_trajectory` → **`SendTrajectory`**
23
+ - 移除 `subscribe_publish_topic` 别名
24
+
25
+ ## 2.1.0 — 运动 API 类型化(Breaking)
26
+
27
+ 与 C++ SDK v2.1.1 / `update1.md` 对齐。
28
+
29
+ ### Added
30
+
31
+ - `JointPoint`、`CartesianPoint`、`MoveInstruction` 及工厂(`Degrees`、`MmDeg`、`MmDegWithRef`、`MovJ`/`MovL`/…)
32
+ - `pack_move_point` / `pack_instruction`(`jp` 优先;笛卡尔缺省 `rj=[20,…,20]`)
33
+ - 门面 API:`MovJ`、`MovL`、`MovC`、`MovCircle`、`Move`、`MoveTo`、`MoveToHeartbeat`
34
+ - `MoveToTarget.Joint` / `MoveToTarget.Cartesian`
35
+ - `InitConsoleUtf8()`(Windows 控制台 UTF-8)
36
+
37
+ ### Changed
38
+
39
+ - `MovePoint.to_dict()` 经统一打包逻辑,仅 `cp` 时 JSON 会带默认 `rj`
40
+ - 示例与 `codroid_test` 运动段改用类型化 API
41
+
42
+ ### Deprecated
43
+
44
+ - 旧版 snake_case 运动方法(2.1.1 起已删除,见 2.1.1 Breaking)
45
+ - 直接 `MovePoint(jp=…)` 作业务目标(请改用 `JointPoint` / `CartesianPoint`)
46
+
47
+ ### Migration
48
+
49
+ 1. 程序入口首行:`InitConsoleUtf8()`
50
+ 2. 关节目标 → `JointPoint.Degrees([...])` + `MovJ` / `MoveInstruction.MovJ`
51
+ 3. TCP 目标 → `CartesianPoint.MmDeg` 或 `MmDegWithRef(pose, cri_joint)`
52
+ 4. 多段路径 → `Move([MoveInstruction.MovJ(...), ...])`
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codroid-robot-sdk
3
- Version: 2.1.0
3
+ Version: 2.1.1
4
4
  Summary: Codroid robot controller Python SDK (TCP/CRI, typed motion API)
5
5
  Project-URL: Documentation, https://guybod.github.io/CodroidSDK/
6
6
  Project-URL: Issues, https://github.com/guybod/CodroidSDK/issues
@@ -71,8 +71,8 @@ InitConsoleUtf8() # Windows cmd 下中文日志不乱码;Linux 上为 no-op
71
71
  ROBOT_IP = "192.168.1.136" # 改成实际控制器 IP
72
72
 
73
73
  with CodroidControlInterface(host=ROBOT_IP) as robot:
74
- robot.to_remote()
75
- robot.switch_on()
74
+ robot.ToRemote()
75
+ robot.SwitchOn()
76
76
  ```
77
77
 
78
78
  运行:
@@ -127,7 +127,7 @@ robot.Move(path)
127
127
 
128
128
  打包规则:`jp` 优先;仅 `cp` 时若未提供 `rj`,JSON 中带默认 `[20,20,20,20,20,20]`(度)。
129
129
 
130
- **Breaking(2.1.0)**:请勿再用 `MovePoint(jp=...)` 作业务入口;`move_j` / `move_l` 已废弃,见 [CHANGELOG.md](CHANGELOG.md)。
130
+ **Breaking(2.1.1)**:公开 API 与 C# 一致,统一 **PascalCase**(`Connect`、`SwitchOn`、`GetDi`、`MovJ`、`SetToolFrame` 等);`CriData` 为属性;`move_j` / `switch_on` snake_case 已移除。见 [CHANGELOG.md](CHANGELOG.md)。
131
131
 
132
132
  ## Windows 控制台 UTF-8
133
133
 
@@ -151,18 +151,22 @@ from codroid import CodroidClient, InitConsoleUtf8
151
151
  InitConsoleUtf8()
152
152
 
153
153
  with CodroidClient(host="192.168.1.136") as robot:
154
- robot.to_remote()
155
- robot.switch_on()
154
+ robot.ToRemote()
155
+ robot.SwitchOn()
156
156
  ```
157
157
 
158
158
  ## 示例
159
159
 
160
160
  ```bash
161
161
  PYTHONPATH=src python examples/08_move.py --robot 192.168.8.136
162
+ PYTHONPATH=src python examples/14_robot_parameters.py --robot 192.168.8.136
162
163
  PYTHONPATH=src python examples/codroid_test.py motion
163
164
  PYTHONPATH=src python examples/codroid_test.py s20
165
+ PYTHONPATH=src python examples/codroid_test.py robotparam
164
166
  ```
165
167
 
168
+ 机器人设置(协议 19.x):`GetRobotParameters`、`SetToolFrame`、`SetDefaultToolId` 等见 `examples/14_robot_parameters.py`。
169
+
166
170
  寄存器与 S20 运动常量见仓库根目录 `AGENTS.md` §5.1。
167
171
 
168
172
  ## 常见问题
@@ -44,8 +44,8 @@ InitConsoleUtf8() # Windows cmd 下中文日志不乱码;Linux 上为 no-op
44
44
  ROBOT_IP = "192.168.1.136" # 改成实际控制器 IP
45
45
 
46
46
  with CodroidControlInterface(host=ROBOT_IP) as robot:
47
- robot.to_remote()
48
- robot.switch_on()
47
+ robot.ToRemote()
48
+ robot.SwitchOn()
49
49
  ```
50
50
 
51
51
  运行:
@@ -100,7 +100,7 @@ robot.Move(path)
100
100
 
101
101
  打包规则:`jp` 优先;仅 `cp` 时若未提供 `rj`,JSON 中带默认 `[20,20,20,20,20,20]`(度)。
102
102
 
103
- **Breaking(2.1.0)**:请勿再用 `MovePoint(jp=...)` 作业务入口;`move_j` / `move_l` 已废弃,见 [CHANGELOG.md](CHANGELOG.md)。
103
+ **Breaking(2.1.1)**:公开 API 与 C# 一致,统一 **PascalCase**(`Connect`、`SwitchOn`、`GetDi`、`MovJ`、`SetToolFrame` 等);`CriData` 为属性;`move_j` / `switch_on` snake_case 已移除。见 [CHANGELOG.md](CHANGELOG.md)。
104
104
 
105
105
  ## Windows 控制台 UTF-8
106
106
 
@@ -124,18 +124,22 @@ from codroid import CodroidClient, InitConsoleUtf8
124
124
  InitConsoleUtf8()
125
125
 
126
126
  with CodroidClient(host="192.168.1.136") as robot:
127
- robot.to_remote()
128
- robot.switch_on()
127
+ robot.ToRemote()
128
+ robot.SwitchOn()
129
129
  ```
130
130
 
131
131
  ## 示例
132
132
 
133
133
  ```bash
134
134
  PYTHONPATH=src python examples/08_move.py --robot 192.168.8.136
135
+ PYTHONPATH=src python examples/14_robot_parameters.py --robot 192.168.8.136
135
136
  PYTHONPATH=src python examples/codroid_test.py motion
136
137
  PYTHONPATH=src python examples/codroid_test.py s20
138
+ PYTHONPATH=src python examples/codroid_test.py robotparam
137
139
  ```
138
140
 
141
+ 机器人设置(协议 19.x):`GetRobotParameters`、`SetToolFrame`、`SetDefaultToolId` 等见 `examples/14_robot_parameters.py`。
142
+
139
143
  寄存器与 S20 运动常量见仓库根目录 `AGENTS.md` §5.1。
140
144
 
141
145
  ## 常见问题
@@ -53,12 +53,12 @@ def main(argv: list[str]) -> int:
53
53
  udp_port=args.udp_port,
54
54
  ) as robot:
55
55
  # 典型上电顺序:先自动再远程(与 C# ConnectRemoteAndSwitchOn 子步骤一致)
56
- robot.enter_remote_mode_via_auto()
57
- robot.switch_on()
56
+ robot.EnterRemoteModeViaAuto()
57
+ robot.SwitchOn()
58
58
 
59
59
  # 后台线程收 CRI UDP,结果写入 robot.cri_cache(线程安全快照)
60
60
  robot._start_cri_receiver()
61
- robot.start_cri_data_push(ip=args.local_ip, port=args.udp_port)
61
+ robot.StartCriDataPush(ip=args.local_ip, port=args.udp_port)
62
62
 
63
63
  try:
64
64
  # 类型化目标:明确是「关节角」而非 TCP
@@ -82,7 +82,7 @@ def main(argv: list[str]) -> int:
82
82
  return 130
83
83
  finally:
84
84
  # 停止推送,释放控制器侧推送任务
85
- robot.stop_cri_data_push(ip=args.local_ip, port=args.udp_port)
85
+ robot.StopCriDataPush(ip=args.local_ip, port=args.udp_port)
86
86
 
87
87
  return 0
88
88
 
@@ -41,9 +41,9 @@ def main(argv: list[str]) -> int:
41
41
 
42
42
  try:
43
43
  with CodroidControlInterface(host=args.robot) as robot:
44
- robot.enter_remote_mode_via_auto()
44
+ robot.EnterRemoteModeViaAuto()
45
45
  print("发送脚本 / Sending script...")
46
- res = robot.run_script(lua_code, vars=vars_data)
46
+ res = robot.RunScript(lua_code, vars=vars_data)
47
47
  if res.is_success:
48
48
  print("脚本请求已发送 / Script request sent")
49
49
  else:
@@ -44,31 +44,31 @@ def main(argv: list[str]) -> int:
44
44
 
45
45
  try:
46
46
  with CodroidControlInterface(host=args.robot) as robot:
47
- robot.enter_remote_mode_via_auto()
47
+ robot.EnterRemoteModeViaAuto()
48
48
 
49
49
  # 按工程名启动
50
- res = robot.run_project(args.project_id)
50
+ res = robot.Run(args.project_id)
51
51
  print("运行 / run:", "ok" if res.is_success else res.err)
52
52
  time.sleep(args.step_sleep)
53
53
 
54
- res = robot.pause_project()
54
+ res = robot.PauseProject()
55
55
  print("暂停 / pause:", "ok" if res.is_success else res.err)
56
56
  time.sleep(args.step_sleep)
57
57
 
58
- res = robot.resume_project()
58
+ res = robot.ResumeProject()
59
59
  print("恢复 / resume:", "ok" if res.is_success else res.err)
60
60
  time.sleep(args.step_sleep)
61
61
 
62
- res = robot.stop_project()
62
+ res = robot.StopProject()
63
63
  print("停止 / stop:", "ok" if res.is_success else res.err)
64
64
  time.sleep(args.step_sleep)
65
65
 
66
66
  # 按索引启动(与示教器工程列表顺序相关)
67
- res = robot.run_project_by_index(args.index)
67
+ res = robot.RunByIndex(args.index)
68
68
  print("按索引启动 / by_index:", "ok" if res.is_success else res.err)
69
69
  time.sleep(args.step_sleep)
70
70
 
71
- res = robot.stop_project()
71
+ res = robot.StopProject()
72
72
  print("再次停止 / stop:", "ok" if res.is_success else res.err)
73
73
  except KeyboardInterrupt:
74
74
  return 130
@@ -46,9 +46,9 @@ def main(argv: list[str]) -> int:
46
46
 
47
47
  try:
48
48
  with CodroidControlInterface(host=args.robot) as robot:
49
- robot.enter_remote_mode_via_auto()
49
+ robot.EnterRemoteModeViaAuto()
50
50
  print("增量保存全局变量 / Saving globals...")
51
- res = robot.save_global_vars(vars_to_save)
51
+ res = robot.SaveGlobalVars(vars_to_save)
52
52
  if res.is_success:
53
53
  print("保存成功 / Saved")
54
54
  else:
@@ -36,20 +36,20 @@ def main(argv: list[str]) -> int:
36
36
 
37
37
  try:
38
38
  with CodroidControlInterface(host=args.robot) as robot:
39
- robot.enter_remote_mode_via_auto()
39
+ robot.EnterRemoteModeViaAuto()
40
40
 
41
41
  # 配置末端 485 参数(枚举与 C# RS485BaudRate 对齐)
42
42
  print("初始化 115200 N 8 1 / RS485 init")
43
- robot.rs485_init(baudrate=RS485BaudRate.B115200)
44
- robot.rs485_flush()
43
+ robot.Rs485Init(baudrate=RS485BaudRate.B115200)
44
+ robot.Rs485Flush()
45
45
 
46
46
  # 示例 Modbus RTU:站号 1,功能码 03,读 2 个寄存器(CRC 已含在帧内)
47
47
  cmd = b"\x01\x03\x00\x00\x00\x02\xC4\x0B"
48
48
  print(f"发送 / TX: {cmd.hex()}")
49
- robot.rs485_write(cmd)
49
+ robot.Rs485Write(cmd)
50
50
 
51
51
  print("读取响应(7 字节,1s 超时)/ Read...")
52
- res = robot.rs485_read(length=7, timeout=1000)
52
+ res = robot.Rs485Read(length=7, timeout=1000)
53
53
  if res.is_success and res.db:
54
54
  received = bytes(res.db)
55
55
  print(f"收到 / RX (hex): {received.hex()}")
@@ -38,7 +38,7 @@ def start_heartbeat(
38
38
  """后台线程:在点动保持期间周期调用 jog_heartbeat。"""
39
39
  while not stop_event.is_set():
40
40
  try:
41
- robot.jog_heartbeat()
41
+ robot.JogHeartbeat()
42
42
  time.sleep(interval)
43
43
  except Exception:
44
44
  # 连接断开或已 stop 时退出线程
@@ -55,10 +55,10 @@ def main(argv: list[str]) -> int:
55
55
 
56
56
  try:
57
57
  with CodroidControlInterface(host=args.robot) as robot:
58
- robot.enter_remote_mode_via_auto()
59
- robot.switch_on()
58
+ robot.EnterRemoteModeViaAuto()
59
+ robot.SwitchOn()
60
60
  # 手动模式运动倍率 1~100(百分比)
61
- robot.set_manual_move_rate(50)
61
+ robot.SetManualMoveRate(50)
62
62
 
63
63
  stop_heartbeat = threading.Event()
64
64
  heartbeat_thread = threading.Thread(
@@ -69,14 +69,14 @@ def main(argv: list[str]) -> int:
69
69
 
70
70
  print("关节 1 点动(示例速度)/ Jog joint 1...")
71
71
  # JogMode.JOINT + index + speed(比例)
72
- robot.start_jog(mode=JogMode.JOINT, index=1, speed=-0.5)
72
+ robot.StartJog(mode=JogMode.JOINT, index=1, speed=-0.5)
73
73
  heartbeat_thread.start()
74
74
  time.sleep(args.duration)
75
75
 
76
76
  print("停止点动 / Stop jog")
77
77
  stop_heartbeat.set()
78
78
  heartbeat_thread.join(timeout=2.0)
79
- robot.stop_jog()
79
+ robot.StopJog()
80
80
  except KeyboardInterrupt:
81
81
  return 130
82
82
  return 0
@@ -18,7 +18,7 @@
18
18
  PYTHONPATH=src python examples/07_move_to.py --robot <IP>
19
19
 
20
20
  【注意】
21
- - 目标请用 ``MoveTarget.Joint`` / ``MoveTarget.Cartesian``(2.1+),勿裸填数组
21
+ - 目标请用 ``MoveToTarget.Joint`` / ``MoveToTarget.Cartesian``,勿裸填数组
22
22
  - moveTo 的 target 不走 movL 的默认 rj 逻辑
23
23
  """
24
24
  from __future__ import annotations
@@ -33,7 +33,7 @@ from codroid import (
33
33
  CodroidControlInterface,
34
34
  InitConsoleUtf8,
35
35
  JointPoint,
36
- MoveTarget,
36
+ MoveToTarget,
37
37
  MoveToType,
38
38
  PrintBanner,
39
39
  )
@@ -63,8 +63,8 @@ def main(argv: list[str]) -> int:
63
63
 
64
64
  try:
65
65
  with CodroidControlInterface(host=args.robot) as robot:
66
- robot.enter_remote_mode_via_auto()
67
- robot.switch_on()
66
+ robot.EnterRemoteModeViaAuto()
67
+ robot.SwitchOn()
68
68
 
69
69
  # --- 场景 1:预设 Home,无需 target ---
70
70
  PrintBanner("Scene 1 — HOME", subtitle="MoveToType.HOME")
@@ -78,7 +78,7 @@ def main(argv: list[str]) -> int:
78
78
 
79
79
  # --- 场景 2:关节空间规划到指定六轴角 ---
80
80
  PrintBanner("Scene 2 — JOINT (Type 4)", subtitle="关节规划")
81
- target_joints = MoveTarget.Joint(JointPoint.Degrees([0.0] * 6))
81
+ target_joints = MoveToTarget.Joint(JointPoint.Degrees([0.0] * 6))
82
82
  robot.MoveTo(MoveToType.JOINT, target=target_joints)
83
83
  stop_event.clear()
84
84
  t = threading.Thread(target=heartbeat_worker, args=(robot, stop_event))
@@ -89,7 +89,7 @@ def main(argv: list[str]) -> int:
89
89
 
90
90
  # --- 场景 3:笛卡尔直线到 TCP 位姿(mm + 度)---
91
91
  PrintBanner("Scene 3 — LINEAR (Type 5)", subtitle="直线规划")
92
- target_pose = MoveTarget.Cartesian(
92
+ target_pose = MoveToTarget.Cartesian(
93
93
  CartesianPoint.MmDeg([350.0, 100.0, 400.0, 180.0, 0.0, 90.0]),
94
94
  )
95
95
  robot.MoveTo(MoveToType.LINEAR, target=target_pose)
@@ -0,0 +1,167 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ 示例 08 — 类型化运动 API(MovJ / MovL / Move 四组合)
4
+
5
+ 【目的】
6
+ 对齐 C++ ``examples_client/04_move.cpp``,演示「运动方式 × 点位类型」四种合法组合:
7
+
8
+ | API / 工厂 | 参数类型 | 协议字段 |
9
+ |------------------|------------------|------------|
10
+ | MovJ | JointPoint | movJ + jp |
11
+ | MovJ | CartesianPoint | movJ + cp |
12
+ | MovL | CartesianPoint | movL + cp |
13
+ | MovL | JointPoint | movL + jp |
14
+ | MovC | CartesianPoint×2 | movC 中间点+终点 |
15
+
16
+ 流程:先逐条单点下发(含 ``MovC``),再一次 ``Move(path)`` 下发多段(末段为圆弧)。
17
+
18
+ 【前置条件】
19
+ - 已使能;CRI 推送正常(movJ→TCP 建议 ``MmDegWithRef``)
20
+ - S20 等机型请核对笛卡尔点位(常量来自 AGENTS.md §5.1)
21
+
22
+ 【运行】
23
+ PYTHONPATH=src python examples/08_move.py --robot <IP> --local-ip <本机IP>
24
+
25
+ 【注意】
26
+ - ``MovJ(CartesianPoint)``:关节插补到 TCP,控制器逆解;有 CRI 时用当前关节作 ``rj``
27
+ - ``MovL(JointPoint)``:直线到关节目标(非 TCP 直线),协议仍带 ``jp``
28
+ - 仅 ``cp`` 且无 ``rj`` 时,打包默认 ``rj=[20,…,20]``(度)
29
+ - ``MovC`` 仅接受两个 ``CartesianPoint``(中间点、终点),与 C++ ``04_move.cpp`` 圆弧常量一致
30
+ """
31
+ from __future__ import annotations
32
+
33
+ import argparse
34
+ import sys
35
+ import time
36
+ from typing import Optional
37
+
38
+ from codroid import (
39
+ CartesianPoint,
40
+ CodroidControlInterface,
41
+ CriRealTimeData,
42
+ InitConsoleUtf8,
43
+ JointPoint,
44
+ MoveInstruction,
45
+ PrintBanner,
46
+ )
47
+
48
+
49
+ def wait_idle(robot: CodroidControlInterface, poll_s: float = 0.05) -> None:
50
+ """轮询 CRI 直到 is_moving 为 False。"""
51
+ while True:
52
+ data = robot.CriData
53
+ if data is not None and not data.status.is_moving:
54
+ return
55
+ if data is not None:
56
+ print(f" 运动中 joint_pos={data.joint_pos}")
57
+ else:
58
+ print(" 等待 CRI / waiting for status...")
59
+ time.sleep(poll_s)
60
+
61
+
62
+ def cartesian_with_cri_ref(
63
+ robot: CodroidControlInterface,
64
+ pose_mm_deg: list[float],
65
+ label: str,
66
+ ) -> CartesianPoint:
67
+ """
68
+ 有 CRI 时用 ``MmDegWithRef``,减少 movJ/movL 到 TCP 时的逆解跳解。
69
+ 无 CRI 时退回 ``MmDeg`` 并打印警告。
70
+ """
71
+ cri: Optional[CriRealTimeData] = robot.CriData
72
+ if cri is not None and len(cri.joint_pos) >= 6:
73
+ return CartesianPoint.MmDegWithRef(pose_mm_deg, list(cri.joint_pos))
74
+ print(f" 警告 [{label}]: 无 CRI 关节快照,使用 MmDeg(无 rj)")
75
+ return CartesianPoint.MmDeg(pose_mm_deg)
76
+
77
+
78
+ def main(argv: list[str]) -> int:
79
+ p = argparse.ArgumentParser(description="MovJ/MovL four-combination demo")
80
+ p.add_argument("--robot", default="192.168.8.136", help="控制器 IP")
81
+ p.add_argument("--local-ip", default="192.168.8.150", help="本机 IP(CRI)")
82
+ p.add_argument("--udp-port", type=int, default=18888, help="本机 UDP 端口")
83
+ p.add_argument("--debug", action="store_true", help="打印 JSON")
84
+ args = p.parse_args(argv)
85
+
86
+ PrintBanner("08 — Move (typed API)", subtitle=args.robot)
87
+
88
+ # AGENTS.md §5.1 S20 常用测试点(度 / mm+度)
89
+ joint_home = JointPoint.Degrees([0, 0, 0, 0, 0, 0])
90
+ joint_pose = JointPoint.Degrees([0, 0, 90, 0, 90, 0])
91
+ cart_p1 = [927.511, 214.489, 486.524, 179.999, 0.0, -89.999]
92
+ cart_p2 = [927.516, 214.489, 900.0, 180.0, 0.0, -89.999]
93
+ # C++ 04_move.cpp 圆弧:中间点 → 终点 line_p1
94
+ circle_middle = CartesianPoint.MmDeg(
95
+ [927.515, 27.23, 738.722, -180.0, 0.0, -89.999]
96
+ )
97
+ circle_end = CartesianPoint.MmDeg(cart_p1)
98
+
99
+ try:
100
+ with CodroidControlInterface(
101
+ host=args.robot,
102
+ local_ip=args.local_ip,
103
+ udp_port=args.udp_port,
104
+ ) as robot:
105
+ robot.debug = args.debug
106
+ robot.EnterRemoteModeViaAuto()
107
+ robot.SwitchOn()
108
+ robot._start_cri_receiver()
109
+ robot.StartCriDataPush(ip=args.local_ip, port=args.udp_port)
110
+ time.sleep(0.3)
111
+
112
+ # -----------------------------------------------------------------
113
+ # 一、单条指令(每种组合各调用一次 MovJ / MovL)
114
+ # -----------------------------------------------------------------
115
+
116
+ print("\n[1] MovJ + JointPoint (movJ + jp)")
117
+ robot.MovJ(joint_pose, speed=40, acceleration=100)
118
+ wait_idle(robot)
119
+
120
+ print("\n[2] MovL + CartesianPoint (movL + cp)")
121
+ line_p1 = cartesian_with_cri_ref(robot, cart_p1, "MovL(cp)")
122
+ robot.MovL(line_p1, speed=150, acceleration=500)
123
+ wait_idle(robot)
124
+
125
+ print("\n[3] MovJ + CartesianPoint (movJ + cp,控制器逆解到 TCP)")
126
+ line_p2 = cartesian_with_cri_ref(robot, cart_p2, "MovJ(cp)")
127
+ robot.MovJ(line_p2, speed=40, acceleration=100)
128
+ wait_idle(robot)
129
+
130
+ print("\n[4] MovL + JointPoint (movL + jp,直线到关节角而非 TCP 直线)")
131
+ robot.MovL(joint_home, speed=150, acceleration=500)
132
+ wait_idle(robot)
133
+
134
+ print("\n[5] MovC + CartesianPoint×2 (movC,中间点 → 终点)")
135
+ robot.MovC(circle_middle, circle_end, speed=120, acceleration=400)
136
+ wait_idle(robot)
137
+
138
+ # -----------------------------------------------------------------
139
+ # 二、多段路径 Move(path) — 四组合 + 末段 MovC(与 C++ path 一致)
140
+ # -----------------------------------------------------------------
141
+ print(
142
+ "\n[6] Move(path): "
143
+ "movJ+jp → movJ+cp → movL+cp → movL+jp → movC"
144
+ )
145
+ path = [
146
+ MoveInstruction.MovJ(joint_pose, speed=40, acc=100),
147
+ MoveInstruction.MovJ(line_p2, speed=40, acc=100),
148
+ MoveInstruction.MovL(line_p1, speed=150, acc=500, blend=25),
149
+ MoveInstruction.MovL(joint_home, speed=150, acc=500, blend=25),
150
+ MoveInstruction.MovC(
151
+ circle_middle, circle_end, speed=120, acc=400, blend=25
152
+ ),
153
+ ]
154
+ robot.Move(path)
155
+ wait_idle(robot)
156
+
157
+ PrintBanner("08 — 完成", subtitle="四组合 + MovC 单点与路径")
158
+ time.sleep(1)
159
+ except KeyboardInterrupt:
160
+ return 130
161
+
162
+ return 0
163
+
164
+
165
+ if __name__ == "__main__":
166
+ InitConsoleUtf8()
167
+ raise SystemExit(main(sys.argv[1:]))
@@ -78,8 +78,8 @@ def main(argv: list[str]) -> int:
78
78
 
79
79
  try:
80
80
  with CodroidControlInterface(host=args.robot) as robot:
81
- robot.enter_remote_mode_via_auto()
82
- robot.switch_on()
81
+ robot.EnterRemoteModeViaAuto()
82
+ robot.SwitchOn()
83
83
  print("发送连续路径 / Sending path...")
84
84
  res = robot.Move(path)
85
85
  if res.is_success:
@@ -38,28 +38,28 @@ def main(argv: list[str]) -> int:
38
38
 
39
39
  try:
40
40
  with CodroidControlInterface(host=args.robot) as robot:
41
- robot.enter_remote_mode_via_auto()
41
+ robot.EnterRemoteModeViaAuto()
42
42
  try:
43
43
  print("清错 / clear_system_error")
44
- robot.clear_system_error()
44
+ robot.ClearSystemError()
45
45
  time.sleep(0.5)
46
46
 
47
47
  print("上使能 / switch_on")
48
- robot.switch_on()
48
+ robot.SwitchOn()
49
49
  time.sleep(1)
50
50
 
51
51
  print("仿真模式 / to_simulation")
52
- robot.to_simulation()
52
+ robot.ToSimulation()
53
53
 
54
54
  print("拖拽开始 / start_drag")
55
- robot.start_drag()
55
+ robot.StartDrag()
56
56
  time.sleep(args.drag_seconds)
57
57
 
58
58
  print("拖拽结束 / stop_drag")
59
- robot.stop_drag()
59
+ robot.StopDrag()
60
60
 
61
61
  print("下使能 / switch_off")
62
- robot.switch_off()
62
+ robot.SwitchOff()
63
63
  except CodroidError as e:
64
64
  # 控制器 err 字段映射为 CodroidError
65
65
  print(f"CodroidError: {e}", file=sys.stderr)
@@ -34,22 +34,22 @@ def main(argv: list[str]) -> int:
34
34
 
35
35
  try:
36
36
  with CodroidControlInterface(host=args.robot) as robot:
37
- robot.enter_remote_mode_via_auto()
37
+ robot.EnterRemoteModeViaAuto()
38
38
 
39
39
  print("DO 10 = 1 / set_do(10, 1)")
40
- robot.set_do(10, 1)
40
+ robot.SetDo(10, 1)
41
41
 
42
- di_val = robot.get_di(0)
42
+ di_val = robot.GetDi(0)
43
43
  print(f"DI 0 = {di_val}")
44
44
 
45
45
  print("AO 2 = 4.44 / set_ao")
46
- robot.set_ao(2, 4.44)
46
+ robot.SetAo(2, 4.44)
47
47
 
48
- ai_val = robot.get_ai(1)
48
+ ai_val = robot.GetAi(1)
49
49
  print(f"AI 1 = {ai_val}")
50
50
 
51
51
  # 批量读:每项为 {type, port},type 为 DI/DO/AI/AO 字符串
52
- res = robot.get_io_values(
52
+ res = robot.GetIoValues(
53
53
  [
54
54
  {"type": "DI", "port": 0},
55
55
  {"type": "AI", "port": 1},
@@ -35,20 +35,20 @@ def main(argv: list[str]) -> int:
35
35
 
36
36
  try:
37
37
  with CodroidControlInterface(host=args.robot) as robot:
38
- robot.enter_remote_mode_via_auto()
38
+ robot.EnterRemoteModeViaAuto()
39
39
 
40
40
  # 浮点寄存器写读(地址因机型/配置而异)
41
41
  print("寄存器 49300 = 123.45 / set_register_value")
42
- robot.set_register_value(49300, 123.45)
43
- val = robot.get_register(49300)
42
+ robot.SetRegisterValue(49300, 123.45)
43
+ val = robot.GetRegisterValue(49300)
44
44
  print(f"读回 / read: {val}")
45
45
 
46
46
  # 将逻辑扩展数组 ID 绑定为 Float32 元素类型
47
47
  print("扩展数组 999 → Float32 / set_extend_array_type")
48
- robot.set_extend_array_type(999, ExtendArrayType.FLOAT32)
48
+ robot.SetExtendArrayType(999, ExtendArrayType.FLOAT32)
49
49
 
50
50
  print("重置扩展数组 999 / remove_extend_array")
51
- robot.remove_extend_array(999)
51
+ robot.RemoveExtendArray(999)
52
52
  except KeyboardInterrupt:
53
53
  return 130
54
54
  return 0
@@ -61,8 +61,8 @@ def main(argv: list[str]) -> int:
61
61
 
62
62
  try:
63
63
  with CodroidControlInterface(host=args.robot) as robot:
64
- robot.enter_remote_mode_via_auto()
65
- res = robot.start_cri_data_push(
64
+ robot.EnterRemoteModeViaAuto()
65
+ res = robot.StartCriDataPush(
66
66
  ip=args.local_ip,
67
67
  port=args.local_port,
68
68
  duration=args.duration,
@@ -129,7 +129,7 @@ def main(argv: list[str]) -> int:
129
129
  print("状态 / status:", ", ".join(flags))
130
130
  time.sleep(0.05)
131
131
  finally:
132
- robot.stop_cri_data_push(ip=args.local_ip, port=args.local_port)
132
+ robot.StopCriDataPush(ip=args.local_ip, port=args.local_port)
133
133
  except KeyboardInterrupt:
134
134
  return 130
135
135
  finally: