main.py 972 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import sensors
  2. import time
  3. import threading
  4. import queue
  5. conf = {
  6. "field":{
  7. "x":450,
  8. "y":450
  9. },
  10. "ac_sensor":{
  11. "sensor_distance":450,
  12. "y_offset":10,
  13. "left_x_offset":0,
  14. "rigth_x_offset":0,
  15. "sonicspeed":343,
  16. "overhead":50
  17. }
  18. }
  19. def main():
  20. up_queue = queue.Queue()
  21. down_queue = queue.Queue()
  22. calibration_sate = 0
  23. ac_sensor = sensors.AcusticSensor(conf,up_queue,down_queue,calibration_sate)
  24. sensor_thread = threading.Thread(target=ac_sensor.start)
  25. sensor_thread.start()
  26. time.sleep(3)
  27. calibration_sate = 1
  28. print(calibration_sate)
  29. time.sleep(3)
  30. down_queue.put("calibrate")
  31. try:
  32. while True:
  33. time.sleep(1)
  34. print(calibration_sate)
  35. except KeyboardInterrupt:
  36. print("stop")
  37. except Exception as e:
  38. print("Error: ",e)
  39. finally:
  40. down_queue.put("stop")
  41. sensor_thread.join()
  42. main()