main.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import sensors
  2. import time
  3. import threading
  4. import queue
  5. import gui.mainWindow as mainWindow
  6. conf = {
  7. "field":{
  8. "x":450,
  9. "y":450
  10. },
  11. "ac_sensor":{
  12. "sensor_distance":450,
  13. "y_offset":10,
  14. "left_x_offset":0,
  15. "rigth_x_offset":0,
  16. "sonicspeed":0.343,
  17. "overhead":150
  18. }
  19. }
  20. class CalibrationStateMashine():
  21. def __init__(self):
  22. self.state = 0
  23. self.value_count = 0
  24. def state_clearname(self):
  25. if self.state == 0:
  26. return "not calibrated"
  27. elif self.state == 1:
  28. return "ready on position one"
  29. elif self.state == 2:
  30. return "gathering values on position one"
  31. elif self.state == 3:
  32. return "finished gathering values from position one"
  33. elif self.state == 4:
  34. return "ready on position two"
  35. elif self.state == 5:
  36. return "gathering values on position two"
  37. elif self.state == 6:
  38. return "calculating calibration values"
  39. elif self.state == 7:
  40. return "calibration done"
  41. def next_state(self):
  42. if self.state < 7:
  43. self.state += 1
  44. print(self.state_clearname())
  45. def add_value(self):
  46. self.value_count += 1
  47. def return_state(self):
  48. return self.state
  49. def return_value_count(self):
  50. return self.value_count
  51. def reset_state(self):
  52. self.state = 0
  53. def reset_value_count(self):
  54. self.value_count = 0
  55. def main():
  56. up_queue = queue.Queue()
  57. down_queue = queue.Queue()
  58. calibration_sate = CalibrationStateMashine()
  59. ac_sensor = sensors.AcusticSensor(conf,up_queue,down_queue,calibration_sate)
  60. sensor_thread = threading.Thread(target=ac_sensor.start)
  61. ui_thread = threading.Thread(target=mainWindow.start_mainwindow, args=(up_queue,down_queue,calibration_sate))
  62. sensor_thread.start()
  63. ui_thread.start()
  64. try:
  65. while True:
  66. time.sleep(1)
  67. except KeyboardInterrupt:
  68. print("stop")
  69. except Exception as e:
  70. print("Error: ",e)
  71. finally:
  72. down_queue.put("stop")
  73. main()