示例#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_pos(self):
     pos = self.microcontroller.read_received_packet_nowait()
     if pos is None:
         return
     self.x_pos = utils.unsigned_to_signed(
         pos[0:3], MicrocontrollerDef.N_BYTES_POS
     ) / Motion.STEPS_PER_MM_XY  # @@@TODO@@@: move to microcontroller?
     self.y_pos = utils.unsigned_to_signed(
         pos[3:6], MicrocontrollerDef.N_BYTES_POS
     ) / Motion.STEPS_PER_MM_XY  # @@@TODO@@@: move to microcontroller?
     self.z_pos = utils.unsigned_to_signed(
         pos[6:9], MicrocontrollerDef.N_BYTES_POS
     ) / Motion.STEPS_PER_MM_Z  # @@@TODO@@@: move to microcontroller?
     self.xPos.emit(self.x_pos)
     self.yPos.emit(self.y_pos)
     self.zPos.emit(self.z_pos * 1000)
示例#3
0
 def collect_data(self):
     data = self.microcontroller.read_received_packet_nowait()
     if data is not None:
         print('data collected')
         for i in range(
                 int(MicrocontrollerDef.MSG_LENGTH_USED /
                     N_BYTES_PER_RECORD)):
             stepper1_pos = utils.unsigned_to_signed(
                 data[i * N_BYTES_PER_RECORD +
                      0:i * N_BYTES_PER_RECORD * 2 + 2], 2)
             stepper2_pos = utils.unsigned_to_signed(
                 data[i * N_BYTES_PER_RECORD +
                      2:i * N_BYTES_PER_RECORD * 2 + 4], 2)
             stepper3_pos = utils.unsigned_to_signed(
                 data[i * N_BYTES_PER_RECORD +
                      4:i * N_BYTES_PER_RECORD * 2 + 6], 2)
             flow = (utils.unsigned_to_signed(
                 data[i * N_BYTES_PER_RECORD +
                      6:i * N_BYTES_PER_RECORD * 2 + 8], 2) /
                     (65536 / 2)) * FLOW_FS
             pressure_1 = (
                 (data[i * N_BYTES_PER_RECORD + 8] * 256 +
                  data[i * N_BYTES_PER_RECORD + 9]) / 65536.0) * PRESSURE_FS
             pressure_2 = ((data[i * N_BYTES_PER_RECORD + 10] * 256 +
                            data[i * N_BYTES_PER_RECORD + 11]) /
                           65536.0) * PRESSURE_FS
             pressure_3 = ((data[i * N_BYTES_PER_RECORD + 12] * 256 +
                            data[i * N_BYTES_PER_RECORD + 13]) /
                           65536.0) * PRESSURE_FS
             self.file.write(
                 str(stepper1_pos) + ',' + str(stepper2_pos) + ',' +
                 str(stepper3_pos) + ',' + str(flow) + ',' +
                 str(pressure_1) + ',' + str(pressure_2) + ',' +
                 str(pressure_3) + '\n')
             print(
                 str(stepper1_pos) + '\t' + str(stepper2_pos) + '\t' +
                 str(stepper3_pos) + '\t' + "{:.2f}".format(flow) + '\t' +
                 "{:.2f}".format(pressure_1) + '\t' +
                 "{:.2f}".format(pressure_2) + '\t' +
                 "{:.2f}".format(pressure_3))
         self.file.flush()
示例#4
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()