def clickMethod_dispLess(self): """Method to """ try: MotorPI.move_rel(-self.step_disp) except: QMessageBox.about(self, "WARNING:", "The motor is not connected")
def connectionCall(self): """Function to connect to pump, motor and arduino""" try: Arduino.connect() except: print("arduino connection problem") if Arduino.isconnected(): self.label_ard.setPixmap(self.pixmap_1) else: self.label_ard.setPixmap(self.pixmap_0) try: Pump_seringe.connect() except: print("pump connection problem") if Pump_seringe.isconnected(): self.label_pum.setPixmap(self.pixmap_1) else: self.label_pum.setPixmap(self.pixmap_0) try: MotorPI.connect() except: print("motor connection problem") if MotorPI.isconnected(): self.label_mot.setPixmap(self.pixmap_1) else: self.label_mot.setPixmap(self.pixmap_0)
def clickMethodStop(self): """Method to stop the acquisition""" self.running = False self.pump_run = False self.button_pause.setIcon( QIcon( resource_path('tension_inflation/resources/button_pause.png'))) self.inibutton.setIcon( QIcon( resource_path( 'tension_inflation/resources/button_start_push.png')) ) #Change the button's icon by the resources self.positioning_phase() self.label_state.setText(" Stopped ") self.label_state.setStyleSheet("background-color: red;") self.label_phase.setText("Phase: Positioning") self.pause = False try: self.CommandThread.stop() except: print("problem CommandThread.stop()") MotorPI.stop() Pump_seringe.stop() QMessageBox.about(self, "Test", "Positionning phase")
def TestConnectionCall(self): ####################################################### ## CONNECTION WITH ARDUINO/PUMP/MOTOR msg = "" try: Arduino.connect() except: print("Can't connect to arduino") if Arduino.isconnected(): msg += "Arduino: Connected\n" else: msg += "Arduino: Not connected\n" try: Pump_seringe.connect() except: print("Can't connect to pump") if Pump_seringe.isconnected(): msg += "Pump: Connected\n" else: msg += "Pump: Not connected\n" try: MotorPI.connect() #MotorPI.ref() except: print("Can't connect to motor") if MotorPI.isconnected(): msg += "Motor: Connected\n" else: msg += "Motor: Not connected\n" QMessageBox.about(self, "Connections", msg)
def VelMotorCall(self): """Change the motor rotation speed""" text, okPressed = QInputDialog.getText(self, "Set motor speed", "Motor speed (mm/min) :", QLineEdit.Normal, "") if okPressed and text != '': try: MotorPI.vel(float(text)) except: QMessageBox.about(self, "WARNING:", "The motor is not connected")
def clickMethod_disp0(self): """Method to """ msg = QMessageBox.question(self, "Come back to the base", "Are u sure ?", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) if msg == QMessageBox.Yes: try: MotorPI.move_rel(-round((self.d - self.tare_disp), 2)) except: QMessageBox.about(self, "WARNING:", "The motor is not connected")
def stop(self): """ Stop the thread """ self.pause = True try: MotorPI.stop() except: print("CommandThread motor") try: Pump_seringe.stop() except: print("CommandThread pump")
def myExitHandler(): """Function that run when the window is stopped""" try: MotorPI.stop() except: pass try: Pump_seringe.stop() except: pass try: controller.IniWindow.timer_ini.stop() except: pass
def clickMethodTare_disp(self): """Method to tare displacement""" reply = QMessageBox.question( self, 'To Tare or not to tare, that is the question !', 'Are you sure ?', QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: self.tare_disp = MotorPI.motor_pos() print("Disp tare")
def DisplacementControl(self): #Cycles first if self.NcycleF != 0: cycle = 0 while cycle < self.NcycleF: MotorPI.move_rel(self.dF_target) while MotorPI.ismoving(): #print("motor running") time.sleep(0.1) if self.pause == True: return MotorPI.move_rel(-self.dF_target) while MotorPI.ismoving(): time.sleep(0.1) cycle = cycle + 1 if self.pause: return MotorPI.move_rel(self.dF_target) while MotorPI.ismoving(): time.sleep(0.1)
def passCall(self): """Function to pass directly to the test window""" self.connectionCall() #Verify the connection #Show a message with the current connection states msg = "" if Arduino.isconnected(): msg += "Arduino: Connected\n" else: msg += "Arduino: Not connected\n" if Pump_seringe.isconnected(): msg += "Pump: Connected\n" else: msg += "Pump: Not connected\n" if MotorPI.isconnected(): msg += "Motor: Connected\n" else: msg += "Motor: Not connected\n" msg = QMessageBox.question(self, "Continue ?", msg + "\n\nDo you want to continue ?", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) if msg == QMessageBox.No: return QMessageBox.about( self, "Acquisition", "Initialisation finished\n\nStart of the acquisition") self.switch_window.emit( self.path) #Send the signal to change window to test window self.close() #Close the initialisation window
def LoadControl(self): self.update_thread.emit() while self.F == False: time.sleep(0.1) while self.F < self.dF_target * 0.9 or self.F > self.dF_target * 1.1: self.update_thread.emit() if self.F < self.dF_target * 0.9: MotorPI.move_rel(0.2) while MotorPI.ismoving(): time.sleep(0.1) if self.F > self.dF_target * 1.1: MotorPI.move_rel(-0.2) while MotorPI.ismoving(): time.sleep(0.1) self.update_thread.emit() time.sleep(0.5)
def ini_processCall(self): """Function that initialise: start the motor to find upper and lower boundaries""" #Button check not more than one time if self.ini_start: return self.ini_start = True #Define the progress bar self.completed = 0 ####################################################### # Define the connections with devices self.label.setText("Connecting...") self.repaint() time.sleep(1) ####################################################### ## CONNECTION WITH ARDUINO/PUMP/MOTOR self.connectionCall() msg = "" if Arduino.isconnected(): msg += "Arduino: Connected\n" else: msg += "Arduino: Not connected\n" if Pump_seringe.isconnected(): msg += "Pump: Connected\n" else: msg += "Pump: Not connected\n" if MotorPI.isconnected(): msg += "Motor: Connected\n" else: msg += "Motor: Not connected\n" QMessageBox.about(self, "Connections", msg) if Arduino.isconnected() == False or MotorPI.isconnected( ) == False or Pump_seringe.isconnected() == False: print('Connection problem') self.ini_start = False self.label.setText("Waiting") return secu = 0 test = 0 while test == 0: try: [secu, ori, F, P] = read_arduino() test = 1 except: print("read step1 problem") if secu == 1: QMessageBox.about(self, "Problem", "Security button activated !") self.completed = 0 self.ini_start = False self.timer_ini.stop() return msg = QMessageBox.question( self, "Continue ?", "Do you want to start the initialisation ?", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) if msg == QMessageBox.No: self.ini_start = False return ####################################################### ## SEARCH FOR BOUNDARIES self.completed = 0 self.progress.setValue(self.completed) self.label.setText("Searching for origin") self.repaint() #First boundary try: MotorPI.vel(55) except: QMessageBox.about(self, "Problem", "Retry please") self.ini_start = False self.timer_ini.stop() MotorPI.disconnect() return MotorPI.ref() try: MotorPI.move_rel(50) except: QMessageBox.about(self, "Problem", "Retry please") self.ini_start = False self.timer_ini.stop() return while ori == 0: if self.completed >= 100: self.completed = 0 self.progress.setValue(self.completed) time.sleep(0.1) try: [secu, ori, F, P] = read_arduino() except: print("read step1 problem") self.completed = self.completed + 20 self.progress.setValue(self.completed) time.sleep(0.5) try: [secu, ori, F, P] = read_arduino() except: print("read step1 problem") if secu == 1: QMessageBox.about(self, "Problem", "Security button activated !") self.completed = 0 self.ini_start = False self.timer_ini.stop() return try: MotorPI.stop() except: print("motor stop") MotorPI.ref() self.completed = 100 self.progress.setValue(self.completed) # QMessageBox.about(self, "Origin", "The origin was found successfully") time.sleep(1) self.completed = 0 self.progress.setValue(self.completed) self.label.setText("Returning mid") self.repaint() #Return L_return = -50 MotorPI.move_rel(L_return) deg = 360 * abs(L_return) / MotorPI.p t = deg / MotorPI.vel_value() debut = time.time() limit = t / 99 while MotorPI.ismoving(): if time.time() - debut > limit: self.completed = self.completed + 1 self.progress.setValue(self.completed) limit = limit + t / 99 try: [secu, ori, F, P] = read_arduino() except: print("read step1 problem") if secu == 1: QMessageBox.about(self, "Problem", "Security button activated !") self.ini_start = False self.timer_ini.stop() return self.completed = 100 self.progress.setValue(self.completed) self.label.setText("Finish") MotorPI.vel(20) self.timer_ini.stop() QMessageBox.about( self, "Acquisition", "Initialisation finished\n\nStart of the acquisition") self.switch_window.emit(self.path) self.close()
def clickMethod_motorStop(self): MotorPI.stop()
def update_window(self): """Method called each time the timer clocks""" self.connectionCall( ) #Method to check the connection of the devices (method in "Left_panel") try: #[self.secu,self.ori,self.F,self.P] = read() #Method to save current value of load and pressure self.ReadThread.start() except: print("ReadThread pb") self.vol = 0 # try: self.d = MotorPI.motor_pos() if self.d < -50.1: self.clickMethodStop() MotorPI.move_rel(1) QMessageBox.about(self, "Warning", "The end course was reached") self.label_disp_abs_display.setText( "Abs: " + str(round(self.d, 2)) + " mm") #Display the value self.label_disp_rel_display.setText( str(round( (self.d - self.tare_disp), 2)) + " mm") #Display the value except: print("Problem MotorPI.motor_pos() in update()") self.label_pressure_display.setText( f"{self.P:.3f} mmHg") #Display the value #self.label_volume_display.setText(str(round(self.vol,4)) + " ml") #Display the value self.label_load_display.setText(f"{self.F:.3f} N") #Display the value if self.secu == 1: self.clickMethodStop() msg = QMessageBox.question( self, "Arret d'urgence ou Fin de course !", "Did you push the emergency stop button ?", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) if msg == QMessageBox.No: QMessageBox.about( self, "Warning", "The end course was activated, you have to move the motor manually and restart the initialisation" ) self.timer.stop() self.return_window.emit() else: try: [self.secu, self.ori, self.F, self.P] = read( ) #Method to save current value of load and pressure except: print("Read problem") while self.secu == 1: QMessageBox.about(self, "Warning", "Un-push the emergency stop button") try: [self.secu, self.ori, self.F, self.P] = read( ) #Method to save current value of load and pressure except: pass MotorPI.connect() return #------------------------------------------------------------------ ## This part is activate when the user start the machanical test #------------------------------------------------------------------ if not self.running: return self.time_now = time.time( ) - self.time_ini_graph #Save the timepassed since the starting time ##################### #Graphic update if not self.time_now or self.F or self.P: #If value are null don't show on graph (because at the beginning values null) #xv = np.array([self.time_now]) self.array_F.append(float(self.F)) self.array_P.append(float(self.P)) self.array_d.append(float(self.d - self.tare_disp)) self.array_t.append(float(self.time_now)) if self.Lxaxis == "Displacement (mm)": Lx = self.array_d elif self.Lxaxis == "Force (N)": Lx = self.array_F elif self.Lxaxis == "Pressure (mmHg)": Lx = self.array_P elif self.Lxaxis == "Time (s)": Lx = self.array_t if self.Lyaxis == "Displacement (mm)": Ly = self.array_d elif self.Lyaxis == "Force (N)": Ly = self.array_F elif self.Lyaxis == "Pressure (mmHg)": Ly = self.array_P elif self.Lyaxis == "Time (s)": Ly = self.array_t if self.Rxaxis == "Displacement (mm)": Rx = self.array_d elif self.Rxaxis == "Force (N)": Rx = self.array_F elif self.Rxaxis == "Pressure (mmHg)": Rx = self.array_P elif self.Rxaxis == "Time (s)": Rx = self.array_t if self.Ryaxis == "Displacement (mm)": Ry = self.array_d elif self.Ryaxis == "Force (N)": Ry = self.array_F elif self.Ryaxis == "Pressure (mmHg)": Ry = self.array_P elif self.Ryaxis == "Time (s)": Ry = self.array_t self.graphL.setData(Lx, Ly) #Show on the graph self.graphR.setData(Rx, Ry) #Show on the graph ##################### # Result file update with open(self.path + '/' + self.file_save + '.txt', 'a') as mon_fichier: mon_fichier.write( str(round(time.time() - self.time_ini, 2)) + " , " + str(round(self.d - self.tare_disp, 3)) + " , " + str(self.F) + " , " + str(self.P) + " , " + str(self.vol) + "\n")