Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sensors(self):
- array_105_x = []
- array_105_y = []
- array_105_z = []
- i = 0
- pbar = tqdm(total=self.time_observation)
- self.arduino_port_sensor.reset_input_buffer()
- self.arduino_port_sensor.write(str(1).encode())
- time.sleep(6)
- print("RECIEVED BACK SENSOR:",self.arduino_port_sensor.readline().decode())
- while i < self.time_observation:
- value = self.arduino_port_sensor.readline()
- value = value.decode('utf-8', 'ignore')
- if value == '': #если данных нет
- print('empty')
- self.sensors() #перезапустить функцию
- v = value.rstrip().replace(" ", "") #разделить данные и тд и тп
- result = [x.strip() for x in v.split(',')]
- if len(result) == 4: #интересуют только "целые" строчки
- if i == 0:
- try:
- self.time_start = float(result[0])
- except ValueError:
- print('error:', result[0])
- pass
- try:
- array_105_x.append(float(result[1]))
- array_105_y.append(float(result[2]))
- array_105_z.append(float(result[3]))
- i+=1
- pbar.update(1)
- except ValueError:
- print(result)
- continue
- pbar.close()
- self.arduino_port_sensor.reset_input_buffer()
- while True:
- self.arduino_port_sensor.write(str(0).encode())
- try:
- value = int(self.arduino_port_sensor.readline().decode('utf-8', 'ignore').rstrip().replace(" ", ""))
- if value == 0:
- print ('данных нет, все ок', value)
- break
- except ValueError:
- continue
- self.time_end = float(result[0])
- return [array_105_x, array_105_y, array_105_z]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement