Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed loop slew functionality #539

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ USER "${userid}"
RUN echo "Building from ${image_url}:${image_tag}" && \
sudo apt-get update && \
sudo apt-get install -y --no-install-recommends \
gcc git udev nano vim-nox && \
gcc git udev nano vim-nox rsync && \
sudo mkdir -p "${POCS}/images" && \
sudo mkdir -p "${POCS}/logs" && \
sudo mkdir -p "${POCS}/archive" && \
Expand Down Expand Up @@ -55,5 +55,8 @@ RUN conda env update -n base -f environment.yaml && \
COPY --chown="${userid}:${userid}" resources resources
COPY --chown="${userid}:${userid}" scripts scripts

# Copy Huntsman resources into main panoptes resources directory
RUN rsync -a /huntsman/resources/** /panoptes-pocs/resources

ENTRYPOINT [ "/usr/bin/env", "bash", "-ic" ]
CMD [ "ipython" ]
12 changes: 12 additions & 0 deletions resources/bisque/mount/closed_loop_slew_to_target.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Java Script */

var Out = '';

sky6RASCOMTele.Asynchronous = $async;
sky6RASCOMTele.Abort();

ClosedLoopSlew.exec();

Out = JSON.stringify({
"success": true
});
82 changes: 82 additions & 0 deletions resources/mounts/bisque/meii.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
# Telescope Information
connect:
file: mount/connect.js
response: 1
disconnect:
file: mount/disconnect.js
response: 1
get_status:
file: mount/get_status.js
response: 1

slew_to_coordinates:
file: mount/slew_to_coordinates.js
params: ra dec async
response: 1

stop_slewing:
file: mount/stop.js
response: 1
stop_moving:
file: mount/stop.js
response: 1

start_tracking:
file: mount/start_tracking.js
response: 1
stop_tracking:
file: mount/stop_tracking.js
response: 1
move_north:
file: mount/move_direction.js
move_east:
file: mount/move_direction.js
move_south:
file: mount/move_direction.js
move_west:
file: mount/move_direction.js
stop_moving_horizontal:
file: mount/stop.js
stop_moving_vertical:
file: mount/stop.js
set_sidereal_tracking:
file: mount/set_sidereal.js
set_custom_tracking_rate:
file: mount/set_rate.js
set_custom_ra_tracking_rate:
file: mount/set_rate.js
is_parked:
file: mount/is_parked.js
park:
file: mount/park.js
response: 1
unpark:
file: mount/unpark.js
response: 1
goto_home:
file: mount/slew_to_home.js
response: 1
set_ra:
file: mount/set_ra.js
params: ra
response: 1
set_dec:
file: mount/set_dec.js
params: dec
response: 1
get_coordinates:
file: mount/get_coordinates.js
response: float float
set_target_coordinates:
file: mount/set_target_coordinates.js
response: float float
set_park_position:
file: mount/set_park_position.js
response: 1

# Huntsman additions
closed_loop_slew_to_target:
file: mount/closed_loop_slew_to_target.js
params: async
response: 1
77 changes: 75 additions & 2 deletions src/huntsman/pocs/mount/bisque.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
""" Minimal overrides to the bisque mount. """
import time

from panoptes.utils import error
from panoptes.utils.time import CountdownTimer

from panoptes.pocs.mount.bisque import Mount as BisqueMount
from panoptes.pocs.utils.location import create_location_from_config

Expand All @@ -16,6 +17,8 @@ def create_mount(**kwargs):

class Mount(BisqueMount):

""" Minimal overrides to the Bisque Mount class. """

def __init__(self, *args, **kwargs):

logger = get_logger()
Expand All @@ -36,4 +39,74 @@ def slew_to_target(self, *args, **kwargs):
self.query('stop_tracking')
time.sleep(10)

return super().slew_to_target(*args, **kwargs)
return self._slew_to_target(*args, **kwargs)

# Private methods

def _slew_to_target(self, timeout=180, blocking=True):
""" Override method to use closed loop slew if necessary. Also improve error handling
compared to base class.
"""
if self.is_parked:
raise RuntimeError("Mount is parked. Cannot slew.")

if not self.has_target:
raise RuntimeError("Target Coordinates not set. Cannot slew.")

mount_coords = self._skycoord_to_mount_coord(self._target_coordinates)

self.logger.info(f"Slewing to target: {mount_coords}")

# Check whether we should do a closed loop slew
# Note that a dynamic config item is used here so it can be changed on the fly
do_normal_slew = not self.get_config("mount.closed_loop_slew", False)

if not do_normal_slew:

# Try doing a closed loop slew
self.logger.info("Performing closed-loop slew")
try:
response = self.query('closed_loop_slew_to_target', timeout=timeout)

# If something went wrong e.g. with plate solve, try normal slew instead
except Exception as err:
self.logger.error(f"Problem with closed loop slew: {err!r}. Trying normal slew.")
do_normal_slew = True

# Do a normal slew if necessary
if do_normal_slew:
response = self.query('slew_to_coordinates',
params={'ra': mount_coords[0], 'dec': mount_coords[1]},
timeout=timeout)

# Issue the command
success = response.get("success", False)

if not success:
raise RuntimeError(f"Exception while slewing. Mount response: {response}.")

# Wait for slew to complete
if blocking:
self._wait_for_slew(timeout=timeout)

# Shouldn't need to return this, but instead rely on Exceptions
return success

def _wait_for_slew(self, sleep_time=1, timeout=300):
"""
"""
# Set up the timeout timer
self.logger.debug(f'Setting slew timeout timer for {timeout} sec')
timeout_timer = CountdownTimer(timeout)

while self.is_tracking is False:

# Check if timer is expired
if timeout_timer.expired():
raise error.Timeout('Timeout while slewing to target.')

# Sleep
self.logger.debug(f'Slewing to target, sleeping for {sleep_time} seconds')
timeout_timer.sleep(max_sleep=sleep_time)

self.logger.info("Finished slewing to target. Now tracking.")