From e09ec154492b6a9b9f72c101470ee16219b26572 Mon Sep 17 00:00:00 2001 From: Jefferson Barros Vieira Date: Mon, 14 Jul 2025 11:03:37 -0300 Subject: [PATCH] vaccum commissioning --- ids_movimentation/vpu29_mov_tests copy.ipynb | 367 +++++++++++++++++++ 1 file changed, 367 insertions(+) create mode 100644 ids_movimentation/vpu29_mov_tests copy.ipynb diff --git a/ids_movimentation/vpu29_mov_tests copy.ipynb b/ids_movimentation/vpu29_mov_tests copy.ipynb new file mode 100644 index 0000000..80a3a8e --- /dev/null +++ b/ids_movimentation/vpu29_mov_tests copy.ipynb @@ -0,0 +1,367 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/opt/mamba/envs/sirius/lib/python3.9/site-packages/epics/ca.py:28: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.\n", + " from pkg_resources import resource_filename\n" + ] + } + ], + "source": [ + "import time\n", + "import os\n", + "from datetime import datetime\n", + "\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "\n", + "from siriuspy.search import IDSearch\n", + "from siriuspy.devices import VPU\n", + "\n", + "import epics\n", + "\n", + "# BEFORE IOC CORRECTION\n", + "# epics.caput('SI-08SB:ID-IVU18:UN_Reset.HIGH', 1)\n", + "# epics.caput('SI-08SB:ID-IVU18:UN_Stop.HIGH', 1)\n", + "# epics.caput('SI-08SB:ID-IVU18:UN_Start.HIGH', 1)\n", + "\n", + "# epics.caput('SI-08SB:ID-IVU18:Reset-Cmd.HIGH', 1)\n", + "# epics.caput('SI-08SB:ID-IVU18:Abort-Cmd.HIGH', 1)\n", + "# epics.caput('SI-08SB:ID-IVU18:KParamChange-Cmd.HIGH', 1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_vpu(beamline):\n", + " \"\"\".\"\"\"\n", + " # Search ID\n", + " devnamevpu = IDSearch.conv_beamline_2_idname(beamline=beamline)\n", + " vpu = VPU(devname=devnamevpu)\n", + "\n", + " # Disable beamline control\n", + " vpu.cmd_beamline_ctrl_disable()\n", + " print(\"beamline control: \", vpu.is_beamline_ctrl_enabled)\n", + " return vpu\n", + "\n", + "\n", + "def move_vpu_gap(vpu: VPU, gap, timeout, verbose=False):\n", + " \"\"\".\"\"\"\n", + " vpu.set_gap(gap)\n", + " time.sleep(0.5)\n", + " print(\"Gap-RB {:.3f} mm\".format(vpu.gap)) if verbose else 0\n", + " if vpu.cmd_move_start(timeout):\n", + " time.sleep(0.5)\n", + " print(\"Undulator is moving...\") if verbose else 0\n", + " while vpu.is_moving:\n", + " time.sleep(0.1)\n", + " print(\n", + " \"Current gap {:.3f} mm.\".format(vpu.gap_mon), end=\"\\r\"\n", + " ) if verbose else 0\n", + " print(\"Gap {:.3f} mm reached.\".format(vpu.gap)) if verbose else 0\n", + " return True\n", + " else:\n", + " print(\"Error while cmd_move_start.\")\n", + " return False\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Search devnames" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'SI-07SP:ID-VPU29'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "devnamevpu_carnauba = IDSearch.conv_beamline_2_idname(beamline=\"CARNAUBA\")\n", + "devnamevpu_caterete = IDSearch.conv_beamline_2_idname(beamline=\"CATERETE\")\n", + "devnamevpu_caterete" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Initialize CATERETE VPU" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Could not set value of SI-07SP:ID-VPU29:BeamLineCtrlEnbl-Sel\n", + "beamline control: False\n" + ] + } + ], + "source": [ + "vpu_caterete = initialize_vpu(beamline=\"CATERETE\")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('PitchOffsetMinPos-Cte',\n", + " 'MoveStart-Cmd',\n", + " 'Reset-Cmd',\n", + " 'MoveAcc-SP',\n", + " 'KParamParked-Cte',\n", + " 'CenterOffset-Mon',\n", + " 'BeamLineCtrlEnbl-Sel',\n", + " 'Moving-Mon',\n", + " 'PitchOffset-Mon',\n", + " 'KParamMaxVelo-SP',\n", + " 'TaperMinPos-Cte',\n", + " 'Taper-SP',\n", + " 'KParam-Mon',\n", + " 'MoveVelo-RB',\n", + " 'KParamMaxVelo-RB',\n", + " 'CenterOffsetVelo-Mon',\n", + " 'BeamLineCtrlEnbl-Sts',\n", + " 'CenterOffset-RB',\n", + " 'TaperVelo-Mon',\n", + " 'CenterOffset-SP',\n", + " 'Taper-RB',\n", + " 'PitchOffsetVelo-Mon',\n", + " 'KParam-RB',\n", + " 'PeriodLength-Cte',\n", + " 'MoveAcc-RB',\n", + " 'CenterOffsetMinPos-Cte',\n", + " 'Abort-Cmd',\n", + " 'PitchOffsetMaxPos-Cte',\n", + " 'KParam-SP',\n", + " 'TaperMaxPos-Cte',\n", + " 'MoveVelo-SP',\n", + " 'CenterOffsetMaxPos-Cte',\n", + " 'Taper-Mon')" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vpu_caterete.PROPERTIES_DEFAULT" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(\"Period: {:.1f} mm\".format(vpu_caterete.period_length))\n", + "print(\"Polarization mon: {:}\".format(vpu_caterete.polarization_mon))\n", + "print(\"Connection:\", vpu_caterete.connected)\n", + "vpu_caterete.disconnected_pvnames" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Fields [T]: \n", + "[0.101 0.2 0.295 0.404 0.512 0.601 0.704 0.763 0.827]\n", + "\n", + "Gaps [mm]: \n", + "[28.68 22.35 18.84 16.03 13.92 12.51 11.11 10.4 9.7 ]\n" + ] + } + ], + "source": [ + "target_fields = np.array([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8])\n", + "\n", + "gaps = np.linspace(80, 9.7, 101)\n", + "\n", + "# VPU CAT Halbach coefficients\n", + "Br = 1.3\n", + "a = 1.9586\n", + "b = -3.4126\n", + "c = 0.1496\n", + "\n", + "bs = Br * a * np.exp(b * (gaps / 29) + c * (gaps / 29) ** 2)\n", + "\n", + "\n", + "mask = np.isclose(bs[:, None], target_fields[None, :], rtol=0.05, atol=1e-8)\n", + "idxs = np.where(mask.any(axis=1))[0]\n", + "\n", + "target_gaps = gaps[idxs]\n", + "\n", + "print(\"Fields [T]: \")\n", + "print(bs[idxs].round(3))\n", + "print(\"\\nGaps [mm]: \")\n", + "print(target_gaps.round(2))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Gap mov tests" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "vpu_caterete.set_gap_speed(0.5)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "move_vpu_gap(vpu_caterete, gap=24, timeout=3, verbose=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "gaps0 = np.arange(24, 3, -1)\n", + "gaps1 = gaps0[::-1]\n", + "gaps = np.concatenate((gaps0, gaps1))\n", + "gaps" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for i, gap in enumerate(gaps):\n", + " sucess = move_vpu_gap(vpu_caterete, gap=gap, timeout=3, verbose=True)\n", + " if not sucess:\n", + " break" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Random movement" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "timeout = 3\n", + "deltat = 180\n", + "t0 = time.time()\n", + "while datetime.now().hour < 14:\n", + " if deltat >= 180:\n", + " t0 = time.time()\n", + " gap = 5 * np.random.random(1) + 20\n", + " speed = 0.08 * np.random.random(1) + 0.02\n", + " vpu_caterete.set_gap_speed(speed, timeout)\n", + " time.sleep(0.5)\n", + " sucess = move_vpu_gap(vpu_caterete, gap=gap, timeout=timeout, verbose=True)\n", + " if not sucess:\n", + " break\n", + " t = time.time()\n", + " deltat = t - t0\n", + " time.sleep(1)\n", + " print(\"waiting...\", end=\"\\r\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Taper mov tests" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Pitch mov tests" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Center Offset tests" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "sirius", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}