2Reads data from a serial port and displays it in real-time using matplotlib.
3Make sure to set COM_PORT to the correct value before running.
7from rendering
import PointsInSpace
16 parity=serial.PARITY_NONE,
17 stopbits=serial.STOPBITS_ONE,
18 bytesize=serial.EIGHTBITS,
22print(
"Connected to: " + ser.portstr)
26joint_0_mirror_list = []
27joint_1_mirror_list = []
37pp.register_plot(
"connected", alpha=0.4)
38pp.register_plot(
"mirror", alpha=0.4)
39pp.register_plot(
"torque")
44 bytes_to_read = ser.in_waiting
45 if bytes_to_read < MIN_MESSAGE_BYTES:
47 line = ser.read(bytes_to_read).decode(
"utf-8")
48 segments = line.split()
54 return float(segments[segments.index(f
"{label}:") + 1])
71 joint_0_list.append(joint_0)
72 joint_1_list.append(joint_1)
73 joint_0_mirror_list.append(joint_0_mirror)
74 joint_1_mirror_list.append(joint_1_mirror)
75 except Exception
as e:
79 if len(joint_0_list) > TRAILING_POINTS:
82 joint_0_mirror_list.pop(0)
83 joint_1_mirror_list.pop(0)
87 pp.draw_points(
"connected", joint_0_list, joint_1_list)
88 pp.draw_points(
"mirror", joint_0_mirror_list, joint_1_mirror_list)
89 pp.draw_points(
"torque", joint_0_torque, joint_1_torque)
91 except Exception
as e:
94 print(
"Closed connection")
98print(
"Closed connection")