Skip to content

Commit

Permalink
Merge branch 'release_candidate' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
brickbots committed May 24, 2024
2 parents f2fc0bf + 2ddfbc2 commit 9582ad8
Show file tree
Hide file tree
Showing 17 changed files with 214 additions and 107 deletions.
24 changes: 3 additions & 21 deletions default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,14 @@
"sleep_timeout": "30s",
"screen_off_timeout": "Off",
"hint_timeout": "2s",
"chart_display_radec": "Off",
"solve_pixel": [256, 256],
"catalogs": [
"NGC",
"IC",
"M",
"C",
"Col",
"H",
"Ta2",
"Str",
"RDS",
"SaA",
"SaR",
"SaM",
"Abl",
"EGC",
"B",
"Sh2"
],
"active_catalogs": [
"NGC",
"M",
"H",
"Ta2",
"Str",
"SaA",
"Sh2"
"PL",
"RDS"
]
}
4 changes: 2 additions & 2 deletions python/PiFinder/calc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def dec_to_dms(dec):
fractional_degree = abs(dec - degree)
minute = int(fractional_degree * 60)
second = (fractional_degree * 60 - minute) * 60
return degree, minute, round(second, 2)
return int(degree), int(minute), int(second)


def ra_to_hms(ra):
Expand All @@ -106,7 +106,7 @@ def ra_to_hms(ra):
mm, hh = math.modf(ra / 15.0)
_, mm = math.modf(mm * 60.0)
ss = round(_ * 60.0)
return hh, mm, ss
return int(hh), int(mm), int(ss)


def b1950_to_j2000(ra_hours, dec_deg):
Expand Down
10 changes: 7 additions & 3 deletions python/PiFinder/camera_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def get_image_loop(
debug = False

screen_direction = cfg.get_option("screen_direction")
camera_rotation = cfg.get_option("camera_rotation")

# Set path for test images
root_dir = os.path.realpath(
Expand Down Expand Up @@ -73,10 +74,13 @@ def get_image_loop(
if not debug:
base_image = self.capture()
base_image = base_image.convert("L")
if screen_direction == "right":
base_image = base_image.rotate(90)
if camera_rotation is None:
if screen_direction == "right":
base_image = base_image.rotate(90)
else:
base_image = base_image.rotate(270)
else:
base_image = base_image.rotate(270)
base_image = base_image.rotate(int(camera_rotation) * -1)
else:
# load image and wait
base_image = Image.open(test_image_path)
Expand Down
22 changes: 15 additions & 7 deletions python/PiFinder/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import time
import datetime
import pytz
from pprint import pformat

from typing import List, Dict, DefaultDict, Optional
from collections import defaultdict
import PiFinder.calc_utils as calc_utils
Expand Down Expand Up @@ -336,18 +338,24 @@ def set(self, catalogs: List[Catalog]):
self._select_all_catalogs()
self._refresh_code_to_pos()

def add(self, catalog: Catalog):
def add(self, catalog: Catalog, select: bool = False):
if catalog.catalog_code not in self._code_to_pos:
self.__catalogs.append(catalog)
self._select_all_catalogs()

# Add the newly added index to the selection list to make sure it's
# selected
if select:
self.__selected_catalogs_idx.append(len(self.__catalogs) - 1)
self._refresh_code_to_pos()
else:
logging.warning(f"Catalog {catalog.catalog_code} already exists")

def remove(self, catalog_code: str):
if catalog_code in self._code_to_pos_sel:
idx = self._code_to_pos_sel[catalog_code]
self.__selected_catalogs_idx.remove(idx)
if catalog_code in self._code_to_pos:
idx = self._code_to_pos[catalog_code]
self.__catalogs.pop(idx)
if idx in self.__selected_catalogs_idx:
self.__selected_catalogs_idx.remove(idx)
self._refresh_code_to_pos()
else:
logging.warning(f"Catalog {catalog_code} does not exist")
Expand Down Expand Up @@ -402,10 +410,10 @@ def _refresh_code_to_pos(self):
}

def _select_all_catalogs(self):
self.__selected_catalogs_idx = [x for x in range(len(self.__catalogs))]
self.__selected_catalogs_idx = list(range(len(self.__catalogs)))

def __repr__(self):
return f"Catalogs({self.get_catalogs()=}, selected {len(self.__selected_catalogs_idx)}/{len(self.__catalogs)})"
return f"Catalogs(\n{pformat(self.get_catalogs(only_selected=False))},\n selected {len(self.__selected_catalogs_idx)}/{len(self.__catalogs)},\n{self.__selected_catalogs_idx})"

def __str__(self):
return self.__repr__()
Expand Down
4 changes: 3 additions & 1 deletion python/PiFinder/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def set_option(self, option, value):
json.dump(self._config_dict, config_file, indent=4)

def get_option(self, option):
return self._config_dict.get(option, self._default_config_dict[option])
return self._config_dict.get(
option, self._default_config_dict.get(option, None)
)

def __str__(self):
return str(self._config_dict)
Expand Down
24 changes: 20 additions & 4 deletions python/PiFinder/gps_pi.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def gps_monitor(gps_queue, console_queue):
lambda x: is_tpv_accurate(x),
client.dict_stream(convert_datetime=True, filter=["TPV"]),
)
sky_filter = client.dict_stream(convert_datetime=True, filter=["SKY"])
readings_list = list(islice(readings_filter, 10))
sky_list = list(islice(sky_filter, 10))
if readings_list:
result = min(
readings_list,
Expand All @@ -42,8 +44,8 @@ def gps_monitor(gps_queue, console_queue):
logging.debug("last reading is %s", result)
if result.get("lat") and result.get("lon") and result.get("altHAE"):
if gps_locked is False:
console_queue.put("GPS: Locked")
gps_locked = True
console_queue.put("GPS: Locked")
msg = (
"fix",
{
Expand All @@ -55,14 +57,28 @@ def gps_monitor(gps_queue, console_queue):
logging.debug("GPS fix: %s", msg)
gps_queue.put(msg)

# Look for any time bearing packet
for result in readings_list:
# search from the newest first, quit if something is found
for result in reversed(readings_list):
if result.get("time"):
msg = ("time", result.get("time"))
logging.debug("Setting time to %s", result.get("time"))
gps_queue.put(msg)
break
else:
logging.debug("GPS client queue is empty")
logging.debug("GPS TPV client queue is empty")

if sky_list:
# search from the newest first, quit if something is found
for result in reversed(sky_list):
if result["class"] == "SKY" and "satellites" in result:
# logging.debug(f"SKY packet found: {result['satellites']}")
sats = result["satellites"]
sats_seen = len(sats)
sats_used = len(list(filter(lambda x: x["used"], sats)))
num_sats = (sats_seen, sats_used)
msg = ("satellites", num_sats)
logging.debug(f"Number of satellites seen: {num_sats}")
gps_queue.put(msg)
break
logging.debug("GPS sleeping now")
time.sleep(7)
4 changes: 3 additions & 1 deletion python/PiFinder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ def main(script_name=None, show_fps=False, verbose=False):
console = UIConsole(display_device, None, shared_state, command_queues, cfg)
console.write("Starting....")
console.update()
time.sleep(2)

# spawn gps service....
console.write(" GPS")
Expand Down Expand Up @@ -468,6 +467,9 @@ def main(script_name=None, show_fps=False, verbose=False):
logging.debug(f"GPS time msg: {gps_content}")
gps_dt = gps_content
shared_state.set_datetime(gps_dt)
if gps_msg == "satellites":
logging.debug(f"Main: GPS nr sats seen: {gps_content}")
shared_state.set_sats(gps_content)
except queue.Empty:
pass

Expand Down
2 changes: 1 addition & 1 deletion python/PiFinder/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def solver(shared_state, solver_queue, camera_image, console_queue, is_debug=Fal
)

if len(centroids) == 0:
logging.debug("No stars found, skipping")
# logging.debug("No stars found, skipping")
continue
else:
solution = t3.solve_from_centroids(
Expand Down
7 changes: 7 additions & 0 deletions python/PiFinder/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def __init__(self):
"imu_delta": 0,
}
self.__solution = None
self.__sats = None
self.__imu = None
self.__location = None
self.__datetime = None
Expand Down Expand Up @@ -182,6 +183,12 @@ def solve_state(self):
def set_solve_state(self, v):
self.__solve_state = v

def sats(self):
return self.__sats

def set_sats(self, v):
self.__sats = v

def imu(self):
return self.__imu

Expand Down
21 changes: 17 additions & 4 deletions python/PiFinder/ui/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class UIModule:
_CAM_ICON = ""
_IMU_ICON = ""
_GPS_ICON = "󰤉"
_LEFT_ARROW = ""
_RIGHT_ARROW = ""
_UP_ARROW = ""
_DOWN_ARROW = ""
_gps_brightness = 0
_unmoved = False # has the telescope moved since the last cam solve?

def __init__(
Expand Down Expand Up @@ -212,10 +217,18 @@ def screen_update(self, title_bar=True, button_hints=True):

# GPS status
if self.shared_state.location()["gps_lock"]:
self.draw.rectangle([100, 2, 110, 14], fill=bg)
self.draw.text(
(102, -2), self._GPS_ICON, font=fonts.icon_bold_large, fill=fg
)
self._gps_brightness = 0
else:
self._gps_brightness += 1
if self._gps_brightness > 64:
self._gps_brightness = -128

_gps_color = self.colors.get(
self._gps_brightness if self._gps_brightness > 0 else 0
)
self.draw.text(
(102, -2), self._GPS_ICON, font=fonts.icon_bold_large, fill=_gps_color
)

if moving:
self._unmoved = False
Expand Down
24 changes: 14 additions & 10 deletions python/PiFinder/ui/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ class UICatalog(UIModule):

def __init__(self, *args):
super().__init__(*args)

# Initialze Catalogs
self.catalogs: Catalogs = CatalogBuilder().build()

self.catalog_names = self.config_object.get_option("active_catalogs")
self._config_options["Catalogs"]["value"] = self.catalog_names.copy()
self._config_options["Catalogs"]["options"] = self.config_object.get_option(
"catalogs"
self._config_options["Catalogs"]["options"] = self.catalogs.get_codes(
only_selected=False
)

self.object_text = ["No Object Found"]
Expand All @@ -118,7 +122,6 @@ def __init__(self, *args):
"No Object Found", font=self.font_bold, color=self.colors.get(255)
),
}
self.catalogs: Catalogs = CatalogBuilder().build()
logging.debug(f"Catalogs created: {self.catalogs}")
logging.debug(
f"Value:{self._config_options['Catalogs']['value']}, Options{self._config_options['Catalogs']['options']}"
Expand All @@ -139,19 +142,21 @@ def __init__(self, *args):
self.catalog_tracker.filter()
self.closest_objects_finder = ClosestObjectsFinder()
self.update_object_info()
self._planets_loaded = False

def add_planets(self, dt):
"""
Since we can't calc planet positions until we know the date/time
this is called once we have a GPS lock to add on the planets catalog
"""
self.catalogs.remove("PL")
self.catalogs.add(PlanetCatalog(dt))

# We need to feed through the planet catalog selection status
# here so when it gets re-added we can re-select it if needed
_select = "PL" in self._config_options["Catalogs"]["value"]
self.catalogs.add(PlanetCatalog(dt), select=_select)
self.catalog_tracker = CatalogTracker(
self.catalogs, self.shared_state, self._config_options
)
self._planets_loaded = True

def _layout_designator(self):
"""
Expand Down Expand Up @@ -374,10 +379,9 @@ def active(self):
super().active()

# check for planet add
if not self._planets_loaded:
dt = self.shared_state.datetime()
if dt:
self.add_planets(dt)
dt = self.shared_state.datetime()
if dt:
self.add_planets(dt)

self.catalog_tracker.filter()
target = self.ui_state.target()
Expand Down
Loading

0 comments on commit 9582ad8

Please sign in to comment.