added image output after each command that modifies the state of the cobot
Browse files
app.py
CHANGED
@@ -97,18 +97,18 @@ CSS = """
|
|
97 |
|
98 |
def handle_request(
|
99 |
command, gripper_value, gripper_speed, angle1, angle2, angle3, angle4,
|
100 |
-
angle5, angle6, angle_speed, xcoord, ycoord, zcoord, roll, pitch, yaw, coord_speed,
|
101 |
):
|
102 |
if command == "enterqueue":
|
103 |
return "", gr.Image(visible=False)
|
104 |
elif command == "query/angles":
|
105 |
resp = client.get_angles()
|
106 |
resp["command"] = command
|
107 |
-
return json.dumps(resp, indent=4),
|
108 |
elif command == "query/coords":
|
109 |
resp = client.get_coords()
|
110 |
resp["command"] = command
|
111 |
-
return json.dumps(resp, indent=4),
|
112 |
elif command == "query/camera":
|
113 |
resp = client.get_camera()
|
114 |
resp["command"] = command
|
@@ -119,31 +119,40 @@ def handle_request(
|
|
119 |
elif command == "query/gripper":
|
120 |
resp = client.get_gripper_value()
|
121 |
resp["command"] = command
|
122 |
-
return json.dumps(resp, indent=4),
|
123 |
elif command == "control/angles":
|
124 |
resp = client.send_angles(
|
125 |
angle_list = [angle1, angle2, angle3, angle4, angle5, angle6],
|
126 |
speed = angle_speed
|
127 |
)
|
128 |
resp["command"] = command
|
129 |
-
|
|
|
|
|
|
|
130 |
elif command == "control/gripper":
|
131 |
resp = client.send_gripper_value(
|
132 |
value = gripper_value,
|
133 |
speed = gripper_speed
|
134 |
)
|
135 |
resp["command"] = command
|
136 |
-
|
|
|
|
|
|
|
137 |
elif command == "control/coords":
|
138 |
resp = client.send_coords(
|
139 |
coord_list = [xcoord, ycoord, zcoord, roll, pitch, yaw],
|
140 |
speed = coord_speed
|
141 |
)
|
142 |
resp["command"] = command
|
143 |
-
|
|
|
|
|
|
|
144 |
|
145 |
def process_user_auth(command, user_id, gripper_value, gripper_speed, angle1, angle2, angle3, angle4,
|
146 |
-
angle5, angle6, angle_speed, xcoord, ycoord, zcoord, roll, pitch, yaw, coord_speed):
|
147 |
if queue_system.current_user is None:
|
148 |
queue_system.start_session(user_id)
|
149 |
queue_system.enqueue_user(user_id)
|
@@ -152,7 +161,7 @@ def process_user_auth(command, user_id, gripper_value, gripper_speed, angle1, an
|
|
152 |
if position == 0:
|
153 |
result, response_image = handle_request(
|
154 |
command, gripper_value, gripper_speed, angle1, angle2, angle3, angle4,
|
155 |
-
angle5, angle6, angle_speed, xcoord, ycoord, zcoord, roll, pitch, yaw, coord_speed
|
156 |
)
|
157 |
remaining_time_msg = f"Your turn!\nTime remaining: {wait_time:.2f} seconds."
|
158 |
return result, response_image, remaining_time_msg
|
@@ -173,7 +182,7 @@ with gr.Blocks(css=CSS) as app:
|
|
173 |
with gr.Row():
|
174 |
with gr.Column():
|
175 |
user_id = gr.Textbox(label="User ID", info="Enter a unique user id of your choice or take note of the automatically generated user id. This user id will be placed into a queue to give you access to the cobot, so make sure you remember it!")
|
176 |
-
enter_queue_button = gr.Button("
|
177 |
with gr.Column():
|
178 |
status_text = gr.Textbox(label="Queue status", value="", interactive=False, lines=5)
|
179 |
|
@@ -235,49 +244,49 @@ with gr.Blocks(css=CSS) as app:
|
|
235 |
angle_query_button.click(
|
236 |
process_user_auth,
|
237 |
inputs = [gr.Textbox(value="query/angles", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
238 |
-
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords],
|
239 |
outputs = [response, response_image, status_text]
|
240 |
)
|
241 |
coord_query_button.click(
|
242 |
process_user_auth,
|
243 |
inputs = [gr.Textbox(value="query/coords", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
244 |
-
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords],
|
245 |
outputs = [response, response_image, status_text]
|
246 |
)
|
247 |
gripper_query_button.click(
|
248 |
process_user_auth,
|
249 |
inputs = [gr.Textbox(value="query/gripper", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
250 |
-
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords],
|
251 |
outputs = [response, response_image, status_text]
|
252 |
)
|
253 |
camera_query_button.click(
|
254 |
process_user_auth,
|
255 |
inputs = [gr.Textbox(value="query/camera", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
256 |
-
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords],
|
257 |
outputs = [response, response_image, status_text]
|
258 |
)
|
259 |
gripper_control_button.click(
|
260 |
process_user_auth,
|
261 |
inputs = [gr.Textbox(value="control/gripper", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
262 |
-
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords],
|
263 |
outputs = [response, response_image, status_text]
|
264 |
)
|
265 |
angle_control_button.click(
|
266 |
process_user_auth,
|
267 |
inputs = [gr.Textbox(value="control/angles", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
268 |
-
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords],
|
269 |
outputs = [response, response_image, status_text]
|
270 |
)
|
271 |
coord_control_button.click(
|
272 |
process_user_auth,
|
273 |
inputs = [gr.Textbox(value="control/coords", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
274 |
-
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords],
|
275 |
outputs = [response, response_image, status_text]
|
276 |
)
|
277 |
enter_queue_button.click(
|
278 |
process_user_auth,
|
279 |
inputs = [gr.Textbox(value="enterqueue", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
280 |
-
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords],
|
281 |
outputs = [response, response_image, status_text]
|
282 |
)
|
283 |
|
|
|
97 |
|
98 |
def handle_request(
|
99 |
command, gripper_value, gripper_speed, angle1, angle2, angle3, angle4,
|
100 |
+
angle5, angle6, angle_speed, xcoord, ycoord, zcoord, roll, pitch, yaw, coord_speed,image_box
|
101 |
):
|
102 |
if command == "enterqueue":
|
103 |
return "", gr.Image(visible=False)
|
104 |
elif command == "query/angles":
|
105 |
resp = client.get_angles()
|
106 |
resp["command"] = command
|
107 |
+
return json.dumps(resp, indent=4), image_box
|
108 |
elif command == "query/coords":
|
109 |
resp = client.get_coords()
|
110 |
resp["command"] = command
|
111 |
+
return json.dumps(resp, indent=4), image_box
|
112 |
elif command == "query/camera":
|
113 |
resp = client.get_camera()
|
114 |
resp["command"] = command
|
|
|
119 |
elif command == "query/gripper":
|
120 |
resp = client.get_gripper_value()
|
121 |
resp["command"] = command
|
122 |
+
return json.dumps(resp, indent=4), image_box
|
123 |
elif command == "control/angles":
|
124 |
resp = client.send_angles(
|
125 |
angle_list = [angle1, angle2, angle3, angle4, angle5, angle6],
|
126 |
speed = angle_speed
|
127 |
)
|
128 |
resp["command"] = command
|
129 |
+
|
130 |
+
image_resp = client.get_camera()
|
131 |
+
image_ret = gr.Image(value=image_resp["image"], visible=True) if image_resp["success"] else gr.Image(visible=False)
|
132 |
+
return json.dumps(resp, indent=4), image_ret
|
133 |
elif command == "control/gripper":
|
134 |
resp = client.send_gripper_value(
|
135 |
value = gripper_value,
|
136 |
speed = gripper_speed
|
137 |
)
|
138 |
resp["command"] = command
|
139 |
+
|
140 |
+
image_resp = client.get_camera()
|
141 |
+
image_ret = gr.Image(value=image_resp["image"], visible=True) if image_resp["success"] else gr.Image(visible=False)
|
142 |
+
return json.dumps(resp, indent=4), image_ret
|
143 |
elif command == "control/coords":
|
144 |
resp = client.send_coords(
|
145 |
coord_list = [xcoord, ycoord, zcoord, roll, pitch, yaw],
|
146 |
speed = coord_speed
|
147 |
)
|
148 |
resp["command"] = command
|
149 |
+
|
150 |
+
image_resp = client.get_camera()
|
151 |
+
image_ret = gr.Image(value=image_resp["image"], visible=True) if image_resp["success"] else gr.Image(visible=False)
|
152 |
+
return json.dumps(resp, indent=4), image_ret
|
153 |
|
154 |
def process_user_auth(command, user_id, gripper_value, gripper_speed, angle1, angle2, angle3, angle4,
|
155 |
+
angle5, angle6, angle_speed, xcoord, ycoord, zcoord, roll, pitch, yaw, coord_speed, output_image):
|
156 |
if queue_system.current_user is None:
|
157 |
queue_system.start_session(user_id)
|
158 |
queue_system.enqueue_user(user_id)
|
|
|
161 |
if position == 0:
|
162 |
result, response_image = handle_request(
|
163 |
command, gripper_value, gripper_speed, angle1, angle2, angle3, angle4,
|
164 |
+
angle5, angle6, angle_speed, xcoord, ycoord, zcoord, roll, pitch, yaw, coord_speed, output_image
|
165 |
)
|
166 |
remaining_time_msg = f"Your turn!\nTime remaining: {wait_time:.2f} seconds."
|
167 |
return result, response_image, remaining_time_msg
|
|
|
182 |
with gr.Row():
|
183 |
with gr.Column():
|
184 |
user_id = gr.Textbox(label="User ID", info="Enter a unique user id of your choice or take note of the automatically generated user id. This user id will be placed into a queue to give you access to the cobot, so make sure you remember it!")
|
185 |
+
enter_queue_button = gr.Button("Join queue")
|
186 |
with gr.Column():
|
187 |
status_text = gr.Textbox(label="Queue status", value="", interactive=False, lines=5)
|
188 |
|
|
|
244 |
angle_query_button.click(
|
245 |
process_user_auth,
|
246 |
inputs = [gr.Textbox(value="query/angles", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
247 |
+
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords, response_image],
|
248 |
outputs = [response, response_image, status_text]
|
249 |
)
|
250 |
coord_query_button.click(
|
251 |
process_user_auth,
|
252 |
inputs = [gr.Textbox(value="query/coords", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
253 |
+
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords, response_image],
|
254 |
outputs = [response, response_image, status_text]
|
255 |
)
|
256 |
gripper_query_button.click(
|
257 |
process_user_auth,
|
258 |
inputs = [gr.Textbox(value="query/gripper", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
259 |
+
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords, response_image],
|
260 |
outputs = [response, response_image, status_text]
|
261 |
)
|
262 |
camera_query_button.click(
|
263 |
process_user_auth,
|
264 |
inputs = [gr.Textbox(value="query/camera", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
265 |
+
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords, response_image],
|
266 |
outputs = [response, response_image, status_text]
|
267 |
)
|
268 |
gripper_control_button.click(
|
269 |
process_user_auth,
|
270 |
inputs = [gr.Textbox(value="control/gripper", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
271 |
+
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords, response_image],
|
272 |
outputs = [response, response_image, status_text]
|
273 |
)
|
274 |
angle_control_button.click(
|
275 |
process_user_auth,
|
276 |
inputs = [gr.Textbox(value="control/angles", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
277 |
+
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords, response_image],
|
278 |
outputs = [response, response_image, status_text]
|
279 |
)
|
280 |
coord_control_button.click(
|
281 |
process_user_auth,
|
282 |
inputs = [gr.Textbox(value="control/coords", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
283 |
+
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords, response_image],
|
284 |
outputs = [response, response_image, status_text]
|
285 |
)
|
286 |
enter_queue_button.click(
|
287 |
process_user_auth,
|
288 |
inputs = [gr.Textbox(value="enterqueue", visible=False), user_id, gripper_value, speed_gripper, angle1, angle2, angle3, angle4,
|
289 |
+
angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords, response_image],
|
290 |
outputs = [response, response_image, status_text]
|
291 |
)
|
292 |
|