diff --git a/Config/config.json b/Config/config.json index 9060893..8ec61bf 100644 --- a/Config/config.json +++ b/Config/config.json @@ -1,5 +1,5 @@ { - "Number_of_cycles": 40, + "Number_of_cycles": 5, "Amplitude_mm": 10, "Time_in_beam_s": 5, "Time_out_of_beam_s": 10 diff --git a/Config/measurement.json b/Config/measurement.json new file mode 100644 index 0000000..095405f --- /dev/null +++ b/Config/measurement.json @@ -0,0 +1,4 @@ +{"std_test_mov": [10, -10], +"std_test_wait": [1], +"backlsh_meas_mov": [10, -10, -10, 10], +"backlash_meas_wait": [1]} \ No newline at end of file diff --git a/Scripts/__pycache__/metrology_functions.cpython-313.pyc b/Scripts/__pycache__/metrology_functions.cpython-313.pyc index c7aad3b..c7c6c10 100644 Binary files a/Scripts/__pycache__/metrology_functions.cpython-313.pyc and b/Scripts/__pycache__/metrology_functions.cpython-313.pyc differ diff --git a/Scripts/__pycache__/myutility.cpython-313.pyc b/Scripts/__pycache__/myutility.cpython-313.pyc new file mode 100644 index 0000000..5c90fd6 Binary files /dev/null and b/Scripts/__pycache__/myutility.cpython-313.pyc differ diff --git a/Scripts/metrology_functions.py b/Scripts/metrology_functions.py index b517497..f8845b2 100644 --- a/Scripts/metrology_functions.py +++ b/Scripts/metrology_functions.py @@ -19,6 +19,8 @@ def check_path(path_str): library_path = r"C:\Users\berti_r\Python_Projects\templates\motion_libs" check_path(library_path) sys.path.append(library_path) +measurement_mov_path = r"C:\Users\berti_r\Python_Projects\StagePerformaceDocu\Config\measurement.json" +check_path(measurement_mov_path) import motionFunctionsLib as mfl from PIL import Image @@ -26,9 +28,10 @@ import numpy as np from image_analysis import image_center_of_mass from utils import get_datestr, get_timestr import ad +import myutility as myu workdir = \ - os.path.expanduser(rf'C:\Users\berti_r\Python_Projects\metrology\metrology\Data{get_datestr()}_alignment_tests') + os.path.expanduser(rf'C:\Users\berti_r\Python_Projects\StagePerformaceDocu\data{get_datestr()}_alignment_tests') if not os.path.exists(workdir): os.makedirs(workdir) @@ -40,8 +43,7 @@ axis1 = mfl.axis(plc, 1) def run_repeatability_series( - motor_pv_prefix, ntries=100, distance=None, direction=1, - meas_pos=None, settling_time=0.0, save_images=True, run_analysis=True): + motor_pv_prefix, ntries=100,save_images=True, run_analysis=False): #improv @@ -50,7 +52,6 @@ def run_repeatability_series( else: os.environ["EPICS_CA_ADDR_LIST"] = "129.129.181.64" - camera = ad.AD() pixel_size = 1.1 @@ -59,10 +60,10 @@ def run_repeatability_series( savefile = os.path.join(savedir, f'repeatibility_{motor_pv_prefix}.dat') os.makedirs(savedir) - camera.start() #enable axis clean up later + axis1.setAcceleration(10000.0) axis1.setDeceleration(20000.0) axis1.setVelocity(-3) @@ -70,30 +71,27 @@ def run_repeatability_series( sleep(1) axis1.enableAxis() sleep(1) + #--------------------------------------load coordinates from file----------------------- + x_coordinates_json = myu.load_object(measurement_mov_path) + x_coordinates = x_coordinates_json.get('std_test_mov') for i in range(ntries): #---------------------------------------------move------------------------------------------ - axis1.moveRelativeAndWait(-1) - sleep(0.1) - axis1.moveRelativeAndWait(1) + #add multithreading for simultanious movement of y and x axis + for mov in x_coordinates: + axis1.moveRelativeAndWait(mov) + sleep(0.1) sleep(1) - # mot.move(meas_pos - np.sign(direction) * distance, wait=True) - # time.sleep(0.1) - # start_pos_rbv = mot.get_position(readback=True) - start_pos_rbv = 4 - # mot.move(meas_pos, wait=True) - # time.sleep(settling_time) - # meas_pos_rbv = mot.get_position(readback=True) - meas_pos_rbv = 5 + start_pos_rbv = 4 #???? + meas_pos_rbv = 5 #???? #---------------------------------------------capture------------------------------------------ im = camera.get_image() com_x, com_y = image_center_of_mass(im, plot=False, verbose=False) data_str = " {:6d} {:18f} {:18f} {:8.3f} {:8.3f} {:14.3f}\n".format( i, start_pos_rbv, meas_pos_rbv, com_x, com_y, time.time()) - # data_str = " {:6d} {:8.3f} {:8.3f} {:14.3f}\n".format( - # i, com_x, com_y, time.time()) print(data_str, end='') +#-------------------------------------------Save---------------------------------------------------- with open(savefile, 'a') as fh: fh.write(data_str) @@ -103,10 +101,11 @@ def run_repeatability_series( f'im_{i:05d}.tif') imobj.save(imfile) - +#--------------------------------------------analyse---------------------------------------------- if run_analysis: print("") analyze_repeatability(savefile, pixel_size=pixel_size, units='um') +#-----------------------------------------cleanup----------------------------------------- axis1.disableAxis() diff --git a/Scripts/myutility.py b/Scripts/myutility.py new file mode 100644 index 0000000..a1c32c1 --- /dev/null +++ b/Scripts/myutility.py @@ -0,0 +1,10 @@ +import json +# Load config from JSON file +def load_object(path): + with open(path, 'r') as f: + return json.load(f) + +# Save updated config to JSON file +def save_config(path, updated_config): + with open(path, 'w') as f: + json.dump(updated_config, f, indent=4) \ No newline at end of file diff --git a/notebooks/sample.ipynb b/notebooks/sample.ipynb index 552c14b..5871a3c 100644 --- a/notebooks/sample.ipynb +++ b/notebooks/sample.ipynb @@ -53,8 +53,8 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-07-14T15:22:58.513182Z", - "start_time": "2025-07-14T15:22:58.266333Z" + "end_time": "2025-07-15T07:13:05.822677Z", + "start_time": "2025-07-15T07:13:05.801198Z" } }, "cell_type": "code", @@ -103,20 +103,21 @@ "\n", "#local includes\n", "import metrology_functions as mf\n", - "\n", + "import myutility as myu\n", + "\"\"\"\n", "# Load config from JSON file\n", - "def load_config():\n", - " with open(config_path, 'r') as f:\n", + "def load_object(path):\n", + " with open(path, 'r') as f:\n", " return json.load(f)\n", "\n", "# Save updated config to JSON file\n", - "def save_config(updated_config):\n", - " with open(config_path, 'w') as f:\n", - " json.dump(updated_config, f, indent=4)\n", + "def save_config(path, updated_config):\n", + " with open(path, 'w') as f:\n", + " json.dump(updated_config, f, indent=4)\"\"\"\n", "\n", "# Get number of cycles from config\n", "def init_nr_of_cycles():\n", - " config = load_config()\n", + " config = myu.load_object(config_path)\n", " return config.get(\"Number_of_cycles\", 1)\n", "\n", "\n", @@ -151,9 +152,9 @@ "# Set number of cycles and save to config\n", "def set_nr_of_cycles(change):\n", " new_cycles = change['new']\n", - " config = load_config()\n", + " config = myu.load_object(config_path)\n", " config['Number_of_cycles'] = new_cycles\n", - " save_config(config)\n", + " myu.save_config(config_path, config)\n", "\n", " with output2:\n", " clear_output()\n", @@ -167,7 +168,8 @@ "# --------------------------------------------------Display-----------------------------------------------\n", "\n", "display(nr_of_cycles, output2)\n", - "display(start_button, output1)\n" + "display(start_button, output1)\n", + "print(\"BIG TODO: ADD dropdown menue for choosing which test to run\")\n" ], "id": "fbc121e30a2defb3", "outputs": [ @@ -175,28 +177,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "Path exists: C:\\Users\\berti_r\\Python_Projects\\metrology\\metrology\n", "Path exists: C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\Scripts\n", - "Path exists: C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\Config\\config.json\n", - "Path exists: C:\\Users\\berti_r\\Python_Projects\\templates\\motion_libs\n", - "Constructor for PLC\n", - "Connect to PLC\n", - "is_open()=True\n", - "get_local_address()=None\n", - "read_device_info()=('Plc30 App', )\n", - "GVL_APP.nAXIS_NUM=3\n", - "Constructor for axis\n" + "Path exists: C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\Config\\config.json\n" ] }, { "data": { "text/plain": [ - "BoundedIntText(value=3, description='Nr of cycles:', max=1000, min=1)" + "BoundedIntText(value=5, description='Nr of cycles:', max=1000, min=1)" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, - "model_id": "1e72fea404844af69b9884b31d9fe2d1" + "model_id": "931ffe1c6a4c4fe1af39442aafcd5a6d" } }, "metadata": {}, @@ -210,7 +203,7 @@ "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, - "model_id": "7459f5fd35314ce99fce8129bda3e8e9" + "model_id": "49d711d81ca94028bd6c60a4ab0d22fa" } }, "metadata": {}, @@ -224,7 +217,7 @@ "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, - "model_id": "40b270d1d2814cfe8d6d876a78591c0f" + "model_id": "39198dfeeaa243cba9d410027dffe994" } }, "metadata": {}, @@ -238,14 +231,28 @@ "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, - "model_id": "44db6c1f5acf4cb4bf04a8d3fabb1c34" + "model_id": "24e25cd7cc814f898ca4503bca9184f1" } }, "metadata": {}, "output_type": "display_data" } ], - "execution_count": 1 + "execution_count": 5 + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "## Original Visualizaton of graphs", + "id": "59f9b1a9982a26db" + }, + { + "metadata": {}, + "cell_type": "code", + "outputs": [], + "execution_count": null, + "source": "", + "id": "35424a827215f084" }, { "metadata": {}, @@ -330,16 +337,35 @@ "execution_count": null }, { - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2025-07-15T07:22:40.123332Z", + "start_time": "2025-07-15T07:22:40.118923Z" + } + }, "cell_type": "code", "source": [ - "#Data loger thread\n", - "import paho-mqtt.client as mqtt\n", - "import" + "x_coordinates_json = myu.load_object(r\"C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\Config\\measurement.json\")\n", + "x_coordinates = x_coordinates_json.get('backlsh_meas_mov')\n", + "print(x_coordinates)\n", + "for mov in x_coordinates:\n", + " print(mov)" ], "id": "9813d493bd439789", - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[10, -10, -10, 10]\n", + "10\n", + "-10\n", + "-10\n", + "10\n" + ] + } + ], + "execution_count": 9 } ], "metadata": {