write_path / write_blazed_grating.pyon commit add dlw module; clean up for handover (d7cac70)
   1"""
   2write_blazed.py
   3Andrew Lorimer, January 2025
   4Monash University
   5
   6Writes a reflective brazed grating pattern (sawtooth) using
   7the confocal direct laser writing setup on Sb2S3 thin-film PCM.
   8"""
   9
  10import configparser as cp
  11import cv2
  12import numpy as np
  13import sys
  14import matplotlib.pyplot as plt
  15import write_path
  16from pipython import datarectools, pitools
  17import nidaqmx
  18import pipython
  19import time
  20
  21def main(task, pidevice):
  22
  23    # Input parameters
  24    grating_pitch = 5000 # Lambda, nm
  25    n = 1      # number of steps ("teeth")
  26    beam_dia = 1350 # diameter of laser beam, nm
  27    wavelength = 450    # nm
  28    order = 1
  29    n_cr = 1.3
  30    length = 12
  31
  32    blaze_angle = np.arcsin(order*wavelength/(2*grating_pitch)) / np.pi * 180
  33    print("Calculated blaze angle: {:.1f} deg".format(blaze_angle))
  34
  35    diff_angle = np.arcsin(wavelength / grating_pitch) / np.pi * 180
  36    print("First order diffraction angle: {:.1f} deg".format(diff_angle))
  37
  38    #y_single_step = np.arange(0, grating_pitch, beam_dia)
  39    y_single_step = []
  40    speeds_single_step = []
  41    #for y in y_single_step:
  42    dia = beam_dia
  43    y = 0
  44    while y <= grating_pitch:
  45        speeds_single_step.append(np.exp(7*y/grating_pitch))
  46        y_single_step.append(y)
  47        y += dia
  48        dia *= 0.9
  49
  50    print(y_single_step)
  51    print(speeds_single_step)
  52
  53    #fig, ax = plt.subplots()
  54    #ax.plot(y_single_step, speeds_single_step, marker='.', linestyle='None')
  55    #ax.set_yscale('log')
  56    #plt.show()
  57
  58    origin = (0, 0)
  59    pidevice.VCO({1: True, 2: True})
  60    pidevice.VEL({1: 100, 2: 100})
  61    y_step = 0
  62
  63    for i in range(n):
  64        pidevice.MOV({1: origin[0], 2: origin[1]})
  65        pitools.waitontarget(pidevice, [1, 2, 3])
  66
  67        updown = 0
  68
  69        pidevice.MOV({1: 10, 2: 0.6})
  70
  71        for j in range(len(speeds_single_step)):
  72            pidevice.MOV({1: origin[0]+updown*length, 2: origin[1]+y_step+y_single_step[j]/1000})
  73            pitools.waitontarget(pidevice, [1, 2, 3])
  74            time.sleep(0.3)
  75
  76            pidevice.VCO({1: True, 2: True})
  77            print(speeds_single_step[j])
  78            pidevice.VEL({1: speeds_single_step[j], 2: speeds_single_step[j]})
  79            
  80            task.write(True)
  81            pidevice.MOV({1: origin[0]+(not updown)*length, 2: origin[1]+y_step+y_single_step[j]/1000})
  82            pitools.waitontarget(pidevice, [1, 2, 3])
  83            task.write(False)
  84            
  85            time.sleep(0.3)
  86
  87            pidevice.VCO({1: True, 2: True})
  88            pidevice.VEL({1: 100, 2: 100})
  89            
  90            updown = int(not updown)
  91
  92        y_step += grating_pitch/1000
  93
  94
  95    # Plot
  96    #fig, ax = plt.subplots()
  97    #ax.set_aspect("equal")
  98    #for pair in lines:
  99    #    ax.plot(pair[:,0], pair[:,1], '-', color='black')  
 100    #plt.show()
 101
 102if __name__ == "__main__":
 103    task, pidevice = write_path.setup()
 104    try:
 105        main(task, pidevice)
 106    finally:
 107        print("Exiting")
 108        task.write(False)
 109        task.close()
 110        pidevice.VCO({1: True, 2: True})
 111        pidevice.VEL({1: 100, 2: 100})
 112        pidevice.MOV({1: 0, 2: 0})
 113        pitools.waitontarget(pidevice, [1, 2])
 114        pitools.stopall(pidevice)