{ "cells": [ { "cell_type": "markdown", "id": "6f6bd53c", "metadata": {}, "source": [ "# KX2 continuous motion\n", "\n", "Complete [hello world](hello-world.ipynb) through setup first. These cells assume a connected `kx2`.\n", "\n", "Streaming sends CANopen interpolation points at 8 ms intervals. Setup configures the drive buffers and synchronized motion channels." ] }, { "cell_type": "markdown", "id": "13a5e9fa", "metadata": {}, "source": [ "## Capture a starting pose\n", "\n", "All locations are absolute grip-center coordinates in millimeters, with the KX2 yaw convention described in hello world." ] }, { "cell_type": "code", "execution_count": null, "id": "9ee496b4", "metadata": {}, "outputs": [], "source": [ "from pylabrobot.paa.kx2 import CartesianPose\n", "from pylabrobot.resources import Coordinate, Rotation\n", "\n", "start = await kx2.request_gripper_pose()" ] }, { "cell_type": "markdown", "id": "d15f5cc3", "metadata": {}, "source": [ "## Linear Cartesian path\n", "\n", "After verifying a clear 5 mm vertical segment, run this move. Both speed and acceleration must be provided. The planner checks joint travel at the sampled poses; it does not check collisions." ] }, { "cell_type": "code", "execution_count": null, "id": "de87d1b2", "metadata": {}, "outputs": [], "source": [ "target = Coordinate(start.location.x, start.location.y, start.location.z + 5)\n", "await kx2.move_to_location(target, start.rotation.z, path=\"linear\",\n", " max_gripper_speed=5, max_gripper_acceleration=20)" ] }, { "cell_type": "markdown", "id": "74892bb5", "metadata": {}, "source": [ "## Rotate at a fixed grip center\n", "\n", "A linear path can change yaw while keeping the grip center in place. Set the tool offsets for your gripper and verify clearance for the rotation. Angular speed and acceleration use degrees per second and degrees per second squared; their defaults are 30 and 100." ] }, { "cell_type": "code", "execution_count": null, "id": "e9119ca5", "metadata": {}, "outputs": [], "source": [ "current = await kx2.request_gripper_pose()\n", "await kx2.move_to_location(\n", " current.location, current.rotation.z + 1, path=\"linear\",\n", " max_gripper_speed=5, max_gripper_acceleration=20,\n", " max_gripper_angular_speed=1, max_gripper_angular_acceleration=2,\n", ")" ] }, { "cell_type": "markdown", "id": "02325b67", "metadata": {}, "source": [ "## Smooth waypoints\n", "\n", "`move_through_waypoints` fits a smooth spline, so the curve can overshoot the line segments joining your points. Check the whole curve. Keep the first waypoint at the measured current pose." ] }, { "cell_type": "code", "execution_count": null, "id": "354d1fed", "metadata": {}, "outputs": [], "source": [ "current = await kx2.request_gripper_pose()\n", "waypoints = [current, CartesianPose(\n", " Coordinate(current.location.x, current.location.y, current.location.z + 5), current.rotation\n", ")]\n", "await kx2.move_through_waypoints(waypoints, speed=5, acceleration=20)" ] }, { "cell_type": "markdown", "id": "c41f93b8", "metadata": {}, "source": [ "## Parametric paths\n", "\n", "`move_parametric(path_fn, duration)` samples absolute poses at times in seconds. It does not impose a speed or acceleration cap. The path must start at the measured pose and remain continuous and within travel and motion limits; this holds the measured pose without a displacement." ] }, { "cell_type": "code", "execution_count": null, "id": "b0a6e8bc", "metadata": {}, "outputs": [], "source": [ "held = await kx2.request_gripper_pose()\n", "\n", "def hold_pose(t: float) -> CartesianPose:\n", " \"\"\"Return the same absolute pose throughout the requested interval.\"\"\"\n", " return held\n", "\n", "await kx2.move_parametric(hold_pose, duration=1)" ] }, { "cell_type": "markdown", "id": "6f93ae2e", "metadata": {}, "source": [ "## Disconnect" ] }, { "cell_type": "code", "execution_count": null, "id": "6d320012", "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 }