Get and set focus position

Discuss macros to control the hardware functions of your ZEISS microscope
Post Reply
user-9
Posts: 82
Joined: Thu Jan 01, 1970 1:00 am

Get and set focus position

Post by user-9 »

Code: Select all

#######################################################
## M I C R O S C O P E 
##
## Macro name: Get and set focus position
## Required files: none
## Required hardware: microscope with motorized focus drive
##
## GET FOCUS POSITION
## SET FOCUS POSITION
##
#######################################################
##
##
## Remove all open images
Zen.Application.Documents.RemoveAll()
##
##
## Get current focus position
## Show focus position 
focPos = Zen.Devices.Focus.ActualPosition
focusinfo = 'Focus Pos: ' + str(focPos) 
Zen.Windows.Show(focusinfo)
##
##
## Set focus position
## Show new focus position 
newfocPos = focPos + 50
Zen.Devices.Focus.MoveTo(newfocPos)
## an alternative to set the position
#Zen.Devices.Focus.TargetPosition = newfocPos
#Zen.Devices.Focus.Apply()
focusinfo = 'New Focus Pos: ' + str(Zen.Devices.Focus.ActualPosition) 
Zen.Windows.Show(focusinfo)
##
#######################################################
user-4947
Posts: 14
Joined: Thu Jan 01, 1970 1:00 am

Move focus to load and work positions

Post by user-4947 »

Is there a direct way to move the objective to the load position and back to the work position? I can do it by storing the values, but I would like to avoid this step.

text=("Focus on sample.\n" +
"Press continue when done.")
Zen.Application.Pause(text)
focusWork=Zen.Devices.Focus.ActualPosition
text=("Move objective to load position.\n" +
"Press continue when done.\n" +
"Objective will move back to work positon.")
Zen.Application.Pause(text)
focusLoad=Zen.Devices.Focus.ActualPosition
Zen.Devices.Focus.MoveTo(focusWork)
user-9
Posts: 82
Joined: Thu Jan 01, 1970 1:00 am

Post by user-9 »

Is there a direct way to move the objective to the load position and back to the work position?
This can be done via hardware settings.

Code: Select all

hws = ZenHardwareSetting()
hws.Load('obj10x load pos',ZenSettingDirectory.User)
Zen.Devices.ApplyHardwareSetting(hws)
hws.Load('obj10x work pos',ZenSettingDirectory.User)
Zen.Devices.ApplyHardwareSetting(hws)
user-5009
Posts: 3
Joined: Thu Jan 01, 1970 1:00 am

Post by user-5009 »

Is there anyway to programatically change the software autofocus settings (e.g. Sampling, Quality, Range Coverage, Sharpness Measure, Search Range, The actual range, Automatic Range and Autofocus ROI) ? I know I could do auto focus by calling Zen.Acquisition.FindAutoFocus()
user-8
Posts: 63
Joined: Thu Jan 01, 1970 1:00 am

Post by user-8 »

Hi,

this is an open feature request already for the ZEN Software regarding OAD interface. So with the current version this is not possible, But there are still a few things one can do.

  • Define a special experiment to do the SWAF
  • Run this particular experiment when needed

Code: Select all

SWAF_experiment = Zen.Acquisition.Experiments.GetByName(SWAF_Experiment_Name)

# !!! ATTENTION - ADVANCED TOPIC !!!
# optional - modify your experiment here when required by modifying the experiment XML directly

# run the SWAF
Zen.Acquisition.FindAutofocus(SWAF_experiment)

# get the resulting z-position after SWAF
z_SWAF = Zen.Devices.Focus.ActualPosition
The actual experiment must be set up on as usual on the acquisition tab.

By the way, it is also possible to create experiments with an extra channel for the SWAF only, which is not used during the actual acquistion.
david bostan
Posts: 1
Joined: Tue Jun 06, 2023 8:52 am

Re: Get and set focus position

Post by david bostan »

See the latest game google if you are a game lover.
Rikkie Tick
Posts: 2
Joined: Wed Jul 19, 2023 12:40 pm

Re:

Post by Rikkie Tick »

user-8 wrote: Tue Mar 08, 2016 8:30 am Hi,

this is an open feature request already for the ZEN Software regarding OAD interface. So with the current version this is not possible, But there are still a few things one can do.

  • Define a special experiment to do the SWAF
  • Run this particular experiment when needed

Code: Select all

SWAF_experiment = Zen.Acquisition.Experiments.GetByName(SWAF_Experiment_Name)

# !!! ATTENTION - ADVANCED TOPIC !!!
# optional - modify your experiment here when required by modifying the experiment XML directly

# run the SWAF
Zen.Acquisition.FindAutofocus(SWAF_experiment)

# get the resulting z-position after SWAF
z_SWAF = Zen.Devices.Focus.ActualPosition
The actual experiment must be set up on as usual on the acquisition tab.

By the way, it is also possible to create experiments with an extra channel for the SWAF only, which is not used during the actual acquistion.
Helpful! thanks
Post Reply