Skip to content

feat: Simulate telescope motion#7

Open
SaltyPotatoe wants to merge 1 commit intoppp-one:mainfrom
SaltyPotatoe:radec_rate_change
Open

feat: Simulate telescope motion#7
SaltyPotatoe wants to merge 1 commit intoppp-one:mainfrom
SaltyPotatoe:radec_rate_change

Conversation

@SaltyPotatoe
Copy link
Copy Markdown

Summary

This pull request introduces dynamic telescope motion based on configured tracking rates.

Key Changes

  • Telescope Motion Tracking:
    • Implemented _advance_telescope_motion to dynamically update Right Ascension (RA) and Declination (Dec) coordinate values based on their respective tracking rates (rightascensionrate and declinationrate) and elapsed wall-clock time.
    • Automatically calculates internal rate conversions for rightascensionrate to conform with expected API simulator internal units (converting ASCOM-style seconds of RA time per sidereal second to arcseconds per sidereal second).

Tests Added

  • Added test_rightascensionrate_advances_rightascension in tests/api/test_telescope.py to explicitly verify that setting tracking rates correctly alters the observed RA coordinate over time.

…. This allows users to specify how quickly the telescope should move in right ascension and declination, which can be useful for tracking objects or performing smooth slews.
Copilot AI review requested due to automatic review settings April 30, 2026 09:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds simulated telescope coordinate drift by advancing stored Right Ascension/Declination based on configured tracking rates and elapsed time, and adds tests to validate the behavior via the API read endpoints.

Changes:

  • Added _advance_telescope_motion() to update RA/Dec using rightascensionrate / declinationrate and last_motion_update.
  • Hooked motion advancement into GET /rightascension and GET /declination, and updated rate setters to advance motion before changing rates.
  • Added new API tests verifying RA/Dec change over time when rates are set in device state.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
src/alpaca_simulators/api/telescope.py Implements motion advancement and integrates it into RA/Dec reads and rate setters.
tests/api/test_telescope.py Adds timing-based tests asserting RA/Dec advance when rates are configured.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +54 to +68
now = datetime.now(timezone.utc).timestamp()
last_update = state.get("last_motion_update")

if last_update is None:
update_device_state("telescope", device_number, {"last_motion_update": now})
return

elapsed_seconds = now - last_update
if elapsed_seconds <= 0:
return

rightascension = normalize_hours(
state.get("rightascension", 0.0)
+ elapsed_seconds * state.get("rightascensionrate", 0.0) / 54000.0
)
Comment on lines 387 to +389
update_device_state("telescope", device_number, {"declinationrate": DeclinationRate})
update_device_state(
"telescope", device_number, {"last_motion_update": datetime.now(timezone.utc).timestamp()}
assert response.status_code == 200

expected_ra = 1.0 + (2.0 * 225.0) / 54000.0
assert response.json()["Value"] == pytest.approx(expected_ra, abs=1e-4)
Comment on lines +131 to +154
def test_rightascensionrate_advances_rightascension(self, setup_telescope_state):
"""Test that RightAscensionRate advances the stored right ascension over time."""
update_device_state(
"telescope",
0,
{
"rightascension": 1.0,
# internal simulator units are arcseconds per sidereal second
# 15 s-of-RA -> 15 * 15 = 225 arcsec/s
"rightascensionrate": 225.0,
"declination": 0.0,
"declinationrate": 0.0,
"last_motion_update": time.time() - 2.0,
},
)

response = client.get(f"{base_api_path}/0/rightascension", params={"ClientTransactionID": 1})
assert response.status_code == 200

expected_ra = 1.0 + (2.0 * 225.0) / 54000.0
assert response.json()["Value"] == pytest.approx(expected_ra, abs=1e-4)

def test_declinationrate_advances_declination(self, setup_telescope_state):
"""Test that DeclinationRate advances the stored declination over time."""
Comment on lines +163 to +170
"last_motion_update": time.time() - 2.0,
},
)

response = client.get(f"{base_api_path}/0/declination", params={"ClientTransactionID": 2})
assert response.status_code == 200

assert response.json()["Value"] == pytest.approx(12.0, abs=5e-2)
Comment on lines +581 to +585
{"rightascensionrate": ra_rate_arcsec_per_sidereal},
)
update_device_state(
"telescope", device_number, {"last_motion_update": datetime.now(timezone.utc).timestamp()}
)
Comment on lines +573 to +581
# Accept ASCOM-style RightAscensionRate (seconds of RA time per sidereal second)
# and convert to the simulator's internal units (arcseconds per sidereal second).
# 1 second of RA time == 15 arcseconds.
ra_rate_as_seconds_of_time = RightAscensionRate
ra_rate_arcsec_per_sidereal = ra_rate_as_seconds_of_time * 15.0
update_device_state(
"telescope",
device_number,
{"rightascensionrate": ra_rate_arcsec_per_sidereal},
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.

2 participants