gursi26 commited on
Commit
d0270ec
·
1 Parent(s): 71be213

fixed requirements, added queue length and enter queue button, added valid ranges for angles and coords

Browse files
Files changed (2) hide show
  1. app.py +35 -14
  2. requirements.txt +0 -49
app.py CHANGED
@@ -61,6 +61,9 @@ class QueueSystem:
61
 
62
  queue_system = QueueSystem()
63
 
 
 
 
64
  # Background timer thread to end session after SESSION_TIME
65
  def background_timer():
66
  while True:
@@ -96,7 +99,9 @@ def handle_request(
96
  command, gripper_value, gripper_speed, angle1, angle2, angle3, angle4,
97
  angle5, angle6, angle_speed, xcoord, ycoord, zcoord, roll, pitch, yaw, coord_speed,
98
  ):
99
- if command == "query/angles":
 
 
100
  resp = client.get_angles()
101
  resp["command"] = command
102
  return json.dumps(resp, indent=4), gr.Image(visible=False)
@@ -168,13 +173,15 @@ with gr.Blocks(css=CSS) as app:
168
  with gr.Row():
169
  with gr.Column():
170
  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!")
 
171
  with gr.Column():
172
- status_text = gr.Textbox(label="Queue status", value="", interactive=False, max_lines=2)
173
 
174
  with gr.Row():
175
  # QUERY PANEL
176
  with gr.Column(elem_id="col"):
177
  gr.Markdown("## Query")
 
178
  angle_query_button = gr.Button("Query Angles")
179
  coord_query_button = gr.Button("Query Coordinates")
180
  gripper_query_button = gr.Button("Query Gripper state")
@@ -183,6 +190,7 @@ with gr.Blocks(css=CSS) as app:
183
  # GRIPPER PANEL
184
  with gr.Column(elem_id="col"):
185
  gr.Markdown("## Gripper Control")
 
186
  gripper_value = gr.Slider(minimum=0.0, maximum=100.0, step=1.0, label="Gripper value")
187
  speed_gripper = gr.Slider(value=50.0, minimum=0.0, maximum=100.0, step=1.0, label="Movement speed")
188
  gripper_control_button = gr.Button("Send gripper command")
@@ -191,30 +199,32 @@ with gr.Blocks(css=CSS) as app:
191
  # ANGLE PANEL
192
  with gr.Column(elem_id="col"):
193
  gr.Markdown("## Angle Control")
 
194
  with gr.Row(elem_id="nogaprow"):
195
  with gr.Column(elem_id="nogapcol"):
196
- angle1 = gr.Number(value=0.0, label="Angle 1", step=5.0)
197
- angle3 = gr.Number(value=0.0, label="Angle 3", step=5.0)
198
- angle5 = gr.Number(value=0.0, label="Angle 5", step=5.0)
199
  with gr.Column(elem_id="nogapcol"):
200
- angle2 = gr.Number(value=0.0, label="Angle 2", step=5.0)
201
- angle4 = gr.Number(value=0.0, label="Angle 4", step=5.0)
202
- angle6 = gr.Number(value=0.0, label="Angle 6", step=5.0)
203
  speed_angles = gr.Slider(value=50.0, minimum=0.0, maximum=100.0, step=1.0, label="Movement speed")
204
  angle_control_button = gr.Button("Send angle command")
205
 
206
  # COORD PANEL
207
  with gr.Column(elem_id="col"):
208
  gr.Markdown("## Coordinate Control")
 
209
  with gr.Row(elem_id="nogaprow"):
210
  with gr.Column(elem_id="nogapcol"):
211
- xcoord = gr.Number(value=0.0, label="X coordinate", step=5.0)
212
- ycoord = gr.Number(value=0.0, label="Y coordinate", step=5.0)
213
- zcoord = gr.Number(value=0.0, label="Z coordinate", step=5.0)
214
  with gr.Column(elem_id="nogapcol"):
215
- roll = gr.Number(value=0.0, label="Roll", step=5.0)
216
- pitch = gr.Number(value=0.0, label="Pitch", step=5.0)
217
- yaw = gr.Number(value=0.0, label="Yaw", step=5.0)
218
  speed_coords = gr.Slider(value=50.0, minimum=0.0, maximum=100.0, step=1.0, label="Movement speed")
219
  coord_control_button = gr.Button("Send coordinate command")
220
 
@@ -264,11 +274,22 @@ with gr.Blocks(css=CSS) as app:
264
  angle5, angle6, speed_angles, xcoord, ycoord, zcoord, roll, pitch, yaw, speed_coords],
265
  outputs = [response, response_image, status_text]
266
  )
 
 
 
 
 
 
267
 
268
  app.load(
269
  namesgenerator.get_random_name,
270
  outputs=[user_id]
271
  )
272
 
 
 
 
 
 
273
  app.queue(default_concurrency_limit=1, max_size=100)
274
  app.launch()
 
61
 
62
  queue_system = QueueSystem()
63
 
64
+ def queue_size():
65
+ return f"There are {len(queue_system.queue)} people in the queue."
66
+
67
  # Background timer thread to end session after SESSION_TIME
68
  def background_timer():
69
  while True:
 
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), gr.Image(visible=False)
 
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("Enter queue")
177
  with gr.Column():
178
+ status_text = gr.Textbox(label="Queue status", value="", interactive=False, lines=5)
179
 
180
  with gr.Row():
181
  # QUERY PANEL
182
  with gr.Column(elem_id="col"):
183
  gr.Markdown("## Query")
184
+ gr.Markdown("Use buttons on this panel to query the current status of the cobot, including information like joint angles, coordinates, gripper state and what the onboard camera sees.")
185
  angle_query_button = gr.Button("Query Angles")
186
  coord_query_button = gr.Button("Query Coordinates")
187
  gripper_query_button = gr.Button("Query Gripper state")
 
190
  # GRIPPER PANEL
191
  with gr.Column(elem_id="col"):
192
  gr.Markdown("## Gripper Control")
193
+ gr.Markdown("Use this panel to control the gripper of the cobot.")
194
  gripper_value = gr.Slider(minimum=0.0, maximum=100.0, step=1.0, label="Gripper value")
195
  speed_gripper = gr.Slider(value=50.0, minimum=0.0, maximum=100.0, step=1.0, label="Movement speed")
196
  gripper_control_button = gr.Button("Send gripper command")
 
199
  # ANGLE PANEL
200
  with gr.Column(elem_id="col"):
201
  gr.Markdown("## Angle Control")
202
+ 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.")
203
  with gr.Row(elem_id="nogaprow"):
204
  with gr.Column(elem_id="nogapcol"):
205
+ angle1 = gr.Slider(value=0.0, label="Angle 1", step=1.0, minimum=-168, maximum=168)
206
+ angle3 = gr.Slider(value=0.0, label="Angle 3", step=1.0, minimum=-135, maximum=135)
207
+ angle5 = gr.Slider(value=0.0, label="Angle 5", step=1.0, minimum=-150, maximum=150)
208
  with gr.Column(elem_id="nogapcol"):
209
+ angle2 = gr.Slider(value=0.0, label="Angle 2", step=1.0, minimum=-145, maximum=145)
210
+ angle4 = gr.Slider(value=0.0, label="Angle 4", step=1.0, minimum=-165, maximum=165)
211
+ angle6 = gr.Slider(value=0.0, label="Angle 6", step=1.0, minimum=-180, maximum=180)
212
  speed_angles = gr.Slider(value=50.0, minimum=0.0, maximum=100.0, step=1.0, label="Movement speed")
213
  angle_control_button = gr.Button("Send angle command")
214
 
215
  # COORD PANEL
216
  with gr.Column(elem_id="col"):
217
  gr.Markdown("## Coordinate Control")
218
+ 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).")
219
  with gr.Row(elem_id="nogaprow"):
220
  with gr.Column(elem_id="nogapcol"):
221
+ xcoord = gr.Slider(value=0.0, label="X coordinate", step=1.0, minimum=-350, maximum=350)
222
+ ycoord = gr.Slider(value=0.0, label="Y coordinate", step=1.0, minimum=-350, maximum=350)
223
+ zcoord = gr.Slider(value=0.0, label="Z coordinate", step=1.0, minimum=-70, maximum=523)
224
  with gr.Column(elem_id="nogapcol"):
225
+ roll = gr.Slider(value=0.0, label="Roll", step=1.0, minimum=-180, maximum=180)
226
+ pitch = gr.Slider(value=0.0, label="Pitch", step=1.0, minimum=-180, maximum=180)
227
+ yaw = gr.Slider(value=0.0, label="Yaw", step=1.0, minimum=-180, maximum=180)
228
  speed_coords = gr.Slider(value=50.0, minimum=0.0, maximum=100.0, step=1.0, label="Movement speed")
229
  coord_control_button = gr.Button("Send coordinate command")
230
 
 
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
 
284
  app.load(
285
  namesgenerator.get_random_name,
286
  outputs=[user_id]
287
  )
288
 
289
+ app.load(
290
+ queue_size,
291
+ outputs=[status_text]
292
+ )
293
+
294
  app.queue(default_concurrency_limit=1, max_size=100)
295
  app.launch()
requirements.txt CHANGED
@@ -1,53 +1,4 @@
1
- aiofiles==23.2.1
2
- annotated-types==0.7.0
3
- anyio==4.6.2.post1
4
- certifi==2024.8.30
5
- charset-normalizer==3.4.0
6
- click==8.1.7
7
- fastapi==0.115.3
8
- ffmpy==0.4.0
9
- filelock==3.16.1
10
- fsspec==2024.10.0
11
  gradio==5.4.0
12
- gradio_client==1.4.2
13
- h11==0.14.0
14
- httpcore==1.0.6
15
- httpx==0.27.2
16
- huggingface-hub==0.26.1
17
- idna==3.10
18
- Jinja2==3.1.4
19
- markdown-it-py==3.0.0
20
- MarkupSafe==2.1.5
21
- mdurl==0.1.2
22
- numpy==2.1.2
23
- orjson==3.10.10
24
- packaging==24.1
25
  paho-mqtt==2.1.0
26
- pandas==2.2.3
27
  pillow==11.0.0
28
- pydantic==2.9.2
29
- pydantic_core==2.23.4
30
- pydub==0.25.1
31
- Pygments==2.18.0
32
- python-dateutil==2.9.0.post0
33
- python-multipart==0.0.12
34
- pytz==2024.2
35
- PyYAML==6.0.2
36
- requests==2.32.3
37
- rich==13.9.3
38
- ruff==0.7.1
39
- safehttpx==0.1.1
40
- semantic-version==2.10.0
41
- shellingham==1.5.4
42
- six==1.16.0
43
- sniffio==1.3.1
44
- starlette==0.41.0
45
- tomlkit==0.12.0
46
- tqdm==4.66.5
47
- typer==0.12.5
48
- typing_extensions==4.12.2
49
- tzdata==2024.2
50
- urllib3==2.2.3
51
- uvicorn==0.32.0
52
- websockets==12.0
53
  namesgenerator==0.3
 
 
 
 
 
 
 
 
 
 
 
1
  gradio==5.4.0
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  paho-mqtt==2.1.0
 
3
  pillow==11.0.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  namesgenerator==0.3