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

API: add hardware control #2349

Merged
merged 3 commits into from
Sep 24, 2018
Merged

API: add hardware control #2349

merged 3 commits into from
Sep 24, 2018

Conversation

sfoster1
Copy link
Member

@sfoster1 sfoster1 commented Sep 24, 2018

overview

Add a new submodule called hardware_control that will, going forward, be the unit that controls all of the hardware in the robot (the implementation of #2232 ).

The hardware_control module is a HAL that presents an API at the lowest semantic level possible while still considering the OT2 as a "robot" rather than as a collection of disparate hardware. For instance, it considers the robot's motion systems as a coherent whole, but uses the absolute deck coordinate frame and does not know about labware. It presents an API on the level of move (specifying the gantry axes and each pipette axis), aspirate and dispense, and pick_up_tip and drop_tip (over wherever the pipette happens to be, not moving to specific locations) but does not have the higher-level commands such as distribute. It does not even have the arc motion planning.

This module should be initialized once per robot (and there are mechanisms to make sure of this using thread and file locks) and should have a drop in simulating replacement.

As of now, until the rest of the functionality in the Robot Refactor milestone is complete, the module is not integrated into the rest of the system aside from its tests (on platforms other than Windows, anyway). This PR just establishes the structure.

Closes #2232

The hardware_control submodule is the controller of the robot's hardware. Its API can move the robot
at a level of abstraction that portrays the robot as a whole, not including the labware. In this PR,
the module is a stub, and not used by default. Further PRs will introduce more functionality.

Closes #2232
@sfoster1 sfoster1 force-pushed the api_add-hardware-control branch from 784b1fa to 20c293f Compare September 24, 2018 15:43
@sfoster1 sfoster1 changed the title Api add hardware control API: add hardware control Sep 24, 2018
@codecov
Copy link

codecov bot commented Sep 24, 2018

Codecov Report

Merging #2349 into edge will increase coverage by 0.61%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             edge    #2349      +/-   ##
==========================================
+ Coverage   30.01%   30.62%   +0.61%     
==========================================
  Files         508      509       +1     
  Lines        8126     8753     +627     
==========================================
+ Hits         2439     2681     +242     
- Misses       5687     6072     +385
Impacted Files Coverage Δ
app-shell/src/update.js 68.75% <0%> (-31.25%) ⬇️
app-shell/src/api-update.js 10.34% <0%> (-5.45%) ⬇️
...tocol-designer/src/file-data/selectors/commands.js 19.26% <0%> (-3.47%) ⬇️
protocol-designer/src/steplist/actions/actions.js 43.07% <0%> (-3.36%) ⬇️
...ol-designer/src/file-data/selectors/fileCreator.js 25% <0%> (-1.67%) ⬇️
components/src/tooltips/HoverTooltip.js 15.38% <0%> (-1.29%) ⬇️
components/src/forms/InputField.js 84.61% <0%> (-1.1%) ⬇️
protocol-designer/src/pipettes/selectors.js 19.64% <0%> (-0.95%) ⬇️
...steplist/formLevel/stepFormToArgs/mixFormToArgs.js 2.22% <0%> (-0.81%) ⬇️
...-designer/src/steplist/actions/handleFormChange.js 1.11% <0%> (-0.59%) ⬇️
... and 30 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 19f9a0d...8edc121. Read the comment docs.

pass

@_log_call
async def cache_instrument_models(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any way we could (or would want to) get rid of the concept of caching the instrument models? Does this HAL have enough state information to know when pinging smoothie for instrument models would be unnecessary / detrimental?

Copy link
Member Author

Choose a reason for hiding this comment

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

This HAL would have enough information (though it would probably be implicit, like a smoothie communications lock) to know when pinging would be unnecessary. Some of the shape of the API duplicates what already exists; before committing to removing caching and always querying the hardware I'd want to think harder about the usage patterns that lead people to want to know what pipettes are attached, and when they want to know. In general I bias towards caching for communication that happens over slow serial links.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, I left out some important words. Definitely think caching instrument models is a good idea, what I meant to ask was "do we want to get rid of the concept of caching instrument models for clients of the hardware API", i.e. move all caching logic to be internal to this module (if possible)

Copy link
Member Author

Choose a reason for hiding this comment

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

We could reword the api methods but I think we need to keep a method for clients to explicitly request a cache update at least for the hardware controlled by smoothie, since smoothie can't tell us asynchronously when pipettes change.


# Global actions API
@_log_call
async def pause(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Would love to chat about this. I'm not convinced pause and resume belong in a hardware_control module. In my mind they could be the domain of some sort of action queuing system that uses hardware_control but is not a part of it.

halt is a different story because a halt is a signal that gets sent to smoothie. If this pause and resume was meant to be a "send a pause or resume signal to smoothie to pause the command that is being acted upon right this instant" then please ignore this comment

Copy link
Member Author

Choose a reason for hiding this comment

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

The second one is the way I'm thinking about it. The key thing about this API is that none of these functions will ever be directly used by client or user code. There's always going to be another wrapper around this. So possibly we should rename some of these functions, but the safe assumption is always that even if the name duplicates some other existing or higher level functionality the implementation here will be at a lower level.

The docstrings and types that get filled out as the functionality gets fleshed out will reflect this.


# Gantry/frame (i.e. not pipette) action API
@_log_call
async def home(self, *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the *args, **kwargs here just a copy paste thing? Or "we haven't decided this method shape yet"? I don't see them anywhere else in this file and it was my understanding that we'd be phasing them out in favor of named arguments

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy paste, absolutely. I wanted to just get the names of the API down here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm down with evicting a lot of our use of args and kwargs, but I think that can be done separately from this

def __init__(self):
global _lock

self._tlock_acquired = _lock.acquire(blocking=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

Very nitpicky request, but for clarity could we maybe expand the tlock and flock names to be a little more explicit? I assume it's thread_lock and file_lock respectively?


# Gantry/frame (i.e. not pipette) action API
@_log_call
async def home(self, *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm down with evicting a lot of our use of args and kwargs, but I think that can be done separately from this

Copy link
Member

@sanni-t sanni-t left a comment

Choose a reason for hiding this comment

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

🎛

@sanni-t sanni-t merged commit ea25b15 into edge Sep 24, 2018
@mcous mcous deleted the api_add-hardware-control branch September 24, 2018 22:03
b-cooper added a commit that referenced this pull request Sep 26, 2018
* fix(app): Open external links in browser instead of app window (#2327)

* feat(api): Remove deck calibration from reset options (#2330)

Remove deck calibration from factory reset options, as deck calibration reset should not be done
outside of the context of recalibration

* docs(contributing): Ask Windows users to set core.autocrlf=input (#2332)

Setting core.autocrlf to something that inserts carriage returns on windows means that API pushes to
robots from windows will have carriage returns in the scripts in api/opentrons/resources, which
prevents the robot from booting.

Closes #2305

* fix(api): Update definitions for tuberacks (#2317)

* fix(api): Update definitions for 15ml tuberack, 50ml tuberack, and 15/50ml tuberack to match actual

Closes #2290

* Modify definitions based on practical test

* feat(app): Enable autoupdate on Linux by switching to AppImage builds (#2329)

Closes #2303

* chore(chore): add exception in gitattributes for our hex files (#2339)

* fix(protocol-designer): fix whitescreen on deleting blowout labware (#2341)

* fix unticketed bug: setting blowout to a trash-box in a step and deleting the trash box caused
whitescreen
*make labware dropdown blank when nonexistent labware selected

* fix(api): Update the aluminum block definitions to match drawings (#2342)

* fix(api): Update the aluminum block definitions to match drawings and experiments
* Rename definition in shared-data to match rename in default_containers.json and fix z height
* Closes #2292

* chore(release): 3.4.0 (#2338)

* fix(protocol-designer): fix tiprack diagram only displaying right (#2340)

Fix a small bug where the tiprack diagram in the new file modal would duplicate the diagram of the
selected right pipette tiprack instead of showing both selections.

* feat(api): add module firmware update endpoint (#2173)

Closes #1654 
Adds firmware update api methods and update server functions (for modules with old as well as new bootloader)
Adds a udev rule for new bootloader
Adds tests for modules and update_server endpoint

* feat(protocol-designer): add "app build date" field to PD saved files (#2350)

* chore(api): Cleanup unused api root level files (#2336)

There were some leftovers from days of old: we don't use pip or anaconda or PyInstaller anymore.

* refactor(api): invert control of system and server (#2318)

Closes #2185
Separates out the previously entangled server and system functions so that opentrons.main handles system configuration while server.main only configures and runs the server. Entrypoint is switched from opentrons.server.main to opentrons.main

* feat(api): Add hardware_control submodule (#2349)

The hardware_control submodule is the controller of the robot's hardware. Its API can move the robot at a level of abstraction that portrays the robot as a whole, not including the labware. In this PR, the module is a stub, and not used by default

Closes #2232

* fixup: More verbose names for file and thread locks
* fixup: use functools.wraps in log_call decorator

* ci(codecov): Fix uploading of python coverage (#2360)

* fix(protocol-designer): tweak analytics copy for accuracy (#2366)

Update the copy in the analytics disclaimer to accurately portray our data collection in beta.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Affects the `api` project refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants