{ "cells": [ { "cell_type": "markdown", "id": "05930479", "metadata": {}, "source": [ "# KX2 proximity sensor\n", "\n", "Complete [hello world](hello-world.ipynb) through setup first. These cells assume a connected `kx2`. The beam between the fingers is wired to input 4 on the Z drive. `True` means the beam is interrupted." ] }, { "cell_type": "code", "execution_count": null, "id": "e2cc9529", "metadata": {}, "outputs": [], "source": [ "await kx2.sense_proximity()" ] }, { "cell_type": "markdown", "id": "ac48affc", "metadata": {}, "source": [ "## Wait for the beam\n", "\n", "This observes the sensor without moving any axis. It returns `False` if the deadline expires." ] }, { "cell_type": "code", "execution_count": null, "id": "38fec4bd", "metadata": {}, "outputs": [], "source": [ "await kx2.wait_for_proximity_sensor(state=True, timeout=5)" ] }, { "cell_type": "markdown", "id": "bc78c5c7", "metadata": {}, "source": [ "## Search downward\n", "\n", "Measure the search range and clear the approach path. This example searches 5 mm below the measured Z. The search first moves to `z_start`, then descends towards `z_end`. It stops when the beam trips and returns the measured Z. The input's original logic is restored even on cancellation; unrelated drive faults propagate." ] }, { "cell_type": "code", "execution_count": null, "id": "4f2fbf37", "metadata": {}, "outputs": [], "source": [ "from pylabrobot.paa.kx2 import Axis\n", "\n", "position = await kx2.request_joint_state()\n", "found_z = await kx2.find_z_with_proximity_sensor(\n", " z_start=position[Axis.Z], z_end=position[Axis.Z] - 5,\n", " max_gripper_speed=5, max_gripper_acceleration=20,\n", ")\n", "found_z" ] }, { "cell_type": "markdown", "id": "f8b0e70f", "metadata": {}, "source": [ "## Cartesian search\n", "\n", "`find_with_proximity_sensor(start, end, max_gripper_speed=..., max_gripper_acceleration=...)` follows a streamed straight segment while retaining the measured yaw. It polls the sensor on the host, so it has different stopping latency from the drive-local input stop used by the Z search. Read the [streaming limitations](continuous-motion.ipynb) and verify clearance and stopping distance before using it." ] }, { "cell_type": "markdown", "id": "2cc94248", "metadata": {}, "source": [ "## Disconnect" ] }, { "cell_type": "code", "execution_count": null, "id": "ad21588a", "metadata": {}, "outputs": [], "source": [ "await kx2.stop()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }