PYTHON   35

predict pw1000 rotator mech py

Guest on 15th August 2022 12:39:35 PM

  1. import random
  2. import time
  3.  
  4. from pwi4_client import PWI4
  5.  
  6. pwi4 = PWI4()
  7.  
  8. def predict_mech_degs(target_field_angle_degs):
  9.     status = pwi4.status()
  10.  
  11.     print("Target field angle:", target_field_angle_degs)
  12.     print("Altitude:", status.mount.altitude_degs)
  13.     print("Mount field angle:", status.mount.field_angle_at_target_degs)
  14.  
  15.     mech_degs = target_field_angle_degs - status.mount.altitude_degs - status.mount.field_angle_at_target_degs
  16.  
  17.     # Unwind into the range (-180 to +180)
  18.     mech_degs = ((mech_degs + 180) % 360) - 180
  19.     print("Expected mech degrees:", mech_degs)
  20.  
  21.     return mech_degs
  22.  
  23.  
  24. def goto_field(target_field_angle_degs):
  25.     pwi4.rotator_goto_field(target_field_angle_degs)
  26.     while True:
  27.         time.sleep(1)
  28.         status = pwi4.status()
  29.         if not status.rotator.is_slewing:
  30.             break
  31.     print("Arrived at mech position", status.rotator.mech_position_degs)
  32.     return status.rotator.mech_position_degs
  33.  
  34. def test_field_angle(target_field_angle_degs):
  35.     expected = predict_mech_degs(target_field_angle_degs)
  36.     actual = goto_field(target_field_angle_degs)
  37.     print("Position error:", actual-expected)
  38.     if abs(actual-expected) > 1:
  39.         print("ERROR ERROR ERROR: POSITION ERROR TOO LARGE!")
  40.  
  41. def slew_random():
  42.     azm = random.uniform(0, 360)
  43.     alt = random.uniform(20, 89)
  44.     print("Slewing to Azm", azm, "Alt", alt)
  45.     pwi4.mount_goto_alt_az(alt, azm)
  46.     while True:
  47.         time.sleep(1)
  48.         status = pwi4.status()
  49.         if not status.mount.is_slewing:
  50.             break
  51.     print("Turn tracking on")
  52.     pwi4.mount_tracking_on()
  53.     time.sleep(1)
  54.     print("Arrived")
  55.  
  56. def test_random():
  57.     test_num = 0
  58.     while True:
  59.         test_num += 1
  60.         print("Test", test_num)
  61.         slew_random()
  62.         target_field_angle = random.uniform(-360, 360)
  63.         test_field_angle(target_field_angle)
  64.  
  65.  
  66. if __name__ == "__main__":
  67.     test_random()

Raw Paste


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