Skip to content

feat(equipment): each telescope keeps its own alignment point - #703

Merged
brickbots merged 2 commits into
mainfrom
brickbots/align_per_scope
Nov 20, 2026
Merged

brickbots merged 2 commits into
mainfrom
brickbots/align_per_scope

Conversation

@brickbots

@brickbots brickbots commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

What this does

Closes #690.

Each telescope now keeps its own alignment. When you align the PiFinder, it saves the alignment for the active telescope. When you select a different telescope, the PiFinder uses the alignment of that telescope. You do not need to align again when you move the PiFinder between telescopes.

Before this change there was one alignment for all telescopes.

This PR also fixes a problem that made a saved alignment disappear after a restart. See "Config saves" below.

What does not change for users

  • No migration. A telescope that you have not aligned uses the old shared alignment. After the update, every telescope works as before until you align it.
  • New PiFinders use the center of the camera image until you align them, as before. The default telescope in default_config.json does not get its own alignment.
  • The web page does not change. You cannot see or reset the alignment there. If you edit a telescope on the web page, it keeps its alignment.
  • The switch is silent. There is no message when the alignment changes.

How it works

  • Telescope has a new field, target_pixel. It is None until the telescope is aligned. The field is not used when telescopes are compared (compare=False), because the code finds telescopes by value (telescopes.index(), the device menu, the DeepskyLog import). Without this, selecting a telescope from a menu built before the alignment would fail.
  • Config.active_target_pixel() gives the point to use: the active telescope's point, else the global target_pixel, else (256, 256). Config.save_target_pixel() saves to the active telescope. Both alignment screens, the reset key, and the start-up value in SharedStateObj use these two functions.
  • When the telescope changes, the new point goes to shared_state, which the solver reads on every solve:
    • On the device: a post_callback on the Telescope menu (callbacks.apply_target_pixel).
    • On the web page: the reload_config handler in main.py.
  • A stored point that is not usable (wrong shape, not numbers, outside the 512×512 image) is removed with a warning when the config loads. That telescope then uses the global point. Before this check, a bad value made Equipment.from_dict fail, and all equipment was replaced by the defaults.
  • When align mode starts, the Align screen goes to the active telescope's point and forgets the star from an earlier alignment. Without this, SQUARE could align again on the old star and save it for the new telescope.
  • Deleting a telescope on the web page keeps the active telescope (Equipment.remove_telescope). Before, deleting a telescope above the active one selected the next telescope, and with it the alignment of that telescope.

The reasons and the rejected options are in docs/adr/0047-alignment-point-belongs-to-the-telescope.md.

Config saves (ADR 0048)

Each PiFinder process (UI, camera, web server, integrator) reads its own copy of the settings when it starts. Before this PR, a save wrote that whole copy back to config.json. This removed every setting that other processes saved after it started.

The problem that showed it: when you leave Align (Day) with a manual exposure, the camera process saves camera_exp. That save wrote the camera's old copy of the file and removed the alignment that you saved a moment before. The same happened when you selected a manual exposure in the Camera Exp menu. On main, this already removes the global target_pixel. You saw the problem only after a restart.

Now a save reads the file, changes only its own keys, and replaces the file in one step. A file lock (flock) prevents two processes from saving at the same time. Details are in docs/adr/0048-config-saves-write-only-their-own-keys.md.

Tests

  • New test files:
    • test_target_pixel_per_telescope.py: the record, the fallback order, saving, bad values, deleting a telescope.
    • test_target_pixel_wiring.py: the real device menu, the start-up value, the three places that save a point, the Align screen.
    • test_config_persist.py: two Config copies that save different keys, filter reset, atomic write.
    • test_server_equipment_forms.py: web edit keeps the point, web delete keeps the active telescope.
  • I checked that each test fails when I undo the fix that it tests (10 of 10).
  • nox -s lint format type_hints smoke_tests unit_tests all pass (2344 unit tests). The docs build has no warnings.
  • Headless run with the debug camera and two telescopes. I measured the distance between the aligned pointing and the camera center:
    • Dobsonian, not aligned (global point): 3.77°
    • Daytime alignment on the Dobsonian: 0.90°
    • Select the Refractor in the menu: 3.77°
    • Select the Dobsonian again: 0.90°
    • The same through the web page: the same results.
  • Headless run of Align (Day) with a manual camera_exp. Before the fix, the saved point was missing from config.json after you left the screen. After the fix, it stays there.

Also found

  • active_telescope_index = -1 selects the last telescope, not "no telescope". docs/ax/equipment.md said otherwise and is corrected. The code is not changed.
  • The web delete route for eyepieces also uses a bare pop, so it can change the active eyepiece. This PR does not change it.

Hardware check before merge

  • Align on telescope A, select telescope B, align on B, select A again. Each telescope keeps its own alignment.
  • Use Align (Day) with a manual exposure, then restart. The alignment is still there.
  • Select a manual value in Camera Exp after an alignment, then restart. The alignment is still there.

All three checks passed on a PiFinder on 2026-11-19.

🤖 Generated with Claude Code

brickbots and others added 2 commits November 18, 2026 18:10
The alignment point (target pixel) depends on how the PiFinder sits on a
particular telescope, but it was one global setting, so moving the
PiFinder between telescopes meant re-aligning every time.

- Telescope gains target_pixel (None until aligned, excluded from
  equality so value lookups still find an aligned record).
- Config.active_target_pixel() resolves telescope -> global
  target_pixel -> image centre; Config.save_target_pixel() writes to
  the active telescope. Both alignment screens, the reset key and the
  boot-time SharedStateObj go through them.
- Selecting a telescope pushes its point to shared_state: a post_callback
  on the device Telescope menu, and the reload_config handler for the
  web page.
- A web edit of a telescope keeps its point; an unusable stored point
  is dropped on load instead of costing the whole equipment section.
- No migration: unaligned telescopes fall back to the global value, so
  nothing changes until a telescope is aligned.

ADR 0047; glossary, architecture and user docs updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…that clobber each other

Review of #703 (per-telescope alignment):
- Align screen: entering align mode clears the star left from an earlier
  alignment, so the marker starts at the active telescope's point and
  SQUARE cannot re-align on an old star onto the telescope now active.
- Deleting a telescope on the web page keeps the active telescope active
  (Equipment.remove_telescope); a bare pop used to select the next one,
  and with it that telescope's alignment point.
- A stored point must be a (Y, X) pixel inside the 512x512 frame; bools
  and off-frame values are now dropped like other unusable values.
- Tests for the wiring: the real device menu pushes the point to shared
  state, SharedStateObj boots from it, and all three save sites land on
  the active telescope. Each was checked by reverting the fix it covers.

Config saves (ADR 0048): every process holds its own Config, read at
start-up, and set_option wrote that whole copy back to config.json. The
camera process saving camera_exp on leaving Align (Day) therefore reverted
the alignment the UI had just saved. A save now re-reads the file, changes
only its own keys, and replaces the file atomically under an flock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@brickbots
brickbots merged commit b709c6f into main Nov 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant