Skip to content

Commit

Permalink
#200 Expose more Helios parameters to config (3)
Browse files Browse the repository at this point in the history
Use `target_pixel_brightness` from config
  • Loading branch information
dostuffthatmatters committed Nov 8, 2023
1 parent 02a351d commit c9270b4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/helios.config.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"min_seconds_between_state_changes": 180,
"edge_pixel_threshold": 0.01,
"edge_color_threshold": 40,
"target_pixel_brightness": 50,
"save_images_to_archive": false,
"save_current_image": false
}
24 changes: 20 additions & 4 deletions packages/core/threads/helios_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(

self.current_exposure: int = min(self.available_exposures)
self.last_autoexposure_time: float = 0.0
self.target_pixel_brightness: int = 0
self.available_exposures: list[int] = available_exposures

self.update_camera_settings(exposure=self.current_exposure)
Expand Down Expand Up @@ -141,7 +142,7 @@ def adjust_exposure(self) -> None:
"""This function will loop over all available exposures and
take one image for each exposure. Then it sets exposure to
the value where the overall mean pixel value color is closest
to 50.
to `self.target_pixel_brightness`.
**For every exposure:**
Expand Down Expand Up @@ -200,8 +201,8 @@ class ExposureResult(pydantic.BaseModel):
new_exposure = int(
min(
exposure_results,
key=lambda r:
abs(sum(r.means) / _NUMBER_OF_EXPOSURE_IMAGES - 50),
key=lambda r: abs((sum(r.means) / _NUMBER_OF_EXPOSURE_IMAGES) -
self.target_pixel_brightness),
).exposure
)
self.update_camera_settings(exposure=new_exposure)
Expand All @@ -216,15 +217,28 @@ def run(
self,
station_id: str,
edge_color_threshold: int,
target_pixel_brightness: int,
save_images_to_archive: bool,
save_current_image: bool,
) -> float:
"""Take an image and evaluate the sun conditions. Run autoexposure
function every 5 minutes. Returns the edge fraction."""
perform_autoexposure: bool = False
now = time.time()
if (now - self.last_autoexposure_time) > 300:
self.adjust_exposure()
self.logger.debug("performing autoexposure after 5 minutes")
perform_autoexposure = True
if self.target_pixel_brightness != target_pixel_brightness:
self.logger.debug(
"performing autoexposure because target_pixel_brightness changed"
+
f" ({self.target_pixel_brightness} -> {target_pixel_brightness})"
)
perform_autoexposure = True
if perform_autoexposure:
self.target_pixel_brightness = target_pixel_brightness
self.last_autoexposure_time = now
self.adjust_exposure()

frame = self.take_image()

Expand Down Expand Up @@ -361,6 +375,8 @@ def main(headless: bool = False) -> None:
new_edge_fraction = helios_instance.run(
station_id=config.general.station_id,
edge_color_threshold=config.helios.edge_color_threshold,
target_pixel_brightness=config.helios.
target_pixel_brightness,
save_images_to_archive=(
config.helios.save_images_to_archive
),
Expand Down
2 changes: 2 additions & 0 deletions packages/core/types/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class HeliosConfig(StricterBaseModel):
min_seconds_between_state_changes: int = pydantic.Field(..., ge=0, le=3600)
edge_pixel_threshold: float = pydantic.Field(..., ge=0, le=1)
edge_color_threshold: int = pydantic.Field(..., ge=5, le=250)
target_pixel_brightness: int = pydantic.Field(..., ge=20, le=235)
save_images_to_archive: bool
save_current_image: bool

Expand All @@ -220,6 +221,7 @@ class PartialHeliosConfig(StricterBaseModel):
)
edge_pixel_threshold: Optional[float] = pydantic.Field(None, ge=0, le=1)
edge_color_threshold: Optional[int] = pydantic.Field(None, ge=5, le=250)
target_pixel_brightness: Optional[int] = pydantic.Field(None, ge=20, le=235)
save_images_to_archive: Optional[bool] = None
save_current_image: Optional[bool] = None

Expand Down

0 comments on commit c9270b4

Please sign in to comment.