diff --git a/integration/integrate.py b/integration/integrate.py index 03f4c133717b49e9a6af05596a792ee56d7a881d..6d69a360b540c9fb825fca05adbcdb9926aa5e02 100644 --- a/integration/integrate.py +++ b/integration/integrate.py @@ -2,7 +2,7 @@ import tkinter as tk from tkinter import ttk from matplotlib.pyplot import Figure from vpython import * -from time import sleep, time +from time import time import serial from math import atan2, asin, cos, sin @@ -55,10 +55,9 @@ class Interface: label1 = ttk.Label(frame2, text="If IMU is connected to the laptop please click the Connect button", wraplength=width / 2) label1.place(relx=0.5, rely=0.9, anchor='center') - label2 = ttk.Label(frame2, text="Port: None ") - label2.place(relx=0.35, rely=0.8, anchor='center') + self.label2 = ttk.Label(frame2, text="Port: None ") + self.label2.place(relx=0.35, rely=0.8, anchor='center') frame2.update_idletasks() - #self._initialise_IUM() # Second row, two sections frame3 = ttk.Frame(popup, borderwidth=1, relief="solid",width=width/3,height=height/2) @@ -90,23 +89,22 @@ class Interface: def IMU_Connect(self): try: + self._iMU_isConnected=True self.arduino = serial.Serial('COM6', 115200, timeout=1) column_limit = 9 - label2 = ttk.Label(frame2, text="Port: COM6 ") - label2.place(relx=0.35, rely=0.8, anchor='center') + self.label2 = ttk.Label(frame2, text="Port: COM6 ") + self.label2.place(relx=0.35, rely=0.8, anchor='center') print("Connected to IMU") except serial.SerialException: print("IMU is not connected") return sleep(1) - # Conversions - toRad = 2 * np.pi / 360 - toDeg = 1 / toRad - - scene.range = 5 - - scene.forward = vector(-1, -1, -1) + scene.range = 5 # 修改场景的范围为10 + scene.forward = vector(-1, -1, -1) # 保持视角不变 + scene.width = 300 # 修改场景的宽度为800 + scene.height = 300 # 修改场景的高度为800 + scene.center = vector(0, 0, 0) # 将场景中心位置调整为 (0, 0, 0) scene.width = 600 scene.height = 600 @@ -122,7 +120,7 @@ class Interface: last_print_time = time() try: - while True: + while (self._iMU_isConnected==True): while self.arduino.inWaiting() == 0: pass @@ -174,6 +172,7 @@ class Interface: print("Disconnected from IMU") def IMU_disconnect(self): + self._iMU_isConnected = False if self.arduino and self.arduino.is_open: self.arduino.close() print("IMU disconnected") @@ -183,9 +182,9 @@ class Interface: def EMG_Connect(self): try: - # self.arduino = serial.Serial('COM5', 115200, timeout=1) - label2 = ttk.Label(frame3, text="Port: COM5 ") - label2.place(relx=0.35, rely=0.8, anchor='e') + self._EMG_isConnected = True + self.label2 = ttk.Label(frame3, text="Port: COM5 ") + self.label2.place(relx=0.35, rely=0.8, anchor='e') label_EMG_title = ttk.Label(frame3, text="Auto Calibralian",font=("Helvetica", 16)) label_EMG_title.place(relx=0.5, rely=0.1, anchor='center') label_EMG_Gesture = ttk.Label(frame3, text="Gesture :", font=("Helvetica", 13)) @@ -199,20 +198,20 @@ class Interface: return def EMG_disconnect(self): - if self._serial_data.configure(port='COM5', baudrate=9600, timeout=1): + self._EMG_isConnected = False + if self._serial_data.connected==True: self._serial_data.disconnect() print("EMG disconnected") def start_data_collection(self): print("Starting EMG data collection...") try: - while True: + while (self._EMG_isConnected==True): emg_data=self._serial_data.read() if emg_data is not None: print(f"EMG Value 1: {emg_data[0]}, EMG Value 2: {emg_data[1]}") else: print("Failed to read EMG data") - time.sleep(0.1) # 控制读取频率 except KeyboardInterrupt: print("Stopping EMG data collection.")