Restructured camera attaching
This commit is contained in:
parent
f7ba68b443
commit
41d9ab51ad
1 changed files with 14 additions and 25 deletions
|
|
@ -7,6 +7,7 @@ import numpy as np
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from openflexure_stage import OpenFlexureStage
|
from openflexure_stage import OpenFlexureStage
|
||||||
|
|
||||||
from .camera.pi import StreamingCamera
|
from .camera.pi import StreamingCamera
|
||||||
|
|
||||||
from .plugins import PluginMount
|
from .plugins import PluginMount
|
||||||
|
|
@ -16,19 +17,12 @@ from .lock import CompositeLock
|
||||||
from .config import OpenflexureConfig
|
from .config import OpenflexureConfig
|
||||||
|
|
||||||
|
|
||||||
class Microscope(object):
|
class Microscope:
|
||||||
"""
|
"""
|
||||||
A basic microscope object.
|
A basic microscope object.
|
||||||
|
|
||||||
The camera and stage should already be initialised, and passed as arguments.
|
The camera and stage should already be initialised, and passed as arguments.
|
||||||
|
|
||||||
Args:
|
|
||||||
camera (:py:class:`openflexure_microscope.camera.pi.StreamingCamera`): camera object
|
|
||||||
stage (:py:class:`openflexure_stage.stage.OpenFlexureStage`): stage object
|
|
||||||
config (:py:class:`openflexure_microscope.config.OpenflexureConfig`): Runtime-config object,
|
|
||||||
automatically created if None.
|
|
||||||
attach_plugins (bool): Should the microscope attach plugins listen in 'config' immediately.
|
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
rc (:py:class:`openflexure_microscope.config.OpenflexureConfig`): Runtime-config object,
|
rc (:py:class:`openflexure_microscope.config.OpenflexureConfig`): Runtime-config object,
|
||||||
automatically created if None.
|
automatically created if None.
|
||||||
|
|
@ -40,26 +34,17 @@ class Microscope(object):
|
||||||
background tasks using microscope hardware
|
background tasks using microscope hardware
|
||||||
plugin (:py:class:`openflexure_microscope.plugins.PluginMount`): Mounting point for all microscope plugins
|
plugin (:py:class:`openflexure_microscope.plugins.PluginMount`): Mounting point for all microscope plugins
|
||||||
"""
|
"""
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
camera: StreamingCamera,
|
|
||||||
stage: OpenFlexureStage,
|
|
||||||
config=None,
|
|
||||||
attach_plugins: bool = True):
|
|
||||||
|
|
||||||
# Create RC object
|
def __init__(self):
|
||||||
if config:
|
# Create runtime config object
|
||||||
self.rc = config
|
self.rc = OpenflexureConfig(expand=True)
|
||||||
else:
|
|
||||||
self.rc = OpenflexureConfig(expand=True)
|
|
||||||
|
|
||||||
# Initialise with an empty composite lock
|
# Initialise with an empty composite lock
|
||||||
self.lock = CompositeLock([])
|
self.lock = CompositeLock([])
|
||||||
|
|
||||||
# Attach initial hardware (may be NoneTypes)
|
# Attach dummy hardware initially
|
||||||
self.camera = None
|
# TODO: Handle better. Maybe monad?
|
||||||
self.stage = None
|
self.attach(None, None)
|
||||||
self.attach(camera, stage)
|
|
||||||
|
|
||||||
# Create a task orchestrator
|
# Create a task orchestrator
|
||||||
self.task = TaskOrchestrator()
|
self.task = TaskOrchestrator()
|
||||||
|
|
@ -68,8 +53,7 @@ class Microscope(object):
|
||||||
self.plugin = PluginMount(self)
|
self.plugin = PluginMount(self)
|
||||||
|
|
||||||
# Attach plugins
|
# Attach plugins
|
||||||
if attach_plugins:
|
self.attach_plugins()
|
||||||
self.attach_plugins()
|
|
||||||
|
|
||||||
# Set default parameters
|
# Set default parameters
|
||||||
if 'name' not in self.rc.config:
|
if 'name' not in self.rc.config:
|
||||||
|
|
@ -106,12 +90,16 @@ class Microscope(object):
|
||||||
camera (:py:class:`openflexure_microscope.camera.pi.StreamingCamera`): camera object
|
camera (:py:class:`openflexure_microscope.camera.pi.StreamingCamera`): camera object
|
||||||
stage (:py:class:`openflexure_stage.stage.OpenFlexureStage`): stage object
|
stage (:py:class:`openflexure_stage.stage.OpenFlexureStage`): stage object
|
||||||
"""
|
"""
|
||||||
|
# TODO: Actually attach dummy hardware!
|
||||||
|
# TODO: Use some form of Mabye monad to say arguments may be actual hardware, else dummy?
|
||||||
|
|
||||||
logging.debug("Attaching camera...")
|
logging.debug("Attaching camera...")
|
||||||
self.camera = camera #: :py:class:`openflexure_microscope.camera.pi.StreamingCamera`: Picamera object
|
self.camera = camera #: :py:class:`openflexure_microscope.camera.pi.StreamingCamera`: Picamera object
|
||||||
if isinstance(self.camera, StreamingCamera):
|
if isinstance(self.camera, StreamingCamera):
|
||||||
logging.info("Attached camera {}".format(camera))
|
logging.info("Attached camera {}".format(camera))
|
||||||
logging.info("Updating camera settings")
|
logging.info("Updating camera settings")
|
||||||
|
self.camera.apply_config(self.rc.read())
|
||||||
|
logging.info("Reading complete camera settings")
|
||||||
self.write_config(self.camera.read_config())
|
self.write_config(self.camera.read_config())
|
||||||
elif not self.camera:
|
elif not self.camera:
|
||||||
logging.info("Attached dummy camera.")
|
logging.info("Attached dummy camera.")
|
||||||
|
|
@ -185,6 +173,7 @@ class Microscope(object):
|
||||||
"""
|
"""
|
||||||
Writes and applies a config dictionary. Missing parameters will be left untouched.
|
Writes and applies a config dictionary. Missing parameters will be left untouched.
|
||||||
"""
|
"""
|
||||||
|
# TODO: Have stage object handle apply_config, like camera does
|
||||||
# If attached to a camera
|
# If attached to a camera
|
||||||
if self.camera:
|
if self.camera:
|
||||||
# Update camera config
|
# Update camera config
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue