-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprimary_interface_read_telemetry.py
More file actions
71 lines (58 loc) 路 2.21 KB
/
Copy pathprimary_interface_read_telemetry.py
File metadata and controls
71 lines (58 loc) 路 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Primary Interface - Read Robot Telemetry Packets
==================================================
Connect via the Primary Interface and subscribe to real-time telemetry
events: robot mode, joint data, TCP cartesian position, and tool data.
The Primary Interface (port 30001) streams binary data packets from the
robot controller at ~10 Hz. This is useful for monitoring robot state
without the complexity of RTDE.
Press Ctrl+C to stop.
"""
import sys, os, time
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
from examples import connect_robot
print("=" * 60)
print(" UR SDK - Primary Interface: Read Telemetry Packets")
print("=" * 60)
print("Press Ctrl+C to stop.\n")
robot = connect_robot(enable_primary_interface=True)
import time as _time
_last_print = [0.0] # use a list so the inner functions can update it
def _should_print():
"""Throttle: print at most once per second."""
now = _time.monotonic()
if now - _last_print[0] >= 1.0:
_last_print[0] = now
return True
return False
# --- Subscribe to robot mode updates ---
@robot.primary_interface.robot_mode_data_received
def on_robot_mode(sender, event):
if not _should_print():
return
e = robot.primary_interface.robot_mode_data
print(f"[RobotMode] connected={e.physical_robot_connected} "
f"power_on={e.robot_power_on} "
f"mode={e.robot_mode} "
f"program_running={e.program_running}")
# --- Subscribe to joint data ---
@robot.primary_interface.joint_data_received
def on_joints(sender, event):
j = robot.primary_interface.joint_data
joints = [j.base, j.shoulder, j.elbow, j.wrist1, j.wrist2, j.wrist3]
q_deg = [round(jnt.position * 57.2958, 2) for jnt in joints]
print(f"[Joints ] {q_deg} deg")
# --- Subscribe to cartesian info ---
@robot.primary_interface.cartesian_info_received
def on_cartesian(sender, event):
c = robot.primary_interface.cartesian_info
print(f"[Cartesian] x={c.x:.4f} m y={c.y:.4f} m z={c.z:.4f} m "
f"rx={c.rx:.4f} ry={c.ry:.4f} rz={c.rz:.4f}")
try:
while True:
time.sleep(0.1)
except KeyboardInterrupt:
print("\nStopped by user.")
finally:
robot.disconnect()
print("Disconnected.")