Spaces:
Sleeping
Sleeping
quickfix
Browse files
app.py
CHANGED
@@ -5,93 +5,85 @@ from client import CobotController
|
|
5 |
st.title("MyCobot280 Pi control demo")
|
6 |
|
7 |
st.markdown("""
|
8 |
-
|
9 |
""")
|
10 |
|
11 |
cobot_stream_url = "https://youtube.com/live/w7zn-Sk3pG0?feature=share"
|
12 |
st.video(
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
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 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
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 |
-
|
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 |
-
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 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
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?")
|