-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot_control.py
185 lines (139 loc) · 9.28 KB
/
robot_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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import time
import ycom
from ycom import (
controllers, CartesianLocation, CartesianRotation, CartesianRobotPositionRobot, ControllerClient,
ProtocolType, PulseRobotPosition
)
class RobotControl:
def __init__(self, controller_client):
self.controller_client = controller_client
def home(self):
# Constructs a cartesian robot position (in the coordinate system of the robot).
cartesian_robot_position = CartesianRobotPositionRobot(
# X-location: 20 millimeters
location = CartesianLocation(value_x = 560 * 1_000, value_y = 0 * 1_000, value_z = 484 * 1_000),
# Z-rotation: 90 degrees
rotation = CartesianRotation(value_x = -164 * 10_000, value_y = -89 * 10_000, value_z = -15 * 10_000)
)
# Moves the robot to a cartesian position using a linear movement with a speed of
# 100 millimeters per second.
self.controller_client.robot_move_linear_cartesian(0, cartesian_robot_position, 100 * 10)
def pick(self):
# Check if gripper is empty, if empty, B021 = 0 else 64
# Gets the value of the first byte variable.
byte = self.controller_client.variable_byte_value_get(20)
#print(byte)
# Check if byte is true, if the robot gripper is empty
if (byte != 64): # This will execute if byte is True
# Move the robot to pre-pick position (above the object)
# Constructs a cartesian robot position (in the coordinate system of the robot).
cartesian_robot_position = CartesianRobotPositionRobot(
# X-location: 20 millimeters
location = CartesianLocation(value_x = 460 * 1_000, value_y = -303 * 1_000, value_z = -157 * 1_000),
# Z-rotation: 90 degrees
rotation = CartesianRotation(value_x = 179 * 10_000, value_y = -1 * 10_000, value_z = 22 * 10_000)
)
# Moves the robot to a cartesian position using a linear movement with a speed of
# 100 millimeters per second.
self.controller_client.robot_move_linear_cartesian(0, cartesian_robot_position, 100 * 10)
# Now move the robot to the pick position (vacuum gripper is touching the product)
# This time, robot will move in linear motion and in robot coordinates
# Constructs a cartesian robot position (in the coordinate system of the robot).
cartesian_robot_position = CartesianRobotPositionRobot(
# X-location: 20 millimeters
location = CartesianLocation(value_x = 460 * 1_000, value_y = -303 * 1_000, value_z = -249 * 1_000),
# Z-rotation: 90 degrees
rotation = CartesianRotation(value_x = 179 * 10_000, value_y = -1 * 10_000, value_z = 22 * 10_000)
)
# Moves the robot to a cartesian position using a linear movement with a speed of
# 100 millimeters per second.
self.controller_client.robot_move_linear_cartesian(0, cartesian_robot_position, 100 * 10)
# Turn on the vacuum gripper
# Sets the value of the first network input group (I/O group number 2,701 for YRC1000).
#controller_client.io_group_value_set(2_701, 0x44)
# Selects a job for execution. This job turns on the output OUT18 in IO307 to turn on the gripper (ycom can access IOs after they are mapped in ladder)
self.controller_client.job_select_execution("GET_PART")
# Adjustment to the ambient noise
# Start the job selected for execution and waits while the job is running.
self.controller_client.job_start_and_wait()
time.sleep(4) # timer to make sure that gripper closes fully (vacuum soft gripper)
# Lift the object with a linear motion
# Constructs a cartesian robot position (in the coordinate system of the robot).
cartesian_robot_position = CartesianRobotPositionRobot(
# X-location: 20 millimeters
location = CartesianLocation(value_x = 460 * 1_000, value_y = -303 * 1_000, value_z = -157 * 1_000),
# Z-rotation: 90 degrees
rotation = CartesianRotation(value_x = 179 * 10_000, value_y = -1 * 10_000, value_z = 22 * 10_000)
)
# Moves the robot to a cartesian position using a linear movement with a speed of
# 100 millimeters per second.
self.controller_client.robot_move_linear_cartesian(0, cartesian_robot_position, 100 * 10)
# Set variable, that object was picked
# Sets the value of the first byte variable.
self.controller_client.variable_byte_value_set(20, 0x40)
# Move away into the middle position after the object is picked with a linear motion
# Constructs a cartesian robot position (in the coordinate system of the robot).
cartesian_robot_position = CartesianRobotPositionRobot(
# X-location: 20 millimeters
location = CartesianLocation(value_x = 460 * 1_000, value_y = -18 * 1_000, value_z = 69 * 1_000),
# Z-rotation: 90 degrees
rotation = CartesianRotation(value_x = 179 * 10_000, value_y = -1 * 10_000, value_z = 22 * 10_000)
)
# Moves the robot to a cartesian position using a linear movement with a speed of
# 100 millimeters per second.
self.controller_client.robot_move_linear_cartesian(0, cartesian_robot_position, 100 * 10)
else:
print("Execution terminated: gripper is full, I cannot pick")
def place(self):
# Check, if the robot is holding the object
# Gets the value of the first byte variable.
byte = self.controller_client.variable_byte_value_get(20)
#print(byte)
# Check if byte is true, if the robot is holding the object
if (byte == 64): # This will execute if byte is True
# Move the robot to pre-place position
# Constructs a cartesian robot position (in the coordinate system of the robot).
cartesian_robot_position = CartesianRobotPositionRobot(
# X-location: 20 millimeters
location = CartesianLocation(value_x = 546 * 1_000, value_y = 168 * 1_000, value_z = -159 * 1_000),
# Z-rotation: 90 degrees
rotation = CartesianRotation(value_x = 179 * 10_000, value_y = -1 * 10_000, value_z = 22 * 10_000)
)
# Moves the robot to a cartesian position using a linear movement with a speed of
# 100 millimeters per second.
self.controller_client.robot_move_linear_cartesian(0, cartesian_robot_position, 100 * 10)
# Move the robot to the place position (object is touching the table)
# Constructs a cartesian robot position (in the coordinate system of the robot).
cartesian_robot_position = CartesianRobotPositionRobot(
# X-location: 20 millimeters
location = CartesianLocation(value_x = 546 * 1_000, value_y = 168 * 1_000, value_z = -253 * 1_000),
# Z-rotation: 90 degrees
rotation = CartesianRotation(value_x = 179 * 10_000, value_y = -1 * 10_000, value_z = 22 * 10_000)
)
# Moves the robot to a cartesian position using a linear movement with a speed of
# 100 millimeters per second.
self.controller_client.robot_move_linear_cartesian(0, cartesian_robot_position, 100 * 10)
# Turn off the vacuum gripper
# Sets the value of the first network input group (I/O group number 2,701 for YRC1000).
#controller_client.io_group_value_set(2_701, 0x00)
# Selects a job for execution. This job turns off the output OUT18 in IO307 to turn off the gripper (ycom can access IOs after they are mapped in ladder)
self.controller_client.job_select_execution("PUT_PART")
# Start the job selected for execution and waits while the job is running.
self.controller_client.job_start_and_wait()
time.sleep(1) # timer to make sure vacuum is off
# Move from the object with a linear motion
# Constructs a cartesian robot position (in the coordinate system of the robot).
cartesian_robot_position = CartesianRobotPositionRobot(
# X-location: 20 millimeters
location = CartesianLocation(value_x = 546 * 1_000, value_y = 168 * 1_000, value_z = -159 * 1_000),
# Z-rotation: 90 degrees
rotation = CartesianRotation(value_x = 179 * 10_000, value_y = -1 * 10_000, value_z = 22 * 10_000)
)
# Moves the robot to a cartesian position using a linear movement with a speed of
# 100 millimeters per second.
self.controller_client.robot_move_linear_cartesian(0, cartesian_robot_position, 100 * 10)
# Set variable, that object was placed (gripper is empty)
# Sets the value of the first byte variable.
self.controller_client.variable_byte_value_set(20, 0x00)
else:
print("Execution terminated: gripper is empty")