opentrons 8.6.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of opentrons might be problematic. Click here for more details.

Files changed (600) hide show
  1. opentrons/__init__.py +150 -0
  2. opentrons/_version.py +34 -0
  3. opentrons/calibration_storage/__init__.py +54 -0
  4. opentrons/calibration_storage/deck_configuration.py +62 -0
  5. opentrons/calibration_storage/encoder_decoder.py +31 -0
  6. opentrons/calibration_storage/file_operators.py +142 -0
  7. opentrons/calibration_storage/helpers.py +103 -0
  8. opentrons/calibration_storage/ot2/__init__.py +34 -0
  9. opentrons/calibration_storage/ot2/deck_attitude.py +85 -0
  10. opentrons/calibration_storage/ot2/mark_bad_calibration.py +27 -0
  11. opentrons/calibration_storage/ot2/models/__init__.py +0 -0
  12. opentrons/calibration_storage/ot2/models/v1.py +149 -0
  13. opentrons/calibration_storage/ot2/pipette_offset.py +129 -0
  14. opentrons/calibration_storage/ot2/tip_length.py +281 -0
  15. opentrons/calibration_storage/ot3/__init__.py +31 -0
  16. opentrons/calibration_storage/ot3/deck_attitude.py +83 -0
  17. opentrons/calibration_storage/ot3/gripper_offset.py +156 -0
  18. opentrons/calibration_storage/ot3/models/__init__.py +0 -0
  19. opentrons/calibration_storage/ot3/models/v1.py +122 -0
  20. opentrons/calibration_storage/ot3/module_offset.py +138 -0
  21. opentrons/calibration_storage/ot3/pipette_offset.py +95 -0
  22. opentrons/calibration_storage/types.py +45 -0
  23. opentrons/cli/__init__.py +21 -0
  24. opentrons/cli/__main__.py +5 -0
  25. opentrons/cli/analyze.py +501 -0
  26. opentrons/config/__init__.py +631 -0
  27. opentrons/config/advanced_settings.py +871 -0
  28. opentrons/config/defaults_ot2.py +214 -0
  29. opentrons/config/defaults_ot3.py +499 -0
  30. opentrons/config/feature_flags.py +86 -0
  31. opentrons/config/gripper_config.py +55 -0
  32. opentrons/config/reset.py +203 -0
  33. opentrons/config/robot_configs.py +187 -0
  34. opentrons/config/types.py +183 -0
  35. opentrons/drivers/__init__.py +0 -0
  36. opentrons/drivers/absorbance_reader/__init__.py +11 -0
  37. opentrons/drivers/absorbance_reader/abstract.py +72 -0
  38. opentrons/drivers/absorbance_reader/async_byonoy.py +352 -0
  39. opentrons/drivers/absorbance_reader/driver.py +81 -0
  40. opentrons/drivers/absorbance_reader/hid_protocol.py +161 -0
  41. opentrons/drivers/absorbance_reader/simulator.py +84 -0
  42. opentrons/drivers/asyncio/__init__.py +0 -0
  43. opentrons/drivers/asyncio/communication/__init__.py +22 -0
  44. opentrons/drivers/asyncio/communication/async_serial.py +183 -0
  45. opentrons/drivers/asyncio/communication/errors.py +88 -0
  46. opentrons/drivers/asyncio/communication/serial_connection.py +552 -0
  47. opentrons/drivers/command_builder.py +102 -0
  48. opentrons/drivers/flex_stacker/__init__.py +13 -0
  49. opentrons/drivers/flex_stacker/abstract.py +214 -0
  50. opentrons/drivers/flex_stacker/driver.py +768 -0
  51. opentrons/drivers/flex_stacker/errors.py +68 -0
  52. opentrons/drivers/flex_stacker/simulator.py +309 -0
  53. opentrons/drivers/flex_stacker/types.py +367 -0
  54. opentrons/drivers/flex_stacker/utils.py +19 -0
  55. opentrons/drivers/heater_shaker/__init__.py +5 -0
  56. opentrons/drivers/heater_shaker/abstract.py +76 -0
  57. opentrons/drivers/heater_shaker/driver.py +204 -0
  58. opentrons/drivers/heater_shaker/simulator.py +94 -0
  59. opentrons/drivers/mag_deck/__init__.py +6 -0
  60. opentrons/drivers/mag_deck/abstract.py +44 -0
  61. opentrons/drivers/mag_deck/driver.py +208 -0
  62. opentrons/drivers/mag_deck/simulator.py +63 -0
  63. opentrons/drivers/rpi_drivers/__init__.py +33 -0
  64. opentrons/drivers/rpi_drivers/dev_types.py +94 -0
  65. opentrons/drivers/rpi_drivers/gpio.py +282 -0
  66. opentrons/drivers/rpi_drivers/gpio_simulator.py +127 -0
  67. opentrons/drivers/rpi_drivers/interfaces.py +15 -0
  68. opentrons/drivers/rpi_drivers/types.py +364 -0
  69. opentrons/drivers/rpi_drivers/usb.py +102 -0
  70. opentrons/drivers/rpi_drivers/usb_simulator.py +22 -0
  71. opentrons/drivers/serial_communication.py +151 -0
  72. opentrons/drivers/smoothie_drivers/__init__.py +4 -0
  73. opentrons/drivers/smoothie_drivers/connection.py +51 -0
  74. opentrons/drivers/smoothie_drivers/constants.py +121 -0
  75. opentrons/drivers/smoothie_drivers/driver_3_0.py +1933 -0
  76. opentrons/drivers/smoothie_drivers/errors.py +49 -0
  77. opentrons/drivers/smoothie_drivers/parse_utils.py +143 -0
  78. opentrons/drivers/smoothie_drivers/simulator.py +99 -0
  79. opentrons/drivers/smoothie_drivers/types.py +16 -0
  80. opentrons/drivers/temp_deck/__init__.py +10 -0
  81. opentrons/drivers/temp_deck/abstract.py +54 -0
  82. opentrons/drivers/temp_deck/driver.py +197 -0
  83. opentrons/drivers/temp_deck/simulator.py +57 -0
  84. opentrons/drivers/thermocycler/__init__.py +12 -0
  85. opentrons/drivers/thermocycler/abstract.py +99 -0
  86. opentrons/drivers/thermocycler/driver.py +395 -0
  87. opentrons/drivers/thermocycler/simulator.py +126 -0
  88. opentrons/drivers/types.py +107 -0
  89. opentrons/drivers/utils.py +222 -0
  90. opentrons/execute.py +742 -0
  91. opentrons/hardware_control/__init__.py +65 -0
  92. opentrons/hardware_control/__main__.py +77 -0
  93. opentrons/hardware_control/adapters.py +98 -0
  94. opentrons/hardware_control/api.py +1347 -0
  95. opentrons/hardware_control/backends/__init__.py +7 -0
  96. opentrons/hardware_control/backends/controller.py +400 -0
  97. opentrons/hardware_control/backends/errors.py +9 -0
  98. opentrons/hardware_control/backends/estop_state.py +164 -0
  99. opentrons/hardware_control/backends/flex_protocol.py +497 -0
  100. opentrons/hardware_control/backends/ot3controller.py +1930 -0
  101. opentrons/hardware_control/backends/ot3simulator.py +900 -0
  102. opentrons/hardware_control/backends/ot3utils.py +664 -0
  103. opentrons/hardware_control/backends/simulator.py +442 -0
  104. opentrons/hardware_control/backends/status_bar_state.py +240 -0
  105. opentrons/hardware_control/backends/subsystem_manager.py +431 -0
  106. opentrons/hardware_control/backends/tip_presence_manager.py +173 -0
  107. opentrons/hardware_control/backends/types.py +14 -0
  108. opentrons/hardware_control/constants.py +6 -0
  109. opentrons/hardware_control/dev_types.py +125 -0
  110. opentrons/hardware_control/emulation/__init__.py +0 -0
  111. opentrons/hardware_control/emulation/abstract_emulator.py +21 -0
  112. opentrons/hardware_control/emulation/app.py +56 -0
  113. opentrons/hardware_control/emulation/connection_handler.py +38 -0
  114. opentrons/hardware_control/emulation/heater_shaker.py +150 -0
  115. opentrons/hardware_control/emulation/magdeck.py +60 -0
  116. opentrons/hardware_control/emulation/module_server/__init__.py +8 -0
  117. opentrons/hardware_control/emulation/module_server/client.py +78 -0
  118. opentrons/hardware_control/emulation/module_server/helpers.py +130 -0
  119. opentrons/hardware_control/emulation/module_server/models.py +31 -0
  120. opentrons/hardware_control/emulation/module_server/server.py +110 -0
  121. opentrons/hardware_control/emulation/parser.py +74 -0
  122. opentrons/hardware_control/emulation/proxy.py +241 -0
  123. opentrons/hardware_control/emulation/run_emulator.py +68 -0
  124. opentrons/hardware_control/emulation/scripts/__init__.py +0 -0
  125. opentrons/hardware_control/emulation/scripts/run_app.py +54 -0
  126. opentrons/hardware_control/emulation/scripts/run_module_emulator.py +72 -0
  127. opentrons/hardware_control/emulation/scripts/run_smoothie.py +37 -0
  128. opentrons/hardware_control/emulation/settings.py +119 -0
  129. opentrons/hardware_control/emulation/simulations.py +133 -0
  130. opentrons/hardware_control/emulation/smoothie.py +192 -0
  131. opentrons/hardware_control/emulation/tempdeck.py +69 -0
  132. opentrons/hardware_control/emulation/thermocycler.py +128 -0
  133. opentrons/hardware_control/emulation/types.py +10 -0
  134. opentrons/hardware_control/emulation/util.py +38 -0
  135. opentrons/hardware_control/errors.py +43 -0
  136. opentrons/hardware_control/execution_manager.py +164 -0
  137. opentrons/hardware_control/instruments/__init__.py +5 -0
  138. opentrons/hardware_control/instruments/instrument_abc.py +39 -0
  139. opentrons/hardware_control/instruments/ot2/__init__.py +0 -0
  140. opentrons/hardware_control/instruments/ot2/instrument_calibration.py +152 -0
  141. opentrons/hardware_control/instruments/ot2/pipette.py +777 -0
  142. opentrons/hardware_control/instruments/ot2/pipette_handler.py +995 -0
  143. opentrons/hardware_control/instruments/ot3/__init__.py +0 -0
  144. opentrons/hardware_control/instruments/ot3/gripper.py +420 -0
  145. opentrons/hardware_control/instruments/ot3/gripper_handler.py +173 -0
  146. opentrons/hardware_control/instruments/ot3/instrument_calibration.py +214 -0
  147. opentrons/hardware_control/instruments/ot3/pipette.py +858 -0
  148. opentrons/hardware_control/instruments/ot3/pipette_handler.py +1030 -0
  149. opentrons/hardware_control/module_control.py +332 -0
  150. opentrons/hardware_control/modules/__init__.py +69 -0
  151. opentrons/hardware_control/modules/absorbance_reader.py +373 -0
  152. opentrons/hardware_control/modules/errors.py +7 -0
  153. opentrons/hardware_control/modules/flex_stacker.py +948 -0
  154. opentrons/hardware_control/modules/heater_shaker.py +426 -0
  155. opentrons/hardware_control/modules/lid_temp_status.py +35 -0
  156. opentrons/hardware_control/modules/magdeck.py +233 -0
  157. opentrons/hardware_control/modules/mod_abc.py +245 -0
  158. opentrons/hardware_control/modules/module_calibration.py +93 -0
  159. opentrons/hardware_control/modules/plate_temp_status.py +61 -0
  160. opentrons/hardware_control/modules/tempdeck.py +299 -0
  161. opentrons/hardware_control/modules/thermocycler.py +731 -0
  162. opentrons/hardware_control/modules/types.py +417 -0
  163. opentrons/hardware_control/modules/update.py +255 -0
  164. opentrons/hardware_control/modules/utils.py +73 -0
  165. opentrons/hardware_control/motion_utilities.py +318 -0
  166. opentrons/hardware_control/nozzle_manager.py +422 -0
  167. opentrons/hardware_control/ot3_calibration.py +1171 -0
  168. opentrons/hardware_control/ot3api.py +3227 -0
  169. opentrons/hardware_control/pause_manager.py +31 -0
  170. opentrons/hardware_control/poller.py +112 -0
  171. opentrons/hardware_control/protocols/__init__.py +106 -0
  172. opentrons/hardware_control/protocols/asyncio_configurable.py +11 -0
  173. opentrons/hardware_control/protocols/calibratable.py +45 -0
  174. opentrons/hardware_control/protocols/chassis_accessory_manager.py +90 -0
  175. opentrons/hardware_control/protocols/configurable.py +48 -0
  176. opentrons/hardware_control/protocols/event_sourcer.py +18 -0
  177. opentrons/hardware_control/protocols/execution_controllable.py +33 -0
  178. opentrons/hardware_control/protocols/flex_calibratable.py +96 -0
  179. opentrons/hardware_control/protocols/flex_instrument_configurer.py +52 -0
  180. opentrons/hardware_control/protocols/gripper_controller.py +55 -0
  181. opentrons/hardware_control/protocols/hardware_manager.py +51 -0
  182. opentrons/hardware_control/protocols/identifiable.py +16 -0
  183. opentrons/hardware_control/protocols/instrument_configurer.py +206 -0
  184. opentrons/hardware_control/protocols/liquid_handler.py +266 -0
  185. opentrons/hardware_control/protocols/module_provider.py +16 -0
  186. opentrons/hardware_control/protocols/motion_controller.py +243 -0
  187. opentrons/hardware_control/protocols/position_estimator.py +45 -0
  188. opentrons/hardware_control/protocols/simulatable.py +10 -0
  189. opentrons/hardware_control/protocols/stoppable.py +9 -0
  190. opentrons/hardware_control/protocols/types.py +27 -0
  191. opentrons/hardware_control/robot_calibration.py +224 -0
  192. opentrons/hardware_control/scripts/README.md +28 -0
  193. opentrons/hardware_control/scripts/__init__.py +1 -0
  194. opentrons/hardware_control/scripts/gripper_control.py +208 -0
  195. opentrons/hardware_control/scripts/ot3gripper +7 -0
  196. opentrons/hardware_control/scripts/ot3repl +7 -0
  197. opentrons/hardware_control/scripts/repl.py +187 -0
  198. opentrons/hardware_control/scripts/tc_control.py +97 -0
  199. opentrons/hardware_control/simulator_setup.py +260 -0
  200. opentrons/hardware_control/thread_manager.py +431 -0
  201. opentrons/hardware_control/threaded_async_lock.py +97 -0
  202. opentrons/hardware_control/types.py +792 -0
  203. opentrons/hardware_control/util.py +234 -0
  204. opentrons/legacy_broker.py +53 -0
  205. opentrons/legacy_commands/__init__.py +1 -0
  206. opentrons/legacy_commands/commands.py +483 -0
  207. opentrons/legacy_commands/helpers.py +153 -0
  208. opentrons/legacy_commands/module_commands.py +215 -0
  209. opentrons/legacy_commands/protocol_commands.py +54 -0
  210. opentrons/legacy_commands/publisher.py +155 -0
  211. opentrons/legacy_commands/robot_commands.py +51 -0
  212. opentrons/legacy_commands/types.py +1115 -0
  213. opentrons/motion_planning/__init__.py +32 -0
  214. opentrons/motion_planning/adjacent_slots_getters.py +168 -0
  215. opentrons/motion_planning/deck_conflict.py +396 -0
  216. opentrons/motion_planning/errors.py +35 -0
  217. opentrons/motion_planning/types.py +42 -0
  218. opentrons/motion_planning/waypoints.py +218 -0
  219. opentrons/ordered_set.py +138 -0
  220. opentrons/protocol_api/__init__.py +105 -0
  221. opentrons/protocol_api/_liquid.py +157 -0
  222. opentrons/protocol_api/_liquid_properties.py +814 -0
  223. opentrons/protocol_api/_nozzle_layout.py +31 -0
  224. opentrons/protocol_api/_parameter_context.py +300 -0
  225. opentrons/protocol_api/_parameters.py +31 -0
  226. opentrons/protocol_api/_transfer_liquid_validation.py +108 -0
  227. opentrons/protocol_api/_types.py +43 -0
  228. opentrons/protocol_api/config.py +23 -0
  229. opentrons/protocol_api/core/__init__.py +23 -0
  230. opentrons/protocol_api/core/common.py +33 -0
  231. opentrons/protocol_api/core/core_map.py +74 -0
  232. opentrons/protocol_api/core/engine/__init__.py +22 -0
  233. opentrons/protocol_api/core/engine/_default_labware_versions.py +179 -0
  234. opentrons/protocol_api/core/engine/deck_conflict.py +348 -0
  235. opentrons/protocol_api/core/engine/exceptions.py +19 -0
  236. opentrons/protocol_api/core/engine/instrument.py +2391 -0
  237. opentrons/protocol_api/core/engine/labware.py +238 -0
  238. opentrons/protocol_api/core/engine/load_labware_params.py +73 -0
  239. opentrons/protocol_api/core/engine/module_core.py +1025 -0
  240. opentrons/protocol_api/core/engine/overlap_versions.py +20 -0
  241. opentrons/protocol_api/core/engine/pipette_movement_conflict.py +358 -0
  242. opentrons/protocol_api/core/engine/point_calculations.py +64 -0
  243. opentrons/protocol_api/core/engine/protocol.py +1153 -0
  244. opentrons/protocol_api/core/engine/robot.py +139 -0
  245. opentrons/protocol_api/core/engine/stringify.py +74 -0
  246. opentrons/protocol_api/core/engine/transfer_components_executor.py +990 -0
  247. opentrons/protocol_api/core/engine/well.py +241 -0
  248. opentrons/protocol_api/core/instrument.py +459 -0
  249. opentrons/protocol_api/core/labware.py +151 -0
  250. opentrons/protocol_api/core/legacy/__init__.py +11 -0
  251. opentrons/protocol_api/core/legacy/_labware_geometry.py +37 -0
  252. opentrons/protocol_api/core/legacy/deck.py +369 -0
  253. opentrons/protocol_api/core/legacy/labware_offset_provider.py +108 -0
  254. opentrons/protocol_api/core/legacy/legacy_instrument_core.py +709 -0
  255. opentrons/protocol_api/core/legacy/legacy_labware_core.py +235 -0
  256. opentrons/protocol_api/core/legacy/legacy_module_core.py +592 -0
  257. opentrons/protocol_api/core/legacy/legacy_protocol_core.py +612 -0
  258. opentrons/protocol_api/core/legacy/legacy_well_core.py +162 -0
  259. opentrons/protocol_api/core/legacy/load_info.py +67 -0
  260. opentrons/protocol_api/core/legacy/module_geometry.py +547 -0
  261. opentrons/protocol_api/core/legacy/well_geometry.py +148 -0
  262. opentrons/protocol_api/core/legacy_simulator/__init__.py +16 -0
  263. opentrons/protocol_api/core/legacy_simulator/legacy_instrument_core.py +624 -0
  264. opentrons/protocol_api/core/legacy_simulator/legacy_protocol_core.py +85 -0
  265. opentrons/protocol_api/core/module.py +484 -0
  266. opentrons/protocol_api/core/protocol.py +311 -0
  267. opentrons/protocol_api/core/robot.py +51 -0
  268. opentrons/protocol_api/core/well.py +116 -0
  269. opentrons/protocol_api/core/well_grid.py +45 -0
  270. opentrons/protocol_api/create_protocol_context.py +177 -0
  271. opentrons/protocol_api/deck.py +223 -0
  272. opentrons/protocol_api/disposal_locations.py +244 -0
  273. opentrons/protocol_api/instrument_context.py +3212 -0
  274. opentrons/protocol_api/labware.py +1579 -0
  275. opentrons/protocol_api/module_contexts.py +1425 -0
  276. opentrons/protocol_api/module_validation_and_errors.py +61 -0
  277. opentrons/protocol_api/protocol_context.py +1688 -0
  278. opentrons/protocol_api/robot_context.py +303 -0
  279. opentrons/protocol_api/validation.py +761 -0
  280. opentrons/protocol_engine/__init__.py +155 -0
  281. opentrons/protocol_engine/actions/__init__.py +65 -0
  282. opentrons/protocol_engine/actions/action_dispatcher.py +30 -0
  283. opentrons/protocol_engine/actions/action_handler.py +13 -0
  284. opentrons/protocol_engine/actions/actions.py +302 -0
  285. opentrons/protocol_engine/actions/get_state_update.py +38 -0
  286. opentrons/protocol_engine/clients/__init__.py +5 -0
  287. opentrons/protocol_engine/clients/sync_client.py +174 -0
  288. opentrons/protocol_engine/clients/transports.py +197 -0
  289. opentrons/protocol_engine/commands/__init__.py +757 -0
  290. opentrons/protocol_engine/commands/absorbance_reader/__init__.py +61 -0
  291. opentrons/protocol_engine/commands/absorbance_reader/close_lid.py +154 -0
  292. opentrons/protocol_engine/commands/absorbance_reader/common.py +6 -0
  293. opentrons/protocol_engine/commands/absorbance_reader/initialize.py +151 -0
  294. opentrons/protocol_engine/commands/absorbance_reader/open_lid.py +154 -0
  295. opentrons/protocol_engine/commands/absorbance_reader/read.py +226 -0
  296. opentrons/protocol_engine/commands/air_gap_in_place.py +162 -0
  297. opentrons/protocol_engine/commands/aspirate.py +244 -0
  298. opentrons/protocol_engine/commands/aspirate_in_place.py +184 -0
  299. opentrons/protocol_engine/commands/aspirate_while_tracking.py +211 -0
  300. opentrons/protocol_engine/commands/blow_out.py +146 -0
  301. opentrons/protocol_engine/commands/blow_out_in_place.py +119 -0
  302. opentrons/protocol_engine/commands/calibration/__init__.py +60 -0
  303. opentrons/protocol_engine/commands/calibration/calibrate_gripper.py +166 -0
  304. opentrons/protocol_engine/commands/calibration/calibrate_module.py +117 -0
  305. opentrons/protocol_engine/commands/calibration/calibrate_pipette.py +96 -0
  306. opentrons/protocol_engine/commands/calibration/move_to_maintenance_position.py +156 -0
  307. opentrons/protocol_engine/commands/command.py +308 -0
  308. opentrons/protocol_engine/commands/command_unions.py +974 -0
  309. opentrons/protocol_engine/commands/comment.py +57 -0
  310. opentrons/protocol_engine/commands/configure_for_volume.py +108 -0
  311. opentrons/protocol_engine/commands/configure_nozzle_layout.py +115 -0
  312. opentrons/protocol_engine/commands/custom.py +67 -0
  313. opentrons/protocol_engine/commands/dispense.py +194 -0
  314. opentrons/protocol_engine/commands/dispense_in_place.py +179 -0
  315. opentrons/protocol_engine/commands/dispense_while_tracking.py +204 -0
  316. opentrons/protocol_engine/commands/drop_tip.py +232 -0
  317. opentrons/protocol_engine/commands/drop_tip_in_place.py +205 -0
  318. opentrons/protocol_engine/commands/flex_stacker/__init__.py +64 -0
  319. opentrons/protocol_engine/commands/flex_stacker/common.py +900 -0
  320. opentrons/protocol_engine/commands/flex_stacker/empty.py +293 -0
  321. opentrons/protocol_engine/commands/flex_stacker/fill.py +281 -0
  322. opentrons/protocol_engine/commands/flex_stacker/retrieve.py +339 -0
  323. opentrons/protocol_engine/commands/flex_stacker/set_stored_labware.py +328 -0
  324. opentrons/protocol_engine/commands/flex_stacker/store.py +326 -0
  325. opentrons/protocol_engine/commands/generate_command_schema.py +61 -0
  326. opentrons/protocol_engine/commands/get_next_tip.py +134 -0
  327. opentrons/protocol_engine/commands/get_tip_presence.py +87 -0
  328. opentrons/protocol_engine/commands/hash_command_params.py +38 -0
  329. opentrons/protocol_engine/commands/heater_shaker/__init__.py +102 -0
  330. opentrons/protocol_engine/commands/heater_shaker/close_labware_latch.py +83 -0
  331. opentrons/protocol_engine/commands/heater_shaker/deactivate_heater.py +82 -0
  332. opentrons/protocol_engine/commands/heater_shaker/deactivate_shaker.py +84 -0
  333. opentrons/protocol_engine/commands/heater_shaker/open_labware_latch.py +110 -0
  334. opentrons/protocol_engine/commands/heater_shaker/set_and_wait_for_shake_speed.py +125 -0
  335. opentrons/protocol_engine/commands/heater_shaker/set_target_temperature.py +90 -0
  336. opentrons/protocol_engine/commands/heater_shaker/wait_for_temperature.py +102 -0
  337. opentrons/protocol_engine/commands/home.py +100 -0
  338. opentrons/protocol_engine/commands/identify_module.py +86 -0
  339. opentrons/protocol_engine/commands/labware_handling_common.py +29 -0
  340. opentrons/protocol_engine/commands/liquid_probe.py +464 -0
  341. opentrons/protocol_engine/commands/load_labware.py +210 -0
  342. opentrons/protocol_engine/commands/load_lid.py +154 -0
  343. opentrons/protocol_engine/commands/load_lid_stack.py +272 -0
  344. opentrons/protocol_engine/commands/load_liquid.py +95 -0
  345. opentrons/protocol_engine/commands/load_liquid_class.py +144 -0
  346. opentrons/protocol_engine/commands/load_module.py +223 -0
  347. opentrons/protocol_engine/commands/load_pipette.py +167 -0
  348. opentrons/protocol_engine/commands/magnetic_module/__init__.py +32 -0
  349. opentrons/protocol_engine/commands/magnetic_module/disengage.py +97 -0
  350. opentrons/protocol_engine/commands/magnetic_module/engage.py +119 -0
  351. opentrons/protocol_engine/commands/move_labware.py +546 -0
  352. opentrons/protocol_engine/commands/move_relative.py +102 -0
  353. opentrons/protocol_engine/commands/move_to_addressable_area.py +176 -0
  354. opentrons/protocol_engine/commands/move_to_addressable_area_for_drop_tip.py +198 -0
  355. opentrons/protocol_engine/commands/move_to_coordinates.py +107 -0
  356. opentrons/protocol_engine/commands/move_to_well.py +119 -0
  357. opentrons/protocol_engine/commands/movement_common.py +338 -0
  358. opentrons/protocol_engine/commands/pick_up_tip.py +241 -0
  359. opentrons/protocol_engine/commands/pipetting_common.py +443 -0
  360. opentrons/protocol_engine/commands/prepare_to_aspirate.py +121 -0
  361. opentrons/protocol_engine/commands/pressure_dispense.py +155 -0
  362. opentrons/protocol_engine/commands/reload_labware.py +90 -0
  363. opentrons/protocol_engine/commands/retract_axis.py +75 -0
  364. opentrons/protocol_engine/commands/robot/__init__.py +70 -0
  365. opentrons/protocol_engine/commands/robot/close_gripper_jaw.py +96 -0
  366. opentrons/protocol_engine/commands/robot/common.py +18 -0
  367. opentrons/protocol_engine/commands/robot/move_axes_relative.py +101 -0
  368. opentrons/protocol_engine/commands/robot/move_axes_to.py +100 -0
  369. opentrons/protocol_engine/commands/robot/move_to.py +94 -0
  370. opentrons/protocol_engine/commands/robot/open_gripper_jaw.py +86 -0
  371. opentrons/protocol_engine/commands/save_position.py +109 -0
  372. opentrons/protocol_engine/commands/seal_pipette_to_tip.py +353 -0
  373. opentrons/protocol_engine/commands/set_rail_lights.py +67 -0
  374. opentrons/protocol_engine/commands/set_status_bar.py +89 -0
  375. opentrons/protocol_engine/commands/temperature_module/__init__.py +46 -0
  376. opentrons/protocol_engine/commands/temperature_module/deactivate.py +86 -0
  377. opentrons/protocol_engine/commands/temperature_module/set_target_temperature.py +97 -0
  378. opentrons/protocol_engine/commands/temperature_module/wait_for_temperature.py +104 -0
  379. opentrons/protocol_engine/commands/thermocycler/__init__.py +152 -0
  380. opentrons/protocol_engine/commands/thermocycler/close_lid.py +87 -0
  381. opentrons/protocol_engine/commands/thermocycler/deactivate_block.py +80 -0
  382. opentrons/protocol_engine/commands/thermocycler/deactivate_lid.py +80 -0
  383. opentrons/protocol_engine/commands/thermocycler/open_lid.py +87 -0
  384. opentrons/protocol_engine/commands/thermocycler/run_extended_profile.py +171 -0
  385. opentrons/protocol_engine/commands/thermocycler/run_profile.py +124 -0
  386. opentrons/protocol_engine/commands/thermocycler/set_target_block_temperature.py +140 -0
  387. opentrons/protocol_engine/commands/thermocycler/set_target_lid_temperature.py +100 -0
  388. opentrons/protocol_engine/commands/thermocycler/wait_for_block_temperature.py +93 -0
  389. opentrons/protocol_engine/commands/thermocycler/wait_for_lid_temperature.py +89 -0
  390. opentrons/protocol_engine/commands/touch_tip.py +189 -0
  391. opentrons/protocol_engine/commands/unsafe/__init__.py +161 -0
  392. opentrons/protocol_engine/commands/unsafe/unsafe_blow_out_in_place.py +100 -0
  393. opentrons/protocol_engine/commands/unsafe/unsafe_drop_tip_in_place.py +121 -0
  394. opentrons/protocol_engine/commands/unsafe/unsafe_engage_axes.py +82 -0
  395. opentrons/protocol_engine/commands/unsafe/unsafe_place_labware.py +208 -0
  396. opentrons/protocol_engine/commands/unsafe/unsafe_stacker_close_latch.py +94 -0
  397. opentrons/protocol_engine/commands/unsafe/unsafe_stacker_manual_retrieve.py +295 -0
  398. opentrons/protocol_engine/commands/unsafe/unsafe_stacker_open_latch.py +91 -0
  399. opentrons/protocol_engine/commands/unsafe/unsafe_stacker_prepare_shuttle.py +136 -0
  400. opentrons/protocol_engine/commands/unsafe/unsafe_ungrip_labware.py +77 -0
  401. opentrons/protocol_engine/commands/unsafe/update_position_estimators.py +90 -0
  402. opentrons/protocol_engine/commands/unseal_pipette_from_tip.py +153 -0
  403. opentrons/protocol_engine/commands/verify_tip_presence.py +100 -0
  404. opentrons/protocol_engine/commands/wait_for_duration.py +76 -0
  405. opentrons/protocol_engine/commands/wait_for_resume.py +75 -0
  406. opentrons/protocol_engine/create_protocol_engine.py +193 -0
  407. opentrons/protocol_engine/engine_support.py +28 -0
  408. opentrons/protocol_engine/error_recovery_policy.py +81 -0
  409. opentrons/protocol_engine/errors/__init__.py +191 -0
  410. opentrons/protocol_engine/errors/error_occurrence.py +182 -0
  411. opentrons/protocol_engine/errors/exceptions.py +1308 -0
  412. opentrons/protocol_engine/execution/__init__.py +50 -0
  413. opentrons/protocol_engine/execution/command_executor.py +216 -0
  414. opentrons/protocol_engine/execution/create_queue_worker.py +102 -0
  415. opentrons/protocol_engine/execution/door_watcher.py +119 -0
  416. opentrons/protocol_engine/execution/equipment.py +819 -0
  417. opentrons/protocol_engine/execution/error_recovery_hardware_state_synchronizer.py +101 -0
  418. opentrons/protocol_engine/execution/gantry_mover.py +686 -0
  419. opentrons/protocol_engine/execution/hardware_stopper.py +147 -0
  420. opentrons/protocol_engine/execution/heater_shaker_movement_flagger.py +207 -0
  421. opentrons/protocol_engine/execution/labware_movement.py +297 -0
  422. opentrons/protocol_engine/execution/movement.py +349 -0
  423. opentrons/protocol_engine/execution/pipetting.py +607 -0
  424. opentrons/protocol_engine/execution/queue_worker.py +86 -0
  425. opentrons/protocol_engine/execution/rail_lights.py +25 -0
  426. opentrons/protocol_engine/execution/run_control.py +33 -0
  427. opentrons/protocol_engine/execution/status_bar.py +34 -0
  428. opentrons/protocol_engine/execution/thermocycler_movement_flagger.py +188 -0
  429. opentrons/protocol_engine/execution/thermocycler_plate_lifter.py +81 -0
  430. opentrons/protocol_engine/execution/tip_handler.py +550 -0
  431. opentrons/protocol_engine/labware_offset_standardization.py +194 -0
  432. opentrons/protocol_engine/notes/__init__.py +17 -0
  433. opentrons/protocol_engine/notes/notes.py +59 -0
  434. opentrons/protocol_engine/plugins.py +104 -0
  435. opentrons/protocol_engine/protocol_engine.py +683 -0
  436. opentrons/protocol_engine/resources/__init__.py +26 -0
  437. opentrons/protocol_engine/resources/deck_configuration_provider.py +232 -0
  438. opentrons/protocol_engine/resources/deck_data_provider.py +94 -0
  439. opentrons/protocol_engine/resources/file_provider.py +161 -0
  440. opentrons/protocol_engine/resources/fixture_validation.py +58 -0
  441. opentrons/protocol_engine/resources/labware_data_provider.py +106 -0
  442. opentrons/protocol_engine/resources/labware_validation.py +73 -0
  443. opentrons/protocol_engine/resources/model_utils.py +32 -0
  444. opentrons/protocol_engine/resources/module_data_provider.py +44 -0
  445. opentrons/protocol_engine/resources/ot3_validation.py +21 -0
  446. opentrons/protocol_engine/resources/pipette_data_provider.py +379 -0
  447. opentrons/protocol_engine/slot_standardization.py +128 -0
  448. opentrons/protocol_engine/state/__init__.py +1 -0
  449. opentrons/protocol_engine/state/_abstract_store.py +27 -0
  450. opentrons/protocol_engine/state/_axis_aligned_bounding_box.py +50 -0
  451. opentrons/protocol_engine/state/_labware_origin_math.py +636 -0
  452. opentrons/protocol_engine/state/_move_types.py +83 -0
  453. opentrons/protocol_engine/state/_well_math.py +193 -0
  454. opentrons/protocol_engine/state/addressable_areas.py +699 -0
  455. opentrons/protocol_engine/state/command_history.py +309 -0
  456. opentrons/protocol_engine/state/commands.py +1158 -0
  457. opentrons/protocol_engine/state/config.py +39 -0
  458. opentrons/protocol_engine/state/files.py +57 -0
  459. opentrons/protocol_engine/state/fluid_stack.py +138 -0
  460. opentrons/protocol_engine/state/geometry.py +2359 -0
  461. opentrons/protocol_engine/state/inner_well_math_utils.py +548 -0
  462. opentrons/protocol_engine/state/labware.py +1459 -0
  463. opentrons/protocol_engine/state/liquid_classes.py +82 -0
  464. opentrons/protocol_engine/state/liquids.py +73 -0
  465. opentrons/protocol_engine/state/module_substates/__init__.py +45 -0
  466. opentrons/protocol_engine/state/module_substates/absorbance_reader_substate.py +35 -0
  467. opentrons/protocol_engine/state/module_substates/flex_stacker_substate.py +112 -0
  468. opentrons/protocol_engine/state/module_substates/heater_shaker_module_substate.py +115 -0
  469. opentrons/protocol_engine/state/module_substates/magnetic_block_substate.py +17 -0
  470. opentrons/protocol_engine/state/module_substates/magnetic_module_substate.py +65 -0
  471. opentrons/protocol_engine/state/module_substates/temperature_module_substate.py +67 -0
  472. opentrons/protocol_engine/state/module_substates/thermocycler_module_substate.py +163 -0
  473. opentrons/protocol_engine/state/modules.py +1500 -0
  474. opentrons/protocol_engine/state/motion.py +373 -0
  475. opentrons/protocol_engine/state/pipettes.py +905 -0
  476. opentrons/protocol_engine/state/state.py +421 -0
  477. opentrons/protocol_engine/state/state_summary.py +36 -0
  478. opentrons/protocol_engine/state/tips.py +420 -0
  479. opentrons/protocol_engine/state/update_types.py +904 -0
  480. opentrons/protocol_engine/state/wells.py +290 -0
  481. opentrons/protocol_engine/types/__init__.py +308 -0
  482. opentrons/protocol_engine/types/automatic_tip_selection.py +39 -0
  483. opentrons/protocol_engine/types/command_annotations.py +53 -0
  484. opentrons/protocol_engine/types/deck_configuration.py +81 -0
  485. opentrons/protocol_engine/types/execution.py +96 -0
  486. opentrons/protocol_engine/types/hardware_passthrough.py +25 -0
  487. opentrons/protocol_engine/types/instrument.py +47 -0
  488. opentrons/protocol_engine/types/instrument_sensors.py +47 -0
  489. opentrons/protocol_engine/types/labware.py +131 -0
  490. opentrons/protocol_engine/types/labware_movement.py +22 -0
  491. opentrons/protocol_engine/types/labware_offset_location.py +111 -0
  492. opentrons/protocol_engine/types/labware_offset_vector.py +16 -0
  493. opentrons/protocol_engine/types/liquid.py +40 -0
  494. opentrons/protocol_engine/types/liquid_class.py +59 -0
  495. opentrons/protocol_engine/types/liquid_handling.py +13 -0
  496. opentrons/protocol_engine/types/liquid_level_detection.py +191 -0
  497. opentrons/protocol_engine/types/location.py +194 -0
  498. opentrons/protocol_engine/types/module.py +303 -0
  499. opentrons/protocol_engine/types/partial_tip_configuration.py +76 -0
  500. opentrons/protocol_engine/types/run_time_parameters.py +133 -0
  501. opentrons/protocol_engine/types/tip.py +18 -0
  502. opentrons/protocol_engine/types/util.py +21 -0
  503. opentrons/protocol_engine/types/well_position.py +124 -0
  504. opentrons/protocol_reader/__init__.py +37 -0
  505. opentrons/protocol_reader/extract_labware_definitions.py +66 -0
  506. opentrons/protocol_reader/file_format_validator.py +152 -0
  507. opentrons/protocol_reader/file_hasher.py +27 -0
  508. opentrons/protocol_reader/file_identifier.py +284 -0
  509. opentrons/protocol_reader/file_reader_writer.py +90 -0
  510. opentrons/protocol_reader/input_file.py +16 -0
  511. opentrons/protocol_reader/protocol_files_invalid_error.py +6 -0
  512. opentrons/protocol_reader/protocol_reader.py +188 -0
  513. opentrons/protocol_reader/protocol_source.py +124 -0
  514. opentrons/protocol_reader/role_analyzer.py +86 -0
  515. opentrons/protocol_runner/__init__.py +26 -0
  516. opentrons/protocol_runner/create_simulating_orchestrator.py +118 -0
  517. opentrons/protocol_runner/json_file_reader.py +55 -0
  518. opentrons/protocol_runner/json_translator.py +314 -0
  519. opentrons/protocol_runner/legacy_command_mapper.py +848 -0
  520. opentrons/protocol_runner/legacy_context_plugin.py +116 -0
  521. opentrons/protocol_runner/protocol_runner.py +530 -0
  522. opentrons/protocol_runner/python_protocol_wrappers.py +179 -0
  523. opentrons/protocol_runner/run_orchestrator.py +496 -0
  524. opentrons/protocol_runner/task_queue.py +95 -0
  525. opentrons/protocols/__init__.py +6 -0
  526. opentrons/protocols/advanced_control/__init__.py +0 -0
  527. opentrons/protocols/advanced_control/common.py +38 -0
  528. opentrons/protocols/advanced_control/mix.py +60 -0
  529. opentrons/protocols/advanced_control/transfers/__init__.py +0 -0
  530. opentrons/protocols/advanced_control/transfers/common.py +180 -0
  531. opentrons/protocols/advanced_control/transfers/transfer.py +972 -0
  532. opentrons/protocols/advanced_control/transfers/transfer_liquid_utils.py +231 -0
  533. opentrons/protocols/api_support/__init__.py +0 -0
  534. opentrons/protocols/api_support/constants.py +8 -0
  535. opentrons/protocols/api_support/deck_type.py +110 -0
  536. opentrons/protocols/api_support/definitions.py +18 -0
  537. opentrons/protocols/api_support/instrument.py +151 -0
  538. opentrons/protocols/api_support/labware_like.py +233 -0
  539. opentrons/protocols/api_support/tip_tracker.py +175 -0
  540. opentrons/protocols/api_support/types.py +32 -0
  541. opentrons/protocols/api_support/util.py +403 -0
  542. opentrons/protocols/bundle.py +89 -0
  543. opentrons/protocols/duration/__init__.py +4 -0
  544. opentrons/protocols/duration/errors.py +5 -0
  545. opentrons/protocols/duration/estimator.py +628 -0
  546. opentrons/protocols/execution/__init__.py +0 -0
  547. opentrons/protocols/execution/dev_types.py +181 -0
  548. opentrons/protocols/execution/errors.py +40 -0
  549. opentrons/protocols/execution/execute.py +84 -0
  550. opentrons/protocols/execution/execute_json_v3.py +275 -0
  551. opentrons/protocols/execution/execute_json_v4.py +359 -0
  552. opentrons/protocols/execution/execute_json_v5.py +28 -0
  553. opentrons/protocols/execution/execute_python.py +169 -0
  554. opentrons/protocols/execution/json_dispatchers.py +87 -0
  555. opentrons/protocols/execution/types.py +7 -0
  556. opentrons/protocols/geometry/__init__.py +0 -0
  557. opentrons/protocols/geometry/planning.py +297 -0
  558. opentrons/protocols/labware.py +312 -0
  559. opentrons/protocols/models/__init__.py +0 -0
  560. opentrons/protocols/models/json_protocol.py +679 -0
  561. opentrons/protocols/parameters/__init__.py +0 -0
  562. opentrons/protocols/parameters/csv_parameter_definition.py +77 -0
  563. opentrons/protocols/parameters/csv_parameter_interface.py +96 -0
  564. opentrons/protocols/parameters/exceptions.py +34 -0
  565. opentrons/protocols/parameters/parameter_definition.py +272 -0
  566. opentrons/protocols/parameters/types.py +17 -0
  567. opentrons/protocols/parameters/validation.py +267 -0
  568. opentrons/protocols/parse.py +671 -0
  569. opentrons/protocols/types.py +159 -0
  570. opentrons/py.typed +0 -0
  571. opentrons/resources/scripts/lpc21isp +0 -0
  572. opentrons/resources/smoothie-edge-8414642.hex +23010 -0
  573. opentrons/simulate.py +1065 -0
  574. opentrons/system/__init__.py +6 -0
  575. opentrons/system/camera.py +51 -0
  576. opentrons/system/log_control.py +59 -0
  577. opentrons/system/nmcli.py +856 -0
  578. opentrons/system/resin.py +24 -0
  579. opentrons/system/smoothie_update.py +15 -0
  580. opentrons/system/wifi.py +204 -0
  581. opentrons/tools/__init__.py +0 -0
  582. opentrons/tools/args_handler.py +22 -0
  583. opentrons/tools/write_pipette_memory.py +157 -0
  584. opentrons/types.py +618 -0
  585. opentrons/util/__init__.py +1 -0
  586. opentrons/util/async_helpers.py +166 -0
  587. opentrons/util/broker.py +84 -0
  588. opentrons/util/change_notifier.py +47 -0
  589. opentrons/util/entrypoint_util.py +278 -0
  590. opentrons/util/get_union_elements.py +26 -0
  591. opentrons/util/helpers.py +6 -0
  592. opentrons/util/linal.py +178 -0
  593. opentrons/util/logging_config.py +265 -0
  594. opentrons/util/logging_queue_handler.py +61 -0
  595. opentrons/util/performance_helpers.py +157 -0
  596. opentrons-8.6.0a1.dist-info/METADATA +37 -0
  597. opentrons-8.6.0a1.dist-info/RECORD +600 -0
  598. opentrons-8.6.0a1.dist-info/WHEEL +4 -0
  599. opentrons-8.6.0a1.dist-info/entry_points.txt +3 -0
  600. opentrons-8.6.0a1.dist-info/licenses/LICENSE +202 -0
@@ -0,0 +1,2359 @@
1
+ """Geometry state getters."""
2
+
3
+ from logging import getLogger
4
+ import enum
5
+ from numpy import array, dot, double as npdouble
6
+ from numpy.typing import NDArray
7
+ from typing import Optional, List, Tuple, Union, cast, TypeVar, Dict, Set
8
+ from dataclasses import dataclass
9
+ from functools import cached_property
10
+
11
+ from opentrons.types import (
12
+ Point,
13
+ DeckSlotName,
14
+ StagingSlotName,
15
+ MountType,
16
+ MeniscusTrackingTarget,
17
+ )
18
+
19
+ from opentrons_shared_data.errors.exceptions import (
20
+ InvalidStoredData,
21
+ PipetteLiquidNotFoundError,
22
+ )
23
+ from opentrons_shared_data.labware.constants import WELL_NAME_PATTERN
24
+ from opentrons_shared_data.labware.labware_definition import (
25
+ LabwareDefinition,
26
+ LabwareDefinition2,
27
+ InnerWellGeometry,
28
+ )
29
+ from opentrons_shared_data.deck.types import CutoutFixture
30
+ from opentrons_shared_data.pipette import PIPETTE_X_SPAN
31
+ from opentrons_shared_data.pipette.types import ChannelCount, LabwareUri
32
+
33
+ from .. import errors
34
+ from ..errors import (
35
+ LabwareNotLoadedError,
36
+ LabwareNotLoadedOnLabwareError,
37
+ LabwareNotLoadedOnModuleError,
38
+ LabwareMovementNotAllowedError,
39
+ InvalidLabwarePositionError,
40
+ LabwareNotOnDeckError,
41
+ )
42
+ from ..errors.exceptions import (
43
+ InvalidLiquidHeightFound,
44
+ )
45
+ from ..resources import (
46
+ fixture_validation,
47
+ labware_validation,
48
+ deck_configuration_provider,
49
+ )
50
+ from ..types import (
51
+ OFF_DECK_LOCATION,
52
+ SYSTEM_LOCATION,
53
+ LoadedLabware,
54
+ LoadedModule,
55
+ WellLocation,
56
+ LiquidHandlingWellLocation,
57
+ DropTipWellLocation,
58
+ PickUpTipWellLocation,
59
+ WellOrigin,
60
+ DropTipWellOrigin,
61
+ WellOffset,
62
+ DeckSlotLocation,
63
+ ModuleLocation,
64
+ OnLabwareLocation,
65
+ LabwareLocation,
66
+ LabwareOffsetVector,
67
+ ModuleOffsetData,
68
+ CurrentWell,
69
+ CurrentPipetteLocation,
70
+ TipGeometry,
71
+ LabwareMovementOffsetData,
72
+ InStackerHopperLocation,
73
+ OnDeckLabwareLocation,
74
+ AddressableAreaLocation,
75
+ AddressableOffsetVector,
76
+ StagingSlotLocation,
77
+ LabwareOffsetLocationSequence,
78
+ OnModuleOffsetLocationSequenceComponent,
79
+ OnAddressableAreaOffsetLocationSequenceComponent,
80
+ OnLabwareOffsetLocationSequenceComponent,
81
+ OnLabwareLocationSequenceComponent,
82
+ ModuleModel,
83
+ PotentialCutoutFixture,
84
+ LabwareLocationSequence,
85
+ OnModuleLocationSequenceComponent,
86
+ OnAddressableAreaLocationSequenceComponent,
87
+ OnCutoutFixtureLocationSequenceComponent,
88
+ NotOnDeckLocationSequenceComponent,
89
+ AreaType,
90
+ labware_location_is_off_deck,
91
+ labware_location_is_system,
92
+ WellLocationType,
93
+ WellLocationFunction,
94
+ LabwareParentDefinition,
95
+ AddressableArea,
96
+ )
97
+ from ..types.liquid_level_detection import SimulatedProbeResult, LiquidTrackingType
98
+ from .config import Config
99
+ from .labware import LabwareView
100
+ from .wells import WellView
101
+ from .modules import ModuleView
102
+ from .pipettes import PipetteView
103
+ from .addressable_areas import AddressableAreaView
104
+ from .inner_well_math_utils import (
105
+ find_height_inner_well_geometry,
106
+ find_volume_inner_well_geometry,
107
+ find_height_user_defined_volumes,
108
+ find_volume_user_defined_volumes,
109
+ )
110
+ from ._well_math import wells_covered_by_pipette_configuration, nozzles_per_well
111
+ from ._labware_origin_math import get_parent_placement_origin_to_lw_origin
112
+
113
+
114
+ _LOG = getLogger(__name__)
115
+ SLOT_WIDTH = 128
116
+ _PIPETTE_HOMED_POSITION_Z = (
117
+ 248.0 # Height of the bottom of the nozzle without the tip attached when homed
118
+ )
119
+
120
+
121
+ class _TipDropSection(enum.Enum):
122
+ """Well sections to drop tips in."""
123
+
124
+ LEFT = "left"
125
+ RIGHT = "right"
126
+
127
+
128
+ class _GripperMoveType(enum.Enum):
129
+ """Types of gripper movement."""
130
+
131
+ PICK_UP_LABWARE = enum.auto()
132
+ DROP_LABWARE = enum.auto()
133
+
134
+
135
+ @dataclass
136
+ class _AbsoluteRobotExtents:
137
+ front_left: Dict[MountType, Point]
138
+ back_right: Dict[MountType, Point]
139
+ deck_extents: Point
140
+ padding_rear: float
141
+ padding_front: float
142
+ padding_left_side: float
143
+ padding_right_side: float
144
+
145
+
146
+ _LabwareLocation = TypeVar("_LabwareLocation", bound=LabwareLocation)
147
+
148
+
149
+ # TODO(mc, 2021-06-03): continue evaluation of which selectors should go here
150
+ # vs which selectors should be in LabwareView
151
+ class GeometryView:
152
+ """Geometry computed state getters."""
153
+
154
+ def __init__(
155
+ self,
156
+ config: Config,
157
+ labware_view: LabwareView,
158
+ well_view: WellView,
159
+ module_view: ModuleView,
160
+ pipette_view: PipetteView,
161
+ addressable_area_view: AddressableAreaView,
162
+ ) -> None:
163
+ """Initialize a GeometryView instance."""
164
+ self._config = config
165
+ self._labware = labware_view
166
+ self._wells = well_view
167
+ self._modules = module_view
168
+ self._pipettes = pipette_view
169
+ self._addressable_areas = addressable_area_view
170
+ self._last_drop_tip_location_spot: Dict[str, _TipDropSection] = {}
171
+
172
+ @cached_property
173
+ def absolute_deck_extents(self) -> _AbsoluteRobotExtents:
174
+ """The absolute deck extents for a given robot deck."""
175
+ left_offset = self._addressable_areas.mount_offsets["left"]
176
+ right_offset = self._addressable_areas.mount_offsets["right"]
177
+
178
+ front_left_abs = {
179
+ MountType.LEFT: Point(left_offset.x, -1 * left_offset.y, left_offset.z),
180
+ MountType.RIGHT: Point(right_offset.x, -1 * right_offset.y, right_offset.z),
181
+ }
182
+ back_right_abs = {
183
+ MountType.LEFT: self._addressable_areas.deck_extents + left_offset,
184
+ MountType.RIGHT: self._addressable_areas.deck_extents + right_offset,
185
+ }
186
+ return _AbsoluteRobotExtents(
187
+ front_left=front_left_abs,
188
+ back_right=back_right_abs,
189
+ deck_extents=self._addressable_areas.deck_extents,
190
+ padding_rear=self._addressable_areas.padding_offsets["rear"],
191
+ padding_front=self._addressable_areas.padding_offsets["front"],
192
+ padding_left_side=self._addressable_areas.padding_offsets["left_side"],
193
+ padding_right_side=self._addressable_areas.padding_offsets["right_side"],
194
+ )
195
+
196
+ def get_labware_highest_z(self, labware_id: str) -> float:
197
+ """Get the highest Z-point of a labware."""
198
+ labware_data = self._labware.get(labware_id)
199
+ return self._get_highest_z_from_labware_data(labware_data)
200
+
201
+ def _is_obstacle_labware(self, labware_id: str) -> bool:
202
+ """Check if the labware is a deck obstacle."""
203
+ for loc in self.get_location_sequence(labware_id):
204
+ if isinstance(loc, InStackerHopperLocation) or isinstance(
205
+ loc, NotOnDeckLocationSequenceComponent
206
+ ):
207
+ return False
208
+ return True
209
+
210
+ def _get_tallest_obstacle_labware(self) -> float:
211
+ """Get the highest Z-point of all labware on the deck."""
212
+ return max(
213
+ (
214
+ self._get_highest_z_from_labware_data(lw_data)
215
+ for lw_data in self._labware.get_all()
216
+ if self._is_obstacle_labware(lw_data.id)
217
+ ),
218
+ default=0.0,
219
+ )
220
+
221
+ def _get_tallest_obstacle_module(self) -> float:
222
+ """Get the highest Z-point of all modules on the deck."""
223
+ return max(
224
+ (
225
+ self._modules.get_module_highest_z(module.id, self._addressable_areas)
226
+ for module in self._modules.get_all()
227
+ ),
228
+ default=0.0,
229
+ )
230
+
231
+ def _get_tallest_obstacle_fixture(self) -> float:
232
+ """Get the highest Z-point of all fixtures on the deck."""
233
+ all_fixtures = self._addressable_areas.get_all_cutout_fixtures()
234
+ if all_fixtures is None:
235
+ # We're using a simulated deck config (see `Config.use_simulated_deck_config`).
236
+ # We only know the addressable areas referenced by the protocol, not the fixtures
237
+ # providing them. And there is more than one possible configuration of fixtures
238
+ # to provide them. So, we can't know what the highest fixture is. Default to 0.
239
+ #
240
+ # Defaulting to 0 may not be the right thing to do here.
241
+ # For example, suppose a protocol references an addressable area that implies a tall
242
+ # fixture must be on the deck, and then it uses long tips that wouldn't be able to
243
+ # clear the top of that fixture. We should perhaps raise an analysis error for that,
244
+ # but defaulting to 0 here means we won't.
245
+ return 0.0
246
+ return max(
247
+ (
248
+ self._addressable_areas.get_fixture_height(cutout_fixture_name)
249
+ for cutout_fixture_name in all_fixtures
250
+ ),
251
+ default=0.0,
252
+ )
253
+
254
+ def get_all_obstacle_highest_z(self) -> float:
255
+ """Get the highest Z-point across all obstacles that the instruments need to fly over."""
256
+ return max(
257
+ self._get_tallest_obstacle_labware(),
258
+ self._get_tallest_obstacle_module(),
259
+ self._get_tallest_obstacle_fixture(),
260
+ )
261
+
262
+ def get_highest_z_in_slot(
263
+ self, slot: Union[DeckSlotLocation, StagingSlotLocation]
264
+ ) -> float:
265
+ """Get the highest Z-point of all items stacked in the given deck slot.
266
+
267
+ This height includes the height of any module that occupies the given slot
268
+ even if it wasn't loaded in that slot (e.g., thermocycler).
269
+ """
270
+ slot_item = self.get_slot_item(slot.slotName)
271
+ if isinstance(slot_item, LoadedModule):
272
+ # get height of module + all labware on it
273
+ module_id = slot_item.id
274
+ try:
275
+ labware_id = self._labware.get_id_by_module(module_id=module_id)
276
+ except LabwareNotLoadedOnModuleError:
277
+ return self._modules.get_module_highest_z(
278
+ module_id=module_id,
279
+ addressable_areas=self._addressable_areas,
280
+ )
281
+ else:
282
+ return self.get_highest_z_of_labware_stack(labware_id)
283
+ elif isinstance(slot_item, LoadedLabware):
284
+ # get stacked heights of all labware in the slot
285
+ return self.get_highest_z_of_labware_stack(slot_item.id)
286
+ elif type(slot_item) is dict:
287
+ # TODO (cb, 2024-02-05): Eventually this logic should become the responsibility of bounding box
288
+ # conflict checking, as fixtures may not always be considered as items from slots.
289
+ return self._addressable_areas.get_fixture_height(slot_item["id"])
290
+ else:
291
+ return 0
292
+
293
+ def get_highest_z_of_labware_stack(self, labware_id: str) -> float:
294
+ """Get the highest Z-point of the topmost labware in the stack of labware on the given labware.
295
+
296
+ If there is no labware on the given labware, returns highest z of the given labware.
297
+ """
298
+ try:
299
+ stacked_labware_id = self._labware.get_id_by_labware(labware_id)
300
+ except LabwareNotLoadedOnLabwareError:
301
+ return self.get_labware_highest_z(labware_id)
302
+ return self.get_highest_z_of_labware_stack(stacked_labware_id)
303
+
304
+ def get_min_travel_z(
305
+ self,
306
+ pipette_id: str,
307
+ labware_id: str,
308
+ location: Optional[CurrentPipetteLocation],
309
+ minimum_z_height: Optional[float],
310
+ ) -> float:
311
+ """Get the minimum allowed travel height of an arc move."""
312
+ if (
313
+ isinstance(location, CurrentWell)
314
+ and pipette_id == location.pipette_id
315
+ and labware_id == location.labware_id
316
+ ):
317
+ min_travel_z = self.get_labware_highest_z(labware_id)
318
+ else:
319
+ min_travel_z = self.get_all_obstacle_highest_z()
320
+ if minimum_z_height:
321
+ min_travel_z = max(min_travel_z, minimum_z_height)
322
+ return min_travel_z
323
+
324
+ def _normalize_module_calibration_offset(
325
+ self,
326
+ module_location: DeckSlotLocation,
327
+ offset_data: Optional[ModuleOffsetData],
328
+ ) -> Point:
329
+ """Normalize the module calibration offset depending on the module location."""
330
+ if not offset_data:
331
+ return Point(x=0, y=0, z=0)
332
+ offset = Point.from_xyz_attrs(offset_data.moduleOffsetVector)
333
+ calibrated_slot = offset_data.location.slotName
334
+ calibrated_slot_column = self.get_slot_column(calibrated_slot)
335
+ current_slot_column = self.get_slot_column(module_location.slotName)
336
+ # make sure that we have valid colums since we cant have modules in the middle of the deck
337
+ assert set([calibrated_slot_column, current_slot_column]).issubset(
338
+ {1, 3}
339
+ ), f"Module calibration offset is an invalid slot {calibrated_slot}"
340
+
341
+ # Check if the module has moved from one side of the deck to the other
342
+ if calibrated_slot_column != current_slot_column:
343
+ # Since the module was rotated, the calibration offset vector needs to be rotated by 180 degrees along the z axis
344
+ saved_offset: NDArray[npdouble] = array([offset.x, offset.y, offset.z])
345
+ rotation_matrix: NDArray[npdouble] = array(
346
+ [[-1, 0, 0], [0, -1, 0], [0, 0, 1]]
347
+ )
348
+ new_offset = dot(saved_offset, rotation_matrix)
349
+ offset = Point(x=new_offset[0], y=new_offset[1], z=new_offset[2])
350
+ return offset
351
+
352
+ def _get_calibrated_module_offset(self, location: LabwareLocation) -> Point:
353
+ """Get a labware location's underlying calibrated module offset, if it is on a module."""
354
+ if isinstance(location, ModuleLocation):
355
+ module_id = location.moduleId
356
+ module_location = self._modules.get_location(module_id)
357
+ offset_data = self._modules.get_module_calibration_offset(module_id)
358
+ return self._normalize_module_calibration_offset(
359
+ module_location, offset_data
360
+ )
361
+ elif isinstance(location, (DeckSlotLocation, AddressableAreaLocation)):
362
+ # TODO we might want to do a check here to make sure addressable area location is a standard deck slot
363
+ # and raise if its not (or maybe we don't actually care since modules will never be loaded elsewhere)
364
+ return Point(x=0, y=0, z=0)
365
+ elif isinstance(location, OnLabwareLocation):
366
+ labware_data = self._labware.get(location.labwareId)
367
+ return self._get_calibrated_module_offset(labware_data.location)
368
+ elif (
369
+ location == OFF_DECK_LOCATION
370
+ or location == SYSTEM_LOCATION
371
+ or isinstance(location, InStackerHopperLocation)
372
+ ):
373
+ raise errors.LabwareNotOnDeckError(
374
+ "Labware does not have a slot or module associated with it"
375
+ " since it is no longer on the deck."
376
+ )
377
+
378
+ def get_labware_origin_position(self, labware_id: str) -> Point:
379
+ """Get the deck coordinates of a labware's origin.
380
+
381
+ This includes module calibration but excludes the calibration of the given labware.
382
+ """
383
+ location = self._labware.get(labware_id).location
384
+ definition = self._labware.get_definition(labware_id)
385
+
386
+ slot_front_left = self._get_labware_ancestor_position(labware_id)
387
+ stackup_origin_to_lw_origin = self._get_stackup_placement_origin_to_lw_origin(
388
+ location=location, definition=definition, is_topmost_labware=True
389
+ )
390
+ module_cal_offset = self._get_calibrated_module_offset(location)
391
+
392
+ return slot_front_left + stackup_origin_to_lw_origin + module_cal_offset
393
+
394
+ def _get_labware_ancestor_position(self, labware_id: str) -> Point:
395
+ """Get the position of the labware's underlying ancestor."""
396
+ slot_name = self._get_underlying_addressable_area_name(
397
+ self._labware.get(labware_id).location
398
+ )
399
+ parent_pos = self._addressable_areas.get_addressable_area_position(slot_name)
400
+
401
+ return parent_pos
402
+
403
+ def _get_stackup_placement_origin_to_lw_origin(
404
+ self,
405
+ location: LabwareLocation,
406
+ definition: LabwareDefinition,
407
+ is_topmost_labware: bool,
408
+ ) -> Point:
409
+ """Get the offset vector from the lowest entity in a stackup to the labware."""
410
+ if isinstance(
411
+ location, (AddressableAreaLocation, DeckSlotLocation, ModuleLocation)
412
+ ):
413
+ return self._get_parent_placement_origin_to_lw_origin(
414
+ labware_location=location,
415
+ labware_definition=definition,
416
+ is_topmost_labware=is_topmost_labware,
417
+ )
418
+ elif isinstance(location, OnLabwareLocation):
419
+ parent_id = location.labwareId
420
+ parent_location = self._labware.get(parent_id).location
421
+ parent_definition = self._labware.get_definition(parent_id)
422
+
423
+ parent_placement_origin_to_lw_origin = (
424
+ self._get_parent_placement_origin_to_lw_origin(
425
+ labware_location=location,
426
+ labware_definition=definition,
427
+ is_topmost_labware=is_topmost_labware,
428
+ )
429
+ )
430
+
431
+ return (
432
+ parent_placement_origin_to_lw_origin
433
+ + self._get_stackup_placement_origin_to_lw_origin(
434
+ location=parent_location,
435
+ definition=parent_definition,
436
+ is_topmost_labware=False,
437
+ )
438
+ )
439
+ else:
440
+ raise errors.LabwareNotOnDeckError(
441
+ "Cannot access labware since it is not on the deck. "
442
+ "Either it has been loaded off-deck or its been moved off-deck."
443
+ )
444
+
445
+ def _get_parent_placement_origin_to_lw_origin(
446
+ self,
447
+ labware_location: LabwareLocation,
448
+ labware_definition: LabwareDefinition,
449
+ is_topmost_labware: bool,
450
+ ) -> Point:
451
+ parent_deck_item = self._get_parent_definition(labware_location)
452
+
453
+ if isinstance(labware_location, ModuleLocation):
454
+ module_parent_to_child_offset = (
455
+ self._modules.get_nominal_offset_to_child_from_addressable_area(
456
+ module_id=labware_location.moduleId,
457
+ )
458
+ )
459
+ return get_parent_placement_origin_to_lw_origin(
460
+ child_labware=labware_definition,
461
+ parent_deck_item=parent_deck_item, # type: ignore[arg-type]
462
+ module_parent_to_child_offset=module_parent_to_child_offset,
463
+ deck_definition=self._addressable_areas.deck_definition,
464
+ is_topmost_labware=is_topmost_labware,
465
+ labware_location=labware_location,
466
+ )
467
+ elif isinstance(labware_location, OnLabwareLocation):
468
+ return get_parent_placement_origin_to_lw_origin(
469
+ child_labware=labware_definition,
470
+ parent_deck_item=parent_deck_item, # type: ignore[arg-type]
471
+ module_parent_to_child_offset=None,
472
+ deck_definition=self._addressable_areas.deck_definition,
473
+ is_topmost_labware=is_topmost_labware,
474
+ labware_location=labware_location,
475
+ )
476
+ elif isinstance(labware_location, (DeckSlotLocation, AddressableAreaLocation)):
477
+ return get_parent_placement_origin_to_lw_origin(
478
+ child_labware=labware_definition,
479
+ parent_deck_item=parent_deck_item, # type: ignore[arg-type]
480
+ module_parent_to_child_offset=None,
481
+ deck_definition=self._addressable_areas.deck_definition,
482
+ is_topmost_labware=is_topmost_labware,
483
+ labware_location=labware_location,
484
+ )
485
+ else:
486
+ raise ValueError(f"Invalid labware location: {labware_location}")
487
+
488
+ def _get_parent_definition(
489
+ self, location: LabwareLocation
490
+ ) -> LabwareParentDefinition:
491
+ """Get the parent's definition given the labware's location."""
492
+ if isinstance(location, DeckSlotLocation):
493
+ addressable_area_name = location.slotName.id
494
+ return self._addressable_areas.get_slot_definition(addressable_area_name)
495
+
496
+ elif isinstance(location, AddressableAreaLocation):
497
+ addressable_area_name = location.addressableAreaName
498
+ return self._addressable_areas.get_addressable_area(addressable_area_name)
499
+
500
+ elif isinstance(location, ModuleLocation):
501
+ module_id = location.moduleId
502
+ return self._modules.get_definition(module_id)
503
+
504
+ elif isinstance(location, OnLabwareLocation):
505
+ below_labware_id = location.labwareId
506
+ return self._labware.get_definition(below_labware_id)
507
+
508
+ elif location == OFF_DECK_LOCATION or location == SYSTEM_LOCATION:
509
+ raise errors.LabwareNotOnDeckError(
510
+ f"Labware location {location} does not have a slot associated with it"
511
+ f" since it is no longer on the deck."
512
+ )
513
+
514
+ elif isinstance(location, InStackerHopperLocation):
515
+ raise errors.LabwareNotOnDeckError(
516
+ "Labware does not have a slot or module associated with it"
517
+ " since it is no longer on the deck."
518
+ )
519
+
520
+ else:
521
+ raise errors.InvalidLabwarePositionError(
522
+ f"Cannot get ancestor from location {location}"
523
+ )
524
+
525
+ def _get_underlying_addressable_area_name(self, location: LabwareLocation) -> str:
526
+ if isinstance(location, DeckSlotLocation):
527
+ return location.slotName.id
528
+ elif isinstance(location, AddressableAreaLocation):
529
+ return location.addressableAreaName
530
+ elif isinstance(location, ModuleLocation):
531
+ return self._modules.get_provided_addressable_area(location.moduleId)
532
+ elif isinstance(location, OnLabwareLocation):
533
+ return self.get_ancestor_addressable_area_name(location.labwareId)
534
+ else:
535
+ raise errors.InvalidLabwarePositionError(
536
+ f"Cannot get ancestor slot of location {location}"
537
+ )
538
+
539
+ def get_labware_position(self, labware_id: str) -> Point:
540
+ """Get the calibrated origin of the labware."""
541
+ origin_pos = self.get_labware_origin_position(labware_id)
542
+ cal_offset = self._labware.get_labware_offset_vector(labware_id)
543
+ return Point(
544
+ x=origin_pos.x + cal_offset.x,
545
+ y=origin_pos.y + cal_offset.y,
546
+ z=origin_pos.z + cal_offset.z,
547
+ )
548
+
549
+ def _validate_well_position(
550
+ self,
551
+ target_height: LiquidTrackingType, # height in mm inside a well relative to the bottom
552
+ well_max_height: float,
553
+ pipette_id: str,
554
+ ) -> LiquidTrackingType:
555
+ """If well offset would be outside the bounds of a well, silently bring it back to the boundary."""
556
+ if isinstance(target_height, SimulatedProbeResult):
557
+ return target_height
558
+ lld_min_height = self._pipettes.get_current_tip_lld_settings(
559
+ pipette_id=pipette_id
560
+ )
561
+ if target_height < lld_min_height:
562
+ target_height = lld_min_height
563
+ elif target_height > well_max_height:
564
+ target_height = well_max_height
565
+ return target_height
566
+
567
+ def validate_probed_height(
568
+ self,
569
+ labware_id: str,
570
+ well_name: str,
571
+ pipette_id: str,
572
+ probed_height: LiquidTrackingType,
573
+ ) -> None:
574
+ """Raise an error if a probed liquid height is not within well bounds."""
575
+ if isinstance(probed_height, SimulatedProbeResult):
576
+ return
577
+ lld_min_height = self._pipettes.get_current_tip_lld_settings(
578
+ pipette_id=pipette_id
579
+ )
580
+ well_def = self._labware.get_well_definition(labware_id, well_name)
581
+ well_depth = well_def.depth
582
+ if probed_height < lld_min_height:
583
+ raise PipetteLiquidNotFoundError(
584
+ f"Liquid Height of {probed_height} mm is lower minumum allowed lld height {lld_min_height} mm."
585
+ )
586
+ if probed_height > well_depth:
587
+ raise PipetteLiquidNotFoundError(
588
+ f"Liquid Height of {probed_height} mm is greater than maximum well height {well_depth} mm."
589
+ )
590
+
591
+ def get_well_position(
592
+ self,
593
+ labware_id: str,
594
+ well_name: str,
595
+ well_location: Optional[WellLocationType] = None,
596
+ operation_volume: Optional[float] = None,
597
+ pipette_id: Optional[str] = None,
598
+ ) -> Point:
599
+ """Given relative well location in a labware, get absolute position."""
600
+ labware_pos = self.get_labware_position(labware_id)
601
+ well_def = self._labware.get_well_definition(labware_id, well_name)
602
+ well_depth = well_def.depth
603
+
604
+ offset = WellOffset(x=0, y=0, z=well_depth)
605
+ if well_location is not None:
606
+ offset = well_location.offset # location of the bottom of the well
607
+ offset_adjustment = self.get_well_offset_adjustment(
608
+ labware_id=labware_id,
609
+ well_name=well_name,
610
+ well_location=well_location,
611
+ well_depth=well_depth,
612
+ operation_volume=operation_volume,
613
+ pipette_id=pipette_id,
614
+ )
615
+ if not isinstance(offset_adjustment, SimulatedProbeResult):
616
+ offset = offset.model_copy(update={"z": offset.z + offset_adjustment})
617
+ return Point(
618
+ x=labware_pos.x + offset.x + well_def.x,
619
+ y=labware_pos.y + offset.y + well_def.y,
620
+ z=labware_pos.z + offset.z + well_def.z,
621
+ )
622
+
623
+ def _get_relative_liquid_handling_well_location(
624
+ self,
625
+ labware_id: str,
626
+ well_name: str,
627
+ absolute_point: Point,
628
+ delta: Point,
629
+ meniscus_tracking: Optional[MeniscusTrackingTarget] = None,
630
+ ) -> Tuple[WellLocationType, bool]:
631
+ """Given absolute position, get relative location of a well in a labware."""
632
+ dynamic_liquid_tracking = False
633
+ if meniscus_tracking:
634
+ location = LiquidHandlingWellLocation(
635
+ origin=WellOrigin.MENISCUS,
636
+ offset=WellOffset(x=0, y=0, z=absolute_point.z),
637
+ )
638
+ # TODO(cm): handle operationVolume being a float other than 0
639
+ if meniscus_tracking == MeniscusTrackingTarget.END:
640
+ location.volumeOffset = "operationVolume"
641
+ elif meniscus_tracking == MeniscusTrackingTarget.DYNAMIC:
642
+ dynamic_liquid_tracking = True
643
+ else:
644
+ location = LiquidHandlingWellLocation(
645
+ offset=WellOffset(x=delta.x, y=delta.y, z=delta.z)
646
+ )
647
+ return location, dynamic_liquid_tracking
648
+
649
+ def get_relative_well_location(
650
+ self,
651
+ labware_id: str,
652
+ well_name: str,
653
+ absolute_point: Point,
654
+ location_type: WellLocationFunction,
655
+ meniscus_tracking: Optional[MeniscusTrackingTarget] = None,
656
+ ) -> Tuple[WellLocationType, bool]:
657
+ """Given absolute position, get relative location of a well in a labware."""
658
+ well_absolute_point = self.get_well_position(labware_id, well_name)
659
+ delta = absolute_point - well_absolute_point
660
+ match location_type:
661
+ case WellLocationFunction.BASE | WellLocationFunction.DROP_TIP:
662
+ return (
663
+ WellLocation(offset=WellOffset(x=delta.x, y=delta.y, z=delta.z)),
664
+ False,
665
+ )
666
+ case WellLocationFunction.PICK_UP_TIP:
667
+ return (
668
+ PickUpTipWellLocation(
669
+ offset=WellOffset(x=delta.x, y=delta.y, z=delta.z)
670
+ ),
671
+ False,
672
+ )
673
+ case WellLocationFunction.LIQUID_HANDLING:
674
+ return self._get_relative_liquid_handling_well_location(
675
+ labware_id=labware_id,
676
+ well_name=well_name,
677
+ absolute_point=absolute_point,
678
+ delta=delta,
679
+ meniscus_tracking=meniscus_tracking,
680
+ )
681
+
682
+ def get_well_height(
683
+ self,
684
+ labware_id: str,
685
+ well_name: str,
686
+ ) -> float:
687
+ """Get the height of a specified well for a labware."""
688
+ well_def = self._labware.get_well_definition(labware_id, well_name)
689
+ return well_def.depth
690
+
691
+ def _get_highest_z_from_labware_data(self, lw_data: LoadedLabware) -> float:
692
+ labware_pos = self.get_labware_position(lw_data.id)
693
+ z_dim = self._labware.get_dimensions(labware_id=lw_data.id).z
694
+ height_over_labware: float = 0
695
+ if isinstance(lw_data.location, ModuleLocation):
696
+ # Note: when calculating highest z of stacked labware, height-over-labware
697
+ # gets accounted for only if the top labware is directly on the module.
698
+ # So if there's a labware on an adapter on a module, then this
699
+ # over-module-height gets ignored. We currently do not have any modules
700
+ # that use an adapter and has height over labware so this doesn't cause
701
+ # any issues yet. But if we add one in the future then this calculation
702
+ # should be updated.
703
+ module_id = lw_data.location.moduleId
704
+ height_over_labware = self._modules.get_height_over_labware(module_id)
705
+ # todo(mm, 2025-07-31): This math needs updating for schema 2:
706
+ # labware_pos.z is not necessarily the bottom of the labware.
707
+ return labware_pos.z + z_dim + height_over_labware
708
+
709
+ def get_nominal_effective_tip_length(
710
+ self,
711
+ pipette_id: str,
712
+ labware_id: str,
713
+ ) -> float:
714
+ """Given a labware and a pipette's config, get the nominal effective tip length.
715
+
716
+ Effective tip length is the nominal tip length less the distance the
717
+ tip overlaps with the pipette nozzle. This does not take calibrated
718
+ tip lengths into account.
719
+ """
720
+ labware_uri = self._labware.get_definition_uri(labware_id)
721
+ nominal_overlap = self._pipettes.get_nominal_tip_overlap(
722
+ pipette_id=pipette_id, labware_uri=labware_uri
723
+ )
724
+
725
+ return self._labware.get_tip_length(
726
+ labware_id=labware_id, overlap=nominal_overlap
727
+ )
728
+
729
+ def get_nominal_tip_geometry(
730
+ self,
731
+ pipette_id: str,
732
+ labware_id: str,
733
+ well_name: Optional[str],
734
+ ) -> TipGeometry:
735
+ """Given a labware, well, and hardware pipette config, get the tip geometry.
736
+
737
+ Tip geometry includes effective tip length, tip diameter, and tip volume,
738
+ which is all data required by the hardware controller for proper tip handling.
739
+
740
+ This geometry data is based solely on labware and pipette definitions and
741
+ does not take calibrated tip lengths into account.
742
+ """
743
+ effective_length = self.get_nominal_effective_tip_length(
744
+ pipette_id=pipette_id,
745
+ labware_id=labware_id,
746
+ )
747
+ well_def = self._labware.get_well_definition(labware_id, well_name)
748
+
749
+ if well_def.shape != "circular":
750
+ raise errors.LabwareIsNotTipRackError(
751
+ f"Well {well_name} in labware {labware_id} is not circular."
752
+ )
753
+
754
+ return TipGeometry(
755
+ length=effective_length,
756
+ diameter=well_def.diameter,
757
+ # TODO(mc, 2020-11-12): WellDefinition type says totalLiquidVolume
758
+ # is a float, but hardware controller expects an int
759
+ volume=int(well_def.totalLiquidVolume),
760
+ )
761
+
762
+ def get_checked_tip_drop_location(
763
+ self,
764
+ pipette_id: str,
765
+ labware_id: str,
766
+ well_location: DropTipWellLocation,
767
+ partially_configured: bool = False,
768
+ override_default_offset: float | None = None,
769
+ ) -> WellLocation:
770
+ """Get tip drop location given labware and hardware pipette.
771
+
772
+ This makes sure that the well location has an appropriate origin & offset
773
+ if one is not already set previously.
774
+ """
775
+ if (
776
+ self._labware.get_definition(labware_id).parameters.isTiprack
777
+ and partially_configured
778
+ ):
779
+ raise errors.UnexpectedProtocolError(
780
+ "Cannot return tip to a tiprack while the pipette is configured for partial tip."
781
+ )
782
+ if well_location.origin != DropTipWellOrigin.DEFAULT:
783
+ return WellLocation(
784
+ origin=WellOrigin(well_location.origin.value),
785
+ offset=well_location.offset,
786
+ )
787
+ if override_default_offset is not None:
788
+ z_offset = override_default_offset
789
+ elif self._labware.get_definition(labware_id).parameters.isTiprack:
790
+ z_offset = self._labware.get_tip_drop_z_offset(
791
+ labware_id=labware_id,
792
+ length_scale=self._pipettes.get_return_tip_scale(pipette_id),
793
+ additional_offset=well_location.offset.z,
794
+ )
795
+ else:
796
+ # return to top if labware is not tip rack
797
+ z_offset = well_location.offset.z
798
+
799
+ return WellLocation(
800
+ origin=WellOrigin.TOP,
801
+ offset=WellOffset(
802
+ x=well_location.offset.x,
803
+ y=well_location.offset.y,
804
+ z=z_offset,
805
+ ),
806
+ )
807
+
808
+ def convert_pick_up_tip_well_location(
809
+ self, well_location: PickUpTipWellLocation
810
+ ) -> WellLocation:
811
+ """Convert PickUpTipWellLocation to WellLocation."""
812
+ return WellLocation(
813
+ origin=WellOrigin(well_location.origin.value), offset=well_location.offset
814
+ )
815
+
816
+ def get_ancestor_slot_name(
817
+ self, labware_id: str
818
+ ) -> Union[DeckSlotName, StagingSlotName]:
819
+ """Get the slot name of the labware or the module that the labware is on."""
820
+ labware = self._labware.get(labware_id)
821
+ slot_name: Union[DeckSlotName, StagingSlotName]
822
+ if isinstance(labware.location, DeckSlotLocation):
823
+ slot_name = labware.location.slotName
824
+ elif isinstance(labware.location, ModuleLocation):
825
+ module_id = labware.location.moduleId
826
+ slot_name = self._modules.get_location(module_id).slotName
827
+ elif isinstance(labware.location, OnLabwareLocation):
828
+ below_labware_id = labware.location.labwareId
829
+ slot_name = self.get_ancestor_slot_name(below_labware_id)
830
+ elif isinstance(labware.location, AddressableAreaLocation):
831
+ area_name = labware.location.addressableAreaName
832
+ if self._labware.is_absorbance_reader_lid(labware_id):
833
+ raise errors.LocationIsLidDockSlotError(
834
+ "Cannot get ancestor slot name for labware on lid dock slot."
835
+ )
836
+ elif fixture_validation.is_staging_slot(area_name):
837
+ slot_name = StagingSlotName.from_primitive(area_name)
838
+ else:
839
+ slot_name = DeckSlotName.from_primitive(area_name)
840
+ elif labware.location == OFF_DECK_LOCATION:
841
+ raise errors.LabwareNotOnDeckError(
842
+ f"Labware {labware_id} does not have a slot associated with it"
843
+ f" since it is no longer on the deck."
844
+ )
845
+ else:
846
+ _LOG.error(
847
+ f"Unhandled location type in get_ancestor_slot_name: {labware.location}"
848
+ )
849
+ raise errors.InvalidLabwarePositionError(
850
+ f"Cannot get ancestor slot of {self._labware.get_display_name(labware_id)} with location {labware.location}"
851
+ )
852
+
853
+ return slot_name
854
+
855
+ def get_ancestor_addressable_area_name(self, labware_id: str) -> str:
856
+ """Get the name of the addressable area the labware is eventually on."""
857
+ labware = self._labware.get(labware_id)
858
+ original_display_name = self._labware.get_display_name(labware_id)
859
+ seen: Set[str] = set((labware_id,))
860
+ while isinstance(labware.location, OnLabwareLocation):
861
+ labware = self._labware.get(labware.location.labwareId)
862
+ if labware.id in seen:
863
+ raise InvalidLabwarePositionError(
864
+ f"Cycle detected in labware positioning for {original_display_name}"
865
+ )
866
+ seen.add(labware.id)
867
+ if isinstance(labware.location, DeckSlotLocation):
868
+ return labware.location.slotName.id
869
+ elif isinstance(labware.location, AddressableAreaLocation):
870
+ return labware.location.addressableAreaName
871
+ elif isinstance(labware.location, ModuleLocation):
872
+ return self._modules.get_provided_addressable_area(
873
+ labware.location.moduleId
874
+ )
875
+ else:
876
+ raise LabwareNotOnDeckError(
877
+ f"Labware {original_display_name} is not loaded on deck",
878
+ details={"eventual-location": repr(labware.location)},
879
+ )
880
+
881
+ def ensure_location_not_occupied(
882
+ self,
883
+ location: _LabwareLocation,
884
+ desired_addressable_area: Optional[str] = None,
885
+ ) -> _LabwareLocation:
886
+ """Ensure that the location does not already have either Labware or a Module in it."""
887
+ # Collect set of existing fixtures, if any
888
+ existing_fixtures = self._get_potential_fixtures_for_location_occupation(
889
+ location
890
+ )
891
+ potential_fixtures = (
892
+ self._get_potential_fixtures_for_location_occupation(
893
+ AddressableAreaLocation(addressableAreaName=desired_addressable_area)
894
+ )
895
+ if desired_addressable_area is not None
896
+ else None
897
+ )
898
+
899
+ # Handle the checking conflict on an incoming fixture
900
+ if potential_fixtures is not None and isinstance(location, DeckSlotLocation):
901
+ if (
902
+ existing_fixtures is not None
903
+ and not any(
904
+ location.slotName.id in fixture.provided_addressable_areas
905
+ for fixture in potential_fixtures[1].intersection(
906
+ existing_fixtures[1]
907
+ )
908
+ )
909
+ ) or (
910
+ self._labware.get_by_slot(location.slotName) is not None
911
+ and not any(
912
+ location.slotName.id in fixture.provided_addressable_areas
913
+ for fixture in potential_fixtures[1]
914
+ )
915
+ ):
916
+ self._labware.raise_if_labware_in_location(location)
917
+
918
+ else:
919
+ self._modules.raise_if_module_in_location(location)
920
+
921
+ # Otherwise handle standard conflict checking
922
+ else:
923
+ if isinstance(
924
+ location,
925
+ (
926
+ DeckSlotLocation,
927
+ ModuleLocation,
928
+ OnLabwareLocation,
929
+ AddressableAreaLocation,
930
+ ),
931
+ ):
932
+ self._labware.raise_if_labware_in_location(location)
933
+
934
+ area = (
935
+ location.slotName.id
936
+ if isinstance(location, DeckSlotLocation)
937
+ else (
938
+ location.addressableAreaName
939
+ if isinstance(location, AddressableAreaLocation)
940
+ else None
941
+ )
942
+ )
943
+ if area is not None and (
944
+ existing_fixtures is None
945
+ or not any(
946
+ area in fixture.provided_addressable_areas
947
+ for fixture in existing_fixtures[1]
948
+ )
949
+ ):
950
+ if isinstance(location, DeckSlotLocation):
951
+ self._modules.raise_if_module_in_location(location)
952
+ elif isinstance(location, AddressableAreaLocation):
953
+ self._modules.raise_if_module_in_location(
954
+ DeckSlotLocation(
955
+ slotName=self._addressable_areas.get_addressable_area_base_slot(
956
+ location.addressableAreaName
957
+ )
958
+ )
959
+ )
960
+
961
+ return location
962
+
963
+ def _get_potential_fixtures_for_location_occupation(
964
+ self, location: _LabwareLocation
965
+ ) -> Tuple[str, Set[PotentialCutoutFixture]] | None:
966
+ loc: DeckSlotLocation | AddressableAreaLocation | None = None
967
+ if isinstance(location, AddressableAreaLocation):
968
+ # Convert the addressable area into a staging slot if applicable
969
+ slots = StagingSlotName._value2member_map_
970
+ for slot in slots:
971
+ if location.addressableAreaName == slot:
972
+ loc = DeckSlotLocation(
973
+ slotName=DeckSlotName(location.addressableAreaName[0] + "3")
974
+ )
975
+ if loc is None:
976
+ loc = location
977
+ elif isinstance(location, DeckSlotLocation):
978
+ loc = location
979
+
980
+ if isinstance(loc, DeckSlotLocation):
981
+ module = self._modules.get_by_slot(loc.slotName)
982
+ if module is not None and self._config.robot_type != "OT-2 Standard":
983
+ fixtures = deck_configuration_provider.get_potential_cutout_fixtures(
984
+ addressable_area_name=self._modules.ensure_and_convert_module_fixture_location(
985
+ deck_slot=loc.slotName,
986
+ model=module.model,
987
+ ),
988
+ deck_definition=self._addressable_areas.deck_definition,
989
+ )
990
+ else:
991
+ fixtures = None
992
+ elif isinstance(loc, AddressableAreaLocation):
993
+ fixtures = deck_configuration_provider.get_potential_cutout_fixtures(
994
+ addressable_area_name=loc.addressableAreaName,
995
+ deck_definition=self._addressable_areas.deck_definition,
996
+ )
997
+ else:
998
+ fixtures = None
999
+ return fixtures
1000
+
1001
+ def _get_potential_disposal_location_cutout_fixtures(
1002
+ self, slot_name: DeckSlotName
1003
+ ) -> CutoutFixture | None:
1004
+ for area in self._addressable_areas.get_all():
1005
+ if (
1006
+ self._addressable_areas.get_addressable_area(area).area_type
1007
+ == AreaType.WASTE_CHUTE
1008
+ or self._addressable_areas.get_addressable_area(area).area_type
1009
+ == AreaType.MOVABLE_TRASH
1010
+ ) and slot_name == self._addressable_areas.get_addressable_area_base_slot(
1011
+ area
1012
+ ):
1013
+ # Given we only have one Waste Chute fixture and one type of Trash bin fixture it's
1014
+ # fine to return the first result of our potential fixtures here. This will need to
1015
+ # change in the future if there multiple trash fixtures that share the same area type.
1016
+ potential_fixture = (
1017
+ deck_configuration_provider.get_potential_cutout_fixtures(
1018
+ area, self._addressable_areas.deck_definition
1019
+ )[1].pop()
1020
+ )
1021
+ return deck_configuration_provider.get_cutout_fixture(
1022
+ potential_fixture.cutout_fixture_id,
1023
+ self._addressable_areas.deck_definition,
1024
+ )
1025
+ return None
1026
+
1027
+ def get_labware_grip_point(
1028
+ self,
1029
+ labware_definition: LabwareDefinition,
1030
+ location: Union[
1031
+ DeckSlotLocation, ModuleLocation, OnLabwareLocation, AddressableAreaLocation
1032
+ ],
1033
+ ) -> Point:
1034
+ """Get the grip point of the labware as placed on the given location.
1035
+
1036
+ Returns the absolute position of the labware's gripping point as if
1037
+ it were placed on the specified location. Labware offset (LPC offset) not included.
1038
+
1039
+ Grip point is the location where critical point of the gripper should move to
1040
+ in order to pick/drop the given labware in the specified location.
1041
+ It is calculated as the xy center of the slot with z as the point indicated by
1042
+ z-position of labware bottom + grip height from labware bottom.
1043
+ """
1044
+ grip_z_from_lw_origin = self._labware.get_grip_z(labware_definition)
1045
+ aa_name = self._get_underlying_addressable_area_name(location)
1046
+ parent_to_lw_offset = self._get_stackup_placement_origin_to_lw_origin(
1047
+ location=location,
1048
+ definition=labware_definition,
1049
+ is_topmost_labware=True, # We aren't concerned with entities above the gripped labware.
1050
+ )
1051
+ addressable_area = self._addressable_areas.get_addressable_area(aa_name)
1052
+ lw_origin_to_parent = self._get_lw_origin_to_parent(
1053
+ labware_definition=labware_definition, addressable_area=addressable_area
1054
+ )
1055
+ mod_cal_offset = self._get_calibrated_module_offset(location)
1056
+ location_center = self._addressable_areas.get_addressable_area_center(aa_name)
1057
+
1058
+ return (
1059
+ location_center
1060
+ + parent_to_lw_offset
1061
+ + lw_origin_to_parent
1062
+ + mod_cal_offset
1063
+ + Point(0, 0, grip_z_from_lw_origin)
1064
+ )
1065
+
1066
+ def _get_lw_origin_to_parent(
1067
+ self, labware_definition: LabwareDefinition, addressable_area: AddressableArea
1068
+ ) -> Point:
1069
+ if isinstance(labware_definition, LabwareDefinition2):
1070
+ return Point(0, 0, 0)
1071
+ else:
1072
+ bb_y = addressable_area.bounding_box.y
1073
+ bb_z = addressable_area.bounding_box.z
1074
+ return (
1075
+ Point(
1076
+ x=0,
1077
+ y=bb_y,
1078
+ z=bb_z,
1079
+ )
1080
+ * -1
1081
+ )
1082
+
1083
+ def get_extra_waypoints(
1084
+ self,
1085
+ location: Optional[CurrentPipetteLocation],
1086
+ to_slot: Union[DeckSlotName, StagingSlotName],
1087
+ ) -> List[Tuple[float, float]]:
1088
+ """Get extra waypoints for movement if thermocycler needs to be dodged."""
1089
+ if location is not None:
1090
+ if isinstance(location, CurrentWell):
1091
+ from_slot = self.get_ancestor_slot_name(location.labware_id)
1092
+ else:
1093
+ from_slot = self._addressable_areas.get_addressable_area_base_slot(
1094
+ location.addressable_area_name
1095
+ )
1096
+ if self._modules.should_dodge_thermocycler(
1097
+ from_slot=from_slot, to_slot=to_slot
1098
+ ):
1099
+
1100
+ middle_slot_fixture = (
1101
+ self._addressable_areas.get_fixture_by_deck_slot_name(
1102
+ DeckSlotName.SLOT_C2
1103
+ )
1104
+ )
1105
+ if middle_slot_fixture is None:
1106
+ middle_slot = DeckSlotName.SLOT_5.to_equivalent_for_robot_type(
1107
+ self._config.robot_type
1108
+ )
1109
+ middle_slot_center = (
1110
+ self._addressable_areas.get_addressable_area_center(
1111
+ addressable_area_name=middle_slot.id,
1112
+ )
1113
+ )
1114
+ else:
1115
+ # todo(chb, 2025-07-30): For now we're defaulting to the first addressable area for these center slot fixtures, but
1116
+ # if we ever introduce a fixture in the center slot with many addressable areas that aren't "centered" over the deck
1117
+ # slot we will enter up generating a pretty whacky movement path (potentially dangerous).
1118
+ middle_slot_center = self._addressable_areas.get_addressable_area_center(
1119
+ addressable_area_name=middle_slot_fixture[
1120
+ "providesAddressableAreas"
1121
+ ][
1122
+ deck_configuration_provider.get_cutout_id_by_deck_slot_name(
1123
+ DeckSlotName.SLOT_C2
1124
+ )
1125
+ ][
1126
+ 0
1127
+ ],
1128
+ )
1129
+ return [(middle_slot_center.x, middle_slot_center.y)]
1130
+ return []
1131
+
1132
+ def get_slot_item(
1133
+ self, slot_name: Union[DeckSlotName, StagingSlotName]
1134
+ ) -> Union[LoadedLabware, LoadedModule, CutoutFixture, None]:
1135
+ """Get the top-most item present in a deck slot, if any.
1136
+
1137
+ This includes any module that occupies the given slot even if it wasn't loaded
1138
+ in that slot (e.g., thermocycler).
1139
+ """
1140
+ maybe_labware = self._labware.get_by_slot(
1141
+ slot_name=slot_name,
1142
+ )
1143
+
1144
+ if isinstance(slot_name, DeckSlotName):
1145
+ maybe_fixture = self._addressable_areas.get_fixture_by_deck_slot_name(
1146
+ slot_name
1147
+ )
1148
+
1149
+ # Ignore generic single slot fixtures
1150
+ if maybe_fixture and maybe_fixture["id"] in {
1151
+ "singleLeftSlot",
1152
+ "singleCenterSlot",
1153
+ "singleRightSlot",
1154
+ }:
1155
+ maybe_fixture = None
1156
+
1157
+ maybe_module = self._modules.get_by_slot(
1158
+ slot_name=slot_name,
1159
+ ) or self._modules.get_overflowed_module_in_slot(slot_name=slot_name)
1160
+
1161
+ # For situations in which the deck config is none
1162
+ if maybe_fixture is None and maybe_labware is None and maybe_module is None:
1163
+ # todo(chb 2025-03-19): This can go away once we solve the problem of no deck config in analysis
1164
+ maybe_fixture = self._get_potential_disposal_location_cutout_fixtures(
1165
+ slot_name
1166
+ )
1167
+ else:
1168
+ # Modules and fixtures can't be loaded on staging slots
1169
+ maybe_fixture = None
1170
+ maybe_module = None
1171
+
1172
+ return maybe_labware or maybe_module or maybe_fixture or None
1173
+
1174
+ @staticmethod
1175
+ def get_slot_column(slot_name: Union[DeckSlotName, StagingSlotName]) -> int:
1176
+ """Get the column number for the specified slot."""
1177
+ if isinstance(slot_name, StagingSlotName):
1178
+ return 4
1179
+ row_col_name = slot_name.to_ot3_equivalent()
1180
+ slot_name_match = WELL_NAME_PATTERN.match(row_col_name.value)
1181
+ assert (
1182
+ slot_name_match is not None
1183
+ ), f"Slot name {row_col_name} did not match required pattern; please check labware location."
1184
+
1185
+ row_name, column_name = slot_name_match.group(1, 2)
1186
+ return int(column_name)
1187
+
1188
+ def get_next_tip_drop_location(
1189
+ self, labware_id: str, well_name: str, pipette_id: str
1190
+ ) -> DropTipWellLocation:
1191
+ """Get the next location within the specified well to drop the tip into.
1192
+
1193
+ In order to prevent tip stacking, we will alternate between two tip drop locations:
1194
+ 1. location in left section: a safe distance from left edge of the well
1195
+ 2. location in right section: a safe distance from right edge of the well
1196
+
1197
+ This safe distance for most cases would be a location where all tips drop
1198
+ reliably inside the labware's well. This can be calculated based off of the
1199
+ span of a pipette, including all its tips, in the x-direction.
1200
+
1201
+ But we also need to account for the not-so-uncommon case of a left pipette
1202
+ trying to drop tips in a labware in the rightmost deck column and vice versa.
1203
+ If this labware extends beyond a regular deck slot, like the Flex's default trash,
1204
+ then even after keeping a margin for x-span of a pipette, we will get
1205
+ a location that's unreachable for the pipette. In such cases, we try to drop tips
1206
+ at the rightmost location that a left pipette is able to reach,
1207
+ and leftmost location that a right pipette is able to reach respectively.
1208
+
1209
+ In these calculations we assume that the critical point of a pipette
1210
+ is considered to be the midpoint of the pipette's tip for single channel,
1211
+ and the midpoint of the entire tip assembly for multi-channel pipettes.
1212
+ We also assume that the pipette_x_span includes any safety margins required.
1213
+ """
1214
+ if not self._labware.is_fixed_trash(labware_id=labware_id):
1215
+ # In order to avoid the complexity of finding tip drop locations for
1216
+ # variety of labware with different well configs, we will allow
1217
+ # location cycling only for fixed trash labware right now.
1218
+ # TODO (spp, 2023-09-12): update this to possibly a labware-width based check,
1219
+ # or a 'trash' quirk check, once movable trash is implemented.
1220
+ return DropTipWellLocation(
1221
+ origin=DropTipWellOrigin.DEFAULT,
1222
+ offset=WellOffset(x=0, y=0, z=0),
1223
+ )
1224
+
1225
+ well_x_dim = self._labware.get_well_size(
1226
+ labware_id=labware_id, well_name=well_name
1227
+ )[0]
1228
+ pipette_channels = self._pipettes.get_config(pipette_id).channels
1229
+ pipette_mount = self._pipettes.get_mount(pipette_id)
1230
+
1231
+ labware_slot_column = self.get_slot_column(
1232
+ slot_name=self.get_ancestor_slot_name(labware_id)
1233
+ )
1234
+
1235
+ if self._last_drop_tip_location_spot.get(labware_id) == _TipDropSection.RIGHT:
1236
+ # Drop tip in LEFT section
1237
+ x_offset = self._get_drop_tip_well_x_offset(
1238
+ tip_drop_section=_TipDropSection.LEFT,
1239
+ well_x_dim=well_x_dim,
1240
+ pipette_channels=pipette_channels,
1241
+ pipette_mount=pipette_mount,
1242
+ labware_slot_column=labware_slot_column,
1243
+ )
1244
+ self._last_drop_tip_location_spot[labware_id] = _TipDropSection.LEFT
1245
+ else:
1246
+ # Drop tip in RIGHT section
1247
+ x_offset = self._get_drop_tip_well_x_offset(
1248
+ tip_drop_section=_TipDropSection.RIGHT,
1249
+ well_x_dim=well_x_dim,
1250
+ pipette_channels=pipette_channels,
1251
+ pipette_mount=pipette_mount,
1252
+ labware_slot_column=labware_slot_column,
1253
+ )
1254
+ self._last_drop_tip_location_spot[labware_id] = _TipDropSection.RIGHT
1255
+
1256
+ return DropTipWellLocation(
1257
+ origin=DropTipWellOrigin.TOP,
1258
+ offset=WellOffset(
1259
+ x=x_offset,
1260
+ y=0,
1261
+ z=0,
1262
+ ),
1263
+ )
1264
+
1265
+ # TODO find way to combine this with above
1266
+ def get_next_tip_drop_location_for_addressable_area(
1267
+ self,
1268
+ addressable_area_name: str,
1269
+ pipette_id: str,
1270
+ ) -> AddressableOffsetVector:
1271
+ """Get the next location within the specified well to drop the tip into.
1272
+
1273
+ See the doc-string for `get_next_tip_drop_location` for more info on execution.
1274
+ """
1275
+ area_x_dim = self._addressable_areas.get_addressable_area(
1276
+ addressable_area_name
1277
+ ).bounding_box.x
1278
+
1279
+ pipette_channels = self._pipettes.get_config(pipette_id).channels
1280
+ pipette_mount = self._pipettes.get_mount(pipette_id)
1281
+
1282
+ labware_slot_column = self.get_slot_column(
1283
+ slot_name=self._addressable_areas.get_addressable_area_base_slot(
1284
+ addressable_area_name
1285
+ )
1286
+ )
1287
+
1288
+ if (
1289
+ self._last_drop_tip_location_spot.get(addressable_area_name)
1290
+ == _TipDropSection.RIGHT
1291
+ ):
1292
+ # Drop tip in LEFT section
1293
+ x_offset = self._get_drop_tip_well_x_offset(
1294
+ tip_drop_section=_TipDropSection.LEFT,
1295
+ well_x_dim=area_x_dim,
1296
+ pipette_channels=pipette_channels,
1297
+ pipette_mount=pipette_mount,
1298
+ labware_slot_column=labware_slot_column,
1299
+ )
1300
+ self._last_drop_tip_location_spot[
1301
+ addressable_area_name
1302
+ ] = _TipDropSection.LEFT
1303
+ else:
1304
+ # Drop tip in RIGHT section
1305
+ x_offset = self._get_drop_tip_well_x_offset(
1306
+ tip_drop_section=_TipDropSection.RIGHT,
1307
+ well_x_dim=area_x_dim,
1308
+ pipette_channels=pipette_channels,
1309
+ pipette_mount=pipette_mount,
1310
+ labware_slot_column=labware_slot_column,
1311
+ )
1312
+ self._last_drop_tip_location_spot[
1313
+ addressable_area_name
1314
+ ] = _TipDropSection.RIGHT
1315
+
1316
+ return AddressableOffsetVector(x=x_offset, y=0, z=0)
1317
+
1318
+ @staticmethod
1319
+ def _get_drop_tip_well_x_offset(
1320
+ tip_drop_section: _TipDropSection,
1321
+ well_x_dim: float,
1322
+ pipette_channels: int,
1323
+ pipette_mount: MountType,
1324
+ labware_slot_column: int,
1325
+ ) -> float:
1326
+ """Get the well x offset for DropTipWellLocation."""
1327
+ drop_location_margin_from_labware_edge = (
1328
+ PIPETTE_X_SPAN[cast(ChannelCount, pipette_channels)] / 2
1329
+ )
1330
+ if tip_drop_section == _TipDropSection.LEFT:
1331
+ if (
1332
+ well_x_dim > SLOT_WIDTH
1333
+ and pipette_channels != 96
1334
+ and pipette_mount == MountType.RIGHT
1335
+ and labware_slot_column == 1
1336
+ ):
1337
+ # Pipette might not reach the default left spot so use a different left spot
1338
+ x_well_offset = (
1339
+ -well_x_dim / 2 + drop_location_margin_from_labware_edge * 2
1340
+ )
1341
+ else:
1342
+ x_well_offset = -well_x_dim / 2 + drop_location_margin_from_labware_edge
1343
+ if x_well_offset > 0:
1344
+ x_well_offset = 0
1345
+ else:
1346
+ if (
1347
+ well_x_dim > SLOT_WIDTH
1348
+ and pipette_channels != 96
1349
+ and pipette_mount == MountType.LEFT
1350
+ and labware_slot_column == 3
1351
+ ):
1352
+ # Pipette might not reach the default right spot so use a different right spot
1353
+ x_well_offset = (
1354
+ -well_x_dim / 2
1355
+ + SLOT_WIDTH
1356
+ - drop_location_margin_from_labware_edge
1357
+ )
1358
+ else:
1359
+ x_well_offset = well_x_dim / 2 - drop_location_margin_from_labware_edge
1360
+ if x_well_offset < 0:
1361
+ x_well_offset = 0
1362
+ return x_well_offset
1363
+
1364
+ def get_final_labware_movement_offset_vectors(
1365
+ self,
1366
+ from_location: OnDeckLabwareLocation,
1367
+ to_location: OnDeckLabwareLocation,
1368
+ additional_pick_up_offset: Point,
1369
+ additional_drop_offset: Point,
1370
+ current_labware: LabwareDefinition,
1371
+ ) -> LabwareMovementOffsetData:
1372
+ """Calculate the final labware offset vector to use in labware movement."""
1373
+ pick_up_offset = (
1374
+ self.get_total_nominal_gripper_offset_for_move_type(
1375
+ location=from_location,
1376
+ move_type=_GripperMoveType.PICK_UP_LABWARE,
1377
+ current_labware=current_labware,
1378
+ )
1379
+ + additional_pick_up_offset
1380
+ )
1381
+ drop_offset = (
1382
+ self.get_total_nominal_gripper_offset_for_move_type(
1383
+ location=to_location,
1384
+ move_type=_GripperMoveType.DROP_LABWARE,
1385
+ current_labware=current_labware,
1386
+ )
1387
+ + additional_drop_offset
1388
+ )
1389
+
1390
+ return LabwareMovementOffsetData(
1391
+ pickUpOffset=LabwareOffsetVector(
1392
+ x=pick_up_offset.x, y=pick_up_offset.y, z=pick_up_offset.z
1393
+ ),
1394
+ dropOffset=LabwareOffsetVector(
1395
+ x=drop_offset.x, y=drop_offset.y, z=drop_offset.z
1396
+ ),
1397
+ )
1398
+
1399
+ @staticmethod
1400
+ def ensure_valid_gripper_location(
1401
+ location: LabwareLocation,
1402
+ ) -> Union[
1403
+ DeckSlotLocation, ModuleLocation, OnLabwareLocation, AddressableAreaLocation
1404
+ ]:
1405
+ """Ensure valid on-deck location for gripper, otherwise raise error."""
1406
+ if not isinstance(
1407
+ location,
1408
+ (
1409
+ DeckSlotLocation,
1410
+ ModuleLocation,
1411
+ OnLabwareLocation,
1412
+ AddressableAreaLocation,
1413
+ ),
1414
+ ):
1415
+ raise errors.LabwareMovementNotAllowedError(
1416
+ "Off-deck labware movements are not supported using the gripper."
1417
+ )
1418
+ return location
1419
+
1420
+ def get_total_nominal_gripper_offset_for_move_type(
1421
+ self,
1422
+ location: OnDeckLabwareLocation,
1423
+ move_type: _GripperMoveType,
1424
+ current_labware: LabwareDefinition,
1425
+ ) -> Point:
1426
+ """Get the total of the offsets to be used to pick up labware in its current location."""
1427
+ if move_type == _GripperMoveType.PICK_UP_LABWARE:
1428
+ if isinstance(
1429
+ location, (ModuleLocation, DeckSlotLocation, AddressableAreaLocation)
1430
+ ):
1431
+ return Point.from_xyz_attrs(
1432
+ self._nominal_gripper_offsets_for_location(location).pickUpOffset
1433
+ )
1434
+ else:
1435
+ # If it's a labware on a labware (most likely an adapter),
1436
+ # we calculate the offset as sum of offsets for the direct parent labware
1437
+ # and the underlying non-labware parent location.
1438
+ direct_parent_offset = self._nominal_gripper_offsets_for_location(
1439
+ location
1440
+ )
1441
+ ancestor = self._labware.get_parent_location(location.labwareId)
1442
+ extra_offset = Point(x=0, y=0, z=0)
1443
+ if (
1444
+ isinstance(ancestor, ModuleLocation)
1445
+ # todo(mm, 2025-06-20): Avoid this private attribute access.
1446
+ and self._modules._state.requested_model_by_id[ancestor.moduleId]
1447
+ == ModuleModel.THERMOCYCLER_MODULE_V2
1448
+ and labware_validation.validate_definition_is_lid(current_labware)
1449
+ ):
1450
+ if "lidOffsets" in current_labware.gripperOffsets.keys():
1451
+ extra_offset = Point(
1452
+ x=current_labware.gripperOffsets[
1453
+ "lidOffsets"
1454
+ ].pickUpOffset.x,
1455
+ y=current_labware.gripperOffsets[
1456
+ "lidOffsets"
1457
+ ].pickUpOffset.y,
1458
+ z=current_labware.gripperOffsets[
1459
+ "lidOffsets"
1460
+ ].pickUpOffset.z,
1461
+ )
1462
+ else:
1463
+ raise errors.LabwareOffsetDoesNotExistError(
1464
+ f"Labware Definition {current_labware.parameters.loadName} does not contain required field 'lidOffsets' of 'gripperOffsets'."
1465
+ )
1466
+
1467
+ assert isinstance(
1468
+ ancestor,
1469
+ (
1470
+ DeckSlotLocation,
1471
+ ModuleLocation,
1472
+ OnLabwareLocation,
1473
+ AddressableAreaLocation,
1474
+ ),
1475
+ ), "No gripper offsets for off-deck labware"
1476
+ return (
1477
+ Point.from_xyz_attrs(direct_parent_offset.pickUpOffset)
1478
+ + Point.from_xyz_attrs(
1479
+ self._nominal_gripper_offsets_for_location(
1480
+ location=ancestor
1481
+ ).pickUpOffset
1482
+ )
1483
+ + extra_offset
1484
+ )
1485
+ else:
1486
+ if isinstance(
1487
+ location, (ModuleLocation, DeckSlotLocation, AddressableAreaLocation)
1488
+ ):
1489
+ return Point.from_xyz_attrs(
1490
+ self._nominal_gripper_offsets_for_location(location).dropOffset
1491
+ )
1492
+ else:
1493
+ # If it's a labware on a labware (most likely an adapter),
1494
+ # we calculate the offset as sum of offsets for the direct parent labware
1495
+ # and the underlying non-labware parent location.
1496
+ direct_parent_offset = self._nominal_gripper_offsets_for_location(
1497
+ location
1498
+ )
1499
+ ancestor = self._labware.get_parent_location(location.labwareId)
1500
+ extra_offset = Point(x=0, y=0, z=0)
1501
+ if (
1502
+ isinstance(ancestor, ModuleLocation)
1503
+ # todo(mm, 2024-11-06): Do not access private module state; only use public ModuleView methods.
1504
+ and self._modules._state.requested_model_by_id[ancestor.moduleId]
1505
+ == ModuleModel.THERMOCYCLER_MODULE_V2
1506
+ and labware_validation.validate_definition_is_lid(current_labware)
1507
+ ):
1508
+ if "lidOffsets" in current_labware.gripperOffsets.keys():
1509
+ extra_offset = Point(
1510
+ x=current_labware.gripperOffsets[
1511
+ "lidOffsets"
1512
+ ].pickUpOffset.x,
1513
+ y=current_labware.gripperOffsets[
1514
+ "lidOffsets"
1515
+ ].pickUpOffset.y,
1516
+ z=current_labware.gripperOffsets[
1517
+ "lidOffsets"
1518
+ ].pickUpOffset.z,
1519
+ )
1520
+ else:
1521
+ raise errors.LabwareOffsetDoesNotExistError(
1522
+ f"Labware Definition {current_labware.parameters.loadName} does not contain required field 'lidOffsets' of 'gripperOffsets'."
1523
+ )
1524
+
1525
+ assert isinstance(
1526
+ ancestor,
1527
+ (
1528
+ DeckSlotLocation,
1529
+ ModuleLocation,
1530
+ OnLabwareLocation,
1531
+ AddressableAreaLocation,
1532
+ ),
1533
+ ), "No gripper offsets for off-deck labware"
1534
+ return (
1535
+ Point.from_xyz_attrs(direct_parent_offset.dropOffset)
1536
+ + Point.from_xyz_attrs(
1537
+ self._nominal_gripper_offsets_for_location(
1538
+ location=ancestor
1539
+ ).dropOffset
1540
+ )
1541
+ + extra_offset
1542
+ )
1543
+
1544
+ # todo(mm, 2024-11-05): This may be incorrect because it does not take the following
1545
+ # offsets into account, which *are* taken into account for the actual gripper movement:
1546
+ #
1547
+ # * The pickup offset in the definition of the parent of the gripped labware.
1548
+ # * The "additional offset" or "user offset", e.g. the `pickUpOffset` and `dropOffset`
1549
+ # params in the `moveLabware` command.
1550
+ #
1551
+ # For robustness, we should combine this with `get_gripper_labware_movement_waypoints()`.
1552
+ #
1553
+ # We should also be more explicit about which offsets act to move the gripper paddles
1554
+ # relative to the gripped labware, and which offsets act to change how the gripped
1555
+ # labware sits atop its parent. Those have different effects on how far the gripped
1556
+ # labware juts beyond the paddles while it's in transit.
1557
+ def check_gripper_labware_tip_collision(
1558
+ self,
1559
+ gripper_homed_position_z: float,
1560
+ labware_id: str,
1561
+ # todo(mm, 2025-07-31): arg unused, investigate or remove.
1562
+ current_location: OnDeckLabwareLocation,
1563
+ ) -> None:
1564
+ """Check for potential collision of tips against labware to be lifted."""
1565
+ labware_definition = self._labware.get_definition(labware_id)
1566
+ pipettes = self._pipettes.get_all()
1567
+ for pipette in pipettes:
1568
+ # TODO(cb, 2024-01-22): Remove the 1 and 8 channel special case once we are doing X axis validation
1569
+ if self._pipettes.get_channels(pipette.id) in [1, 8]:
1570
+ return
1571
+
1572
+ tip = self._pipettes.get_attached_tip(pipette.id)
1573
+ if not tip:
1574
+ continue
1575
+
1576
+ labware_origin_to_grip_point = self._labware.get_grip_z(labware_definition)
1577
+ grip_point_to_labware_origin = -labware_origin_to_grip_point
1578
+ height_above_labware_origin = self._labware.get_extents_around_lw_origin(
1579
+ labware_definition
1580
+ ).max_z
1581
+ labware_top_z_when_gripped = (
1582
+ gripper_homed_position_z
1583
+ + grip_point_to_labware_origin
1584
+ + height_above_labware_origin
1585
+ )
1586
+
1587
+ # TODO(cb, 2024-01-18): Utilizing the nozzle map and labware X coordinates,
1588
+ # verify if collisions will occur on the X axis (analysis will use hard coded data
1589
+ # to measure from the gripper critical point to the pipette mount)
1590
+ if (_PIPETTE_HOMED_POSITION_Z - tip.length) < labware_top_z_when_gripped:
1591
+ raise LabwareMovementNotAllowedError(
1592
+ f"Cannot move labware '{labware_definition.parameters.loadName}' when {int(tip.volume)} µL tips are attached."
1593
+ )
1594
+
1595
+ def _nominal_gripper_offsets_for_location(
1596
+ self, location: OnDeckLabwareLocation
1597
+ ) -> LabwareMovementOffsetData:
1598
+ """Provide the default gripper offset data for the given location type."""
1599
+ if isinstance(location, (DeckSlotLocation, AddressableAreaLocation)):
1600
+ # TODO we might need a separate type of gripper offset for addressable areas but that also might just
1601
+ # be covered by the drop labware offset/location
1602
+ offsets = self._labware.get_deck_default_gripper_offsets()
1603
+ elif isinstance(location, ModuleLocation):
1604
+ offsets = self._modules.get_default_gripper_offsets(location.moduleId)
1605
+ else:
1606
+ # Labware is on a labware/adapter
1607
+ offsets = self._labware_gripper_offsets(location.labwareId)
1608
+ return offsets or LabwareMovementOffsetData(
1609
+ pickUpOffset=LabwareOffsetVector(x=0, y=0, z=0),
1610
+ dropOffset=LabwareOffsetVector(x=0, y=0, z=0),
1611
+ )
1612
+
1613
+ def _labware_gripper_offsets(
1614
+ self, labware_id: str
1615
+ ) -> Optional[LabwareMovementOffsetData]:
1616
+ """Provide the most appropriate gripper offset data for the specified labware.
1617
+
1618
+ We check the types of gripper offsets available for the labware ("default" or slot-based)
1619
+ and return the most appropriate one for the overall location of the labware.
1620
+ Currently, only module adapters (specifically, the H/S universal flat adapter)
1621
+ have non-default offsets that are specific to location of the module on deck,
1622
+ so, this code only checks for the presence of those known offsets.
1623
+ """
1624
+ parent_location = self._labware.get_parent_location(labware_id)
1625
+ assert isinstance(
1626
+ parent_location,
1627
+ (
1628
+ DeckSlotLocation,
1629
+ ModuleLocation,
1630
+ AddressableAreaLocation,
1631
+ OnLabwareLocation,
1632
+ ),
1633
+ ), "No gripper offsets for off-deck labware"
1634
+
1635
+ if isinstance(parent_location, DeckSlotLocation):
1636
+ slot_name = parent_location.slotName
1637
+ elif isinstance(parent_location, AddressableAreaLocation):
1638
+ slot_name = self._addressable_areas.get_addressable_area_base_slot(
1639
+ parent_location.addressableAreaName
1640
+ )
1641
+ else:
1642
+ module_loc = self._modules.get_location(parent_location.moduleId)
1643
+ slot_name = module_loc.slotName
1644
+
1645
+ slot_based_offset = self._labware.get_child_gripper_offsets(
1646
+ labware_id=labware_id, slot_name=slot_name.to_ot3_equivalent()
1647
+ )
1648
+
1649
+ return slot_based_offset or self._labware.get_child_gripper_offsets(
1650
+ labware_id=labware_id, slot_name=None
1651
+ )
1652
+
1653
+ def get_location_sequence(self, labware_id: str) -> LabwareLocationSequence:
1654
+ """Provide the LocationSequence specifying the current position of the labware.
1655
+
1656
+ Elements in this sequence contain instance IDs of things. The chain is valid only until the
1657
+ labware is moved.
1658
+ """
1659
+ return self.get_predicted_location_sequence(
1660
+ self._labware.get_location(labware_id)
1661
+ )
1662
+
1663
+ def get_predicted_location_sequence(
1664
+ self,
1665
+ labware_location: LabwareLocation,
1666
+ labware_pending_load: dict[str, LoadedLabware] | None = None,
1667
+ ) -> LabwareLocationSequence:
1668
+ """Get the location sequence for this location. Useful for a labware that hasn't been loaded."""
1669
+ return self._recurse_labware_location(
1670
+ labware_location, [], labware_pending_load or {}
1671
+ )
1672
+
1673
+ def _cutout_fixture_location_sequence_from_addressable_area(
1674
+ self, addressable_area_name: str
1675
+ ) -> OnCutoutFixtureLocationSequenceComponent:
1676
+ (
1677
+ cutout_id,
1678
+ potential_fixtures,
1679
+ ) = self._addressable_areas.get_current_potential_cutout_fixtures_for_addressable_area(
1680
+ addressable_area_name
1681
+ )
1682
+ return OnCutoutFixtureLocationSequenceComponent(
1683
+ possibleCutoutFixtureIds=sorted(
1684
+ [fixture.cutout_fixture_id for fixture in potential_fixtures]
1685
+ ),
1686
+ cutoutId=cutout_id,
1687
+ )
1688
+
1689
+ def _recurse_labware_location_from_aa_component(
1690
+ self,
1691
+ labware_location: AddressableAreaLocation,
1692
+ building: LabwareLocationSequence,
1693
+ ) -> LabwareLocationSequence:
1694
+ cutout_location = self._cutout_fixture_location_sequence_from_addressable_area(
1695
+ labware_location.addressableAreaName
1696
+ )
1697
+ # If the labware is loaded on an AA that is a module, we want to respect the convention
1698
+ # of giving it an OnModuleLocation.
1699
+ possible_module = self._modules.get_by_addressable_area(
1700
+ labware_location.addressableAreaName
1701
+ )
1702
+ if possible_module is not None:
1703
+ return building + [
1704
+ OnAddressableAreaLocationSequenceComponent(
1705
+ addressableAreaName=labware_location.addressableAreaName
1706
+ ),
1707
+ OnModuleLocationSequenceComponent(moduleId=possible_module.id),
1708
+ cutout_location,
1709
+ ]
1710
+ else:
1711
+ return building + [
1712
+ OnAddressableAreaLocationSequenceComponent(
1713
+ addressableAreaName=labware_location.addressableAreaName,
1714
+ ),
1715
+ cutout_location,
1716
+ ]
1717
+
1718
+ def _recurse_labware_location_from_module_component(
1719
+ self, labware_location: ModuleLocation, building: LabwareLocationSequence
1720
+ ) -> LabwareLocationSequence:
1721
+ module_id = labware_location.moduleId
1722
+ module_aa = self._modules.get_provided_addressable_area(module_id)
1723
+ base_location: (
1724
+ OnCutoutFixtureLocationSequenceComponent
1725
+ | NotOnDeckLocationSequenceComponent
1726
+ ) = self._cutout_fixture_location_sequence_from_addressable_area(module_aa)
1727
+
1728
+ if self._modules.get_deck_supports_module_fixtures():
1729
+ # On a deck with modules as cutout fixtures, we want, in order,
1730
+ # - the addressable area of the module
1731
+ # - the module with its module id, which is what clients want
1732
+ # - the cutout
1733
+ loc = self._modules.get_location(module_id)
1734
+ model = self._modules.get_connected_model(module_id)
1735
+ module_aa = self._modules.ensure_and_convert_module_fixture_location(
1736
+ loc.slotName, model
1737
+ )
1738
+ return building + [
1739
+ OnAddressableAreaLocationSequenceComponent(
1740
+ addressableAreaName=module_aa
1741
+ ),
1742
+ OnModuleLocationSequenceComponent(moduleId=module_id),
1743
+ base_location,
1744
+ ]
1745
+ else:
1746
+ # If the module isn't a cutout fixture, then we want
1747
+ # - the module
1748
+ # - the addressable area the module is loaded on
1749
+ # - the cutout
1750
+ location = self._modules.get_location(module_id)
1751
+ return building + [
1752
+ OnModuleLocationSequenceComponent(moduleId=module_id),
1753
+ OnAddressableAreaLocationSequenceComponent(
1754
+ addressableAreaName=location.slotName.value
1755
+ ),
1756
+ base_location,
1757
+ ]
1758
+
1759
+ def _recurse_labware_location_from_stacker_hopper(
1760
+ self,
1761
+ labware_location: InStackerHopperLocation,
1762
+ building: LabwareLocationSequence,
1763
+ ) -> LabwareLocationSequence:
1764
+ loc = self._modules.get_location(labware_location.moduleId)
1765
+ model = self._modules.get_connected_model(labware_location.moduleId)
1766
+ module_aa = self._modules.ensure_and_convert_module_fixture_location(
1767
+ loc.slotName, model
1768
+ )
1769
+ cutout_base = self._cutout_fixture_location_sequence_from_addressable_area(
1770
+ module_aa
1771
+ )
1772
+ return building + [labware_location, cutout_base]
1773
+
1774
+ def _recurse_labware_location(
1775
+ self,
1776
+ labware_location: LabwareLocation,
1777
+ building: LabwareLocationSequence,
1778
+ labware_pending_load: dict[str, LoadedLabware],
1779
+ ) -> LabwareLocationSequence:
1780
+ if isinstance(labware_location, AddressableAreaLocation):
1781
+ return self._recurse_labware_location_from_aa_component(
1782
+ labware_location, building
1783
+ )
1784
+ elif labware_location_is_off_deck(
1785
+ labware_location
1786
+ ) or labware_location_is_system(labware_location):
1787
+ return building + [
1788
+ NotOnDeckLocationSequenceComponent(logicalLocationName=labware_location)
1789
+ ]
1790
+
1791
+ elif isinstance(labware_location, OnLabwareLocation):
1792
+ labware = self._get_or_default_labware(
1793
+ labware_location.labwareId, labware_pending_load
1794
+ )
1795
+ return self._recurse_labware_location(
1796
+ labware.location,
1797
+ building
1798
+ + [
1799
+ OnLabwareLocationSequenceComponent(
1800
+ labwareId=labware_location.labwareId, lidId=labware.lid_id
1801
+ )
1802
+ ],
1803
+ labware_pending_load,
1804
+ )
1805
+ elif isinstance(labware_location, ModuleLocation):
1806
+ return self._recurse_labware_location_from_module_component(
1807
+ labware_location, building
1808
+ )
1809
+ elif isinstance(labware_location, DeckSlotLocation):
1810
+ return building + [
1811
+ OnAddressableAreaLocationSequenceComponent(
1812
+ addressableAreaName=labware_location.slotName.value,
1813
+ ),
1814
+ self._cutout_fixture_location_sequence_from_addressable_area(
1815
+ labware_location.slotName.value
1816
+ ),
1817
+ ]
1818
+ elif isinstance(labware_location, InStackerHopperLocation):
1819
+ return self._recurse_labware_location_from_stacker_hopper(
1820
+ labware_location, building
1821
+ )
1822
+ else:
1823
+ _LOG.warn(f"Unhandled labware location kind: {labware_location}")
1824
+ return building
1825
+
1826
+ def get_offset_location(
1827
+ self, labware_id: str
1828
+ ) -> Optional[LabwareOffsetLocationSequence]:
1829
+ """Provide the LegacyLabwareOffsetLocation specifying the current position of the labware.
1830
+
1831
+ If the labware is in a location that cannot be specified by a LabwareOffsetLocationSequence
1832
+ (for instance, OFF_DECK) then return None.
1833
+ """
1834
+ parent_location = self._labware.get_location(labware_id)
1835
+ return self.get_projected_offset_location(parent_location)
1836
+
1837
+ def get_projected_offset_location(
1838
+ self,
1839
+ labware_location: LabwareLocation,
1840
+ labware_pending_load: dict[str, LoadedLabware] | None = None,
1841
+ ) -> Optional[LabwareOffsetLocationSequence]:
1842
+ """Get the offset location that a labware loaded into this location would match.
1843
+
1844
+ `None` indicates that the very concept of a labware offset would not make sense
1845
+ for the given location, such as if it's some kind of off-deck location. This
1846
+ is a difference from `get_predicted_location_sequence()`, where off-deck
1847
+ locations are still represented as lists, but with special final elements.
1848
+ """
1849
+ return self._recurse_labware_offset_location(
1850
+ labware_location, [], labware_pending_load or {}
1851
+ )
1852
+
1853
+ def _recurse_labware_offset_location(
1854
+ self,
1855
+ labware_location: LabwareLocation,
1856
+ building: LabwareOffsetLocationSequence,
1857
+ labware_pending_load: dict[str, LoadedLabware],
1858
+ ) -> LabwareOffsetLocationSequence | None:
1859
+ if isinstance(labware_location, DeckSlotLocation):
1860
+ return building + [
1861
+ OnAddressableAreaOffsetLocationSequenceComponent(
1862
+ addressableAreaName=labware_location.slotName.value
1863
+ )
1864
+ ]
1865
+
1866
+ elif isinstance(labware_location, ModuleLocation):
1867
+ module_id = labware_location.moduleId
1868
+ # Allow ModuleNotLoadedError to propagate.
1869
+ # Note also that we match based on the module's requested model, not its
1870
+ # actual model, to implement robot-server's documented HTTP API semantics.
1871
+ module_model = self._modules.get_requested_model(module_id=module_id)
1872
+
1873
+ # If `module_model is None`, it probably means that this module was added by
1874
+ # `ProtocolEngine.use_attached_modules()`, instead of an explicit
1875
+ # `loadModule` command.
1876
+ #
1877
+ # This assert should never raise in practice because:
1878
+ # 1. `ProtocolEngine.use_attached_modules()` is only used by
1879
+ # robot-server's "stateless command" endpoints, under `/commands`.
1880
+ # 2. Those endpoints don't support loading labware, so this code will
1881
+ # never run.
1882
+ #
1883
+ # Nevertheless, if it does happen somehow, we do NOT want to pass the
1884
+ # `None` value along to `LabwareView.find_applicable_labware_offset()`.
1885
+ # `None` means something different there, which will cause us to return
1886
+ # wrong results.
1887
+ assert module_model is not None, (
1888
+ "Can't find offsets for labware"
1889
+ " that are loaded on modules"
1890
+ " that were loaded with ProtocolEngine.use_attached_modules()."
1891
+ )
1892
+
1893
+ module_location = self._modules.get_location(module_id=module_id)
1894
+ if self._modules.get_deck_supports_module_fixtures():
1895
+ module_aa = self._modules.ensure_and_convert_module_fixture_location(
1896
+ module_location.slotName, module_model
1897
+ )
1898
+ else:
1899
+ module_aa = module_location.slotName.value
1900
+ return building + [
1901
+ OnModuleOffsetLocationSequenceComponent(moduleModel=module_model),
1902
+ OnAddressableAreaOffsetLocationSequenceComponent(
1903
+ addressableAreaName=module_aa
1904
+ ),
1905
+ ]
1906
+
1907
+ elif isinstance(labware_location, OnLabwareLocation):
1908
+ parent_labware_id = labware_location.labwareId
1909
+ parent_labware = self._get_or_default_labware(
1910
+ parent_labware_id, labware_pending_load
1911
+ )
1912
+ parent_labware_uri = LabwareUri(parent_labware.definitionUri)
1913
+ base_location = parent_labware.location
1914
+ return self._recurse_labware_offset_location(
1915
+ base_location,
1916
+ building
1917
+ + [
1918
+ OnLabwareOffsetLocationSequenceComponent(
1919
+ labwareUri=parent_labware_uri
1920
+ )
1921
+ ],
1922
+ labware_pending_load,
1923
+ )
1924
+
1925
+ else: # Off deck
1926
+ return None
1927
+
1928
+ def get_liquid_handling_z_change(
1929
+ self,
1930
+ labware_id: str,
1931
+ well_name: str,
1932
+ pipette_id: str,
1933
+ operation_volume: float,
1934
+ ) -> float:
1935
+ """Get the change in height from a liquid handling operation."""
1936
+ initial_handling_height = self.get_meniscus_height(
1937
+ labware_id=labware_id, well_name=well_name
1938
+ )
1939
+ final_height = self.get_well_height_after_liquid_handling(
1940
+ labware_id=labware_id,
1941
+ well_name=well_name,
1942
+ pipette_id=pipette_id,
1943
+ initial_height=initial_handling_height,
1944
+ volume=operation_volume,
1945
+ )
1946
+ # this function is only called by
1947
+ # HardwarePipetteHandler::aspirate/dispense while_tracking, and shouldn't
1948
+ # be reached in the case of a simulated liquid_probe
1949
+ assert not isinstance(
1950
+ initial_handling_height, SimulatedProbeResult
1951
+ ), "Initial handling height got SimulatedProbeResult"
1952
+ assert not isinstance(
1953
+ final_height, SimulatedProbeResult
1954
+ ), "final height is SimulatedProbeResult"
1955
+ return final_height - initial_handling_height
1956
+
1957
+ def get_well_offset_adjustment(
1958
+ self,
1959
+ labware_id: str,
1960
+ well_name: str,
1961
+ well_location: WellLocationType,
1962
+ well_depth: float,
1963
+ pipette_id: Optional[str] = None,
1964
+ operation_volume: Optional[float] = None,
1965
+ ) -> LiquidTrackingType:
1966
+ """Return a z-axis distance that accounts for well handling height and operation volume.
1967
+
1968
+ Distance is with reference to the well bottom.
1969
+ """
1970
+ # TODO(pbm, 10-23-24): refactor to smartly reduce height/volume conversions
1971
+
1972
+ initial_handling_height = self.get_well_handling_height(
1973
+ labware_id=labware_id,
1974
+ well_name=well_name,
1975
+ well_location=well_location,
1976
+ well_depth=well_depth,
1977
+ )
1978
+ # if we're tracking a MENISCUS origin, and targeting either the beginning
1979
+ # position of the liquid or doing dynamic tracking, return the initial height
1980
+ if (
1981
+ well_location.origin == WellOrigin.MENISCUS
1982
+ and not well_location.volumeOffset
1983
+ ):
1984
+ return initial_handling_height
1985
+ volume: Optional[float] = None
1986
+ if isinstance(well_location, PickUpTipWellLocation):
1987
+ volume = 0.0
1988
+ elif isinstance(well_location, LiquidHandlingWellLocation):
1989
+ if well_location.volumeOffset == "operationVolume":
1990
+ volume = operation_volume or 0.0
1991
+ else:
1992
+ if not isinstance(well_location.volumeOffset, float):
1993
+ raise ValueError("Invalid volume offset.")
1994
+ volume = well_location.volumeOffset
1995
+
1996
+ if volume:
1997
+ if pipette_id is None:
1998
+ raise ValueError(
1999
+ "cannot get liquid handling offset without pipette id."
2000
+ )
2001
+ liquid_height_after = self.get_well_height_after_liquid_handling(
2002
+ labware_id=labware_id,
2003
+ well_name=well_name,
2004
+ pipette_id=pipette_id,
2005
+ initial_height=initial_handling_height,
2006
+ volume=volume,
2007
+ )
2008
+ return liquid_height_after
2009
+ else:
2010
+ return initial_handling_height
2011
+
2012
+ def get_current_well_volume(
2013
+ self,
2014
+ labware_id: str,
2015
+ well_name: str,
2016
+ ) -> LiquidTrackingType:
2017
+ """Returns most recently updated volume in specified well."""
2018
+ last_updated = self._wells.get_last_liquid_update(labware_id, well_name)
2019
+ if last_updated is None:
2020
+ raise errors.LiquidHeightUnknownError(
2021
+ "Must LiquidProbe or LoadLiquid before specifying WellOrigin.MENISCUS."
2022
+ )
2023
+
2024
+ well_liquid = self._wells.get_well_liquid_info(
2025
+ labware_id=labware_id, well_name=well_name
2026
+ )
2027
+ if (
2028
+ well_liquid.probed_height is not None
2029
+ and well_liquid.probed_height.height is not None
2030
+ and well_liquid.probed_height.last_probed == last_updated
2031
+ ):
2032
+ volume = self.get_well_volume_at_height(
2033
+ labware_id=labware_id,
2034
+ well_name=well_name,
2035
+ height=well_liquid.probed_height.height,
2036
+ )
2037
+ return volume
2038
+ elif (
2039
+ well_liquid.loaded_volume is not None
2040
+ and well_liquid.loaded_volume.volume is not None
2041
+ and well_liquid.loaded_volume.last_loaded == last_updated
2042
+ ):
2043
+ return well_liquid.loaded_volume.volume
2044
+ elif (
2045
+ well_liquid.probed_volume is not None
2046
+ and well_liquid.probed_volume.volume is not None
2047
+ and well_liquid.probed_volume.last_probed == last_updated
2048
+ ):
2049
+ return well_liquid.probed_volume.volume
2050
+ else:
2051
+ # This should not happen if there was an update but who knows
2052
+ raise errors.LiquidVolumeUnknownError(
2053
+ f"Unable to find liquid volume despite an update at {last_updated}."
2054
+ )
2055
+
2056
+ def get_meniscus_height(
2057
+ self,
2058
+ labware_id: str,
2059
+ well_name: str,
2060
+ ) -> LiquidTrackingType:
2061
+ """Returns stored meniscus height in specified well."""
2062
+ last_updated = self._wells.get_last_liquid_update(labware_id, well_name)
2063
+ if last_updated is None:
2064
+ raise errors.LiquidHeightUnknownError(
2065
+ "Must LiquidProbe or LoadLiquid before specifying WellOrigin.MENISCUS."
2066
+ )
2067
+
2068
+ well_liquid = self._wells.get_well_liquid_info(
2069
+ labware_id=labware_id, well_name=well_name
2070
+ )
2071
+ if (
2072
+ well_liquid.probed_height is not None
2073
+ and well_liquid.probed_height.height is not None
2074
+ and well_liquid.probed_height.last_probed == last_updated
2075
+ ):
2076
+ return well_liquid.probed_height.height
2077
+ elif (
2078
+ well_liquid.loaded_volume is not None
2079
+ and well_liquid.loaded_volume.volume is not None
2080
+ and well_liquid.loaded_volume.last_loaded == last_updated
2081
+ ):
2082
+ return self.get_well_height_at_volume(
2083
+ labware_id=labware_id,
2084
+ well_name=well_name,
2085
+ volume=well_liquid.loaded_volume.volume,
2086
+ )
2087
+ elif (
2088
+ well_liquid.probed_volume is not None
2089
+ and well_liquid.probed_volume.volume is not None
2090
+ and well_liquid.probed_volume.last_probed == last_updated
2091
+ ):
2092
+ return self.get_well_height_at_volume(
2093
+ labware_id=labware_id,
2094
+ well_name=well_name,
2095
+ volume=well_liquid.probed_volume.volume,
2096
+ )
2097
+ else:
2098
+ # This should not happen if there was an update but who knows
2099
+ raise errors.LiquidHeightUnknownError(
2100
+ f"Unable to find liquid height despite an update at {last_updated}."
2101
+ )
2102
+
2103
+ def get_well_handling_height(
2104
+ self,
2105
+ labware_id: str,
2106
+ well_name: str,
2107
+ well_location: WellLocationType,
2108
+ well_depth: float,
2109
+ ) -> LiquidTrackingType:
2110
+ """Return the handling height for a labware well (with reference to the well bottom)."""
2111
+ handling_height: LiquidTrackingType = 0.0
2112
+ if well_location.origin == WellOrigin.TOP:
2113
+ handling_height = float(well_depth)
2114
+ elif well_location.origin == WellOrigin.CENTER:
2115
+ handling_height = float(well_depth / 2.0)
2116
+ elif well_location.origin == WellOrigin.MENISCUS:
2117
+ handling_height = self.get_meniscus_height(
2118
+ labware_id=labware_id, well_name=well_name
2119
+ )
2120
+ return handling_height
2121
+
2122
+ def find_volume_at_well_height(
2123
+ self,
2124
+ labware_id: str,
2125
+ well_name: str,
2126
+ target_height: LiquidTrackingType,
2127
+ ) -> LiquidTrackingType:
2128
+ """Call the correct volume from height function based on well geoemtry type."""
2129
+ well_geometry = self._labware.get_well_geometry(
2130
+ labware_id=labware_id, well_name=well_name
2131
+ )
2132
+ if isinstance(well_geometry, InnerWellGeometry):
2133
+ return find_volume_inner_well_geometry(
2134
+ target_height=target_height, well_geometry=well_geometry
2135
+ )
2136
+ else:
2137
+ return find_volume_user_defined_volumes(
2138
+ target_height=target_height, well_geometry=well_geometry
2139
+ )
2140
+
2141
+ def find_height_at_well_volume(
2142
+ self,
2143
+ labware_id: str,
2144
+ well_name: str,
2145
+ target_volume: LiquidTrackingType,
2146
+ ) -> LiquidTrackingType:
2147
+ """Call the correct height from volume function based on well geometry type."""
2148
+ well_geometry = self._labware.get_well_geometry(
2149
+ labware_id=labware_id, well_name=well_name
2150
+ )
2151
+ if isinstance(well_geometry, InnerWellGeometry):
2152
+ return find_height_inner_well_geometry(
2153
+ target_volume=target_volume, well_geometry=well_geometry
2154
+ )
2155
+ else:
2156
+ return find_height_user_defined_volumes(
2157
+ target_volume=target_volume, well_geometry=well_geometry
2158
+ )
2159
+
2160
+ def get_well_height_after_liquid_handling(
2161
+ self,
2162
+ labware_id: str,
2163
+ well_name: str,
2164
+ pipette_id: str,
2165
+ initial_height: LiquidTrackingType,
2166
+ volume: float,
2167
+ ) -> LiquidTrackingType:
2168
+ """Return the height of liquid in a labware well after a given volume has been handled.
2169
+
2170
+ This is given an initial handling height, with reference to the well bottom.
2171
+ """
2172
+ well_def = self._labware.get_well_definition(labware_id, well_name)
2173
+ well_depth = well_def.depth
2174
+
2175
+ try:
2176
+ initial_volume = self.find_volume_at_well_height(
2177
+ labware_id=labware_id, well_name=well_name, target_height=initial_height
2178
+ )
2179
+ final_volume = initial_volume + (
2180
+ volume
2181
+ * self.get_nozzles_per_well(
2182
+ labware_id=labware_id,
2183
+ target_well_name=well_name,
2184
+ pipette_id=pipette_id,
2185
+ )
2186
+ )
2187
+ # NOTE(cm): if final_volume is outside the bounds of the well, it will get
2188
+ # adjusted inside find_height_at_well_volume to accomodate well the height
2189
+ # calculation.
2190
+ height_inside_well = self.find_height_at_well_volume(
2191
+ labware_id=labware_id, well_name=well_name, target_volume=final_volume
2192
+ )
2193
+ return self._validate_well_position(
2194
+ target_height=height_inside_well,
2195
+ well_max_height=well_depth,
2196
+ pipette_id=pipette_id,
2197
+ )
2198
+ except InvalidLiquidHeightFound as _exception:
2199
+ raise InvalidLiquidHeightFound(
2200
+ message=_exception.message
2201
+ + f"for well {well_name} of {self._labware.get_display_name(labware_id)} on slot {self.get_ancestor_slot_name(labware_id)}"
2202
+ )
2203
+
2204
+ def get_well_height_at_volume(
2205
+ self, labware_id: str, well_name: str, volume: LiquidTrackingType
2206
+ ) -> LiquidTrackingType:
2207
+ """Convert well volume to height."""
2208
+ try:
2209
+ return self.find_height_at_well_volume(
2210
+ labware_id=labware_id, well_name=well_name, target_volume=volume
2211
+ )
2212
+ except InvalidLiquidHeightFound as _exception:
2213
+ raise InvalidLiquidHeightFound(
2214
+ message=_exception.message
2215
+ + f"for well {well_name} of {self._labware.get_display_name(labware_id)} on slot {self.get_ancestor_slot_name(labware_id)}"
2216
+ )
2217
+
2218
+ def get_well_volume_at_height(
2219
+ self,
2220
+ labware_id: str,
2221
+ well_name: str,
2222
+ height: LiquidTrackingType,
2223
+ ) -> LiquidTrackingType:
2224
+ """Convert well height to volume."""
2225
+ try:
2226
+ return self.find_volume_at_well_height(
2227
+ labware_id=labware_id, well_name=well_name, target_height=height
2228
+ )
2229
+ except InvalidLiquidHeightFound as _exception:
2230
+ raise InvalidLiquidHeightFound(
2231
+ message=_exception.message
2232
+ + f"for well {well_name} of {self._labware.get_display_name(labware_id)} on slot {self.get_ancestor_slot_name(labware_id)}"
2233
+ )
2234
+
2235
+ def validate_dispense_volume_into_well(
2236
+ self,
2237
+ labware_id: str,
2238
+ well_name: str,
2239
+ well_location: WellLocationType,
2240
+ volume: float,
2241
+ ) -> None:
2242
+ """Raise InvalidDispenseVolumeError if planned dispense volume will overflow well."""
2243
+ well_def = self._labware.get_well_definition(labware_id, well_name)
2244
+ well_volumetric_capacity = float(well_def.totalLiquidVolume)
2245
+ if well_location.origin == WellOrigin.MENISCUS:
2246
+ # TODO(pbm, 10-23-24): refactor to smartly reduce height/volume conversions
2247
+ meniscus_height = self.get_meniscus_height(
2248
+ labware_id=labware_id, well_name=well_name
2249
+ )
2250
+ try:
2251
+ meniscus_volume = self.find_volume_at_well_height(
2252
+ labware_id=labware_id,
2253
+ well_name=well_name,
2254
+ target_height=meniscus_height,
2255
+ )
2256
+ except InvalidLiquidHeightFound as _exception:
2257
+ raise InvalidLiquidHeightFound(
2258
+ message=_exception.message
2259
+ + f"for well {well_name} of {self._labware.get_display_name(labware_id)} on slot {self.get_ancestor_slot_name(labware_id)}"
2260
+ )
2261
+ # if meniscus volume is a simulated value, comparisons aren't meaningful
2262
+ if isinstance(meniscus_volume, SimulatedProbeResult):
2263
+ return
2264
+ remaining_volume = well_volumetric_capacity - meniscus_volume
2265
+ if volume > remaining_volume:
2266
+ raise errors.InvalidDispenseVolumeError(
2267
+ f"Attempting to dispense {volume}µL of liquid into a well that can currently only hold {remaining_volume}µL (well {well_name} in labware_id: {labware_id})"
2268
+ )
2269
+ else:
2270
+ # TODO(pbm, 10-08-24): factor in well (LabwareStore) state volume
2271
+ if volume > well_volumetric_capacity:
2272
+ raise errors.InvalidDispenseVolumeError(
2273
+ f"Attempting to dispense {volume}µL of liquid into a well that can only hold {well_volumetric_capacity}µL (well {well_name} in labware_id: {labware_id})"
2274
+ )
2275
+
2276
+ def get_wells_covered_by_pipette_with_active_well(
2277
+ self, labware_id: str, target_well_name: str, pipette_id: str
2278
+ ) -> list[str]:
2279
+ """Get a flat list of wells that are covered by a pipette when moved to a specified well.
2280
+
2281
+ When you move a pipette in a multichannel configuration to a specific well - the target well -
2282
+ the pipette will operate on other wells as well.
2283
+
2284
+ For instance, a pipette with a COLUMN configuration with well A1 of an SBS standard labware target
2285
+ will also "cover", under this definition, wells B1-H1. That same pipette, when C5 is the target well, will "cover"
2286
+ wells C5-H5.
2287
+
2288
+ This math only works, and may only be applied, if one of the following is true:
2289
+ - The pipette is in a SINGLE configuration
2290
+ - The pipette is in a non-SINGLE configuration, and the labware is an SBS-format 96 or 384 well plate (and is so
2291
+ marked in its definition's parameters.format key, as 96Standard or 384Standard)
2292
+
2293
+ If all of the following do not apply, regardless of the nozzle configuration of the pipette this function will
2294
+ return only the labware covered by the primary well.
2295
+ """
2296
+ pipette_nozzle_map = self._pipettes.get_nozzle_configuration(pipette_id)
2297
+ labware_columns = [
2298
+ column for column in self._labware.get_definition(labware_id).ordering
2299
+ ]
2300
+ try:
2301
+ return list(
2302
+ wells_covered_by_pipette_configuration(
2303
+ pipette_nozzle_map, target_well_name, labware_columns
2304
+ )
2305
+ )
2306
+ except InvalidStoredData:
2307
+ return [target_well_name]
2308
+
2309
+ def get_nozzles_per_well(
2310
+ self, labware_id: str, target_well_name: str, pipette_id: str
2311
+ ) -> int:
2312
+ """Get the number of nozzles that will interact with each well."""
2313
+ return nozzles_per_well(
2314
+ self._pipettes.get_nozzle_configuration(pipette_id),
2315
+ target_well_name,
2316
+ self._labware.get_definition(labware_id).ordering,
2317
+ )
2318
+
2319
+ def get_height_of_labware_stack(
2320
+ self, definitions: list[LabwareDefinition]
2321
+ ) -> float:
2322
+ """Get the overall height of a stack of labware listed by definition in top-first order."""
2323
+ if len(definitions) == 0:
2324
+ return 0
2325
+ if len(definitions) == 1:
2326
+ return self._labware.get_dimensions(labware_definition=definitions[0]).z
2327
+ total_height = 0.0
2328
+ upper_def: LabwareDefinition = definitions[0]
2329
+ for lower_def in definitions[1:]:
2330
+ overlap = self._labware.get_labware_overlap_offsets(
2331
+ upper_def, lower_def.parameters.loadName
2332
+ ).z
2333
+ total_height += (
2334
+ self._labware.get_dimensions(labware_definition=upper_def).z - overlap
2335
+ )
2336
+ upper_def = lower_def
2337
+ return (
2338
+ total_height + self._labware.get_dimensions(labware_definition=upper_def).z
2339
+ )
2340
+ return total_height + upper_def.dimensions.zDimension
2341
+
2342
+ def get_height_of_stacker_labware_pool(self, module_id: str) -> float:
2343
+ """Get the overall height of a stack of labware in a Stacker module."""
2344
+ stacker = self._modules.get_flex_stacker_substate(module_id)
2345
+ pool_list = stacker.get_pool_definition_ordered_list()
2346
+ if not pool_list:
2347
+ return 0.0
2348
+ return self.get_height_of_labware_stack(pool_list)
2349
+
2350
+ def _get_or_default_labware(
2351
+ self, labware_id: str, pending_labware: dict[str, LoadedLabware]
2352
+ ) -> LoadedLabware:
2353
+ try:
2354
+ return self._labware.get(labware_id)
2355
+ except LabwareNotLoadedError as lnle:
2356
+ try:
2357
+ return pending_labware[labware_id]
2358
+ except KeyError as ke:
2359
+ raise lnle from ke