Пример #1
0
    def update_waveforms(self):
        # self.time = self.time + (1/1000)*WAVEFORMS.UPDATE_INTERVAL_MS

        # Use the processor clock to determine elapsed time since last function call
        self.time_now = time.time()
      
        if SIMULATION:
            self.Paw = (self.Paw + 0.2)%5
            self.Volume = (self.Volume + 0.2)%5
            self.Flow = (self.Flow + 0.2)%5
            self.file.write(str(self.time_now)+','+str(self.Paw)+','+str(self.Flow)+','+str(self.Volume)+'\n')
        else:
            readout = self.microcontroller.read_received_packet_nowait()
            if readout is not None:
                self.Paw = (utils.unsigned_to_signed(readout[0:2],MicrocontrollerDef.N_BYTES_DATA)/(65536/2))*MicrocontrollerDef.PAW_FS 
                self.Flow = (utils.unsigned_to_signed(readout[2:4],MicrocontrollerDef.N_BYTES_DATA)/(65536/2))*MicrocontrollerDef.FLOW_FS
                self.Volume = (utils.unsigned_to_unsigned(readout[4:6],MicrocontrollerDef.N_BYTES_DATA)/65536)*MicrocontrollerDef.VOLUME_FS
                # self.time = float(utils.unsigned_to_unsigned(readout[6:8],MicrocontrollerDef.N_BYTES_DATA))*MicrocontrollerDef.TIMER_PERIOD_ms/1000
                self.file.write(str(self.time_now)+','+str(self.Paw)+','+str(self.Flow)+','+str(self.Volume)+','+str(self.ventController.Vt)+','+str(self.ventController.Ti)+','+str(self.ventController.RR)+','+str(self.ventController.PEEP) +'\n')
        
        # reduce display refresh rate
        self.counter = self.counter + 1
        if self.counter>=1:
            self.time_diff = self.time_now - self.time_prev
            self.time_prev = self.time_now
            self.time += self.time_diff

            self.counter = 0
            self.signal_Paw.emit(self.time,self.Paw)
            self.signal_Flow.emit(self.time,self.Flow)
            self.signal_Volume.emit(self.time,self.Volume)
Пример #2
0
    def update_waveforms(self):
        # self.time = self.time + (1/1000)*WAVEFORMS.UPDATE_INTERVAL_MS

        if SIMULATION:
            # test plotting multiple data points at a time
            for i in range(MCU.TIMEPOINT_PER_UPDATE):
                # Use the processor clock to determine elapsed time since last function call
                self.time_now = time.time()
                self.time_diff = self.time_now - self.time_prev
                self.time_prev = self.time_now
                self.time += self.time_diff
                self.Paw = (self.Paw + 0.2 / MCU.TIMEPOINT_PER_UPDATE) % 5
                self.Volume = (self.Volume +
                               0.2 / MCU.TIMEPOINT_PER_UPDATE) % 5
                self.Flow = (self.Flow + 0.2 / MCU.TIMEPOINT_PER_UPDATE) % 5
                # self.file.write(str(self.time_now)+','+str(self.Paw)+','+str(self.Flow)+','+str(self.Volume)+'\n')
                self.signal_Paw.emit(self.time, self.Paw)
                self.signal_Flow.emit(self.time, self.Flow)
                self.signal_Volume.emit(self.time, self.Volume)

        else:
            readout = self.microcontroller.read_received_packet_nowait()
            if readout is not None:
                self.time_now = time.time()
                self.time_diff = self.time_now - self.time_prev
                self.time_prev = self.time_now
                self.time += self.time_diff

                self.timestamp = int.from_bytes(readout[0:4],
                                                byteorder='big',
                                                signed=False)
                print(self.timestamp)
                self.Paw = (utils.unsigned_to_signed(
                    readout[0:2], MicrocontrollerDef.N_BYTES_DATA) /
                            (65536 / 2)) * MicrocontrollerDef.PAW_FS
                self.Flow = (utils.unsigned_to_signed(
                    readout[2:4], MicrocontrollerDef.N_BYTES_DATA) /
                             (65536 / 2)) * MicrocontrollerDef.FLOW_FS
                self.Volume = (utils.unsigned_to_unsigned(
                    readout[4:6], MicrocontrollerDef.N_BYTES_DATA) /
                               65536) * MicrocontrollerDef.VOLUME_FS
                self.file.write(
                    str(self.time_now) + ',' + "{:.2f}".format(self.Paw) +
                    ',' + "{:.2f}".format(self.Flow) + ',' +
                    "{:.2f}".format(self.Volume) + ',' +
                    str(self.ventController.Vt) + ',' +
                    str(self.ventController.Ti) + ',' +
                    str(self.ventController.RR) + ',' +
                    str(self.ventController.PEEP) + '\n')
                # print("{:.2f}".format(self.Paw)+'\t'+"{:.2f}".format(self.Flow)+'\t'+"{:.2f}".format(self.Volume))

            # reduce display refresh rate
            self.counter_display = self.counter_display + 1
            if self.counter_display >= 1:
                self.counter_display = 0

                self.signal_Paw.emit(self.time, self.Paw)
                self.signal_Flow.emit(self.time, self.Flow)
                self.signal_Volume.emit(self.time, self.Volume)

                # self.signal_Paw.emit(self.time+0.01,self.Paw+2)
                # self.signal_Flow.emit(self.time+0.001,self.Flow+2)
                # self.signal_Volume.emit(self.time+0.01,self.Volume+2)

                # self.signal_Paw.emit(self.time+0.0002,self.Paw)
                # self.signal_Flow.emit(self.time+0.0002,self.Flow)
                # self.signal_Volume.emit(self.time+0.0002,self.Volume)

                # self.signal_Paw.emit(self.time+0.0003,self.Paw)
                # self.signal_Flow.emit(self.time+0.0003,self.Flow)
                # self.signal_Volume.emit(self.time+0.0003,self.Volume)

                # self.signal_Paw.emit(self.time+0.0004,self.Paw)
                # self.signal_Flow.emit(self.time+0.0004,self.Flow)
                # self.signal_Volume.emit(self.time+0.0004,self.Volume)

        # file flushing
        self.counter_file_flush = self.counter_file_flush + 1
        if self.counter_file_flush >= 500:
            self.counter_file_flush = 0
            self.file.flush()
Пример #3
0
    def update_waveforms(self):
      
        if SIMULATION:
            # test plotting multiple data points at a time
            #for i in range(MCU.TIMEPOINT_PER_UPDATE):
            t_chunck = np.array([])
            ch1_chunck = np.array([])
            ch2_chunck = np.array([])
            ch3_chunck = np.array([])

            for i in range(MCU.TIMEPOINT_PER_UPDATE):
                self.time = time.time()
                self.ch1 = (self.ch1 + 0.2/MCU.TIMEPOINT_PER_UPDATE)%5
                self.ch2 = (self.ch2 + 0.1/MCU.TIMEPOINT_PER_UPDATE)%5
                self.ch3 = 0

                # append variables for plotting
                t_chunck = np.append(t_chunck,self.time)
                ch1_chunck = np.append(ch1_chunck,self.ch1)
                ch2_chunck = np.append(ch2_chunck,self.ch2)
                ch3_chunck = np.append(ch3_chunck,self.ch3)

            self.time_array = np.append(self.time_array,t_chunck)
            self.ch1_array = np.append(self.ch1_array,ch1_chunck)
            self.ch2_array = np.append(self.ch2_array,ch2_chunck)
            self.ch3_array = np.append(self.ch3_array,ch2_chunck)

            self.signal_plot1.emit(self.time_array,self.ch1_array)
            self.signal_plot2.emit(self.time_array,self.ch2_array)
            self.signal_plot3.emit(self.time_array,self.ch3_array)
            self.signal_ch1.emit("{:.2f}".format(self.ch1))
            self.signal_ch2.emit("{:.2f}".format(self.ch2))
            self.signal_ch3.emit("{:.2f}".format(self.ch3))

        else:
            readout = self.microcontroller.read_received_packet_nowait()
            if readout is not None:

                self.time_now = time.time()

                t_chunck = np.array([])
                ch1_chunck = np.array([])
                ch2_chunck = np.array([])
                temp1_chunck = np.array([])
                temp2_chunck = np.array([])

                for i in range(MCU.TIMEPOINT_PER_UPDATE):
                    # time
                    self.time_ticks = int.from_bytes(readout[i*MCU.RECORD_LENGTH_BYTE:i*MCU.RECORD_LENGTH_BYTE+4], byteorder='big', signed=False)
                    if self.first_run:
                        self.time_ticks_start = self.time_ticks
                        self.first_run = False
                    self.time = (self.time_ticks - self.time_ticks_start)*MCU.TIMER_PERIOD_ms/1000
                    self.ch1 = utils.unsigned_to_unsigned(readout[i*MCU.RECORD_LENGTH_BYTE+4:i*MCU.RECORD_LENGTH_BYTE+6],2)
                    self.ch2 = utils.unsigned_to_unsigned(readout[i*MCU.RECORD_LENGTH_BYTE+6:i*MCU.RECORD_LENGTH_BYTE+8],2)

                    self.ch1 = (self.ch1/65535)*(comm._comm_flow_max-comm._comm_flow_min)+comm._comm_flow_min
                    self.ch2 = (self.ch2/65535)*(comm._comm_pressure_max-comm._comm_pressure_min)+comm._comm_pressure_min

                    record_from_MCU = (
                        str(self.time_ticks) + '\t' + str(self.ch1) + '\t' + "{:.2f}".format(self.ch2) )
                    record_settings = (str(self.time_now))
                    # print(record_from_MCU)
                   
                    # saved variables
                    if self.logging_is_on:
                        self.file.write(record_from_MCU + '\t' + record_settings + '\n')

                    # append variables for plotting
                    t_chunck = np.append(t_chunck,self.time)
                    ch1_chunck = np.append(ch1_chunck,self.ch1)
                    ch2_chunck = np.append(ch2_chunck,self.ch2)

                self.ch1_array = np.append(self.ch1_array,ch1_chunck)
                self.ch2_array = np.append(self.ch2_array,ch2_chunck)
                self.time_array = np.append(self.time_array,t_chunck)

                # reduce display refresh rate
                self.counter_display = self.counter_display + 1
                if self.counter_display>=1:
                    self.counter_display = 0

                    self.signal_plot1.emit(self.time_array[-200*20:],self.ch1_array[-200*20:])
                    self.signal_plot2.emit(self.time_array[-200*20:],self.ch2_array[-200*20:])
                    self.signal_plotyy.emit(self.time_array[-200*20:],self.ch1_array[-200*20:],self.ch2_array[-200*20:])
                    self.signal_ch1.emit("{:.2f}".format(self.ch1))
                    self.signal_ch2.emit("{:.2f}".format(self.ch2))

        # file flushing
        if self.logging_is_on:
            self.counter_file_flush = self.counter_file_flush + 1
            if self.counter_file_flush>=500:
                self.counter_file_flush = 0
                self.file.flush()