Skip to content

Instantly share code, notes, and snippets.

@lauzadis
Created April 24, 2026 01:37
Show Gist options
  • Select an option

  • Save lauzadis/45778ea41d1e7fdde22091551cdcbcf6 to your computer and use it in GitHub Desktop.

Select an option

Save lauzadis/45778ea41d1e7fdde22091551cdcbcf6 to your computer and use it in GitHub Desktop.
Test RTDE connection to UR robot
#!/usr/bin/env python3
import rtde_control
import rtde_receive
import time
ROBOT_IP = "192.168.1.150"
def test_ur_rtde():
try:
print(f"Connecting to UR5 at {ROBOT_IP}...")
# Connect to receive interface (read robot state)
rtde_r = rtde_receive.RTDEReceiveInterface(ROBOT_IP)
print("✓ Successfully connected to RTDE receive interface")
# Read some basic robot data
actual_q = rtde_r.getActualQ() # Joint positions
actual_tcp = rtde_r.getActualTCPPose() # TCP position
robot_mode = rtde_r.getRobotMode() # Robot mode
print("\n--- Robot State ---")
print(f"Joint positions: {[f'{q:.3f}' for q in actual_q]}")
print(f"TCP pose: {[f'{p:.3f}' for p in actual_tcp]}")
print(f"Robot mode: {robot_mode}")
# Connect to control interface
rtde_c = rtde_control.RTDEControlInterface(ROBOT_IP)
print("\n✓ Successfully connected to RTDE control interface")
print("\n✓ All connections working!")
print("✓ Robot is ready for control")
# Cleanup
rtde_r.disconnect()
rtde_c.disconnect()
return True
except Exception as e:
print(f"\n✗ Error: {e}")
print("\nTroubleshooting:")
print("- Make sure the robot is powered on")
print("- Check that RTDE is enabled on the robot")
print("- Verify IP address is correct")
return False
if __name__ == "__main__":
# First, make sure ur-rtde is installed
try:
import rtde_control
import rtde_receive
except ImportError:
print("ur-rtde not installed. Installing...")
print("Run: pip3 install ur-rtde")
exit(1)
test_ur_rtde()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment