PYTHON   19

custom path full axis0 range test py

Guest on 15th August 2022 12:36:34 PM

  1. import math
  2. import time
  3.  
  4. import pwi4_client
  5.  
  6. # Use the "custom path" feature of PWI4, along with custom handling of the
  7. # No Wrap range feature, to move a mount back and forth along its full allowed
  8. # range of Axis0 (Azimuth / RA) positions.
  9. #
  10. # NOTE: This script uses features that were introduced in PWI 4.0.13
  11.  
  12. pwi4 = pwi4_client.PWI4()
  13.  
  14. status = pwi4.status()
  15.  
  16. # Get the PWI4-imposed position limits for Axis0.
  17. # We will travel between this range
  18. min_degs = status.mount.axis0.min_mech_position_degs
  19. max_degs = status.mount.axis0.max_mech_position_degs
  20.  
  21. print("Axis0 min mechanical position:", min_degs)
  22. print("Axis0 max mechanical position:", max_degs)
  23. range_degs = max_degs - min_degs
  24. print("Range:", range_degs)
  25.  
  26. # Set some additional parameters defining how we will move along this range
  27. degs_per_sec = 3
  28. seconds_to_slew_full_range = range_degs / degs_per_sec
  29. settle_time_sec = 20
  30. altitude_degs = 45
  31.  
  32. # coord_type can be "raw" or "altaz"
  33. # raw: use the native "mechanical" axis coordinates (matching mount.axisN.position_degs)
  34. #      without applying pointing model corrections
  35. # altaz: use unrefracted altaz coordinates, passing through the pointing model
  36. coord_type = "raw"
  37.  
  38. # Define the path that we will follow
  39. points = [
  40.         (0, min_degs, altitude_degs),  # At 0 seconds, we should be at Axis0=min_degs
  41.         (seconds_to_slew_full_range, max_degs, altitude_degs),  # At N seconds, we should be at Axis0=max_degs
  42.         (2*seconds_to_slew_full_range , min_degs, altitude_degs)  # At 2*N seconds, we should be back at Axis0=min_degs
  43. ]
  44.  
  45.  
  46. # Subdivide the point list so that no single interval in the path covers more than
  47. # 90 degrees in the Axis0 direction. Otherwise, it may be ambiguous which direction to move
  48. # due to Modulo 360 effects.
  49. # For example, if we try to move from 1 to 359 degrees, the PWI4 interpolation may try to
  50. # simplify the move to simply move by a total of -2 degrees.
  51. i=0
  52. while i < len(points)-1:
  53.     p0 = points[i]
  54.     p1 = points[i+1]
  55.     if abs(p1[1] - p0[1]) > 90:
  56.         p_new = (
  57.             (p0[0]+p1[0])/2,
  58.             (p0[1]+p1[1])/2,
  59.             (p0[2]+p1[2])/2
  60.         )
  61.         points.insert(i+1, p_new)
  62.     else:
  63.         i += 1
  64.  
  65. print("Subdivided point list:")
  66. for point in points:
  67.     print(point)
  68.  
  69.  
  70. #########################################################
  71.  
  72.  
  73. # Make sure the mount is not currently following another target
  74. # before we adjust the wrap range
  75. pwi4.mount_stop()
  76.  
  77.  
  78. # Set the wrap range such that our target position is in the middle of the
  79. # allowable modulo range, in absolute coordinates.
  80. pwi4.mount_set_axis0_wrap_range_min(min_degs - 180)
  81.  
  82. # Slew to the starting point so that we are already in position prior to
  83. # sending the custom path
  84. print("Slewing to minimum axis0 position (axis0=%f, axis1=%f)" % (
  85.     min_degs,
  86.     altitude_degs
  87.     ))
  88.  
  89. pwi4.mount_goto_coord_pair(min_degs, altitude_degs, "raw")
  90.  
  91. # Monitor the slew for completion
  92. while True:
  93.     status = pwi4.status()
  94.     if not status.mount.is_slewing:
  95.         print("Slew finished. Arrived at %.3f, %.3f" % (
  96.             status.mount.axis0.position_degs,
  97.             status.mount.axis1.position_degs
  98.             ))
  99.         break
  100.  
  101. # Convert the path we built above from (seconds_from_now, axis0, axis1) format
  102. # to the (julian_day, axis0, axis1) format expected by PWI4.
  103. # First, get the JD right now
  104. jd0 = pwi4.status().mount.julian_date
  105.  
  106. # Build a table of tuples to send to PWI4:
  107. #   (jd, coord0_degs, coord1_degs)
  108. jd_points = []
  109. for point in points:
  110.     seconds = point[0]
  111.     jd = jd0 + seconds / 86400.0
  112.     jd_points.append((jd, point[1], point[2]))
  113.  
  114.  
  115. # Start a new path of the selected coordinate type
  116. print("Creating new path with coord_type =", coord_type)
  117. pwi4.mount_custom_path_new(coord_type)
  118. # Upload a list of points
  119. print("Uploading %d points" % len(jd_points))
  120. pwi4.mount_custom_path_add_point_list(jd_points)
  121. # Begin following the path
  122. print("Following...")
  123. pwi4.mount_custom_path_apply()
  124.  
  125. # Monitor the path, and update the wrap range to keep our current "absolute" position
  126. # in the middle of the wrap range so that PWI4 will not attempt to perform any unwrapping.
  127. while True:
  128.     status = pwi4.status()
  129.     if not status.mount.is_slewing:
  130.         break
  131.  
  132.     # Update the wrap range to surround our current mechanical position so that no
  133.     # automatic unwrapping is performed
  134.     pwi4.mount_set_axis0_wrap_range_min(status.mount.axis0.position_degs - 180)
  135.  
  136.     print("Axis0=%.3f tgt %.3f, Axis1=%.3f, Axis0WrapMin=%.3f" % (
  137.         status.mount.axis0.position_degs,
  138.         status.mount.axis0.target_mech_position_degs,
  139.         status.mount.axis1.position_degs,
  140.         status.mount.axis0_wrap_range_min_degs
  141.         ))
  142.  
  143.     time.sleep(0.5)
  144.  
  145. print("Finished")

Raw Paste


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