File size: 3,267 Bytes
be196d0
2554ae8
ef09ab9
0078aeb
758dfad
 
 
e11c5af
758dfad
 
9e2f67d
758dfad
e11c5af
 
 
 
758dfad
 
2182a6b
ef09ab9
4be4378
 
705d0f3
758dfad
 
 
 
e11c5af
 
 
 
 
 
 
758dfad
 
 
 
 
 
e11c5af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
758dfad
e11c5af
 
 
 
 
 
 
 
 
 
 
 
6c01cfd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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?")