added coord/angle reset and update buttons, refactor
Browse files
app.py
CHANGED
@@ -187,85 +187,30 @@ def control_gripper(user_id, gripper_value, movement_speed):
|
|
187 |
else:
|
188 |
return None, queue_status_msg
|
189 |
|
190 |
-
def
|
191 |
-
|
192 |
-
|
193 |
-
)
|
194 |
-
|
195 |
-
return "", gr.Image(visible=False)
|
196 |
-
elif command == "query/angles":
|
197 |
-
resp = client.get_angles()
|
198 |
-
resp["command"] = command
|
199 |
-
return json.dumps(resp, indent=4), image_box
|
200 |
-
elif command == "query/coords":
|
201 |
-
resp = client.get_coords()
|
202 |
-
resp["command"] = command
|
203 |
-
return json.dumps(resp, indent=4), image_box
|
204 |
-
elif command == "query/camera":
|
205 |
-
resp = client.get_camera()
|
206 |
-
resp["command"] = command
|
207 |
if not resp["success"]:
|
208 |
-
return
|
209 |
-
|
210 |
-
return json.dumps(resp, indent=4), gr.Image(visible=True, value=img)
|
211 |
-
elif command == "query/gripper":
|
212 |
-
resp = client.get_gripper_value()
|
213 |
-
resp["command"] = command
|
214 |
-
return json.dumps(resp, indent=4), image_box
|
215 |
-
elif command == "control/angles":
|
216 |
-
resp = client.send_angles(
|
217 |
-
angle_list = [angle1, angle2, angle3, angle4, angle5, angle6],
|
218 |
-
speed = angle_speed
|
219 |
-
)
|
220 |
-
resp["command"] = command
|
221 |
-
|
222 |
-
image_resp = client.get_camera()
|
223 |
-
image_ret = gr.Image(value=image_resp["image"], visible=True) if image_resp["success"] else gr.Image(visible=False)
|
224 |
-
return json.dumps(resp, indent=4), image_ret
|
225 |
-
elif command == "control/gripper":
|
226 |
-
resp = client.send_gripper_value(
|
227 |
-
value = gripper_value,
|
228 |
-
speed = gripper_speed
|
229 |
-
)
|
230 |
-
resp["command"] = command
|
231 |
-
|
232 |
-
image_resp = client.get_camera()
|
233 |
-
image_ret = gr.Image(value=image_resp["image"], visible=True) if image_resp["success"] else gr.Image(visible=False)
|
234 |
-
return json.dumps(resp, indent=4), image_ret
|
235 |
-
elif command == "control/coords":
|
236 |
-
resp = client.send_coords(
|
237 |
-
coord_list = [xcoord, ycoord, zcoord, roll, pitch, yaw],
|
238 |
-
speed = coord_speed
|
239 |
-
)
|
240 |
-
resp["command"] = command
|
241 |
-
|
242 |
-
image_resp = client.get_camera()
|
243 |
-
image_ret = gr.Image(value=image_resp["image"], visible=True) if image_resp["success"] else gr.Image(visible=False)
|
244 |
-
return json.dumps(resp, indent=4), image_ret
|
245 |
-
|
246 |
-
def process_user_auth(command, user_id, gripper_value, gripper_speed, angle1, angle2, angle3, angle4,
|
247 |
-
angle5, angle6, angle_speed, xcoord, ycoord, zcoord, roll, pitch, yaw, coord_speed, output_image):
|
248 |
-
if queue_system.current_user is None:
|
249 |
-
queue_system.start_session(user_id)
|
250 |
-
queue_system.enqueue_user(user_id)
|
251 |
-
position, wait_time = queue_system.get_queue_info(user_id)
|
252 |
-
|
253 |
-
if position == 0:
|
254 |
-
result, response_image = handle_request(
|
255 |
-
command, gripper_value, gripper_speed, angle1, angle2, angle3, angle4,
|
256 |
-
angle5, angle6, angle_speed, xcoord, ycoord, zcoord, roll, pitch, yaw, coord_speed, output_image
|
257 |
-
)
|
258 |
-
remaining_time_msg = f"Your turn!\nTime remaining: {wait_time:.2f} seconds."
|
259 |
-
return result, response_image, remaining_time_msg
|
260 |
-
elif position is not None:
|
261 |
-
if position == 1:
|
262 |
-
wait_msg = f"You are next!\nWait time: {wait_time:.2f} seconds."
|
263 |
-
else:
|
264 |
-
wait_msg = f"There are {position - 1} people ahead of you in the queue.\nWait time: {wait_time:.2f} seconds."
|
265 |
-
return None, None, wait_msg
|
266 |
else:
|
267 |
-
return None, None,
|
268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
|
270 |
with gr.Blocks(css=CSS) as app:
|
271 |
gr.Markdown("# MyCobot 280pi MQTT Control Demo")
|
@@ -306,6 +251,8 @@ with gr.Blocks(css=CSS) as app:
|
|
306 |
with gr.Column(elem_id="col"):
|
307 |
gr.Markdown("## Angle Control")
|
308 |
gr.Markdown("Use this panel to control the joint angles of the cobot. Each angle corresponds to one of the 6 joints on the cobot.")
|
|
|
|
|
309 |
with gr.Row(elem_id="nogaprow"):
|
310 |
with gr.Column(elem_id="nogapcol"):
|
311 |
angle1 = gr.Slider(value=0.0, label="Angle 1", step=1.0, minimum=-168, maximum=168)
|
@@ -322,6 +269,8 @@ with gr.Blocks(css=CSS) as app:
|
|
322 |
with gr.Column(elem_id="col"):
|
323 |
gr.Markdown("## Coordinate Control")
|
324 |
gr.Markdown("Use this panel to control the joint coordinates of the cobot head. The angles are in [6-DoF format](https://en.wikipedia.org/wiki/Six_degrees_of_freedom).")
|
|
|
|
|
325 |
with gr.Row(elem_id="nogaprow"):
|
326 |
with gr.Column(elem_id="nogapcol"):
|
327 |
xcoord = gr.Slider(value=0.0, label="X coordinate", step=1.0, minimum=-350, maximum=350)
|
@@ -373,6 +322,24 @@ with gr.Blocks(css=CSS) as app:
|
|
373 |
inputs = [user_id, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords],
|
374 |
outputs = [response, status_text]
|
375 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
376 |
enter_queue_button.click(
|
377 |
enter_queue,
|
378 |
inputs = [user_id],
|
|
|
187 |
else:
|
188 |
return None, queue_status_msg
|
189 |
|
190 |
+
def set_coords_to_current(user_id):
|
191 |
+
to_execute, queue_status_msg = authenticate_user(user_id)
|
192 |
+
if to_execute:
|
193 |
+
resp, _ = query_coords(user_id)
|
194 |
+
resp = json.loads(resp)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
if not resp["success"]:
|
196 |
+
return None, None, None, None, None, None, queue_status_msg
|
197 |
+
return resp["coords"] + [queue_status_msg]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
else:
|
199 |
+
return None, None, None, None, None, None, queue_status_msg
|
200 |
|
201 |
+
def set_angles_to_current(user_id):
|
202 |
+
to_execute, queue_status_msg = authenticate_user(user_id)
|
203 |
+
if to_execute:
|
204 |
+
resp, _ = query_angles(user_id)
|
205 |
+
resp = json.loads(resp)
|
206 |
+
if not resp["success"]:
|
207 |
+
return None, None, None, None, None, None, queue_status_msg
|
208 |
+
return resp["angles"] + [queue_status_msg]
|
209 |
+
else:
|
210 |
+
return None, None, None, None, None, None, queue_status_msg
|
211 |
+
|
212 |
+
def reset():
|
213 |
+
return 0, 0, 0, 0, 0, 0, 50
|
214 |
|
215 |
with gr.Blocks(css=CSS) as app:
|
216 |
gr.Markdown("# MyCobot 280pi MQTT Control Demo")
|
|
|
251 |
with gr.Column(elem_id="col"):
|
252 |
gr.Markdown("## Angle Control")
|
253 |
gr.Markdown("Use this panel to control the joint angles of the cobot. Each angle corresponds to one of the 6 joints on the cobot.")
|
254 |
+
angle_set_button = gr.Button("Set to current angles")
|
255 |
+
reset_angle_button = gr.Button("Reset angles")
|
256 |
with gr.Row(elem_id="nogaprow"):
|
257 |
with gr.Column(elem_id="nogapcol"):
|
258 |
angle1 = gr.Slider(value=0.0, label="Angle 1", step=1.0, minimum=-168, maximum=168)
|
|
|
269 |
with gr.Column(elem_id="col"):
|
270 |
gr.Markdown("## Coordinate Control")
|
271 |
gr.Markdown("Use this panel to control the joint coordinates of the cobot head. The angles are in [6-DoF format](https://en.wikipedia.org/wiki/Six_degrees_of_freedom).")
|
272 |
+
coord_set_button = gr.Button("Set to current coords")
|
273 |
+
reset_coords_button = gr.Button("Reset coordinates")
|
274 |
with gr.Row(elem_id="nogaprow"):
|
275 |
with gr.Column(elem_id="nogapcol"):
|
276 |
xcoord = gr.Slider(value=0.0, label="X coordinate", step=1.0, minimum=-350, maximum=350)
|
|
|
322 |
inputs = [user_id, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords],
|
323 |
outputs = [response, status_text]
|
324 |
)
|
325 |
+
coord_set_button.click(
|
326 |
+
set_coords_to_current,
|
327 |
+
inputs = [user_id],
|
328 |
+
outputs = [xcoord, ycoord, zcoord, roll, pitch, yaw, status_text]
|
329 |
+
)
|
330 |
+
angle_set_button.click(
|
331 |
+
set_angles_to_current,
|
332 |
+
inputs = [user_id],
|
333 |
+
outputs = [angle1, angle2, angle3, angle4, angle5, angle6, status_text]
|
334 |
+
)
|
335 |
+
reset_angle_button.click(
|
336 |
+
reset,
|
337 |
+
outputs = [angle1, angle2, angle3, angle4, angle5, angle6, speed_angles]
|
338 |
+
)
|
339 |
+
reset_coords_button.click(
|
340 |
+
reset,
|
341 |
+
outputs = [xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords]
|
342 |
+
)
|
343 |
enter_queue_button.click(
|
344 |
enter_queue,
|
345 |
inputs = [user_id],
|