diff --git a/config/preferences.json b/config/preferences.json index 8e49321..9c4eed9 100644 --- a/config/preferences.json +++ b/config/preferences.json @@ -46,7 +46,7 @@ "simpleEditor" : false, "hideEditorLineNumbers" : false, "hideEditorContextMenu" : false, - "consoleLocation" : "Status", + "consoleLocation" : "Plot", "dataPanelLocation" : null, "openDataFilesInDocTab" : false, "noVariableEvaluationPropagation" : false, diff --git a/config/settings.properties b/config/settings.properties index 0905ce0..4a8ab0f 100644 --- a/config/settings.properties +++ b/config/settings.properties @@ -1,4 +1,4 @@ -#Fri Sep 20 10:59:23 CEST 2024 +#Tue Oct 15 10:20:20 CEST 2024 barcode_reader_scan_pucks=false beamline_status_enabled=false cold_position_timeout=3600 @@ -7,7 +7,7 @@ dry_timestamp=1.69564645367E9 force_dry_mount_count=4 force_dry_timeout=27000 imaging_enabled=true -led_level=0.0 +led_level=100.0 pin_cleaner_timer=60 pin_offset=-0.0 puck_types=true diff --git a/devices/cover_detection.properties b/devices/cover_detection.properties index 37b3411..8c96648 100644 --- a/devices/cover_detection.properties +++ b/devices/cover_detection.properties @@ -1,21 +1,24 @@ -#Fri Sep 20 10:59:27 CEST 2024 -center_x=917.0 -center_y=1015.0 +#Wed Oct 16 10:41:00 CEST 2024 +center_x=1019.0 +center_y=1052.0 continuous=false correlation_threshold=0.0 diam_dewar=null diam_disk=null diam_target=null -diameter_target=95 +diameter_dewar=1800 +diameter_disk=670 +diameter_target=100 diamter_dewar=1800 diamter_disk=670 mask_dewar=null mask_disk=null max_detect_offset=10 -modulo=3 -number_images=2 +modulo=2 +number_images=1 offset_threshold=null open_strategy=both +rotation_degrees=0.0 scale_x=0.3 scale_y=0.3 size_mask_dewar=0.98 diff --git a/devices/image.properties b/devices/image.properties index 72317ce..ab01857 100644 --- a/devices/image.properties +++ b/devices/image.properties @@ -1,4 +1,4 @@ -#Fri Sep 20 09:24:26 CEST 2024 +#Wed Oct 16 10:43:18 CEST 2024 colormap=Grayscale colormapAutomatic=true colormapLogarithmic=false @@ -14,7 +14,7 @@ roiHeight=-1 roiWidth=-1 roiX=0 roiY=0 -rotation=0.0 +rotation=90.0 rotationCrop=false scale=1.0 spatialCalOffsetX=NaN diff --git a/devices/robot_j1.properties b/devices/robot_j1.properties index effc910..c36c2d2 100644 --- a/devices/robot_j1.properties +++ b/devices/robot_j1.properties @@ -1,4 +1,5 @@ -#Tue Jun 19 16:41:28 CEST 2018 +#Mon Sep 23 10:42:00 CEST 2024 +description=null maxValue=180.0 minValue=-180.0 offset=0.0 diff --git a/devices/robot_j2.properties b/devices/robot_j2.properties index 483dbce..5c2cc64 100644 --- a/devices/robot_j2.properties +++ b/devices/robot_j2.properties @@ -1,4 +1,5 @@ -#Tue Jun 19 16:41:28 CEST 2018 +#Mon Sep 23 10:42:00 CEST 2024 +description=null maxValue=127.5 minValue=-127.5 offset=0.0 diff --git a/devices/robot_j3.properties b/devices/robot_j3.properties index 57ef9b6..1f4b6ec 100644 --- a/devices/robot_j3.properties +++ b/devices/robot_j3.properties @@ -1,4 +1,5 @@ -#Tue Jun 19 16:41:28 CEST 2018 +#Mon Sep 23 10:42:00 CEST 2024 +description=null maxValue=152.5 minValue=-152.5 offset=0.0 diff --git a/devices/robot_j4.properties b/devices/robot_j4.properties index 813162f..fa07367 100644 --- a/devices/robot_j4.properties +++ b/devices/robot_j4.properties @@ -1,4 +1,5 @@ -#Tue Jun 19 16:41:28 CEST 2018 +#Mon Sep 23 10:42:00 CEST 2024 +description=null maxValue=270.0 minValue=-270.0 offset=0.0 diff --git a/devices/robot_j5.properties b/devices/robot_j5.properties index e15853d..adf5197 100644 --- a/devices/robot_j5.properties +++ b/devices/robot_j5.properties @@ -1,4 +1,5 @@ -#Tue Jun 19 16:41:28 CEST 2018 +#Mon Sep 23 10:42:00 CEST 2024 +description=null maxValue=132.5 minValue=-122.5 offset=0.0 diff --git a/devices/robot_j6.properties b/devices/robot_j6.properties index 86f954a..490ff2c 100644 --- a/devices/robot_j6.properties +++ b/devices/robot_j6.properties @@ -1,4 +1,5 @@ -#Fri Aug 24 14:56:42 CEST 2018 +#Mon Sep 23 10:42:00 CEST 2024 +description=null maxValue=400.0 minValue=-400.0 offset=0.0 diff --git a/devices/robot_rx.properties b/devices/robot_rx.properties index bc44a7f..3462b01 100644 --- a/devices/robot_rx.properties +++ b/devices/robot_rx.properties @@ -1,4 +1,5 @@ -#Tue Jun 19 16:41:28 CEST 2018 +#Mon Sep 23 10:42:00 CEST 2024 +description=null maxValue=180.0 minValue=-180.0 offset=0.0 diff --git a/devices/robot_ry.properties b/devices/robot_ry.properties index da7bc27..8cc03e1 100644 --- a/devices/robot_ry.properties +++ b/devices/robot_ry.properties @@ -1,4 +1,5 @@ -#Tue Jun 19 16:41:28 CEST 2018 +#Mon Sep 23 10:42:00 CEST 2024 +description=null maxValue=180.0 minValue=-180.0 offset=0.0 diff --git a/devices/robot_rz.properties b/devices/robot_rz.properties index 852eba0..f263f51 100644 --- a/devices/robot_rz.properties +++ b/devices/robot_rz.properties @@ -1,4 +1,5 @@ -#Tue Jun 19 16:41:28 CEST 2018 +#Mon Sep 23 10:42:00 CEST 2024 +description=null maxValue=360.0 minValue=-360.0 offset=0.0 diff --git a/devices/robot_x.properties b/devices/robot_x.properties index 5c10107..6f29510 100644 --- a/devices/robot_x.properties +++ b/devices/robot_x.properties @@ -1,4 +1,5 @@ -#Tue Jun 19 16:41:28 CEST 2018 +#Mon Sep 23 10:42:00 CEST 2024 +description=null maxValue=1000.0 minValue=-1000.0 offset=0.0 diff --git a/devices/robot_y.properties b/devices/robot_y.properties index ac371ea..49ae523 100644 --- a/devices/robot_y.properties +++ b/devices/robot_y.properties @@ -1,4 +1,5 @@ -#Tue Jun 19 16:41:28 CEST 2018 +#Mon Sep 23 10:42:00 CEST 2024 +description=null maxValue=1000.0 minValue=-1000.0 offset=0.0 diff --git a/devices/robot_z.properties b/devices/robot_z.properties index ac371ea..49ae523 100644 --- a/devices/robot_z.properties +++ b/devices/robot_z.properties @@ -1,4 +1,5 @@ -#Tue Jun 19 16:41:28 CEST 2018 +#Mon Sep 23 10:42:00 CEST 2024 +description=null maxValue=1000.0 minValue=-1000.0 offset=0.0 diff --git a/script/devices/CoverDetection.py b/script/devices/CoverDetection.py index caaa685..63abb83 100644 --- a/script/devices/CoverDetection.py +++ b/script/devices/CoverDetection.py @@ -11,10 +11,11 @@ class CoverDetectionConfig(RegisterConfig): self.center_y = 570.0 self.scale_x = 1.0 self.scale_y = 1.0 + self.rotation_degrees = 0.0 self.correlation_threshold = 0.60 self.diameter_target=95 - self.diamter_disk=670 - self.diamter_dewar=1800 + self.diameter_disk=670 + self.diameter_dewar=1800 self.size_mask_disk=0.8 self.size_mask_dewar=0.98 self.max_detect_offset=10 @@ -106,7 +107,7 @@ class CoverDetection(ReadonlyAsyncRegisterBase, ReadonlyRegisterArray): self.error = None center = (self.config.center_x, self.config.center_y) x,y = detect(ip, center, \ - diam_target=self.config.diameter_target, diam_disk= self.config.diamter_disk, diam_dewar=self.config.diamter_dewar, \ + diam_target=self.config.diameter_target, diam_disk= self.config.diameter_disk, diam_dewar=self.config.diameter_dewar, \ mask_disk=self.config.size_mask_disk, mask_dewar=self.config.size_mask_dewar, \ offset_threshold=self.config.max_detect_offset ,open_strategy= self.config.open_strategy) @@ -131,6 +132,28 @@ class CoverDetection(ReadonlyAsyncRegisterBase, ReadonlyRegisterArray): if not self.config.continuous: self.images=[] + + def calculate_factors(self, x1, y1, x2, y2, mx1, my1, mx2, my2): + dx = x2-x1 + dy = y2-y1 + dmx = mx2-mx1 + dmy = my2-my1 + sx = dmx/dx + sy = dmy / dy + tp=math.atan(dy/dx) + tm=math.atan(dmy/dmx) + t = tm - tp + return sx, sy, math.degrees(t) + + def pixel_to_millis(self, x, y): + try: + t = math.radians(self.config.rotation_degrees) + offx, offy = x-self.config.center_x, y-self.config.center_y + rx, ry = (offx * math.cos(t) + offy * math.sin(t)), (-offx * math.sin(t) + offy * math.cos(t)) + mx, my = self.config.scale_x*rx, self.config.scale_y*ry + return round(mx,3), round(my,3) + except: + return float('nan'), float('nan') def set(self, x, y, tm, error): if self.enabled: @@ -138,9 +161,9 @@ class CoverDetection(ReadonlyAsyncRegisterBase, ReadonlyRegisterArray): self.offset_px = self.offset_um = None value = None else: - offx, offy = x-cover_detection.config.center_x, -(y-cover_detection.config.center_y) + offx, offy = x-self.config.center_x, y-self.config.center_y self.offset_px = opx, opy = round(offx), round(offy) - self.offset_um = omx, omy = self.config.scale_x * offx * 1000.0, self.config.scale_y * offy *1000.0 + self.offset_um = omx, omy = self.pixel_to_millis(x,y) value = to_array([x, y, opx, opy, omx, omy, tm], 'i') self.onReadout(value) if self.renderer is not None: diff --git a/script/imgproc/NewCoverCorrelation.py b/script/imgproc/NewCoverCorrelation.py index ae686a0..f8808ff 100644 --- a/script/imgproc/NewCoverCorrelation.py +++ b/script/imgproc/NewCoverCorrelation.py @@ -32,10 +32,28 @@ def rms_error(ip1, ip2): -def get_roi_img(img, img_size=1024, radius=800, offset_x=0, offset_y=0): +def clear_dc(img, width=2): + img = load_image(img.getBufferedImage()) + ip=img.getProcessor() + w, h = ip.getWidth(), ip.getHeight() + mask = ip.createProcessor(w, h) # Creates a new blank ImageProcessor + mask.setColor(255) # Set the drawing color to white (255) + o=width/2 + mask.fillRect(0, 0,(w/2)-o,(h/2)-o) + mask.fillRect(0, int(h/2)+o,(w/2)-o,(h/2)-o) + mask.fillRect(int(w/2)+o,0,(w/2)-o,(h/2)-o) + mask.fillRect(int(w/2)+o, int(h/2)+o,(w/2)-o,(h/2)-o) + mask.autoThreshold() # Ensures the mask is binary (if needed) + ip.copyBits(mask, 0, 0, Blitter.AND) # Apply the mask using a bitwise AND + return img + + + + +def _get_roi_img(img, img_size=1024, radius=800, offset_x=0, offset_y=0): x,y,w,h = int(cover_detection.config.center_x-img_size/2 + offset_x), \ int(cover_detection.config.center_y-img_size/2 + offset_y), \ - img_size, img_size + img_size, img_size roi = ImagingUtils.copy(img, None, Rectangle(x,y,w,h)) ip = load_image(roi, title="Img") p = ip.getProcessor() @@ -49,6 +67,17 @@ def get_roi_img(img, img_size=1024, radius=800, offset_x=0, offset_y=0): p.blurGaussian(1.0) return ip.getBufferedImage() +def get_roi_img(img, offset_x=0, offset_y=0): + img = ImagingUtils.copy(img, None, None) + center = cover_detection.config.center_x, cover_detection.config.center_y + #radius = cover_detection.config.diameter_dewar*(cover_detection.config.size_mask_dewar/2.0) + radius = cover_detection.config.diameter_dewar*0.45 + ip = load_image(img, title="Img") + p = ip.getProcessor() + set_circle_mask(p, center_x=center[0], center_y=center[1],radius=radius) + p.translate(offset_x, offset_y) + return ip.getBufferedImage() + def get_edge_img(ib): ed = ImagingUtils.edgeDetect(ib) ret = load_image(ed, title="Refe") @@ -57,9 +86,18 @@ def get_edge_img(ib): return ret def save_ref_img(img): - path = os.path.abspath(expand_path("{images}/ip_ref_fe.png")) + global ip_ref_fe + path = os.path.abspath(expand_path("{images}/ip_ref.png")) roi=get_roi_img(img, offset_x=0, offset_y=0) ImageBuffer.saveImage(roi, path, "png") + + + path = os.path.abspath(expand_path("{images}/ip_ref_e.png")) + ip_ref_e =get_edge_img(roi) + ImageBuffer.saveImage(ip_ref_e.getBufferedImage(), path, "png") + path = os.path.abspath(expand_path("{images}/ip_ref_fe.png")) + ip_ref_fe = image_fft(ip_ref_e) + ImageBuffer.saveImage(ip_ref_fe.getBufferedImage(), path, "png") #ip_ref = load_image(roi, title="ip_ref") #save_image(ip_ref, path ,"png") @@ -72,20 +110,21 @@ def save_ref_img(img): def put_mark(ib): - for x in range(450, 470): - for y in range(450, 470): + for x in range(700,750): + for y in range(650, 700): ib.setRGB(x,y, 0) def get_correlation(img): global ip_ref_fe if "ip_ref_fe" not in globals() or ip_ref_fe is None: - path = os.path.abspath(expand_path("{images}/ip_ref_fe.png")) + path = os.path.abspath(expand_path("{images}/ip_ref.png")) roi = ImagingUtils.newImage(path) #ip_ref_fe=open_imagroie(path+"ip_ref_fe.png" ,"png") #ip_ref = load_image(roi, title="ip_ref") ip_ref_e =get_edge_img(roi) ip_ref_fe = image_fft(ip_ref_e) - print "Opend reference image" + #ip_ref_fe = clear_dc(ip_ref_fe) + print "Opened reference image" roi =get_roi_img(img, offset_x=-offset, offset_y=-offset) if add_mark: @@ -94,6 +133,7 @@ def get_correlation(img): ip_cur_e =get_edge_img(roi) #ip_cur_f = image_fft(ip_cur) ip_cur_fe = image_fft(ip_cur_e) - return correlator.getCorrelation(ip_ref_fe, ip_cur_fe)[0] + #ip_cur_fe = clear_dc(ip_cur_fe) + return max(correlator.getCorrelation(ip_ref_fe, ip_cur_fe)[0], 0.0) \ No newline at end of file diff --git a/script/test/test_callc_calibration.py b/script/test/test_callc_calibration.py new file mode 100644 index 0000000..4525915 --- /dev/null +++ b/script/test/test_callc_calibration.py @@ -0,0 +1,21 @@ +x1, y1 = 1678, 365 +x2, y2 = 416, 1641 + +mx1, my1 = 210.2, -210.2 +mx2, my2 = -210.2, 210.2 + + +print cover_detection.calculate_factors(x1, y1, x2, y2, mx1, my1, mx2, my2) + + + + +x1,y1 = cover_detection.config.center_x, cover_detection.config.center_y +x2, y2 = 1678, 365 + +mx1, my1 = 0.0, 0.0 +mx2, my2 = 210.2, -210.2 + + +print cover_detection.calculate_factors(x1, y1, x2, y2, mx1, my1, mx2, my2) +