PYTHON   109
pwi4 startup
Guest on 15th August 2022 12:45:20 PM


  1. import time
  2.  
  3. from pwi4_client import PWI4
  4.  
  5. pwi4 = PWI4()
  6.  
  7. def main():
  8.     connect_to_mount()
  9.     enable_motors()
  10.     find_home()
  11.  
  12. def connect_to_mount():
  13.     print("Connecting to mount...")
  14.     pwi4.mount_connect()
  15.     while not pwi4.status().mount.is_connected:
  16.         time.sleep(1)
  17.     print("Done")
  18.  
  19. def enable_motors():
  20.     print("Enabling motors")
  21.     pwi4.mount_enable(0)
  22.     pwi4.mount_enable(1)
  23.     while True:
  24.         status = pwi4.status()
  25.         if status.mount.axis0.is_enabled and status.mount.axis1.is_enabled:
  26.             break
  27.         time.sleep(1)
  28.     print("Done")
  29.  
  30. def find_home():
  31.     print("Finding home")
  32.     pwi4.mount_find_home()
  33.     last_axis0_pos_degs = -99999
  34.     last_axis1_pos_degs = -99999
  35.     while True:
  36.         status = pwi4.status()
  37.         delta_axis0_pos_degs = status.mount.axis0.position_degs - last_axis0_pos_degs
  38.         delta_axis1_pos_degs = status.mount.axis1.position_degs - last_axis1_pos_degs
  39.  
  40.         if abs(delta_axis0_pos_degs) < 0.001 and abs(delta_axis1_pos_degs) < 0.001:
  41.             break
  42.  
  43.         last_axis0_pos_degs = status.mount.axis0.position_degs
  44.         last_axis1_pos_degs = status.mount.axis1.position_degs
  45.  
  46.         time.sleep(1)
  47.     print("Done")
  48.  
  49. if __name__ == "__main__":
  50.     main()

Raw Paste

Login or Register to edit or fork this paste. It's free.