-
Notifications
You must be signed in to change notification settings - Fork 0
/
ur10_control.py
118 lines (87 loc) · 3.46 KB
/
ur10_control.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from urx import Robot
import time
# Created by Coder Shiyar | https://codershiyar.com
# Netherlands Kurdistan | 25,
def connect_to_robot(robot_ip):
"""
Connects to the UR10 robot.
Parameters:
robot_ip (str): The IP address of the robot.
Returns:
Robot: The connected robot object.
"""
robot = Robot(robot_ip)
return robot
def move_to_position(robot, target_pose, acceleration=0.5, velocity=0.5):
"""
Moves the robot to a specified position.
Parameters:
robot (Robot): The connected robot object.
target_pose (tuple): Target position and orientation (X, Y, Z, RX, RY, RZ).
acceleration (float): Acceleration value for the movement (default: 0.5).
velocity (float): Velocity value for the movement (default: 0.5).
"""
robot.movej(target_pose, acc=acceleration, vel=velocity)
def stop_robot(robot):
"""
Stops the movement of the robot.
Parameters:
robot (Robot): The connected robot object.
"""
robot.stopl()
def disconnect_robot(robot):
"""
Disconnects from the robot.
Parameters:
robot (Robot): The connected robot object.
"""
robot.close()
def rotate_robot(robot, rx_offset, ry_offset, acceleration=0.5, velocity=0.5):
"""
Rotates the robot around its fixed position by adjusting RX and RY angles.
Parameters:
robot (Robot): The connected robot object.
rx_offset (float): Offset value for RX angle (in radians).
ry_offset (float): Offset value for RY angle (in radians).
acceleration (float): Acceleration value for the movement (default: 0.5).
velocity (float): Velocity value for the movement (default: 0.5).
"""
current_pose = robot.getl()
new_orientation = (current_pose[3], current_pose[4] + rx_offset, current_pose[5] + ry_offset)
robot.movel(current_pose[0:3] + new_orientation, acc=acceleration, vel=velocity)
if __name__ == "__main__":
# Example usage:
robot_ip_address = "192.168.1.100" # Replace with the actual IP address of your UR10 robot
# Connect to the robot
ur10_robot = connect_to_robot(robot_ip_address)
# Example target position (X, Y, Z, RX, RY, RZ)
target_position = (0.5, 0.5, 0.5, 0, 0, 0)
# Move to the target position
move_to_position(ur10_robot, target_position)
# Pause for safety
time.sleep(2)
# Stop the robot
stop_robot(ur10_robot)
# Rotate the robot around its fixed position by adjusting RX and RY angles
rotate_robot(ur10_robot, rx_offset=0.1, ry_offset=0.1)
# Pause for safety
time.sleep(2)
# Stop the robot
stop_robot(ur10_robot)
# Disconnect from the robot
disconnect_robot(ur10_robot)
# Simple example to move robot to the target position.
# from urx import Robot
# def main(robot_ip):
# # Connect to the robot
# robot = Robot(robot_ip)
# # Set a target pose (position and orientation)
# target_pose = (0.5, 0.5, 0.5, 0, 0, 0) # Example target pose (X, Y, Z, RX, RY, RZ)
# # Move to the target pose
# robot.movej(target_pose, acc=0.5, vel=0.5) # MoveJ command (joint movement)
# # Close the connection
# robot.close()
# if __name__ == "__main__":
# # Specify the IP address of your UR10 robot
# robot_ip_address = "192.168.1.100" # Example IP address, replace with your robot's IP
# main(robot_ip_address)