229 self.log.debug(f
"I was configured! See? {self.config=}")
231 fsm = properties.TextVector(name=
'fsm')
232 fsm.add_element(DefText(name=
'state', _value=StateCodes.INITIALIZED.name))
233 self.add_property(fsm)
235 sv = properties.SwitchVector(
237 rule=constants.SwitchRule.ONE_OF_MANY,
238 perm=constants.PropertyPerm.READ_WRITE,
240 sv.add_element(DefSwitch(name=
"idle", _value=constants.SwitchState.ON))
241 sv.add_element(DefSwitch(name=
"adcLoop", _value=constants.SwitchState.OFF))
242 sv.add_element(DefSwitch(name=
"oneshot", _value=constants.SwitchState.OFF))
243 sv.add_element(DefSwitch(name=
"calibrate", _value=constants.SwitchState.OFF))
246 nv = properties.NumberVector(name=
'n_avg')
247 nv.add_element(DefNumber(
248 name=
'current', label=
'Number of frames', format=
'%i',
249 min=1, max=150, step=1, _value=1
251 nv.add_element(DefNumber(
252 name=
'target', label=
'Number of frames', format=
'%i',
253 min=1, max=150, step=1, _value=1
257 nv = properties.NumberVector(name=
'no_measurements')
258 nv.add_element(DefNumber(
259 name=
'number', label=
'number', format=
'%i',
260 min=1, max=100.00, step=1, _value=1
264 nv = properties.NumberVector(name=
'gain')
265 nv.add_element(DefNumber(
266 name=
'current', label=
'ADC Loop Gain', format=
'%.2f',
267 min=0.00, max=1.00, step=0.01, _value=0.10
269 nv.add_element(DefNumber(
270 name=
'target', label=
'ADC Loop Gain', format=
'%.2f',
271 min=0.00, max=1.00, step=0.01, _value=0.10
275 nv = properties.NumberVector(name=
'offset')
276 nv.add_element(DefNumber(
277 name=
'current', label=
'offset', format=
'%.2f',
278 min=-45, max=45, step=0.01, _value=0.0
280 nv.add_element(DefNumber(
281 name=
'target', label=
'offset', format=
'%.2f',
282 min=-45, max=45, step=0.01, _value=0.0
286 nv = properties.NumberVector(name=
'ctrl_mtx')
287 nv.add_element(DefNumber(
288 name=
'm00', label=
'm00', format=
'%.4f',
289 min=-10.00, max=10.00, step=0.0001, _value=0.21178766
291 nv.add_element(DefNumber(
292 name=
'm01', label=
'm01', format=
'%.4f',
293 min=-10.00, max=10.00, step=0.0001, _value=0.19275196
297 sv = properties.SwitchVector(
299 rule=constants.SwitchRule.ONE_OF_MANY,
300 perm=constants.PropertyPerm.READ_WRITE,
302 sv.add_element(DefSwitch(name=
"toggle", _value=constants.SwitchState.OFF))
305 sv = properties.SwitchVector(
307 rule=constants.SwitchRule.ONE_OF_MANY,
308 perm=constants.PropertyPerm.READ_WRITE,
310 sv.add_element(DefSwitch(name=
"toggle", _value=constants.SwitchState.OFF))
313 sv = properties.SwitchVector(
314 name=
'knife_edge_findzero',
315 rule=constants.SwitchRule.ONE_OF_MANY,
316 perm=constants.PropertyPerm.READ_WRITE,
318 sv.add_element(DefSwitch(name=
"request", _value=constants.SwitchState.OFF))
321 sv = properties.SwitchVector(
322 name=
'reset_deltaADCs',
323 rule=constants.SwitchRule.ONE_OF_MANY,
324 perm=constants.PropertyPerm.READ_WRITE,
326 sv.add_element(DefSwitch(name=
"request", _value=constants.SwitchState.OFF))
329 self.client.get_properties(
'adctrack')
330 self.client.get_properties(
'fwsci1')
332 self.log.info(
"Found camera: {:s}".format(self.
config.camera.shmim))
337 indi_client=self.client
358 if self.client[
'adctrack.deltaADC1.current'] != 0:
362 if self.client[
'fwsci1.filterName.i'] == constants.SwitchState.ON:
365 elif self.client[
'fwsci1.filterName.z'] == constants.SwitchState.ON:
373 self.log.debug(f
'initial normalized wavelength value: {self.ADC.normalized_wavelength}')
377 self.properties[
'fsm'][
'state'] = StateCodes.READY.name
378 self.update_property(self.properties[
'fsm'])
566 if self.
_state == States.CLOSED_LOOP:
572 transpose = img.shaped.T
573 img = transpose.ravel()
575 if self.
_lab ==
False:
576 img = self.
ADC.filter_image(img)
579 self.
ADC.set_psf(img)
582 angles = self.
ADC.find_speckle_angles2()
584 self.log.debug(f
'angle offsets: {angles}')
585 error = self.
ADC.calculate_command(bottom_speckle_angles)
587 angles = self.
ADC.find_speckle_angles2()
588 pair_angles = self.
ADC.speckle_pairs(angles)
589 self.log.debug(f
'angle offsets: {angles}')
590 error = self.
ADC.calculate_command(pair_angles)
592 self.log.debug(f
'measured error: {error}')
593 measurements.append(error)
596 error = np.mean(measurements)
597 self.log.debug(f
'mean error: {error}')
599 if np.abs(error) < 2:
602 self.log.debug(f
'ADC command sent: {error * self._gain}')
603 else: self.log.info(f
'ADC command {self._command} exceeds acceptable threshold and was not sent')
605 elif self.
_state == States.ONESHOT:
609 transpose = img.shaped.T
610 img = transpose.ravel()
612 if self.
_lab ==
False:
613 img = self.
ADC.filter_image(img)
616 self.
ADC.set_psf(img)
621 angles = self.
ADC.find_speckle_angles2()
622 bottom_speckle_angles = np.array([angles[1],angles[2]])
623 self.log.debug(f
'angle offsets: {angles}')
624 self.
_command = np.squeeze(self.
ADC.calculate_command(bottom_speckle_angles))
626 angles = self.
ADC.find_speckle_angles2()
627 pair_angles = self.
ADC.speckle_pairs(angles)
628 self.log.debug(f
'angle offsets: {angles}')
629 self.
_command = np.squeeze(self.
ADC.calculate_command(pair_angles))
632 self.log.debug(f
'single measurement command: {self._command}')
634 error = np.mean(measurements)
635 self.log.debug(f
'average command: {error} (just calculated, not sent)')
644 self.log.info(
'transitioning to idle')
647 self.log.info(
'successfully transitioned to idle')
649 elif self.
_state == States.CALIB:
650 sweep_angles = np.linspace(-3,3,26)
651 diff_pointing_pairs = np.zeros((len(sweep_angles),2))
654 self.log.debug(f
'calibrating in regular mode')
655 for i, orientation
in enumerate(sweep_angles):
656 self.log.debug(f
'Step {i:d}')
661 transpose = img.shaped.T
662 img = transpose.ravel()
664 if self.
_lab ==
False:
665 img = self.
ADC.filter_image(img)
668 self.
ADC.set_psf(img)
670 angles = self.
ADC.find_speckle_angles2()
671 pointing_pair = self.
ADC.speckle_pairs(angles)
672 diff_pointing_pairs[i,] = pointing_pair
695 self.log.debug(f
'calibrating in knife-edge mode')
696 for i, orientation
in enumerate(sweep_angles):
697 self.log.debug(f
'Step {i:d}')
702 transpose = img.shaped.T
703 img = transpose.ravel()
705 if self.
_lab ==
False:
706 img = self.
ADC.filter_image(img)
709 self.
ADC.set_psf(img)
711 angles = self.
ADC.find_speckle_angles2()
712 bottom_speckle_angles = np.array([angles[1],angles[2]])
713 diff_pointing_pairs[i,] = bottom_speckle_angles
722 b1[j] , a1[j] = np.polyfit(sweep_angles,diff_pointing_pairs[:,j],deg=1)
724 response = np.matrix([b1])
725 self.log.debug(f
'response matrix: {response}')
727 if np.isnan(np.sum(response)):
728 self.log.info(f
'calibration failed, measured response is NaN')
731 new_control_mtx = np.linalg.pinv(response)
735 self.log.info(f
'calibration updated control matrix to: {self._control_mtx}')
737 self.properties[
'ctrl_mtx'][
'm00'] = self.
_control_mtx[0,0]
738 self.properties[
'ctrl_mtx'][
'm01'] = self.
_control_mtx[0,1]
739 self.update_property(self.properties[
'ctrl_mtx'])