Skip to content

Commit

Permalink
Make align system more dynamic and user-friendly (#277)
Browse files Browse the repository at this point in the history
* Stashing dynamic align

* Working on hybrid

* More refinement

* Refined Align system, cleaned up no-solve messages in align/chart
  • Loading branch information
brickbots authored Feb 14, 2025
1 parent 48d6e96 commit 133be6b
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 55 deletions.
74 changes: 62 additions & 12 deletions python/PiFinder/integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,18 @@ def integrator(shared_state, solver_queue, console_queue, log_queue, is_debug=Fa
"RA": None,
"Dec": None,
"Roll": None,
"RA_camera": None,
"Dec_camera": None,
"Roll_camera": None,
"camera_center": {
"RA": None,
"Dec": None,
"Roll": None,
"Alt": None,
"Az": None,
},
"camera_solve": {
"RA": None,
"Dec": None,
"Roll": None,
},
"Roll_offset": 0, # May/may not be needed - for experimentation
"imu_pos": None,
"Alt": None,
Expand Down Expand Up @@ -115,6 +124,14 @@ def integrator(shared_state, solver_queue, console_queue, log_queue, is_debug=Fa
solved["Alt"] = alt
solved["Az"] = az

alt, az = calc_utils.sf_utils.radec_to_altaz(
solved["camera_center"]["RA"],
solved["camera_center"]["Dec"],
dt,
)
solved["camera_center"]["Alt"] = alt
solved["camera_center"]["Az"] = az

# Experimental: For monitoring roll offset
# Estimate the roll offset due misalignment of the
# camera sensor with the Pole-to-Source great circle.
Expand All @@ -129,7 +146,19 @@ def integrator(shared_state, solver_queue, console_queue, log_queue, is_debug=Fa
# as seen by the camera.
solved["Roll"] = roll_target_calculated + solved["Roll_offset"]

last_image_solve = copy.copy(solved)
# calculate roll for camera center
roll_target_calculated = calc_utils.sf_utils.radec_to_roll(
solved["camera_center"]["RA"],
solved["camera_center"]["Dec"],
dt,
)
# Compensate for the roll offset. This gives the roll at the target
# as seen by the camera.
solved["camera_center"]["Roll"] = (
roll_target_calculated + solved["Roll_offset"]
)

last_image_solve = copy.deepcopy(solved)
solved["solve_source"] = "CAM"

# Use IMU dead-reckoning from the last camera solve:
Expand All @@ -150,14 +179,17 @@ def integrator(shared_state, solver_queue, console_queue, log_queue, is_debug=Fa
alt_offset = ((alt_offset + 180) % 360 - 180) * -1
else:
alt_offset = (alt_offset + 180) % 360 - 180
alt_upd = (last_image_solve["Alt"] - alt_offset) % 360
solved["Alt"] = (last_image_solve["Alt"] - alt_offset) % 360
solved["camera_center"]["Alt"] = (
last_image_solve["camera_center"]["Alt"] - alt_offset
) % 360

az_offset = imu_pos[IMU_AZ] - lis_imu[IMU_AZ]
az_offset = (az_offset + 180) % 360 - 180
az_upd = (last_image_solve["Az"] + az_offset) % 360

solved["Alt"] = alt_upd
solved["Az"] = az_upd
solved["Az"] = (last_image_solve["Az"] + az_offset) % 360
solved["camera_center"]["Az"] = (
last_image_solve["camera_center"]["Az"] + az_offset
) % 360

# N.B. Assumes that location hasn't changed since last solve
# Turn this into RA/DEC
Expand All @@ -167,7 +199,6 @@ def integrator(shared_state, solver_queue, console_queue, log_queue, is_debug=Fa
) = calc_utils.sf_utils.altaz_to_radec(
solved["Alt"], solved["Az"], dt
)

# Calculate the roll at the target RA/Dec and compensate for the offset.
solved["Roll"] = (
calc_utils.sf_utils.radec_to_roll(
Expand All @@ -176,6 +207,25 @@ def integrator(shared_state, solver_queue, console_queue, log_queue, is_debug=Fa
+ solved["Roll_offset"]
)

# Now for camera centered solve
(
solved["camera_center"]["RA"],
solved["camera_center"]["Dec"],
) = calc_utils.sf_utils.altaz_to_radec(
solved["camera_center"]["Alt"],
solved["camera_center"]["Az"],
dt,
)
# Calculate the roll at the target RA/Dec and compensate for the offset.
solved["camera_center"]["Roll"] = (
calc_utils.sf_utils.radec_to_roll(
solved["camera_center"]["RA"],
solved["camera_center"]["Dec"],
dt,
)
+ solved["Roll_offset"]
)

solved["solve_time"] = time.time()
solved["solve_source"] = "IMU"

Expand Down Expand Up @@ -205,8 +255,8 @@ def estimate_roll_offset(solved, dt):
# Calculate the expected roll at the camera center given the RA/Dec of
# of the camera center.
roll_camera_calculated = calc_utils.sf_utils.radec_to_roll(
solved["RA_camera"], solved["Dec_camera"], dt
solved["camera_center"]["RA"], solved["camera_center"]["Dec"], dt
)
roll_offset = solved["Roll_camera"] - roll_camera_calculated
roll_offset = solved["camera_center"]["Roll"] - roll_camera_calculated

return roll_offset
31 changes: 24 additions & 7 deletions python/PiFinder/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,22 @@ def solver(
align_ra = 0
align_dec = 0
solved = {
# RA, Dec, Roll solved at the center of the camera FoV:
"RA_camera": None,
"Dec_camera": None,
"Roll_camera": None,
# RA, Dec, Roll solved at the center of the camera FoV
# update by integrator
"camera_center": {
"RA": None,
"Dec": None,
"Roll": None,
"Alt": None,
"Az": None,
},
# RA, Dec, Roll from the camera, not
# affected by IMU in integrator
"camera_solve": {
"RA": None,
"Dec": None,
"Roll": None,
},
# RA, Dec, Roll at the target pixel
"RA": None,
"Dec": None,
Expand Down Expand Up @@ -165,9 +177,14 @@ def solver(

if solved["RA"] is not None:
# RA, Dec, Roll at the center of the camera's FoV:
solved["RA_camera"] = solved["RA"]
solved["Dec_camera"] = solved["Dec"]
solved["Roll_camera"] = solved["Roll"]
solved["camera_center"]["RA"] = solved["RA"]
solved["camera_center"]["Dec"] = solved["Dec"]
solved["camera_center"]["Roll"] = solved["Roll"]

# RA, Dec, Roll at the center of the camera's not imu:
solved["camera_solve"]["RA"] = solved["RA"]
solved["camera_solve"]["Dec"] = solved["Dec"]
solved["camera_solve"]["Roll"] = solved["Roll"]
# RA, Dec, Roll at the target pixel:
solved["RA"] = solved["RA_target"]
solved["Dec"] = solved["Dec_target"]
Expand Down
Loading

0 comments on commit 133be6b

Please sign in to comment.