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(hardware): Implement moving baseline readings for sensor-move #15494

Merged
merged 9 commits into from
Jun 26, 2024
Prev Previous commit
Next Next commit
fixups to the new syncing of buffer
  • Loading branch information
ryanthecoder committed Jun 21, 2024
commit 59a8a68c9b9103cf3f2081c9fa08331d3b5eaccd
21 changes: 6 additions & 15 deletions hardware/opentrons_hardware/hardware_control/tool_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,27 +196,18 @@ async def run_sync_buffer_to_csv(
)
async with sensor_capturer:
messenger.add_listener(sensor_capturer, None)
await messenger.send(
node_id=tool,
message=SendAccumulatedSensorDataRequest(
request = SendAccumulatedSensorDataRequest(
payload=SendAccumulatedSensorDataPayload(
sensor_id=SensorIdField(sensor_id),
sensor_type=SensorTypeField(sensor_type),
)
),
)
await messenger.send(
node_id=tool,
message=request,
)
await sensor_capturer.wait_for_complete()
await sensor_capturer.wait_for_complete(message_index=request.payload.message_index.value)
messenger.remove_listener(sensor_capturer)
await messenger.send(
node_id=tool,
message=BindSensorOutputRequest(
payload=BindSensorOutputRequestPayload(
sensor=SensorTypeField(sensor_type),
sensor_id=SensorIdField(sensor_id),
binding=SensorOutputBindingField(SensorOutputBinding.none),
)
),
)
return positions


Expand Down
5 changes: 3 additions & 2 deletions hardware/opentrons_hardware/sensors/sensor_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,11 @@ async def __aexit__(self, *args: Any) -> None:
"""Close csv file."""
self.data_file.close()

async def wait_for_complete(self, wait_time: float = 5, message_index: int = 0) -> None:
async def wait_for_complete(self, wait_time: float = 10, message_index: int = 0) -> None:
"""Wait for the data to stop, only use this with a send_accumulated_data_request."""
self.event = asyncio.Event()
self.expected_ack = message_index
start = time.time()
while True:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
while True:
try:
await asyncio.wait_for(event.wait(), wait_time)
except asyncio.TimeoutError:
pass
self.event.clear()

?

await asyncio.sleep(0.2)
if self.event.is_set():
Expand All @@ -278,5 +279,5 @@ def __call__(
current_time = round((time.time() - self.start_time), 3)
self.csv_writer.writerow([current_time, data]) # type: ignore
if isinstance(message, message_definitions.Acknowledgement):
if self.event is not None and message.message_index == self.expected_ack:
if self.event is not None and message.payload.message_index.value == self.expected_ack:
self.event.set()