Implementing temperature compensated focusing
Posted: Tue Jan 06, 2026 2:58 pm
Hello all. I've writen a script to accomplish temperature compensated focusing with the ZWO EAF, which is not implemented in the ASCOM driver.
Any feedback is welcome. This is my first IronPython script in SharpCap. It seems to work in testing, but if there is something I haven't thought of or a way to do this better, please let me know.
You would need to measure the temperature coefficient for your rig. Technically I need to remeasure mine because I have changed the optical train. I will probably write a similar script to do that.
Any feedback is welcome. This is my first IronPython script in SharpCap. It seems to work in testing, but if there is something I haven't thought of or a way to do this better, please let me know.
You would need to measure the temperature coefficient for your rig. Technically I need to remeasure mine because I have changed the optical train. I will probably write a similar script to do that.
Code: Select all
# IronPython Pad. Write code snippets here and F5 to run. If code is selected, only selection is run.
import time
# Get the ASCOM focuser object (assumes focuser is selected and connected)
#focuser = SharpCap.Focusers.SelectedFocuser.AscomFocuser
# Initial reference values
initial_temp = SharpCap.Focusers.SelectedFocuser.Temperature
initial_pos = SharpCap.Focusers.SelectedFocuser.Position
coefficient = -50.5 # steps per degree C
print("Temperature compensation started.")
print("Initial temperature: {0:.2f} C".format(initial_temp))
print("Initial position: {0}".format(initial_pos))
print("Coefficient: {0} steps/deg C".format(coefficient))
while True:
current_temp = SharpCap.Focusers.SelectedFocuser.Temperature
#print("Current temp = {0:.2f}".format(current_temp)) #uncomment to print current temperature
delta_temp = current_temp - initial_temp
adjustment = int(round(delta_temp * coefficient))
new_pos = initial_pos + adjustment
if abs(new_pos - SharpCap.Focusers.SelectedFocuser.Position) >= 5:
print("Temperature change detected.")
print("Moving to {0}".format(new_pos))
SharpCap.Focusers.SelectedFocuser.Move(new_pos)
time.sleep(60) # Check every 60 seconds; adjust as needed