From c810f36bdbe06b65a5c7fb885a08c56e9776650c Mon Sep 17 00:00:00 2001 From: Leonhard Date: Thu, 28 Jan 2021 17:39:01 +0100 Subject: [PATCH 1/2] bugs fixed --- .../lockbox/models/fabryperot.py | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/pyrpl/software_modules/lockbox/models/fabryperot.py b/pyrpl/software_modules/lockbox/models/fabryperot.py index 3a4fa0bd1..4f876d323 100644 --- a/pyrpl/software_modules/lockbox/models/fabryperot.py +++ b/pyrpl/software_modules/lockbox/models/fabryperot.py @@ -523,3 +523,56 @@ class HighFinesseFabryPerot(FabryPerot): inputs = LockboxModuleDictProperty(transmission=HighFinesseTransmission, reflection=HighFinesseReflection, pdh=HighFinessePdh) + + +class DoublyResonantFabryPerot(FabryPerot): + _setup_attributes = ["fsr_voltage", "resonance_voltage"] + _gui_attributes = _setup_attributes + ["switch_resonance"] + fsr_voltage = FloatProperty(default=0.9, doc="approximate piezo voltage difference between two adjacent resonances") + resonance_voltage = FloatProperty(default=0.0, doc="approximate piezo voltage difference between two adjacent resonances") + + def is_locked(self, input=None, loglevel=logging.INFO): + """ returns True if locked, else False. Also updates an internal + dict that contains information about the current error signals. The + state of lock is logged at loglevel """ + is_locked = super().is_locked(input=input, loglevel=loglevel) + is_locked_and_final = is_locked and self.current_state == 'final_stage' + if is_locked_and_final: + self.resonance_voltage = self.outputs.piezo.mean + self._logger.info(f"Current resonance voltage: {self.resonance_voltage}") + return is_locked + + def switch_resonance(self): + """Switches between doubly resonant and non-doubly resonant resonances and relocks.""" + self.unlock() + self.resonance_voltage -= self.fsr_voltage + self.lock() + + @property + def _new_lock_offset(self): + """Returns the new piezo offset voltage with which one has the best chances to hit the same resonance + as during the last successful lock.""" + minimum_voltage = self.outputs.piezo.min_voltage + distance_to_minimum = self.resonance_voltage - minimum_voltage + # start lock between the current resonance and the one below + new_distance_to_minimum = (distance_to_minimum - 0.5 * self.fsr_voltage) + # start at the lowest such voltage in range + new_resonance_voltage = minimum_voltage + (new_distance_to_minimum % (2.0 * self.fsr_voltage)) + return new_resonance_voltage + + def setup_new_lock_offset(self): + """update the offset voltage for the resonance search step at the beginning of a lock sequence""" + if not self.sequence[0].outputs.piezo.reset_offset: + self._logger.warning("For DoublyResonantFabryPerot's lock function to function properly, the first " + "lock stage should reset the piezo offset.") + self.sequence[0].outputs.piezo.offset = self._new_lock_offset + + def lock(self, **kwds): + """ + Launches the full lock sequence, stage by stage until the end. + optional kwds are stage attributes that are set after iteration through + the sequence, e.g. a modified setpoint. + """ + self.unlock() + self.setup_new_lock_offset() + return super().lock(**kwds) From 255d77761bf98194c2390da3800c54c9389bfa58 Mon Sep 17 00:00:00 2001 From: Leonhard Date: Fri, 29 Jan 2021 16:33:13 +0100 Subject: [PATCH 2/2] remove excessive logging --- pyrpl/software_modules/lockbox/models/fabryperot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyrpl/software_modules/lockbox/models/fabryperot.py b/pyrpl/software_modules/lockbox/models/fabryperot.py index 4f876d323..396be5071 100644 --- a/pyrpl/software_modules/lockbox/models/fabryperot.py +++ b/pyrpl/software_modules/lockbox/models/fabryperot.py @@ -539,7 +539,6 @@ def is_locked(self, input=None, loglevel=logging.INFO): is_locked_and_final = is_locked and self.current_state == 'final_stage' if is_locked_and_final: self.resonance_voltage = self.outputs.piezo.mean - self._logger.info(f"Current resonance voltage: {self.resonance_voltage}") return is_locked def switch_resonance(self):