-
Notifications
You must be signed in to change notification settings - Fork 14
Starcamera - first PR request for testing starcamera at the LAT #335
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
base: main
Are you sure you want to change the base?
Conversation
sanahabhimani
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, Karen! Sorry it took us a while to get back to you; since your initial request, we've restructured socs so PR's are now made to merge into main instead of develop.
I changed a lot of the key structure of your star camera agent branch to make it compatible with the updated socs. This way, the comments are more related to the agent itself. As a result, when you go to make updates to this agent, be sure to pull from the starcamera branch first to make sure you have the up-to-date version of this branch.
A couple notes were made on the extra files pushed to the branch.
One major note that isn't present in the comments below: you'll also need to write documentation for your agent so that it's available to see on the socs readthedocs page.
BrianJKoopman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks @karenperezsarmiento! And thanks @sanahabhimani for the thorough review!
I've commented on some points that Sanah brought up, and also have a structural question about the way the task and process interact to command the starcamera.
…ocs/socs/agents/starcam_lat
in agent.py:
- changed class names from starcam_Helper and starcam_Agent to StarcamHelper and StarcamAgent
- combined pack_cmds() and send_cmds() into single function: pack_and_send_cmds()
- in pack_and_send_cmds(),
added all values to a list (named values)
packed and sent said commands
added a return values
- in get_astrom_data(),
added a list of keys for a dictionary
made dictionary from unpacked data
added a return for this dictionary
- in acq(),
replace dictionary definition given the changes to get_astrom_data()
changed job = 'init' to job = 'acq'
- in add_agent_args()
removed defult ip address
changed --user-port to --port
change all instances of parser_in to parser
moved import statement to top of file
- in main()
removed startup=True
added txaio commands for logging and import txaio at top of file
- changed doc strings across file
- insterted ocs param decorator above send_commands()
- changed latitude, longitude, and height params in send_commands() to reflect chilean coords
001a752 to
3fc8d8b
Compare
for more information, see https://pre-commit.ci
…tarcamera changes: - reduced line lengths to satisfy pep8 rules -- some variable names changed to accomodate this change
for more information, see https://pre-commit.ci
BrianJKoopman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @AlexManduca, sorry I haven't had a chance to review your recent changes in detail yet, but there are a couple of things to address first anyway. In addition to the comment below the pre-commit checks are failing due to invalid characters in the code, see details here: https://results.pre-commit.ci/run/github/186511668/1732120479.uB-orrk5RL2nfbGl2oGNXg
(This link is linked at the bottom of the PR if you click "details" next to "pre-commit.ci - pr" in the checks section.)
for more information, see https://pre-commit.ci
BrianJKoopman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good, thanks @AlexManduca. A few more comments to address below.
Another general comment is we need a page for this agent in the documentation. That will live in socs/docs/agents/. A template for this page can be found in the ocs docs. Feel free to reference any of the existing pages too. Once you create a page, please add it to the index here as well.
| try: | ||
| self.StarcamHelper = StarcamHelper(ip_address, port) | ||
| except socket.timeout: | ||
| self.log.error("Starcamera connection has times out") | ||
| return False, "Timeout" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would still be useful to separate this part into an init operation that can be called from an ocs client (as hinted at in #335 (comment).) That would allow users to re-initialize the connection to the star camera without needing to completely restart the agent. That structure is in many of the other agents, one good example is the CryomechAgent:
socs/socs/agents/cryomech_cpa/agent.py
Lines 50 to 91 in 9242ab2
| @ocs_agent.param('auto_acquire', default=False, type=bool) | |
| def init(self, session, params=None): | |
| """init(auto_acquire=False) | |
| **Task** - Initializes the connection to the PTC. | |
| Parameters: | |
| auto_acquire (bool): Automatically start acq process after | |
| initialization if True. Defaults to False. | |
| """ | |
| if self.initialized: | |
| return True, "Already Initialized" | |
| with self.lock.acquire_timeout(0, job='init') as acquired: | |
| if not acquired: | |
| self.log.warn("Could not start init because " | |
| "{} is already running".format(self.lock.job)) | |
| return False, "Could not acquire lock." | |
| # Establish connection to ptc | |
| self.ptc = PTC(self.ip_address, port=self.port, | |
| fake_errors=self.fake_errors) | |
| # Test connection and display identifying info | |
| try: | |
| self.ptc.get_data() | |
| except ConnectionError: | |
| self.log.error("Could not establish connection to compressor.") | |
| return False, "PTC agent initialization failed" | |
| print("PTC Model:", self.ptc.model) | |
| print("PTC Serial Number:", self.ptc.serial) | |
| print("Software Revision is:", self.ptc.software_revision) | |
| self.initialized = True | |
| # Start data acquisition if requested | |
| if params['auto_acquire']: | |
| resp = self.agent.start('acq', params={}) | |
| self.log.info(f'Response from acq.start(): {resp[1]}') | |
| return True, "PTC agent initialized" |
I'd be happy to help with this, and to simultaneously set this up to use the new TCPInterface base class for the TCP connection to the star camera, as that will help make the agent robust against network issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so that would mean there would be e.g. an "init" button on ocs-web. Cool! And added robustness for TCP connection would be great, the connection does tend to drop pretty frequently.
Thanks for offering that, let me know how best to proceed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for offering that, let me know how best to proceed!
Just let me know when you're done making changes.
Docstrings are now consistently formatted according to the 'Example Google Style Python Docstrings' document found at the following URL: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/ex ample_google.html#example-google Several different ways of writing "starcam" (e.g. "starcamera", "star camera", etc.) made references to the instrument name inconsistent. All instances have been changed to a succinct "starcam". One or two typos were also fixed, and periods were added where appropriate. Resolves:
The buffer size had been set to an unusual 224. It is now set to 256.
- In StarcamAgent’s __init__(), self.active = True and
self.job = None are leftover from the agent this one was based on.
- In acq(), if params is None: params = {} is not necessary.
- In _stop_acq(), the comment should be removed as we currently
have no way to re-establish connection without restarting the
agent.
Attribute names changed from Pascal case to snake case. e.g. self.StarcamHelper --> self.starcam
Docstrings: The docstrings for Tasks in this agent were not correctly formatted. They have been adjusted to accomodate the standards set forth in the following document: https://ocs.readthedocs.io/en/main/developer/agent_references/ documentation.html#session-data Accompanying this reformatting, the session.data object structure was documented in the acq() docstring. Timeout: The timeout for acquiring a lock was set to 100s. This has been changed to 10s. Typo: The self.log.warn String was changed from “Could not start init because {} is already running” to “Could not start acq because {} is already running”.
for more information, see https://pre-commit.ci
The 'Returns:' sections were removed from the acq() and the send_commands() agent operation docstrings.
for more information, see https://pre-commit.ci
Edited docstrings to be more consistent with other agents' docstrings. Nothing outside of docstrings was touched.
for more information, see https://pre-commit.ci
BrianJKoopman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the changes @AlexManduca, this is looking good. I made some small commits, including adding a docs page. Would you mind filling out the sections that have text starting with '#' -- the brief description, any dependencies, and more detailed description of the agent/hardware it controls in this file?
Besides that all that's left is for me to implement that 'init' task with TCP connection handling that I said I'd implement. I should be able to get that done by end of day tomorrow, then we'll just want to test things work alright. Is the star camera in a state where we can do that?
Description
The latest version of the starcamera agent is able to connect to the device, receive telemetry/astrometry data and save it to the correct registries.
Motivation and Context
Agent is capable to connecting to device and receiving telemetry data.
How Has This Been Tested?
The agent has been tested with the starcamera system connected but dark (test run not done on real sky).
Types of changes
Checklist:
developbranch.