-
Notifications
You must be signed in to change notification settings - Fork 178
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): add module emulation #7353
Conversation
Codecov Report
@@ Coverage Diff @@
## edge #7353 +/- ##
=======================================
Coverage ? 81.94%
=======================================
Files ? 321
Lines ? 21419
Branches ? 0
=======================================
Hits ? 17551
Misses ? 3868
Partials ? 0 Continue to review full report at Codecov.
|
@@ -80,8 +80,8 @@ def _write_to_device_and_return(cmd, ack, device_connection, tag=None): | |||
|
|||
|
|||
def _connect(port_name, baudrate): | |||
ser = serial.Serial( | |||
port=port_name, | |||
ser = serial.serial_for_url( |
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.
Under the covers, if the url
doesn't specify a protocol (ie "socket://") pyserial will Serial.
@@ -190,6 +190,8 @@ async def enter_programming_mode(self): | |||
|
|||
|
|||
class TCPoller(threading.Thread): | |||
POLLING_FD_PATH = '/var/run/' |
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.
Moved here in order be able to patch in tests. Otherwise need root permission.
|
||
@pytest.fixture(scope="session") | ||
def emulation_app(): | ||
"""""" |
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.
Add explanation for Thread.
Remove commnted out line
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 really cool!
It's a great setup. I think the things I mentioned during the review meeting about adding more gcode responses can be handled in follow-up PRs if it works for you.
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 think this is a really good start. The idea of eventually moving this to its own repository (with a Docker container) really resonates with me, but I think this will be helpful off the bat for testing out new serial driver code
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.
🎮
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.
Really good start, thanks for taking this on! The code looks good to me, but we should definitely test
logger.info(f"Got command {cmd}") | ||
if cmd == GCODE_HOME: | ||
pass | ||
elif cmd == GCODE_MOVE: |
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.
shouldn't these set height
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 definitely should. I deliberately did not implement any command that changes the state of any of the emulators.
Looking at the c++ code made think that updating the state is not at all trivial for any of these modules and the smoothie. So left it for another day.
ff97f3c
to
7759b0f
Compare
Overview
In our HMG-CPX sync we discussed refactoring the hardware controller to go full on asyncio. When I've thought about how to tackle this task I've felt dread over how I'd test it. Would it be mandatory to have an OT2 and all the modules to make any progress?
So I looked into how to emulate the smoothie and modules. Happily,
pyserial
supports alternative underlying transport methods. Specifically over a socket.Changelog
This PR introduces very elementary emulation of our three modules. Each module (and eventually smoothie) is a socket server to process GCODE commands. Only commands that read parameters are implemented. The emulators live in
opentrons.hardware_control.emulation
. Anapp
module can be run to start all modules.Finally, some tests are added to exercise the emulators: one for each module. A fixture starts the emulators. We create module objects using pyserial's socket url (
socket://127.0.0.1:XXXX
) to build the module objects.This PR does NOT enable running the robot-server connecting to the emulators. I would like to support that eventually. I could see a docker configuration that runs the robot-server with emulators and environment set up for fast development. I would use that all the time.
Review requests
Testing: does serial comms still work?
opentron
? I could see this being a separate package.Thermocycler
tests to run. I feel pretty strongly that theTCPoller
will be modified making the hacks unnecessary.Thermocycler
test fails on Windows. It's using very unix-y file descriptor techniques.Risk assessment
Small changes to how we create
Serial
objects.