Skip to content
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

Add support for Astrohaven dome #188

Merged
merged 12 commits into from
Dec 18, 2017
Merged

Conversation

jamessynge
Copy link
Contributor

Includes a simulator for the PLC (programmable logic controller) that controls the dome's motors.

Addresses #134, though there is not yet any integration of domes into the state machine.

Includes a simulator for the PLC (programmable logic controller) that
controls the dome's motors.
Copy link
Member

@wtgee wtgee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is the same PR as before but with squashed commits. Added some comments here but there were some other comments in old PR).

def is_connected(self):
"""True if connected to the hardware or driver."""
if self.ser:
return self.ser.is_connected
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we should be setting the self._is_connected property and then returning that. Not that someone should be messing with the private variable, but this would get it out of sync.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've decided that it doesn't make great sense to put the _is_connected in the base class, AbstractDome, in part because of issues exactly like this. So, I'm inclined to respond to this feedback by stripping it out from AbstractDome, and implementing it in the sub-classes as appropriate to the means to establishing that connection.

return False

def connect(self):
""" Connects to the device via the serial port (`self._port`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't like advertising a private variable in the docstring. But I still kind of think the port shouldn't be private anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, will move it to public.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I assume you agree that port shouldn't be changed, right?

except OSError as err:
self.logger.error("OS error: {0}".format(err))
except error.BadSerialConnection as err:
self.logger.warning('Could not create serial connection to mount.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still refers to mount here and in line below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed locally, will push later.

self.logger.debug("Closing serial port for dome")
self._is_connected = self.ser.disconnect()

def verifyConnected(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify_connected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done locally.

import pytest
import serial

from pocs.dome import CreateDomeFromConfig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be create_dome_from_config but I couldn't comment on file up above and must have skipped it in previous review.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return self.is_closed

@property
def state(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment in other PR was about switching this to status. You seem to be using read_latest_state for all decision making so this seems like it is for a user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is for the end user. Will create another issue/branch/PR for general changes to the dome API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed issue #189 for this.

return chr(data[-1])
return None

def nudge_shutter(self, send, target_feedback):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstrings missing. Important here where there are parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return feedback == target_feedback

def full_move(self, send, target_feedback):
"""Send a command code until the target_feedback is recieved, or a timeout is reached."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document the parameters. Not sure if send should be bytes or a string nor what target_feedback represents.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

feedback = self.read_latest_state()
return feedback == target_feedback

def full_move(self, send, target_feedback):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this should just be named open_shutter or open. When I think of a dome moving I think of it rotating. For consistency with (eventual) other dome subclasses I think an open method makes the most sense. All domes open in some way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

full_move goes in either direction, i.e. opens or closes, o it moves from whatever the current position is to the commanded position (i.e. until target_feedback is the output).

@jamessynge jamessynge mentioned this pull request Dec 13, 2017
Also renamed internal methods to have a leading underscore.
Tried to be more consistent in describing the Astrohaven protocol
(command vs. action).
@codecov
Copy link

codecov bot commented Dec 13, 2017

Codecov Report

Merging #188 into develop will decrease coverage by 0.39%.
The diff coverage is 76.92%.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop     #188     +/-   ##
==========================================
- Coverage    80.52%   80.13%   -0.4%     
==========================================
  Files           39       42      +3     
  Lines         2794     3136    +342     
  Branches       354      404     +50     
==========================================
+ Hits          2250     2513    +263     
- Misses         435      490     +55     
- Partials       109      133     +24
Impacted Files Coverage Δ
pocs/utils/rs232.py 93.93% <100%> (+0.06%) ⬆️
pocs/dome/simulator.py 100% <100%> (ø) ⬆️
pocs/utils/error.py 92.85% <100%> (+0.35%) ⬆️
pocs/dome/abstract_serial_dome.py 63.04% <63.04%> (ø)
pocs/dome/protocol_astrohaven_simulator.py 76% <76%> (ø)
pocs/dome/astrohaven.py 80% <80%> (ø)
pocs/dome/__init__.py 91.66% <92.85%> (+14.92%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c582bef...7057db2. Read the comment docs.

only. Modified existing code to make it readily apparent that it is a
presentation string and NOT a keyword or enum.

Fixed imports in the dome code to be root relative (~absolute), and to
be imports of packages and modules, not symbols in modules.
Fix error dereferencing SerialData.ser in __del__. Issue panoptes#194.
@jamessynge
Copy link
Contributor Author

PTAL

Copy link
Member

@wtgee wtgee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm approving so you are not blocked by me as I think this is good. See comment about self.ser.

@@ -210,7 +211,7 @@ def __del__(self):
# If an exception is thrown when running __init__, then self.ser may not have
# been set, in which case reading that field will generate a NameError.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update comment to reflect error.

baudrate = int(cfg.get('baudrate', 9600))

# Setup our serial connection to the given port.
self.ser = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only other comment was about turning this into self.serial so we have self.serial.ser instead of self.ser.ser, which is more consistent with the mount. Any reason you want to keep it this way?

@jamessynge jamessynge merged commit da4d735 into panoptes:develop Dec 18, 2017
@jamessynge jamessynge deleted the astrohaven3 branch December 18, 2017 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants