-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove most use of literal lists of simulators. (#200)
* Add pocs/hardware.py, with info about all the types of hardware that could exist, and support for producing the list of simulators. Use this in place of hardcoded lists of simulators.
- Loading branch information
1 parent
b3ca111
commit b8f0026
Showing
6 changed files
with
89 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""Information about hardware supported by Panoptes.""" | ||
|
||
ALL_NAMES = sorted(['camera', 'dome', 'mount', 'night', 'weather']) | ||
|
||
|
||
def get_all_names(all_names=ALL_NAMES, without=list()): | ||
"""Returns the names of all the categories of hardware that POCS supports. | ||
Note that this doesn't extend to the Arduinos for the telemetry and camera boards, for | ||
which no simulation is supported at this time. | ||
""" | ||
return [v for v in all_names if v not in without] | ||
|
||
|
||
def get_simulator_names(simulator=None, kwargs=None, config=None): | ||
"""Returns the names of the simulators to be used in lieu of hardware drivers. | ||
Note that returning a list containing 'X' doesn't mean that the config calls for a driver | ||
of type 'X'; that is up to the code working with the config to create drivers for real or | ||
simulated hardware. | ||
This funciton is intended to be called from PanBase or similar, which receives kwargs that | ||
may include simulator, config or both. For example: | ||
get_simulator_names(config=self.config, kwargs=kwargs) | ||
Or: | ||
get_simulator_names(simulator=simulator, config=self.config) | ||
The reason this function doesn't just take **kwargs as its sole arg is that we need to allow | ||
for the case where the caller is passing in simulator (or config) twice, once on its own, | ||
and once in the kwargs (which won't be examined). Python doesn't permit a keyword argument | ||
to be passed in twice. | ||
Args: | ||
simulator: | ||
An explicit list of names of hardware to be simulated (i.e. hardware drivers | ||
to be replaced with simulators). | ||
kwargs: | ||
The kwargs passed in to the caller, which is inspected for an arg called 'simulator'. | ||
config: | ||
Dictionary created from pocs.yaml or similar. | ||
Returns: | ||
List of names of the hardware to be simulated. | ||
""" | ||
empty = dict() | ||
|
||
def extract_simulator(d): | ||
return (d or empty).get('simulator') | ||
|
||
for v in [simulator, extract_simulator(kwargs), extract_simulator(config)]: | ||
if not v: | ||
continue | ||
if isinstance(v, str): | ||
v = [v] | ||
if 'all' in v: | ||
return get_all_names() | ||
else: | ||
return sorted(v) | ||
return [] |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from pocs import hardware | ||
from pocs import POCS | ||
|
||
pocs = POCS(simulator=['camera', 'weather']) | ||
pocs = POCS(simulator=hardware.get_all_names(without=['mount', 'night'])) | ||
pocs.observatory.mount.initialize() | ||
pocs.observatory.mount.home_and_park() | ||
pocs.power_down() |