- import random
- import time
- from pwi4_client import PWI4
- pwi4 = PWI4()
- def predict_mech_degs(target_field_angle_degs):
- status = pwi4.status()
- print("Target field angle:", target_field_angle_degs)
- print("Altitude:", status.mount.altitude_degs)
- print("Mount field angle:", status.mount.field_angle_at_target_degs)
- mech_degs = target_field_angle_degs - status.mount.altitude_degs - status.mount.field_angle_at_target_degs
- # Unwind into the range (-180 to +180)
- mech_degs = ((mech_degs + 180) % 360) - 180
- print("Expected mech degrees:", mech_degs)
- return mech_degs
- def goto_field(target_field_angle_degs):
- pwi4.rotator_goto_field(target_field_angle_degs)
- while True:
- time.sleep(1)
- status = pwi4.status()
- if not status.rotator.is_slewing:
- break
- print("Arrived at mech position", status.rotator.mech_position_degs)
- return status.rotator.mech_position_degs
- def test_field_angle(target_field_angle_degs):
- expected = predict_mech_degs(target_field_angle_degs)
- actual = goto_field(target_field_angle_degs)
- print("Position error:", actual-expected)
- if abs(actual-expected) > 1:
- print("ERROR ERROR ERROR: POSITION ERROR TOO LARGE!")
- def slew_random():
- azm = random.uniform(0, 360)
- alt = random.uniform(20, 89)
- print("Slewing to Azm", azm, "Alt", alt)
- pwi4.mount_goto_alt_az(alt, azm)
- while True:
- time.sleep(1)
- status = pwi4.status()
- if not status.mount.is_slewing:
- break
- print("Turn tracking on")
- pwi4.mount_tracking_on()
- time.sleep(1)
- print("Arrived")
- def test_random():
- test_num = 0
- while True:
- test_num += 1
- print("Test", test_num)
- slew_random()
- target_field_angle = random.uniform(-360, 360)
- test_field_angle(target_field_angle)
- if __name__ == "__main__":
- test_random()
Raw Paste