Skip to content

Conversation

@karenperezsarmiento
Copy link

@karenperezsarmiento karenperezsarmiento commented Aug 1, 2022

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Unless I am preparing a release, I have opened this PR onto the develop branch.

@BrianJKoopman BrianJKoopman self-requested a review August 2, 2022 18:23
@BrianJKoopman BrianJKoopman added the new agent New OCS agent needs to be created label Aug 2, 2022
@sanahabhimani sanahabhimani changed the base branch from develop to main May 25, 2023 17:30
Copy link
Contributor

@sanahabhimani sanahabhimani left a 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.

Copy link
Member

@BrianJKoopman BrianJKoopman left a 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
pre-commit-ci bot and others added 5 commits November 13, 2024 19:23
- reduced line lengths to satisfy pep8 rules
-- some variable names were adjusted to accomodate this change
…tarcamera

changes:
- reduced line lengths to satisfy pep8 rules
-- some variable names changed to accomodate this change
- changed invalid character in print statement to pass flake8 check
Copy link
Member

@BrianJKoopman BrianJKoopman left a 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.)

tanaybhandarkar and others added 5 commits November 20, 2024 16:07
- fixed invalid character to pass pre-commit check
- resolved merge conflict
- changed a couple variable names that were wrong before
- added import for os environ
- corrected typo in import
- deleted 'LOG =' for txaio logging in main since LOG is never used
@BrianJKoopman BrianJKoopman self-requested a review January 8, 2025 03:09
Copy link
Member

@BrianJKoopman BrianJKoopman left a 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.

Comment on lines 154 to 158
try:
self.StarcamHelper = StarcamHelper(ip_address, port)
except socket.timeout:
self.log.error("Starcamera connection has times out")
return False, "Timeout"
Copy link
Member

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:

@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.

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!

Copy link
Member

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.

AlexManduca and others added 6 commits January 15, 2025 18:36
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”.
AlexManduca and others added 6 commits February 12, 2025 15:38
The 'Returns:' sections were removed from the acq() and the
send_commands() agent operation docstrings.
Edited docstrings to be more consistent with other agents'
docstrings. Nothing outside of docstrings was touched.
Copy link
Member

@BrianJKoopman BrianJKoopman left a 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new agent New OCS agent needs to be created

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants