gursi26 commited on
Commit
e11c5af
·
1 Parent(s): 758dfad
Files changed (1) hide show
  1. app.py +61 -69
app.py CHANGED
@@ -5,93 +5,85 @@ from client import CobotController
5
  st.title("MyCobot280 Pi control demo")
6
 
7
  st.markdown("""
8
- This app is a public demo of remote control of the MyCobot280 Pi through the MQTT Communication Protocol.
9
  """)
10
 
11
  cobot_stream_url = "https://youtube.com/live/w7zn-Sk3pG0?feature=share"
12
  st.video(
13
- cobot_stream_url
14
- # Optionally enable autoplay which requires muting as browsers don't allow autoplay of unmuted video
15
- # muted=True,
16
- # autoplay=True
17
  )
18
 
19
  render_log_window()
20
 
21
  user_id = get_user_id()
22
  user, passwd, host, endpoint, port = get_credentials(False)
23
- client = CobotController(user, passwd, host, port, endpoint, user_id)
24
  # refresh_once()
25
 
26
  st.markdown("## Commands")
27
  commands = [
28
- "query/angles",
29
- "query/coords",
30
- "query/gripper",
31
- "query/camera",
32
- "control/angles",
33
- "control/coords",
34
- "control/gripper"
35
  ]
36
  selected = st.selectbox("Select command: ", commands, key="selected_command", disabled=False)
37
 
38
  args = {}
39
  command = None
40
  with st.form("mqtt_form"):
41
- if st.session_state.selected_command == "query/angles":
42
- command = client.get_angles
43
- elif st.session_state.selected_command == "query/coords":
44
- command = client.get_coords
45
- elif st.session_state.selected_command == "query/gripper":
46
- command = client.get_gripper_value
47
- elif st.session_state.selected_command == "query/camera":
48
- quality = st.slider("Image quality", 1, 100, 50)
49
- command = client.get_camera
50
- args = {"quality": quality}
51
- elif st.session_state.selected_command == "control/angles":
52
- col1, col2, col3 = st.columns(3)
53
- with col1:
54
- angle_1 = st.number_input("Angle 1", format="%.2f", step=5.0)
55
- angle_4 = st.number_input("Angle 4", format="%.2f", step=5.0)
56
- with col2:
57
- angle_2 = st.number_input("Angle 2", format="%.2f", step=5.0)
58
- angle_5 = st.number_input("Angle 5", format="%.2f", step=5.0)
59
- with col3:
60
- angle_3 = st.number_input("Angle 3", format="%.2f", step=5.0)
61
- angle_6 = st.number_input("Angle 6", format="%.2f", step=5.0)
62
- speed = st.slider("Speed", 1, 100, 50)
63
- command = client.send_angles
64
- args = {"angle_list": [angle_1, angle_2, angle_3, angle_4, angle_5, angle_6], "speed": speed}
65
- elif st.session_state.selected_command == "control/coords":
66
- col1, col2, col3 = st.columns(3)
67
- with col1:
68
- x = st.number_input("x", format="%.2f", step=5.0)
69
- rx = st.number_input("rx (Rotation x)", format="%.2f", step=5.0)
70
- with col2:
71
- y = st.number_input("y", format="%.2f", step=5.0)
72
- ry = st.number_input("ry (Rotation y)", format="%.2f", step=5.0)
73
- with col3:
74
- z = st.number_input("z", format="%.2f", step=5.0)
75
- rz = st.number_input("rz (Rotation z)", format="%.2f", step=5.0)
76
- speed = st.slider("Speed", 1, 100, 50)
77
- command = client.send_coords
78
- args = {"coord_list": [x, y, z, rx, ry, rz], "speed": speed}
79
- elif st.session_state.selected_command == "control/gripper":
80
- gripper_value = st.slider("Gripper value", 1, 100, 50)
81
- speed = st.slider("Speed", 1, 100, 50)
82
- command = client.send_gripper_value
83
- args = {"value": gripper_value, "speed": speed}
84
 
85
- submitted = st.form_submit_button("Send Command")
86
- if submitted:
87
- response = command(**args)
88
- st.markdown("### Response")
89
- if response is not None:
90
- if "image" in response:
91
- image = response.pop("image")
92
- st.write(response)
93
- st.image(image, caption="Cobot camera view")
94
- else:
95
- st.write(response)
96
- else:
97
- st.write("Timed out waiting for response. Is the on-device server running?")
 
5
  st.title("MyCobot280 Pi control demo")
6
 
7
  st.markdown("""
8
+ This app is a public demo of remote control of the MyCobot280 Pi through the MQTT Communication Protocol.
9
  """)
10
 
11
  cobot_stream_url = "https://youtube.com/live/w7zn-Sk3pG0?feature=share"
12
  st.video(
13
+ cobot_stream_url
14
+ # Optionally enable autoplay which requires muting as browsers don't allow autoplay of unmuted video
15
+ # muted=True,
16
+ # autoplay=True
17
  )
18
 
19
  render_log_window()
20
 
21
  user_id = get_user_id()
22
  user, passwd, host, endpoint, port = get_credentials(False)
23
+ # client = CobotController(user, passwd, host, port, endpoint, user_id)
24
  # refresh_once()
25
 
26
  st.markdown("## Commands")
27
  commands = [
28
+ "query/angles",
29
+ "query/coords",
30
+ "query/gripper",
31
+ "query/camera",
32
+ "control/angles",
33
+ "control/coords",
34
+ "control/gripper"
35
  ]
36
  selected = st.selectbox("Select command: ", commands, key="selected_command", disabled=False)
37
 
38
  args = {}
39
  command = None
40
  with st.form("mqtt_form"):
41
+ if st.session_state.selected_command == "query/angles":
42
+ command = client.get_angles
43
+ elif st.session_state.selected_command == "query/coords":
44
+ command = client.get_coords
45
+ elif st.session_state.selected_command == "query/gripper":
46
+ command = client.get_gripper_value
47
+ elif st.session_state.selected_command == "query/camera":
48
+ quality = st.slider("Image quality", 1, 100, 100)
49
+ command = client.get_camera
50
+ args = {"quality": quality}
51
+ elif st.session_state.selected_command == "control/angles":
52
+ angle_1 = st.number_input("Angle 1", format="%.2f", step=5.0)
53
+ angle_2 = st.number_input("Angle 2", format="%.2f", step=5.0)
54
+ angle_3 = st.number_input("Angle 3", format="%.2f", step=5.0)
55
+ angle_4 = st.number_input("Angle 4", format="%.2f", step=5.0)
56
+ angle_5 = st.number_input("Angle 5", format="%.2f", step=5.0)
57
+ angle_6 = st.number_input("Angle 6", format="%.2f", step=5.0)
58
+ speed = st.slider("Speed", 1, 100, 50)
59
+ command = client.send_angles
60
+ args = {"angle_list": [angle_1, angle_2, angle_3, angle_4, angle_5, angle_6], "speed": speed}
61
+ elif st.session_state.selected_command == "control/coords":
62
+ x = st.number_input("x", format="%.2f", step=5.0)
63
+ y = st.number_input("y", format="%.2f", step=5.0)
64
+ z = st.number_input("z", format="%.2f", step=5.0)
65
+ rx = st.number_input("rx (Rotation x)", format="%.2f", step=5.0)
66
+ ry = st.number_input("ry (Rotation y)", format="%.2f", step=5.0)
67
+ rz = st.number_input("rz (Rotation z)", format="%.2f", step=5.0)
68
+ speed = st.slider("Speed", 1, 100, 50)
69
+ command = client.send_coords
70
+ args = {"coord_list": [x, y, z, rx, ry, rz], "speed": speed}
71
+ elif st.session_state.selected_command == "control/gripper":
72
+ gripper_value = st.slider("Gripper value", 1, 100, 50)
73
+ speed = st.slider("Speed", 1, 100, 50)
74
+ command = client.send_gripper_value
75
+ args = {"value": gripper_value, "speed": speed}
 
 
 
 
 
 
 
 
76
 
77
+ submitted = st.form_submit_button("Send Command")
78
+ if submitted:
79
+ response = command(**args)
80
+ st.markdown("### Response")
81
+ if response is not None:
82
+ if "image" in response:
83
+ image = response.pop("image")
84
+ st.write(response)
85
+ st.image(image, caption="Cobot camera view")
86
+ else:
87
+ st.write(response)
88
+ else:
89
+ st.write("Timed out waiting for response. Is the on-device server running?")