cobot280pi / app.py
j-woo's picture
updated youtube link
9e2f67d
raw
history blame
3.27 kB
import streamlit as st
from utils import *
from client import CobotController
st.title("MyCobot280 Pi control demo")
st.markdown("""
This app is a public demo of remote control of the MyCobot280 Pi through the MQTT Communication Protocol.
""")
cobot_stream_url = "https://www.youtube.com/live/fF4zEp6LSkg?si=wS0yuA-7dlhLk9ZD"
st.video(
cobot_stream_url
# Optionally enable autoplay which requires muting as browsers don't allow autoplay of unmuted video
# muted=True,
# autoplay=True
)
render_log_window()
user_id = get_user_id()
user, passwd, host, endpoint, port = get_credentials(False)
client = CobotController(user, passwd, host, port, endpoint, user_id)
# refresh_once()
st.markdown("## Commands")
commands = [
"query/angles",
"query/coords",
"query/gripper",
"query/camera",
"control/angles",
"control/coords",
"control/gripper"
]
selected = st.selectbox("Select command: ", commands, key="selected_command", disabled=False)
args = {}
command = None
with st.form("mqtt_form"):
if st.session_state.selected_command == "query/angles":
command = client.get_angles
elif st.session_state.selected_command == "query/coords":
command = client.get_coords
elif st.session_state.selected_command == "query/gripper":
command = client.get_gripper_value
elif st.session_state.selected_command == "query/camera":
quality = st.slider("Image quality", 1, 100, 100)
command = client.get_camera
args = {"quality": quality}
elif st.session_state.selected_command == "control/angles":
angle_1 = st.number_input("Angle 1", format="%.2f", step=5.0)
angle_2 = st.number_input("Angle 2", format="%.2f", step=5.0)
angle_3 = st.number_input("Angle 3", format="%.2f", step=5.0)
angle_4 = st.number_input("Angle 4", format="%.2f", step=5.0)
angle_5 = st.number_input("Angle 5", format="%.2f", step=5.0)
angle_6 = st.number_input("Angle 6", format="%.2f", step=5.0)
speed = st.slider("Speed", 1, 100, 50)
command = client.send_angles
args = {"angle_list": [angle_1, angle_2, angle_3, angle_4, angle_5, angle_6], "speed": speed}
elif st.session_state.selected_command == "control/coords":
x = st.number_input("x", format="%.2f", step=5.0)
y = st.number_input("y", format="%.2f", step=5.0)
z = st.number_input("z", format="%.2f", step=5.0)
rx = st.number_input("rx (Rotation x)", format="%.2f", step=5.0)
ry = st.number_input("ry (Rotation y)", format="%.2f", step=5.0)
rz = st.number_input("rz (Rotation z)", format="%.2f", step=5.0)
speed = st.slider("Speed", 1, 100, 50)
command = client.send_coords
args = {"coord_list": [x, y, z, rx, ry, rz], "speed": speed}
elif st.session_state.selected_command == "control/gripper":
gripper_value = st.slider("Gripper value", 1, 100, 50)
speed = st.slider("Speed", 1, 100, 50)
command = client.send_gripper_value
args = {"value": gripper_value, "speed": speed}
submitted = st.form_submit_button("Send Command")
if submitted:
response = command(**args)
st.markdown("### Response")
if response is not None:
if "image" in response:
image = response.pop("image")
st.write(response)
st.image(image, caption="Cobot camera view")
else:
st.write(response)
else:
st.write("Timed out waiting for response. Is the on-device server running?")