Skip to content

Commit 8cf0126

Browse files
committed
fix: ur.robot_state (#10)
- replace broken command with RTDE integration (robot status and safety checks) revert logger send.
1 parent e81e5bd commit 8cf0126

3 files changed

Lines changed: 61 additions & 2 deletions

File tree

armctl/universal_robots/protocols/config.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
<recipe key="out">
44
<field name="actual_TCP_pose" type="VECTOR6D" />
55
<field name="actual_q" type="VECTOR6D" />
6+
<field name="robot_status_bits" type="UINT32" />
7+
<field name="safety_status_bits" type="UINT32" />
68
</recipe>
79
</rtde_config>

armctl/universal_robots/protocols/rtde.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from pathlib import Path
2+
from typing import NewType
23
import rtde.rtde as rtde
34
import rtde.rtde_config as rtde_config
45

6+
UINT32 = NewType("UINT32", int)
7+
58

69
class RTDE:
710
def __init__(self, ip: str):
@@ -27,3 +30,49 @@ def joint_angles(self) -> list[float]:
2730
def tcp_pose(self) -> list[float]:
2831
"""Return TCP pose [x, y, z, rx, ry, rz]."""
2932
return list(self._get_data().actual_TCP_pose)
33+
34+
def robot_status(self) -> dict[str, bool]:
35+
"""Return robot status.
36+
37+
Robot status bits (UINT32):
38+
- **`Bit 0`**: Is power on
39+
- **`Bit 1`**: Is program running
40+
- **`Bit 2`**: Is teach button pressed
41+
- **`Bit 3`**: Is power button pressed
42+
43+
Safety status bits (UINT32):
44+
- **`Bit 0`**: Is normal mode
45+
- **`Bit 1`**: Is reduced mode
46+
- **`Bit 2`**: Is protective stop
47+
- **`Bit 3`**: Is recovery mode
48+
- **`Bit 4`**: Is safeguard stopped
49+
- **`Bit 5`**: Is system emergency stopped
50+
- **`Bit 6`**: Is robot emergency stopped
51+
- **`Bit 7`**: Is Emergency Stopped
52+
- **`Bit 8`**: Is violation
53+
- **`Bit 9`**: Is Fault
54+
- **`Bit 10`**: Is stopped due to safety
55+
"""
56+
data = self._get_data()
57+
rsb: UINT32 = data.robot_status_bits
58+
ssb: UINT32 = data.safety_status_bits
59+
60+
return {
61+
# Robot status bits
62+
"Power On": bool(rsb & 1),
63+
"Program Running": bool(rsb & 2),
64+
"Teach Button": bool(rsb & 4),
65+
"Power Button": bool(rsb & 8),
66+
# Safety status bits
67+
"Normal Mode": bool(ssb & 1),
68+
"Reduced Mode": bool(ssb & 2),
69+
"Protective Stop": bool(ssb & 4),
70+
"Recovery Mode": bool(ssb & 8),
71+
"Safeguard Stopped": bool(ssb & 16),
72+
"System Emergency Stopped": bool(ssb & 32),
73+
"Robot Emergency Stopped": bool(ssb & 64),
74+
"Emergency Stopped": bool(ssb & 128),
75+
"Violation": bool(ssb & 256),
76+
"Fault": bool(ssb & 512),
77+
"Stopped Due to Safety": bool(ssb & 1024),
78+
}

armctl/universal_robots/universal_robots.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,13 @@ def stop_motion(self) -> None:
184184
"stopj({})\n".format(deceleration), suppress_output=True
185185
)
186186

187-
def get_robot_state(self):
188-
return self.send_command("get_robot_status()\n")
187+
def get_robot_state(self) -> dict[str, bool]:
188+
status = self.rtde.robot_status()
189+
190+
key_out = ["Power On", "Program Running", "Emergency Stopped", "Stopped Due to Safety"]
191+
logger.receive(
192+
"Received response: " +
193+
", ".join(f"{k}: {status[k]}" for k in key_out) +
194+
" ..."
195+
)
196+
return status

0 commit comments

Comments
 (0)