python-microscope / microscope

Python library for control of microscope devices, supporting hardware triggers and distribution of devices over the network for performance and flexibility.
https://www.python-microscope.org
GNU General Public License v3.0
69 stars 41 forks source link

Cobolt laser not setting correct power #75

Open mickp opened 5 years ago

mickp commented 5 years ago

Cockpit calls set_power_mw(value) on laser devices to set laser power. This appears to work correctly for a dummy laser device and the DeepStar lasers, but does not always work correctly for Cobolt lasers.

Monitoring the Cobolt log shows that sometimes the laser power is set correctly, other times it is set to zero, or 0.0001W, often several times in quick succession.

In the LaserDevice base class:

    def set_power_mw(self, mw):
        """Set the power from an argument in mW and save the set point.

        Args:
            mw (float): Power in mW.  Value will be clipped to the
                valid range for the laser.  See the methods
                :func:`get_max_power_mw` and :func:`get_min_power_mw`
                to retrieve the valid range.

        Returns:
            void
        """
        mw = max(min(mw, self.get_max_power_mw()), self.get_min_power_mw())
        self._set_point = mw
        self._set_power_mw(mw)

In the Cobolt implementation:

    def _set_power_mw(self, mW):
        ## There is no minimum power in cobolt lasers.  Any
        ## non-negative number is accepted.
        W_str = '%.4f' % (mW / 1000.0)
        self._logger.info("Setting laser power to %s W.", W_str)
        return self.send(b'@cobasp ' + W_str.encode())

The correct power is not getting to CoboltLaser._set_power_mw. I suspect it's because the laser is reporting its max power incorrectly in the bounds check in LaserDevice.set_power_mw. We should perhaps query this once on device init, and store it on the device instance.

carandraug commented 5 years ago

[...] We should perhaps query this once on device init, and store it on the device instance.

Definitely.

[...] I suspect it's because the laser is reporting its max power incorrectly. [...]

Any clue why this is happening? Is this another case of the laser sending garbage back?