feat: Simulate telescope motion#7
Open
SaltyPotatoe wants to merge 1 commit intoppp-one:mainfrom
Open
Conversation
…. 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.
There was a problem hiding this comment.
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 usingrightascensionrate/declinationrateandlast_motion_update. - Hooked motion advancement into
GET /rightascensionandGET /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}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request introduces dynamic telescope motion based on configured tracking rates.
Key Changes
_advance_telescope_motionto dynamically update Right Ascension (RA) and Declination (Dec) coordinate values based on their respective tracking rates (rightascensionrateanddeclinationrate) and elapsed wall-clock time.rightascensionrateto conform with expected API simulator internal units (converting ASCOM-style seconds of RA time per sidereal second to arcseconds per sidereal second).Tests Added
test_rightascensionrate_advances_rightascensionintests/api/test_telescope.pyto explicitly verify that setting tracking rates correctly alters the observed RA coordinate over time.