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

feat(api): allow robot to discover thermocycler and return live data #3239

Merged
merged 17 commits into from
Mar 22, 2019

Conversation

b-cooper
Copy link
Contributor

In addition to allowing for thermocyclers to be discovered by the hardware controller and returned
from a GET /modules call, this adds a synchronous adapter to the module class instances to allow for
communication with peripherals with out clogging the main pipes. Now all attached modules to a
hardware controller instance will be wrapped in a synchronous adapter. Calls to GET
/modules/{serial}/data should return the expected payload in the presence of a connected
thermocycler board.

Note: the firmware should shim the serial and model strings until further
development on the FW side. I will follow up with a quick PR in the FW repo that I'll link here: [], that adds the stubbed strings for now.

Closes #2958

b-cooper added 11 commits March 15, 2019 15:49
In addition to allowing for thermocyclers to be discovered by the hardware controller and returned
from a GET /modules call, this adds a synchronous adapter to the module class instances to allow for
communication with peripherals with out clogging the main pipes. Now all attached modules to a
hardware controller instance will be wrapped in a synchronous adapter. Calls to GET
/modules/{serial}/data should return the expected payload in the presence of a connected
thermocycler board. Note: the firmware should shim the serial and model strings until further
development on the FW side.

Closes #2958
@b-cooper b-cooper added api Affects the `api` project ready for review feature Ticket is a feature request / PR introduces a feature labels Mar 21, 2019
@codecov
Copy link

codecov bot commented Mar 21, 2019

Codecov Report

Merging #3239 into edge will increase coverage by 0.89%.
The diff coverage is 76.37%.

Impacted file tree graph

@@            Coverage Diff             @@
##             edge    #3239      +/-   ##
==========================================
+ Coverage   53.71%   54.61%   +0.89%     
==========================================
  Files         699      700       +1     
  Lines       20470    20930     +460     
==========================================
+ Hits        10996    11431     +435     
- Misses       9474     9499      +25
Impacted Files Coverage Δ
api/src/opentrons/server/endpoints/control.py 82.56% <0%> (ø) ⬆️
api/src/opentrons/legacy_api/modules/tempdeck.py 71.66% <100%> (ø) ⬆️
api/src/opentrons/drivers/temp_deck/driver.py 69.93% <100%> (-0.16%) ⬇️
api/src/opentrons/protocol_api/contexts.py 84.35% <100%> (ø) ⬆️
api/src/opentrons/hardware_control/simulator.py 90.56% <100%> (ø) ⬆️
api/src/opentrons/legacy_api/modules/magdeck.py 62.06% <100%> (ø) ⬆️
...src/opentrons/hardware_control/modules/__init__.py 63.26% <100%> (ø) ⬆️
.../src/opentrons/hardware_control/modules/mod_abc.py 75% <100%> (ø) ⬆️
api/src/opentrons/drivers/thermocycler/driver.py 26.66% <36%> (-1.32%) ⬇️
api/src/opentrons/hardware_control/controller.py 62.5% <50%> (ø) ⬆️
... and 11 more

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 341385c...168c082. Read the comment docs.

Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

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

Looks good from a high level, but some issues with smaller things throughout.

api/src/opentrons/drivers/temp_deck/driver.py Outdated Show resolved Hide resolved
api/src/opentrons/drivers/thermocycler/driver.py Outdated Show resolved Hide resolved
api/src/opentrons/drivers/thermocycler/driver.py Outdated Show resolved Hide resolved
@@ -312,10 +316,14 @@ def port(self) -> Optional[str]:
def lid_status(self):
return self._lid_status

def get_device_info(self):
raise NotImplementedError
async def get_device_info(self):
Copy link
Member

Choose a reason for hiding this comment

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

We should add type annotations here, including for the return type, and carefully consider whether returning None is the right thing to do if there's no response (vs raising an exception)

api/src/opentrons/drivers/utils.py Outdated Show resolved Hide resolved
api/src/opentrons/drivers/utils.py Outdated Show resolved Hide resolved
api/src/opentrons/hardware_control/adapters.py Outdated Show resolved Hide resolved
@@ -60,6 +60,7 @@ def _write_to_device_and_return(cmd, ack, device_connection):
- return parsed response'''
log.debug('Write -> {}'.format(cmd.encode()))
device_connection.write(cmd.encode())
log.debug(f"After write -> cmd encoded: {cmd.encode()}, connection: {device_connection}, ack: {ack}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to keep this debug statement here?

Copy link
Member

Choose a reason for hiding this comment

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

fwiw I think that's a perfectly ok thing to have, it is debug level after all

@@ -155,7 +153,7 @@ def _wait_for_ack(self):
self._send_command(SERIAL_ACK, timeout=DEFAULT_TC_TIMEOUT)

def _send_command(self, command, timeout=DEFAULT_TC_TIMEOUT):
command_line = command + ' ' + TC_COMMAND_TERMINATOR
command_line = command + ' ' + SERIAL_ACK # TC_COMMAND_TERMINATOR
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we put this back to TC_COMMAND_TERMINATOR?

@@ -13,13 +13,14 @@ def __init__(self):
self._port = None
self._lid_status = 'open'

def open(self):
async def open(self):
print(f"FROM OPEN INSIDE SIMULATING DRIVER active: {self._active}, lid_status: {self._lid_status}")
Copy link
Contributor

Choose a reason for hiding this comment

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

pls remove print statement here.

self.disconnect()
self._poller = TCPoller(
port, self._interrupt_callback, self._temp_status_update_callback)

# Check initial device lid state
_lid_status_res = self._write_and_wait(GCODES['GET_LID_STATUS'])
self._lid_status = _lid_status_res.split()[-1].lower()
log.debug(f"Connected before get lid status write: {self._poller}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this debug statement?

Copy link
Member

Choose a reason for hiding this comment

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

Debug statements are ok if they're logged at debug level

self._lid_status = _lid_status_res.split()[-1].lower()
log.debug(f"Connected before get lid status write: {self._poller}")
_lid_status_res = await self._write_and_wait(GCODES['GET_LID_STATUS'])
log.debug(f"Connected AFTER get lid status write: {_lid_status_res}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here? Or maybe make it a more helpful debug statement if we keep it.

@sfoster1
Copy link
Member

LGTM pending CI

@b-cooper b-cooper merged commit 34af269 into edge Mar 22, 2019
@b-cooper b-cooper deleted the api_tc-status-endpoint branch March 22, 2019 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Affects the `api` project feature Ticket is a feature request / PR introduces a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants