diff --git a/integration/Window2.py b/integration/Window2.py index fc88a66605b3911c38ceba07ef4f9ec42791e321..8d1dc1a29bd438dac4f64300ee08de3f77a3e09d 100644 --- a/integration/Window2.py +++ b/integration/Window2.py @@ -16,7 +16,7 @@ from time import sleep, time class Window: def __init__(self, root): - self.input_port='COM5' + self.input_port='COM9' self.root = root self.root.title("Integration") self.ports = [port.device for port in serial.tools.list_ports.comports()] @@ -203,11 +203,11 @@ class Window: wraplength=self.width / 2) self.label1.place(relx=0.5, rely=0.9, anchor='center') # Add a button to start data transmission - self.start_button = tk.Button(self.frame3, text="connect", command=self.start_EMG_data_transmission) - self.start_button.place(relx=0.45, rely=0.8, anchor='center') + #self.start_button = tk.Button(self.frame3, text="connect", command=self.start_EMG_data_transmission) + #self.start_button.place(relx=0.45, rely=0.8, anchor='center') #self.start_button = tk.Button(self.frame3, text="Disconnect", command=self.disconnect) - self.start_button.place(relx=0.7, rely=0.8, anchor='center') + #self.start_button.place(relx=0.7, rely=0.8, anchor='center') else: print("EMG is not connected") @@ -313,26 +313,6 @@ class Window: self.arduino.close() self.arduino = None - def collect_emg_data(self): - column_limit = 6 - emg_data = [] - start_time = time.time() - while (self.arduino.inWaiting() > 0): - data = self.arduino.readline().decode().strip().split(',') - if len(data) == column_limit: - try: - emg1 = float(data[0]) - emg2 = float(data[1]) - #print("Emg1: ",emg1) - #print("Emg2: ",emg2) - emg_data.append((emg1, emg2)) - except ValueError: - continue - if emg_data: - return np.mean(emg_data, axis=0) - else: - return np.array([0.0, 0.0]) # Default value if no data is collected - @@ -610,7 +590,7 @@ class WelcomeWindow: class trainingInterface: def __init__(self, root): - self.input_port='COM5' + self.input_port='COM9' self.root = root self.root.title("preparation Interface") self.width = 1000 @@ -892,7 +872,7 @@ class Algorithm: class gameScreen: def __init__(self, root): - self.input_port='COM5' + self.input_port='COM9' self.root = root self.root.title("game Interface") self.width = 1000 @@ -1142,10 +1122,9 @@ class gameScreen: self.roll_label.config( text="roll is : "+str(roll)) self.pitch_label.config(text="pitch is : "+str(pitch)) self.yaw_label.config(text="yaw is : "+str(yaw)) - #print(roll, pitch, yaw) + print(roll, pitch, yaw) current_time = time() if current_time - self.last_print_time >= 0.01: - print(f"roll is: {roll}") print(f"last roll is: {self.last_averageRoll}") differ_roll = self.last_averageRoll - roll @@ -1153,8 +1132,10 @@ class gameScreen: CalculatedAngle = differ_roll * 3000 / 2.5 print(f"CalculatedAngle is: {CalculatedAngle}") if (differ_roll) > 0: + print("send_command_to_unity"+(f"Command : down {CalculatedAngle}")) self.send_command_to_unity(f"Command : down {CalculatedAngle}") if (differ_roll) < 0: + print("send_command_to_unity" + (f"Command : down {CalculatedAngle}")) self.send_command_to_unity(f"Command : up {-CalculatedAngle}") if (yaw < 0): @@ -1167,8 +1148,10 @@ class gameScreen: yawAngle = differ_yaw * 90 / 2 print(f"yawAngle is: {yawAngle}") if (differ_yaw) < 0: + print("send_command_to_unity"+(f"Command : back {-yawAngle}")) self.send_command_to_unity(f"Command : back {-yawAngle}") if (differ_yaw) > 0: + print("send_command_to_unity" + (f"Command : roll {-yawAngle}")) self.send_command_to_unity(f"Command : roll {yawAngle}") self.last_print_time = current_time